Skip to content

Commit

Permalink
Make FencedFrameConfigs serializable.
Browse files Browse the repository at this point in the history
There is a use case where a FencedFrameConfig object is created inside
of a cross-origin iframe, and then passed to its embedder via
postMessage() to load in a fenced frame. To support that, this CL makes
the FencedFrameConfig object serializable, which allows it to be deep
copied through structuredClone() or sent as a message in postMessage().

Change-Id: I5bfc1d12d813790e767b992f2561167719833035
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4721701
Reviewed-by: Garrett Tanzer <gtanzer@chromium.org>
Commit-Queue: Liam Brady <lbrady@google.com>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1179242}
  • Loading branch information
Liam Brady authored and chromium-wpt-export-bot committed Aug 3, 2023
1 parent 107a058 commit 87b1ee9
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions fenced-frame/deep-copy-config.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<title>Test deep copying FencedFrameConfig objects</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="resources/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>

<body>
<script>
promise_test(async(t) => {
const key = token();

// Create a FencedFrameConfig from a FLEDGE auction, then deep copy it.
let old_config = await generateURNFromFledge(
"resources/embeddee.html", [key], [], true);
assert_true(old_config instanceof FencedFrameConfig);
let new_config = structuredClone(old_config);

const fencedframe = attachFencedFrame(new_config);
const response = await nextValueFromServer(key);
assert_equals(response, "PASS",
"The page should have loaded from the cloned config.");
}, 'A cloned config with a URN will navigate.');

promise_test(async(t) => {
const key = token();

// Create a FencedFrameConfig from a FLEDGE auction, then deep copy it.
let old_config = new FencedFrameConfig(generateURL(
"resources/embeddee.html", [key]));
assert_true(old_config instanceof FencedFrameConfig);
let new_config = structuredClone(old_config);

const fencedframe = attachFencedFrame(new_config);
const response = await nextValueFromServer(key);
assert_equals(response, "PASS",
"The page should have loaded from the cloned config.");
}, 'A cloned config with a URL will navigate.');

promise_test(async(t) => {
const key = token();
const fenced_url = generateURL("resources/embeddee.html", [key]);

// Create a fenced frame once the config comes in through postMessage.
window.addEventListener(
"message",
(event) => {
attachFencedFrame(event.data);
},
false,
);

// Create an iframe that creates a FencedFrameConfig
const frame = await attachIFrameContext(
{origin: get_host_info().HTTPS_REMOTE_ORIGIN});
await frame.execute(async (fenced_url) => {
const config = await generateURNFromFledge(fenced_url, [], [], true);
window.parent.postMessage(config, "*");
}, [fenced_url]);

const response = await nextValueFromServer(key);
assert_equals(response, "PASS",
"The page should have loaded from the postMessage'd config.");
}, 'A config received through window.postMessage will navigate.');

promise_test(async(t) => {
// Create a FencedFrameConfig from a FLEDGE auction.
let config = await generateURNFromFledge(
"resources/embeddee.html", [], [], true);
assert_true(config instanceof FencedFrameConfig);

assert_throws_dom("DataCloneError", () => {
history.pushState(config, "", location.href);
}, "The write should fail for a FencedFrameConfig.");
}, 'A FencedFrameConfig cannot be written to storage.');

</script>
</body>
</html>

0 comments on commit 87b1ee9

Please sign in to comment.