Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prerender: Add testcase for storage.persist
This CL adds tests for storage.persist() method, which is also expected to be deferred until prerender activation as well as storage.estimate(). Bug: 1321490 Change-Id: I8eca896804ce974b5040f8fdb831e5e9b94e2c19 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3810764 Commit-Queue: Yoshiki Tanioka <tanioka@google.com> Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org> Reviewed-by: Lingqi Chi <lingqi@chromium.org> Cr-Commit-Position: refs/heads/main@{#1031841}
- Loading branch information
Yoshiki Tanioka
authored and
Chromium LUCI CQ
committed
Aug 5, 2022
1 parent
abe497e
commit 0d93a3b
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
third_party/blink/web_tests/wpt_internal/prerender/resources/storage-persist.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,23 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/speculation-rules/prerender/resources/utils.js"></script> | ||
<script src="/speculation-rules/prerender/resources/deferred-promise-utils.js"></script> | ||
<script> | ||
|
||
const params = new URLSearchParams(location.search); | ||
|
||
// The main test page (restriction-storage-persist.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.storage.persist(), 'navigator.storage.persist'); | ||
} | ||
|
||
</script> |
54 changes: 54 additions & 0 deletions
54
third_party/blink/web_tests/wpt_internal/prerender/restriction-storage-persist.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,54 @@ | ||
<!DOCTYPE html> | ||
<title>Access to storage.persist() is deferred</title> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="/speculation-rules/prerender/resources/utils.js"></script> | ||
<body> | ||
<script> | ||
|
||
promise_test(async t => { | ||
const uid = token(); | ||
const bc = new PrerenderChannel('test-channel', uid); | ||
|
||
const gotMessage = new Promise(resolve => { | ||
bc.addEventListener('message', e => { | ||
resolve(e.data); | ||
}, { | ||
once: true | ||
}); | ||
}); | ||
const url = `resources/storage-persist.https.html?uid=${uid}`; | ||
window.open(url, '_blank', 'noopener'); | ||
|
||
const result = await gotMessage; | ||
const expected = [ | ||
{ | ||
event: 'started waiting navigator.storage.persist', | ||
prerendering: true | ||
}, | ||
{ | ||
event: 'prerendering change', | ||
prerendering: false | ||
}, | ||
{ | ||
event: 'finished waiting navigator.storage.persist', | ||
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(); | ||
|
||
// Send a close signal to PrerenderEventCollector on the prerendered page. | ||
new PrerenderChannel('close', uid).postMessage(''); | ||
}, `the access to the storage.persist() should be deferred until the prerendered | ||
page is activated`); | ||
|
||
</script> | ||
</body> |