forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prerender: Test access to the Web Serial API Info is deferred
This CL adds the tests to ensure if the Web Serial API can be deferred until a prerenderer page is activated. Because the current decision is to defer the access to the Web Serial API until the prerendered page is activated. The Mojo capability control defers the access by default. So, this CL just adds a wpt-internal test to check it works as expected. Bug: 1200680 Change-Id: Icb77c83e9f3ad4f55a5702a7319806afecfabe9b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2837968 Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com> Reviewed-by: Lingqi Chi <lingqi@chromium.org> Reviewed-by: Matt Falkenhagen <falken@chromium.org> Cr-Commit-Position: refs/heads/master@{#874558}
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
third_party/blink/web_tests/wpt_internal/prerender/resources/web-serial.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<script src="/common/utils.js"></script> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="utils.js"></script> | ||
<script src="deferred-promise-utils.js"></script> | ||
<script> | ||
|
||
const params = new URLSearchParams(location.search); | ||
|
||
// The main test page (restriction-web-serial.https.html) loads the | ||
// initiator page, then the initiator page will prerender itself with the | ||
// `prerendering` parameter. | ||
const isPrerendering = params.has('prerendering'); | ||
|
||
if (!isPrerendering) { | ||
loadInitiatorPage(); | ||
} else { | ||
const prerenderEventCollector = new PrerenderEventCollector(); | ||
prerenderEventCollector.start( | ||
navigator.serial.getPorts(), 'navigator.serial.getPorts'); | ||
} | ||
|
||
</script> |
41 changes: 41 additions & 0 deletions
41
third_party/blink/web_tests/wpt_internal/prerender/restriction-web-serial.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!DOCTYPE html> | ||
<title>Access to the Web Serial API is deferred</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/utils.js"></script> | ||
<body> | ||
<script> | ||
|
||
// This test cannot be upstreamed to WPT until: | ||
// - startPrerendering() usage is replaced with a WebDriver API. | ||
promise_test(async t => { | ||
const bc = new BroadcastChannel('test-channel'); | ||
|
||
const gotMessage = new Promise(resolve => { | ||
bc.addEventListener('message', e => { | ||
resolve(e.data); | ||
}, { | ||
once: true | ||
}); | ||
}); | ||
const url = `resources/web-serial.https.html`; | ||
window.open(url, '_blank', 'noopener'); | ||
|
||
const result = await gotMessage; | ||
const expected = [ | ||
{event: 'started waiting navigator.serial.getPorts', prerendering: true}, | ||
{event: 'prerendering change', prerendering: false}, | ||
{event: 'finished waiting navigator.serial.getPorts', prerendering: false}, | ||
]; | ||
assert_equals(result.length, expected.length); | ||
for (let i = 0; i < result.length; i++) { | ||
assert_equals(result[i].event, expected[i].event, `event[${i}]`); | ||
assert_equals(result[i].prerendering, expected[i].prerendering, | ||
`prerendering[${i}]`); | ||
} | ||
bc.close(); | ||
}, `the access to the Web Serial API should be deferred until the prerendered | ||
page is activated`); | ||
|
||
</script> | ||
</body> |