Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<title>Test that a user activation in window that owns a document picture-in-picture window is usable in the
document picture-in-picture window</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<iframe id="cross-origin-iframe" src="https://{{hosts[alt][www]}}:{{ports[https][0]}}/common/blank.html"></iframe>
<body>
<script>
promise_test(async (t) => {
await test_driver.bless('request PiP window');
const pipWindow = await documentPictureInPicture.requestWindow();
assert_false(navigator.userActivation.isActive, 'the opener should initially not have user activation');
assert_false(pipWindow.navigator.userActivation.isActive, 'the PiP window should initially not have user activation');
// Activating this window should also activate the picture-in-picture window.
await test_driver.bless('activate opener window');
assert_true(navigator.userActivation.isActive, 'the opener should be activated');
assert_true(pipWindow.navigator.userActivation.isActive, 'the PiP window should be activated when the opener is activated');
// Consuming activation in the opener should also consume it in the picture-in-picture window.
window.open().close();
assert_false(navigator.userActivation.isActive, 'the opener should no longer be active once it consumes activation');
assert_false(pipWindow.navigator.userActivation.isActive, 'the PiP window should no longer be active once the opener consumes activation');
}, 'user activation propagates from opener to PiP');
promise_test(async (t) => {
await test_driver.bless('request PiP window');
const pipWindow = await documentPictureInPicture.requestWindow();
assert_false(navigator.userActivation.isActive, 'opener initially not active');
assert_false(pipWindow.navigator.userActivation.isActive, 'PiP initially not active');
const ifr = document.getElementById("cross-origin-iframe");
await test_driver.bless('activate cross-origin iframe', null, ifr.contentWindow);
assert_true(pipWindow.navigator.userActivation.isActive, 'activation propagated to PiP');
window.open().close();
assert_false(navigator.userActivation.isActive, 'activation was consumed in opener');
assert_false(pipWindow.navigator.userActivation.isActive, 'activation was consumed in PiP');
}, 'user activation propagates from cross-origin iframe in opener to PiP');
promise_test(async (t) => {
await test_driver.bless('request PiP window');
const pipWindow = await documentPictureInPicture.requestWindow();
if (pipWindow.document.readyState != "complete") {
// about:blank should load synchronous, but Gecko is still working on that...
assert_true(true, "Waiting for pip window to load");
await new Promise(res => pipWindow.addEventListener("load", res, { once: true }));
}
const ifr = pipWindow.document.createElement("iframe");
pipWindow.document.body.append(ifr);
assert_false(navigator.userActivation.isActive, 'opener initially not active');
assert_false(pipWindow.navigator.userActivation.isActive, 'PiP initially not active');
assert_false(ifr.contentWindow.navigator.userActivation.isActive, 'iframe in PiP initially not active');
await test_driver.bless('activate opener window');
assert_true(pipWindow.navigator.userActivation.isActive, 'activation propagated to PiP');
assert_true(ifr.contentWindow.navigator.userActivation.isActive, 'activation propagated to iframe in PiP');
ifr.contentWindow.open().close();
assert_false(navigator.userActivation.isActive, 'activation was consumed in opener');
assert_false(pipWindow.navigator.userActivation.isActive, 'activation was consumed in PiP');
assert_false(ifr.contentWindow.navigator.userActivation.isActive, 'activation was consumed in iframe in PiP');
}, 'user activation propagates from opener to iframe PiP');
</script>