|
| 1 | +<!DOCTYPE html> |
| 2 | +<title>Test that window.fence.disableUntrustedNetwork disables |
| 3 | + embedder-initiated navigation of nested fenced frames.</title> |
| 4 | +<meta name="timeout" content="long"> |
| 5 | +<script src="/resources/testharness.js"></script> |
| 6 | +<script src="/resources/testharnessreport.js"></script> |
| 7 | +<script src="/common/utils.js"></script> |
| 8 | +<script src="/common/dispatcher/dispatcher.js"></script> |
| 9 | +<script src="resources/utils.js"></script> |
| 10 | + |
| 11 | +<body> |
| 12 | +<script> |
| 13 | + |
| 14 | +// Run a test with a fenced frame nested in a fenced frame. |
| 15 | +// If `should_disable_network` is true, window.fence.disableUntrustedNetwork |
| 16 | +// will be called before creating the nested fenced frame. |
| 17 | +async function ff_ff_test(t, should_disable_network) { |
| 18 | + const fencedframe = await attachFencedFrameContext(); |
| 19 | + return Promise.race([ |
| 20 | + fencedframe.execute(async (should_disable_network) => { |
| 21 | + if (should_disable_network) { |
| 22 | + await window.fence.disableUntrustedNetwork(); |
| 23 | + } |
| 24 | + const nested_fenced_frame = await attachFencedFrameContext(); |
| 25 | + return nested_fenced_frame.execute(() => { return 'nav success'; }); }, |
| 26 | + [should_disable_network]), |
| 27 | + new Promise((resolve, reject) => t.step_timeout( |
| 28 | + () => resolve('timeout'), 3000)) |
| 29 | + ]); |
| 30 | +} |
| 31 | + |
| 32 | +// Run a test with a fenced frame nested in an iframe nested in a fenced frame. |
| 33 | +// If `should_disable_network` is true, window.fence.disableUntrustedNetwork |
| 34 | +// will be called before creating the nested fenced frame. |
| 35 | +// If `use_urn_iframe` is true, the nested iframe will be a urn iframe. |
| 36 | +async function ff_if_ff_test(t, should_disable_network, use_urn_iframe) { |
| 37 | +const fencedframe = await attachFencedFrameContext({generator_api: 'sharedstorage'}); |
| 38 | + return Promise.race([ |
| 39 | + fencedframe.execute(async (should_disable_network, use_urn_iframe) => { |
| 40 | + let args = {}; |
| 41 | + if (use_urn_iframe) { |
| 42 | + args = {generator_api: 'sharedstorage'}; |
| 43 | + } |
| 44 | + const nested_iframe = await attachIFrameContext(args); |
| 45 | + await nested_iframe.execute(() => {}); |
| 46 | + if (should_disable_network) { |
| 47 | + await window.fence.disableUntrustedNetwork(); |
| 48 | + } |
| 49 | + return nested_iframe.execute(async () => { |
| 50 | + const nested_fenced_frame = await attachFencedFrameContext({ |
| 51 | + generator_api: 'sharedstorage'}); |
| 52 | + return nested_fenced_frame.execute(() => { return 'nav success'; }); |
| 53 | + }); |
| 54 | + }, |
| 55 | + [should_disable_network, use_urn_iframe]), |
| 56 | + new Promise((resolve, reject) => t.step_timeout( |
| 57 | + () => resolve('timeout'), 3000)) |
| 58 | + ]); |
| 59 | +} |
| 60 | + |
| 61 | +promise_test(async(t) => { |
| 62 | + const result = await ff_ff_test(t, /*should_disable_network=*/false); |
| 63 | + assert_equals(result, 'nav success'); |
| 64 | +}, 'FF->FF navigation works'); |
| 65 | + |
| 66 | +promise_test(async(t) => { |
| 67 | + const result = await ff_ff_test(t, /*should_disable_network=*/true); |
| 68 | + assert_equals(result, 'timeout'); |
| 69 | +}, 'window.fence.disableUntrustedNetwork disables FF->FF navigation'); |
| 70 | + |
| 71 | +promise_test(async(t) => { |
| 72 | + const result = await ff_if_ff_test(t, /*should_disable_network=*/false, /*use_urn_iframe=*/false); |
| 73 | + assert_equals(result, 'nav success'); |
| 74 | +}, 'FF->IF->FF navigation works'); |
| 75 | + |
| 76 | +promise_test(async(t) => { |
| 77 | + const result = await ff_if_ff_test(t, /*should_disable_network=*/false, /*use_urn_iframe=*/true); |
| 78 | + assert_equals(result, 'nav success'); |
| 79 | +}, 'FF->UIF->FF navigation works'); |
| 80 | + |
| 81 | +promise_test(async(t) => { |
| 82 | + const result = await ff_if_ff_test(t, /*should_disable_network=*/true, /*use_urn_iframe=*/false); |
| 83 | + assert_equals(result, 'timeout'); |
| 84 | +}, 'window.fence.disableUntrustedNetwork disables FF->IF->FF navigation'); |
| 85 | + |
| 86 | +promise_test(async(t) => { |
| 87 | + const result = await ff_if_ff_test(t, /*should_disable_network=*/true, /*use_urn_iframe=*/true); |
| 88 | + assert_equals(result, 'timeout'); |
| 89 | +}, 'window.fence.disableUntrustedNetwork disables FF->UF->FF navigation'); |
| 90 | +</script> |
| 91 | +</body> |
0 commit comments