propagation-crossorigin.sub.html (4501B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta name="timeout" content="long"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <script src="resources/utils.js"></script> 10 <script> 11 // Frame layout: 12 // top=origin0:this-file [ 13 // child1=origin1:child-one.html, 14 // child-xo=origin2:propagation-crossorigin-child.html [ 15 // gchild=origin3:child-two.html 16 // ] 17 // ] 18 let propagation_test = async_test("Propagation test"); 19 20 let num_children_to_load = 3; 21 let num_children_to_report = 3; 22 23 function finishLoadPhase() { 24 assert_equals(num_children_to_load, 0); 25 26 test(() => { 27 assert_false(navigator.userActivation.isActive); 28 assert_false(navigator.userActivation.hasBeenActive); 29 }, "Parent frame initial state"); 30 31 delayByFrames(() => test_driver.click(document.getElementById("child-xo")), 7); 32 } 33 34 function finishReportPhase() { 35 assert_equals(num_children_to_report, 0); 36 37 test(() => { 38 assert_true(navigator.userActivation.isActive); 39 assert_true(navigator.userActivation.hasBeenActive); 40 }, "Parent frame final state"); 41 42 propagation_test.done(); 43 } 44 45 window.addEventListener("message", event => { 46 // Test driver can send messages too... 47 if (typeof event.data !== "string") return; 48 49 var msg = JSON.parse(event.data); 50 51 if (msg.type == 'child-one-loaded') { 52 test(() => { 53 assert_false(msg.isActive); 54 assert_false(msg.hasBeenActive); 55 }, "Child1 frame initial state"); 56 } else if (msg.type == 'child-crossorigin-loaded') { 57 test(() => { 58 assert_false(msg.isActive); 59 assert_false(msg.hasBeenActive); 60 }, "Child2 frame initial state"); 61 } else if (msg.type == 'child-two-loaded') { 62 test(() => { 63 assert_false(msg.isActive); 64 assert_false(msg.hasBeenActive); 65 }, "Grandchild frame initial state"); 66 } else if (msg.type == 'child-one-report') { 67 test(() => { 68 assert_false(msg.isActive); 69 assert_false(msg.hasBeenActive); 70 }, "Child1 frame final state"); 71 } else if (msg.type == 'child-crossorigin-report') { 72 // This msg was triggered by a user click. 73 test(() => { 74 assert_true(msg.isActive); 75 assert_true(msg.hasBeenActive); 76 }, "Child2 frame final state"); 77 78 // Ask remaining frames to report states. 79 let ask_report = JSON.stringify({"type": "report"}); 80 frames[0].postMessage(ask_report, "*"); 81 frames[1].frames[0].postMessage(ask_report, "*"); 82 } else if (msg.type == 'child-two-report') { 83 test(() => { 84 assert_false(msg.isActive); 85 assert_false(msg.hasBeenActive); 86 }, "Grand child frame final state"); 87 } 88 89 // Phase switching. 90 if (msg.type.endsWith("-loaded")) { 91 if (--num_children_to_load == 0) 92 finishLoadPhase(); 93 } else if (msg.type.endsWith("-report")) { 94 if (--num_children_to_report == 0) 95 finishReportPhase(); 96 } 97 }); 98 async function createIframes() { 99 const child1 = document.createElement("iframe"); 100 child1.src = "http://{{hosts[alt][]}}:{{ports[http][0]}}/html/user-activation/resources/child-one.html"; 101 child1.id = "child1"; 102 document.body.appendChild(child1); 103 await new Promise((resolve) => { 104 child1.onload = resolve; 105 document.body.appendChild(child1); 106 }); 107 const childXO = document.createElement("iframe"); 108 childXO.id = "child-xo"; 109 childXO.src = "http://{{hosts[alt][]}}:{{ports[http][1]}}/html/user-activation/resources/propagation-crossorigin-child.sub.html"; 110 document.body.appendChild(childXO); 111 } 112 </script> 113 </head> 114 <body onload="createIframes()"> 115 <h1>User activation propagation across cross-origin frame boundary</h1> 116 <p>Tests that user activation does not propagate across cross-origin frame boundary.</p> 117 <ol id="instructions"> 118 <li>Click anywhere on the green area (child frame). 119 </ol> 120 </body> 121 </html>