resource-popup.https.html (3047B)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <meta charset="utf-8"> 4 <title>Cross-Origin-Opener-Policy forces browsing context switch in various popup document types</title> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/common/utils.js"></script> 8 9 <p>These tests create a "parent" popup window which is an HTML document with a 10 specific Cross-Origin-Opener-Policy. The parent creates a "child" popup window 11 which is a non-HTML document with a Cross-Origin-Opener-Policy of its own. The 12 parent waits for the child's location to change from "<code>about:blank</code>" 13 and then inspects its <code>name</code> and <code>closed</code> properties 14 which it reports back to the test context.</p> 15 16 <p>The HTTP `Refresh` header is used to ensure the child eventually closes 17 itself (since proper observance of COOP will prevent the parent from closing 18 the child in some cases).</p> 19 20 <script> 21 'use strict'; 22 23 const coop_resource_test = ({parentCoop, resourceCoop, resource, resourceName, validate}) => { 24 async_test((t) => { 25 const bc = new BroadcastChannel(token()); 26 bc.onmessage = t.step_func_done(({data}) => validate(data)); 27 const childLocation = resource + 28 `?pipe=header(Refresh,2;url=/html/cross-origin-opener-policy/resources/resource-cleanup.html?channel=${bc.name})` + 29 (resourceCoop ? `|header(Cross-Origin-Opener-Policy,${resourceCoop})` : ''); 30 const parentLocation = 'resources/resource-popup.html' + 31 `?channel_name=${bc.name}` + 32 `&resource=${encodeURIComponent(childLocation)}` + 33 `&resource_name=${resourceName}` + 34 (parentCoop ? `&pipe=header(Cross-Origin-Opener-Policy,${parentCoop})` : ''); 35 36 open(parentLocation); 37 38 t.add_cleanup(() => { 39 // Close the "parent" popup and the "child" popup if it has already 40 // redirected to the HTML document. 41 bc.postMessage(null); 42 // Prepare to close the "child" popup in the case that it has not yet 43 // redirected to the HTML document. 44 bc.onmessage = () => bc.postMessage(null); 45 }); 46 }, `${resource} - parent COOP: "${parentCoop}"; child COOP: "${resourceCoop}"`); 47 }; 48 49 const resources = [ 50 '/common/dummy.xml', 51 '/images/red.png', 52 '/common/text-plain.txt', 53 '/media/2x2-green.mp4', 54 ]; 55 56 for (const resource of resources) { 57 coop_resource_test({ 58 parentCoop: '', 59 resourceCoop: 'same-origin', 60 resource, 61 resourceName: 'foobar', 62 validate(data) { 63 assert_equals(data.name, null); 64 assert_equals(data.closed, true); 65 } 66 }); 67 68 coop_resource_test({ 69 parentCoop: 'same-origin', 70 resourceCoop: '', 71 resource, 72 resourceName: 'foobar', 73 validate(data) { 74 assert_equals(data.name, null); 75 assert_equals(data.closed, true); 76 } 77 }); 78 79 coop_resource_test({ 80 parentCoop: 'same-origin', 81 resourceCoop: 'same-origin', 82 resource, 83 resourceName: 'foobar', 84 validate(data) { 85 assert_equals(data.name, 'foobar'); 86 assert_equals(data.closed, false); 87 } 88 }); 89 } 90 </script> 91 </html>