Skip to content

Commit

Permalink
Bug 1925636 [wpt PR 48701] - Reland "Fenced frame: Fix some WPTs in h…
Browse files Browse the repository at this point in the history
…eadless mode.", a=testonly

Automatic update from web-platform-tests
Reland "Fenced frame: Fix some WPTs in headless mode." (#48701)

The original CL was crashing in an instance where multiClick() was
invoked without an await. This fixes the crash by awaiting the clicks
instead of continuing with/finishing the test before all the clicks
have propagated inside navigate-ancestor-test-runner.https.html.

Original change's description:
> Fenced frame: Fix some WPTs in headless mode.
>
> There is currently a push to allow Chromium web platform tests to run
> in headless mode (i.e. without a content shell). This requires some
> changes to how fenced frame tests work. Headless mode does not support
> test_driver functions from inside of fenced frames, as those require
> access to the main frame's window to pass the message onto, which
> fenced frames deliberately block for privacy reasons. This CL fixes
> some of the tests that fail in headless mode by moving those
> test_driver calls to the main frame, specifically clicking actions
> (which we already have multiClick() to handle this in main frames),
> and set_permission().
>
> See the headless mode explainer:
> https://chromium.googlesource.com/chromium/src/+/HEAD/headless/README.md
>
> Change-Id: Iab82a581b67f8f8851c7716a2d72caf566f3b2ae
> Bug: 366257368
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5935060
> Reviewed-by: Andrew Verge <[email protected]>
> Commit-Queue: Liam Brady <[email protected]>
> Cr-Commit-Position: refs/heads/main@{#1370151}

Bug: 366257368
Change-Id: Id998687c2f3de41a7b0dcd5197ba74fb22ef979e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5938155
Reviewed-by: Andrew Verge <[email protected]>
Commit-Queue: Liam Brady <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1370703}

Co-authored-by: Liam Brady <[email protected]>
--

wpt-commits: f50cf7fbd84ccdf90f6973b8ce7d75175adb3dc1
wpt-pr: 48701
  • Loading branch information
chromium-wpt-export-bot authored and moz-wptsync-bot committed Oct 22, 2024
1 parent 742c7d7 commit 7394a2f
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<body>
<script>
promise_test(async(t) => {
const actions = new test_driver.Actions();
const fencedframe = await attachFencedFrameContext(
{generator_api: 'fledge', register_beacon: true,
origin: get_host_info().HTTPS_REMOTE_ORIGIN});
Expand All @@ -30,7 +29,8 @@

// The first click should trigger the automatic beacon and clear the beacon
// data.
await actions.pointerMove(0, 0, {origin: fencedframe.element})
await new test_driver.Actions()
.pointerMove(0, 0, {origin: fencedframe.element})
.pointerDown()
.pointerUp()
.send();
Expand All @@ -41,7 +41,8 @@
// no beacon should be sent.
// Set up a timeout to ensure that there's enough time to send any potential
// automatic beacons.
await actions.pointerMove(0, 0, {origin: fencedframe.element})
await new test_driver.Actions()
.pointerMove(0, 0, {origin: fencedframe.element})
.pointerDown()
.pointerUp()
.send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<body>
<script>
promise_test(async(t) => {
const actions = new test_driver.Actions();
const fencedframe = await attachFencedFrameContext(
{generator_api: 'fledge', register_beacon: true,
origin: get_host_info().HTTPS_REMOTE_ORIGIN});
Expand All @@ -29,7 +28,8 @@

// The first click should trigger the automatic beacon, but the beacon data
// should not be cleared out.
await actions.pointerMove(0, 0, {origin: fencedframe.element})
await new test_driver.Actions()
.pointerMove(0, 0, {origin: fencedframe.element})
.pointerDown()
.pointerUp()
.send();
Expand All @@ -38,7 +38,8 @@

// The second click should still have associated automatic beacon data, and a
// beacon should be sent.
await actions.pointerMove(0, 0, {origin: fencedframe.element})
await new test_driver.Actions()
.pointerMove(0, 0, {origin: fencedframe.element})
.pointerDown()
.pointerUp()
.send();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<script>
promise_test(async () => {
const frame = attachFencedFrameContext();
await multiClick(10, 10, frame.element);
const result = await frame.execute(async () => {
await simulateGesture();
try {
await documentPictureInPicture.requestWindow();
return null;
Expand Down
10 changes: 9 additions & 1 deletion testing/web-platform/tests/fenced-frame/download.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<title>Test fenced frame does not allow triggering download</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/common/utils.js"></script>
<script src="resources/utils.js"></script>
<script src="resources/download-helper.js"></script>
Expand All @@ -26,11 +29,16 @@

// The download link is clicked inside the fenced frame after the loading
const fenced_frame_url = generateURL("resources/download-inner.html", [download_key, download_ack_key]) + `&type=${type}`;
attachFencedFrame(fenced_frame_url);
const fenced_frame = attachFencedFrame(fenced_frame_url);

const response = await nextValueFromServer(download_ack_key);
assert_equals(response, 'Triggered the action for download');

// Clicks must originate from the primary frame.
if (type === "anchor") {
await multiClick(20, 20, fenced_frame);
}

const result = await VerifyDownload(t, download_key);
assert_false(result, 'Expect no download to happen');
}, description);
Expand Down
2 changes: 1 addition & 1 deletion testing/web-platform/tests/fenced-frame/hid.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<script>
promise_test(async () => {
const frame = attachFencedFrameContext();
await multiClick(10, 10, frame.element);
const result = await frame.execute(async () => {
await simulateGesture();
try {
await navigator.hid.getDevices();
return 'HID getDevice succeeded';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@

// Send a mousedown event to the fenced frame. We can't send a full
// click because it will interfere with the manual event dispatch.
let actions = new test_driver.Actions();
for (let i = 0; i < 3; i++) {
await actions.pointerMove(10, 10, {origin: fencedframe.element})
await new test_driver.Actions()
.pointerMove(10, 10, {origin: fencedframe.element})
.pointerDown()
.send();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
await new Promise(resolve => {
win.onload = resolve;
});
await test_driver.set_permission({name: 'geolocation'}, 'granted');

// Pagehide can be used to detect the document destruction.
const pagehidePromise = new Promise(resolve => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

<head>
<title>The page triggering download embedded as a Fenced Frame</title>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="download-helper.js"></script>
<script src="utils.js"></script>
<script>
Expand All @@ -14,9 +12,10 @@
const href = `download-stash.py?token=${download_key}`;

if (type == 'anchor') {
// This link will be clicked in the main frame.
// See: ../download.https.html
const anchor = document.querySelector('#download');
anchor.href = href;
test_driver.click(anchor);
} else {
const delay = StreamDownloadFinishDelay();
location.href = `${href}&finish-delay=${delay}`
Expand All @@ -28,7 +27,8 @@
</head>

<body>
<a id="download" download>Download</a>
<a style="position: absolute; width: 100%; height: 100%;" id="download"
download>Download</a>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<!DOCTYPE html>
<title>Navigate ancestor helper</title>

<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="utils.js"></script>
<body>
<script>
Expand All @@ -22,7 +19,6 @@
const [navigate_ancestor_key, ancestor_type] = parseKeylist();
const url = generateURL(`navigate-ancestor-destination.https.html`,
[navigate_ancestor_key]);
await simulateGesture();
try {
window[ancestor_type].location = url;
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
<title>Test navigating an ancestor frame from within a fenced frame</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="utils.js"></script>

<body>
<script>
// This function is called by `window.opener`, which is a same-origin window.
window.runTest = function(test_type, ancestor_type) {
window.runTest = async function(test_type, ancestor_type) {
// Messages by this key are sent from
// `navigate-ancestor-destination.https.html` to let us know if the "_parent"
// navigations performed inside fenced frames landed on the right page.
Expand All @@ -30,23 +33,26 @@
});

let test_promise = null;
let fenced_frame = null;
switch (test_type) {
case 'top-level fenced frame':
// This fenced frame will attempt to navigate its parent to
// `navigate-ancestor-destination.https.html`. It should end up navigating
// *itself* since it is a top-level browsing context. Just in case it
// accidentally navigates *this* frame, we have an `onbeforeunload`
// handler that will automatically fail the test before.
attachFencedFrame(generateURL(
fenced_frame = attachFencedFrame(generateURL(
`navigate-ancestor-helper.https.html`,
[navigate_ancestor_key, ancestor_type]));
await multiClick(10, 10, fenced_frame);
test_promise = nextValueFromServer(navigate_ancestor_key);
break;
case 'nested fenced frame':
attachFencedFrame(generateURL(
fenced_frame = attachFencedFrame(generateURL(
`navigate-ancestor-from-nested-fenced-frame.https.html`,
[navigate_ancestor_key, navigate_ancestor_from_nested_key,
ancestor_type]));
await multiClick(10, 10, fenced_frame);
test_promise = nextValueFromServer(navigate_ancestor_from_nested_key)
.then(message => {
if (message != "PASS") {
Expand All @@ -55,10 +61,11 @@
});
break;
case 'nested iframe':
attachFencedFrame(generateURL(
fenced_frame = attachFencedFrame(generateURL(
`navigate-ancestor-from-nested-iframe.https.html`,
[navigate_ancestor_key, navigate_ancestor_from_nested_key,
ancestor_type]));
await multiClick(10, 10, fenced_frame);
test_promise = nextValueFromServer(navigate_ancestor_from_nested_key)
.then(message => {
if (message != `PASS: [${ancestor_type}] location change failed.`) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

window.runTest = async (fenced_frame_url) => {
const [permission_geolocation_key] = parseKeylist();
await test_driver.set_permission({name: 'geolocation'}, 'granted', true);

attachFencedFrame(generateURL(fenced_frame_url, [permission_geolocation_key]));
const actual_result = await nextValueFromServer(permission_geolocation_key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="utils.js"></script>
<script src="sandboxed-features.js"></script>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const run_in_fenced_frame = (func_name, description, is_nested) => {
frame.remove();
});
document.body.appendChild(frame);
// The test_pointer_lock() function expects the frame to be user activated.
// This is done at this point because headless mode WPTs do not support
// testdriver functions from within fenced frames.
if (func_name == "test_pointer_lock") {
await multiClick(10, 10, document.body);
}
assert_equals(await nextValueFromServer(key), 'done');
}, description);
};
Expand Down Expand Up @@ -105,8 +111,6 @@ async function test_screen_orientation_lock() {
}

async function test_pointer_lock() {
await simulateGesture();

const canvas = document.createElement('canvas');
document.body.appendChild(canvas);
const pointerlockerror_promise = new Promise(resolve => {
Expand Down
17 changes: 5 additions & 12 deletions testing/web-platform/tests/fenced-frame/resources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,11 @@ async function stringToStashKey(string) {
// Create a fenced frame. Then navigate it using the given `target`, which can
// be either an urn:uuid or a fenced frame config object.
function attachFencedFrame(target) {
assert_implements(
window.HTMLFencedFrameElement,
'The HTMLFencedFrameElement should be exposed on the window object');
if (window.test_driver) {
assert_implements(
window.HTMLFencedFrameElement,
'The HTMLFencedFrameElement should be exposed on the window object');
}

const fenced_frame = document.createElement('fencedframe');

Expand Down Expand Up @@ -628,15 +630,6 @@ async function writeValueToServer(key, value, origin = '') {
await fetch(serverURL, {"mode": "no-cors"});
}

// Simulates a user gesture.
async function simulateGesture() {
// Wait until the window size is initialized.
while (window.innerWidth == 0) {
await new Promise(resolve => requestAnimationFrame(resolve));
}
await test_driver.bless('simulate gesture');
}

// Fenced frames are always put in the public IP address space which is the
// least privileged. In case a navigation to a local data: URL or blob: URL
// resource is allowed, they would only be able to fetch things that are *also*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
<!DOCTYPE html>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="utils.js"></script>
<title>Fenced frame content to test Web Bluetooth</title>

<body>
<button id="button">Button</button>
<script>
(async () => {
await simulateGesture();
const [bluetooth_request_device_key] = parseKeylist();
try {
await navigator.bluetooth.requestDevice({filters: [{name: 'device'}]});
writeValueToServer(bluetooth_request_device_key,
'Web Bluetooth requestDevice() succeeded');
} catch(e) {
if (e.name == 'NotAllowedError' &&
e.message.includes(
'Web Bluetooth is not allowed in a fenced frame tree.')) {
document.addEventListener("click", async () => {
const [bluetooth_request_device_key] = parseKeylist();
try {
await navigator.bluetooth.requestDevice({filters: [{name: 'device'}]});
writeValueToServer(bluetooth_request_device_key,
'Web Bluetooth requestDevice() failed');
} else {
writeValueToServer(
bluetooth_request_device_key,
'Web Bluetooth requestDevice() failed with unknown error - ' +
`${e.name}: ${e.message}`);
'Web Bluetooth requestDevice() succeeded');
} catch(e) {
if (e.name == 'NotAllowedError' &&
e.message.includes(
'Web Bluetooth is not allowed in a fenced frame tree.')) {
writeValueToServer(bluetooth_request_device_key,
'Web Bluetooth requestDevice() failed');
} else {
writeValueToServer(
bluetooth_request_device_key,
'Web Bluetooth requestDevice() failed with unknown error - ' +
`${e.name}: ${e.message}`);
}
}
}
});
})();
</script>
</body>
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<!DOCTYPE html>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="utils.js"></script>
<title>Fenced frame content to test Web Share</title>

<body>
<script>
(async () => {
await simulateGesture();
const [navigator_share_key] = parseKeylist();
try {
await navigator.share({text: 'hello world'});
writeValueToServer(navigator_share_key, 'Web Share succeeded');
} catch(error) {
writeValueToServer(navigator_share_key, 'Web Share failed');
}
document.addEventListener("click", async () => {
const [navigator_share_key] = parseKeylist();
try {
await navigator.share({text: 'hello world'});
writeValueToServer(navigator_share_key, 'Web Share succeeded');
} catch(error) {
writeValueToServer(navigator_share_key, 'Web Share failed');
}
});
})();
</script>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<script src="/common/utils.js"></script>
<script src="resources/utils.js"></script>
<script src="resources/sandboxed-features.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<body>
<script>
Expand Down
Loading

0 comments on commit 7394a2f

Please sign in to comment.