Skip to content

Commit

Permalink
[document picture-in-picture] Propagate user activation to the opener
Browse files Browse the repository at this point in the history
This CL changes browser-process-side user activation logic to allow
activations in document picture-in-picture windows to be used in their
opener windows.

This feature is behind a disabled-by-default feature flag.

Specification change:
WICG/document-picture-in-picture#117

Chromestatus: https://chromestatus.com/feature/5185710702460928

Intent to Prototype:
https://groups.google.com/a/chromium.org/g/blink-dev/c/MwH0ODG4bec

Bug: 331246719
Change-Id: Iedad1e0cb60e04fc1ccf350405f04a399a2b72a1
  • Loading branch information
steimelchrome authored and chromium-wpt-export-bot committed Apr 9, 2024
1 parent fc96c50 commit 888ffce
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<title>Test that a user activation in a document picture-in-picture window is usable in its opener 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>
<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');

// Attempting to use our test_driver to activate the document
// picture-in-picture window via:
//
// test_driver.bless('activate pip window', null, pipWindow);
//
// does not actually work, since under the hood the test_driver calculates the
// position of a button and then clicks that position in *our* window instead
// of in the picture-in-picture window, activating us instead.
// Below is another approach, which loads the testdriver scripts directly into
// the picture-in-picture window and then tries to bless with the
// picture-in-picture window's test_driver. This still does not work (neither
// window gets activated and the `await test_driver.bless(...);` call never
// completes), so I'm not actually sure how to activate the picture-in-picture
// window.
//
// I also tried running the script to call test_driver.bless() in the
// picture-in-picture window itself, but that had the same result as the
// attempt below.

// Add test_driver scripts to the document picture-in-picture window so we can
// activate it.
const scriptsLoadedPromise = new Promise(async (resolve) => {
let numLoaded=0;
let scriptLoaded = function() {
numLoaded++
if (numLoaded == 2) {
resolve();
}
};

const testDriverScript = pipWindow.document.createElement('script');
testDriverScript.setAttribute('src', '/resources/testdriver.js');
testDriverScript.addEventListener('load', scriptLoaded);
pipWindow.document.body.append(testDriverScript);

const testDriverVendorScript = pipWindow.document.createElement('script');
testDriverVendorScript.setAttribute('src', '/resources/testdriver-vendor.js');
testDriverVendorScript.addEventListener('load', scriptLoaded);
pipWindow.document.body.append(testDriverVendorScript);
});
await scriptsLoadedPromise;

await pipWindow.test_driver.bless('Activate the picture-in-picture window');

// Activating the picture-in-picture window should also activate the opener.
assert_true(navigator.userActivation.isActive, 'the opener should be activated when the PiP window is activated');
assert_true(pipWindow.navigator.userActivation.isActive, 'the PiP window should be activated');
});
</script>

0 comments on commit 888ffce

Please sign in to comment.