detached-iframe.html (1576B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <script src="resources/utils.js"></script> 9 </head> 10 <body></body> 11 <script> 12 async function attachIframe() { 13 const iframe = document.createElement("iframe"); 14 iframe.src = "about:blank"; 15 await new Promise((r) => { 16 iframe.addEventListener("load", r, { once: true }); 17 document.body.append(iframe); 18 }); 19 return iframe; 20 } 21 22 promise_test(async () => { 23 const iframe = await attachIframe(); 24 const { userActivation } = iframe.contentWindow.navigator; 25 26 assert_false( 27 userActivation.isActive, 28 "No transient activation before click" 29 ); 30 assert_false( 31 userActivation.hasBeenActive, 32 "No sticky activation before click" 33 ); 34 35 // Confirm we have activation 36 await test_driver.bless("click", null, iframe.contentWindow); 37 assert_true(userActivation.isActive, "is active after click"); 38 assert_true(userActivation.hasBeenActive, "has been active"); 39 40 // Remove the context 41 iframe.remove(); 42 assert_equals(iframe.contentWindow, null, "No more global"); 43 assert_true(userActivation.isActive, "isActive"); 44 assert_true(userActivation.hasBeenActive, "hasBeenActive"); 45 }, "navigator.userActivation retains state even if global is removed"); 46 </script> 47 </html>