Skip to content

Commit

Permalink
Prerender: Test access to the Web Serial API Info is deferred
Browse files Browse the repository at this point in the history
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
Gyuyoung authored and Chromium LUCI CQ committed Apr 21, 2021
1 parent c64186e commit eaa9be7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
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>
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>

0 comments on commit eaa9be7

Please sign in to comment.