propagate-user-activation-to-opener.https.html (4575B)
1 <!DOCTYPE html> 2 <title>Test that a user activation in a document picture-in-picture window is usable in its opener window</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/resources/testdriver.js"></script> 6 <script src="/resources/testdriver-vendor.js"></script> 7 <script src="/common/get-host-info.sub.js"></script> 8 <iframe id="same-origin-iframe" src="/common/blank.html"></iframe> 9 <body> 10 <script> 11 promise_test(async (t) => { 12 await test_driver.bless('request PiP window'); 13 const pipWindow = await documentPictureInPicture.requestWindow(); 14 15 assert_false(navigator.userActivation.isActive, 'the opener should initially not have user activation'); 16 assert_false(pipWindow.navigator.userActivation.isActive, 'the PiP window should initially not have user activation'); 17 18 // Activating the picture-in-picture window should also activate the opener. 19 await test_driver.bless('activate pip window', null, pipWindow); 20 assert_true(navigator.userActivation.isActive, 'the opener should be activated when the PiP window is activated'); 21 assert_true(pipWindow.navigator.userActivation.isActive, 'the PiP window should be activated'); 22 23 // Consuming activation in the picture-in-picture window should also consume it in the opener. 24 pipWindow.open().close(); 25 assert_false(navigator.userActivation.isActive, 'the opener should no longer be active once the PiP window consumes activation'); 26 assert_false(pipWindow.navigator.userActivation.isActive, 'the PiP window should no longer be active once it consumes activation'); 27 }, 'user activation propagates from PiP to opener'); 28 29 promise_test(async (t) => { 30 await test_driver.bless('request PiP window'); 31 const pipWindow = await documentPictureInPicture.requestWindow(); 32 33 const ifr = pipWindow.document.createElement("iframe"); 34 pipWindow.document.body.append(ifr); 35 36 assert_false(navigator.userActivation.isActive, 'opener initially not active'); 37 assert_false(pipWindow.navigator.userActivation.isActive, 'PiP initially not active'); 38 39 await test_driver.bless('activate iframe', null, ifr.contentWindow); 40 41 assert_true(navigator.userActivation.isActive, 'activation propagated to opener'); 42 43 pipWindow.open().close(); 44 45 assert_false(navigator.userActivation.isActive, 'activation was consumed in opener'); 46 assert_false(pipWindow.navigator.userActivation.isActive, 'activation was consumed in PiP'); 47 }, 'user activation propagates from iframe in PiP to opener'); 48 49 promise_test(async (t) => { 50 await test_driver.bless('request PiP window'); 51 const pipWindow = await documentPictureInPicture.requestWindow(); 52 53 const ifr = document.getElementById("same-origin-iframe"); 54 55 assert_false(navigator.userActivation.isActive, 'opener initially not active'); 56 assert_false(ifr.contentWindow.navigator.userActivation.isActive, 'iframe in opener initially not active'); 57 assert_false(pipWindow.navigator.userActivation.isActive, 'PiP initially not active'); 58 59 await test_driver.bless('activate pip window', null, pipWindow); 60 61 assert_true(navigator.userActivation.isActive, 'activation propagated to opener'); 62 assert_false(ifr.contentWindow.navigator.userActivation.isActive, 'activation did not propagate to iframe in opener'); 63 }, 'user activation does not propagate from PiP to iframe in opener'); 64 65 // Note how activation is not propagated to an iframe in the opener, but consumption is 66 promise_test(async (t) => { 67 await test_driver.bless('request PiP window'); 68 const pipWindow = await documentPictureInPicture.requestWindow(); 69 70 const ifr = document.getElementById("same-origin-iframe"); 71 72 assert_false(navigator.userActivation.isActive, 'opener initially not active'); 73 assert_false(ifr.contentWindow.navigator.userActivation.isActive, 'iframe in opener initially not active'); 74 assert_false(pipWindow.navigator.userActivation.isActive, 'PiP initially not active'); 75 76 await test_driver.bless('activate iframe in opener', null, ifr.contentWindow); 77 await test_driver.bless('activate pip window', null, pipWindow); 78 79 assert_true(ifr.contentWindow.navigator.userActivation.isActive, 'iframe in opener is active'); 80 assert_true(pipWindow.navigator.userActivation.isActive, 'PiP is active'); 81 82 pipWindow.open().close(); 83 84 assert_false(ifr.contentWindow.navigator.userActivation.isActive, 'activation was consumed in iframe in opener'); 85 assert_false(pipWindow.navigator.userActivation.isActive, 'activation was consumed in PiP'); 86 }, 'Consuming activation in PiP also consumes activation in iframes in opener'); 87 </script>