blob: 6be77bad8fd4cf7d93b282463549323b3a918baf [file] [log] [blame] [edit]
<!DOCTYPE html>
<title>Same-origin prerendering can access Storage Foundation API</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="resources/utils.js"></script>
<body>
<script>
setup(() => assertSpeculationRulesIsSupported());
const expectedReadBuffer = [65, 66, 67, 68];
async function writeToFile() {
let f = await storageFoundation.open('test_file');
const writeBuffer = new Uint8Array(4);
writeBuffer.set(expectedReadBuffer);
await storageFoundation.requestCapacity(4);
const {writtenBytes} = await f.write(writeBuffer, 0);
await f.flush();
await f.close();
return writtenBytes == 4;
}
async function readFromFile() {
let f = await storageFoundation.open('test_file');
const {buffer, readBytes} = await f.read(new Uint8Array(4), 0);
await f.close();
return buffer;
}
promise_test(async t => {
const uid = token();
const bc = new PrerenderChannel('prerender-channel', uid);
const gotMessage = new Promise(resolve => {
bc.addEventListener('message', e => {
resolve(e.data);
}, {
once: true
});
});
const writeResult = await writeToFile();
assert_true(
writeResult,
'primary page should be able to write to storage foundation API.');
// Start prerendering a page that attempts to access storage foundation API.
startPrerendering(`resources/storage-foundation-access.https.html`);
const result = await gotMessage;
assert_array_equals(
result.readBuffer, expectedReadBuffer,
'prerendering page should be able to read from storage foundation API');
const readBufferWrittenByPrerender = await readFromFile();
assert_array_equals(
result.writtenBuffer, readBufferWrittenByPrerender,
'prerendering page should be able to write to storage foundation API');
await storageFoundation.delete('test_file');
}, 'prerendering page should be able to access storage foundation API');
</script>
</body>