report-event-inactive-document.https.html (1661B)
1 <!DOCTYPE html> 2 <title>Test window.fence.reportEvent</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/utils.js"></script> 6 <script src="/common/dispatcher/dispatcher.js"></script> 7 <script src="resources/utils.js"></script> 8 9 <body> 10 <script> 11 promise_test(async(t) => { 12 const key = token(); 13 const urn = await generateURNFromFledge("resources/embeddee.html", [key]); 14 const iframe = document.createElement("iframe"); 15 iframe.src = urn; 16 document.body.appendChild(iframe); 17 18 // Wait for the page in the iframe to load and tell us that it's loaded. 19 await nextValueFromServer(key); 20 21 // Get access to the iframe's window's fence object before removing. 22 let inner_fence = iframe.contentWindow.fence; 23 24 // window.fence calls should succeed before the iframe is removed. 25 inner_fence.setReportEventDataForAutomaticBeacons({ 26 eventType: "reserved.top_navigation_commit", 27 eventData: 'This is the event data!', 28 destination: ['buyer'] 29 }); 30 31 // Remove the iframe to make the iframe's document an inactive document. 32 iframe.remove(); 33 34 // window.fence calls should fail once the iframe is removed and the document 35 // becomes inactive. 36 try { 37 inner_fence.setReportEventDataForAutomaticBeacons({ 38 eventType: "reserved.top_navigation_commit", 39 eventData: 'This is the event data!', 40 destination: ['buyer'] 41 }); 42 assert_unreached("The call should not have succeeded."); 43 } catch (error) { 44 assert_equals(error.name, "SecurityError"); 45 } 46 }, 'attempts to call set report event in an inactive document should fail'); 47 </script> 48 </body>