зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1901149 [wpt PR 46649] - [shared storage] Allow createWorklet() in opaque origin contexts, a=testonly
Automatic update from web-platform-tests [shared storage] Allow createWorklet() in opaque origin contexts PR: https://github.com/WICG/shared-storage/pull/156 Bug: 345274915 Change-Id: I748df668635d77a2d158bd86222aa2fdecfed3eb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5564969 Reviewed-by: Cammie Smith Barnes <cammie@chromium.org> Commit-Queue: Yao Xiao <yaoxia@chromium.org> Cr-Commit-Position: refs/heads/main@{#1311659} -- wpt-commits: ffb30418af724f933a640e1142b349b10e129be7 wpt-pr: 46649
This commit is contained in:
Родитель
cc60ea4e68
Коммит
e7e74925fa
|
@ -0,0 +1,60 @@
|
|||
<!doctype html>
|
||||
<body>
|
||||
<script src=/resources/testharness.js></script>
|
||||
<script src=/resources/testharnessreport.js></script>
|
||||
<script src=/common/utils.js></script>
|
||||
<script src=/fenced-frame/resources/utils.js></script>
|
||||
<script src=/shared-storage/resources/util.js></script>
|
||||
<script>
|
||||
promise_test(async t => {
|
||||
const cross_origin = 'https://{{domains[www]}}:{{ports[https][0]}}';
|
||||
const ancestor_token = token();
|
||||
const set_key = 'a';
|
||||
const set_value = 'b';
|
||||
|
||||
// Create sandboxed iframe.
|
||||
let frame = document.createElement('iframe');
|
||||
frame.sandbox = 'allow-scripts';
|
||||
frame.src = '/shared-storage/resources/' +
|
||||
'cross-origin-worklet-in-sandboxed-frame-inner.https.sub.html' +
|
||||
`?cross_origin=${cross_origin}` +
|
||||
`&ancestor_token=${ancestor_token}` +
|
||||
`&mock_select_url_result_index=0` +
|
||||
`&set_key=${set_key}` +
|
||||
`&set_value=${set_value}`;
|
||||
|
||||
let select_url_result_urn;
|
||||
|
||||
// We expect a message to bubble up via the sandboxed iframe.
|
||||
const createWorkletAndSelectUrlInsideSandboxedFramePromise = new Promise((resolve, reject) => {
|
||||
window.addEventListener('message', async function handler(evt) {
|
||||
if (evt.source === frame.contentWindow) {
|
||||
assert_true(evt.data.success,
|
||||
"createWorklet() failed inside the sandboxed iframe");
|
||||
select_url_result_urn = evt.data.selectUrlResultUrn;
|
||||
|
||||
document.body.removeChild(frame);
|
||||
window.removeEventListener('message', handler);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
window.addEventListener('error', () => {
|
||||
reject(new Error('Navigation error'));
|
||||
});
|
||||
});
|
||||
|
||||
// Navigate and wait for notification.
|
||||
document.body.appendChild(frame);
|
||||
await createWorkletAndSelectUrlInsideSandboxedFramePromise;
|
||||
|
||||
attachFencedFrame(select_url_result_urn, 'opaque-ads');
|
||||
const result0 = await nextValueFromServer(ancestor_token);
|
||||
assert_equals(result0, "frame0_loaded");
|
||||
|
||||
await verifyKeyValueForOrigin(set_key, set_value, cross_origin);
|
||||
|
||||
// Clean up and finish.
|
||||
await sharedStorage.delete(set_key);
|
||||
}, 'test createWorklet() in sandboxed iframe and verify its data origin');
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,51 @@
|
|||
<!doctype html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/common/utils.js"></script>
|
||||
<script src="/shared-storage/resources/util.js"></script>
|
||||
<script src="/fenced-frame/resources/utils.js"></script>
|
||||
|
||||
<body>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
async function test() {
|
||||
const url = new URL(location.href);
|
||||
const cross_origin = url.searchParams.get('cross_origin');
|
||||
const ancestor_token = url.searchParams.get('ancestor_token');
|
||||
const mock_select_url_result_index = url.searchParams.get('mock_select_url_result_index');
|
||||
const set_key = url.searchParams.get('set_key');
|
||||
const set_value = url.searchParams.get('set_value');
|
||||
|
||||
const script_url = cross_origin +
|
||||
`/shared-storage/resources/simple-module.js`;
|
||||
|
||||
const worklet = await sharedStorage.createWorklet(
|
||||
script_url,
|
||||
{ credentials: "omit" });
|
||||
|
||||
let url0 = generateURL("/shared-storage/resources/frame0.html",
|
||||
[ancestor_token]);
|
||||
|
||||
let select_url_result_urn = await worklet.selectURL(
|
||||
"test-url-selection-operation",
|
||||
[{ url: url0 }], {
|
||||
data: {
|
||||
'mockResult': mock_select_url_result_index,
|
||||
'setKey': set_key,
|
||||
'setValue': set_value
|
||||
},
|
||||
resolveToConfig: false,
|
||||
keepAlive: true
|
||||
});
|
||||
|
||||
assert_true(validateSelectURLResult(select_url_result_urn, /*resolve_to_config=*/false));
|
||||
|
||||
let parentOrOpener = window.opener || window.parent;
|
||||
parentOrOpener.postMessage({success: true, selectUrlResultUrn: select_url_result_urn}, "*");
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
</script>
|
||||
</body>
|
|
@ -52,7 +52,7 @@
|
|||
test_shared_storage_in_sandboxed_iframe(t,
|
||||
/*sandbox_flags=*/'allow-scripts',
|
||||
/*method=*/'createWorklet',
|
||||
/*expect_success=*/false);
|
||||
/*expect_success=*/true);
|
||||
}, 'test sharedStorage.createWorklet() in sandboxed iframe without "allow-same-origin"');
|
||||
|
||||
async_test(t => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче