blob: 49c9a08168bb759bdbe18aed97fbafbf17e53583 [file] [log] [blame]
<!doctype html>
<title>Cache Storage: verify cache_storage padding behavior</title>
<link rel="help" href="https://w3c.github.io/ServiceWorker/#cache-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';
async function usage_for_credentials(cache, url, mode) {
const r = await fetch(url, { mode: 'no-cors', credentials: mode });
assert_equals('opaque', r.type);
await cache.put(url, r);
return (await navigator.storage.estimate()).usage;
}
promise_test(async t => {
const cache = await caches.open('padding');
const url = 'http://localhost:8000/cachestorage/resources/simple.txt';
// Get the reported disk usage for an opaque response without credentials.
const usage1 = await usage_for_credentials(cache, url, 'omit');
const usage2 = await usage_for_credentials(cache, url, 'same-origin');
// Get the reported disk usage for an opaque response with the same URL,
// but also with credentials enabled.
const usage3 = await usage_for_credentials(cache, url, 'include');
assert_equals(usage1, usage2,
"Credentials mode 'omit' and 'same-origin' should have the " +
"same padding size since credentials are not sent.");
assert_not_equals(usage1, usage3,
"Credentials mode 'include' should result in a different " +
"padding size.");
}, 'Cache padding varies based on if Response was loaded with credentials.');
</script>