Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
// Here's the set-up for this test:
// Step 1 (main window) Open first window with first url putting some resource
// into the cache and maybe receiving clear-site-data header
// Step 2 (first window) Message main window with uuid
// Step 3 (main window) Open second window with second url
// Step 4 (second window) Message main window with uuid (either cached or non-cached)
// Optional Step 5 (main window) Open third window with third url
// Optional Step 6 (third window) Message main window with uuid (either cached or non-cached)
// Step 7 (main window): Assert first and last uuid not equal due to `clear-site-data: "cache"` header
function test_cache_clear(test, params1, params2, params3) {
let cache_helper = "cache_helper=" + self.crypto.randomUUID() + "&";
let firstUrl = "/clear-site-data/support/clear-site-data-cache.py?" + cache_helper + params1
let secondUrl = "/clear-site-data/support/clear-site-data-cache.py?" + cache_helper + params2;
let thirdUrl = params3 ? "/clear-site-data/support/clear-site-data-cache.py?" + cache_helper + params3 : null;
return new Promise(resolve => {
window.addEventListener("message", test.step_func(e => {
// Result Step 2
let firstUuid = e.data;
window.addEventListener("message", test.step_func(e => {
// Result Step 4
let secondUuid = e.data;
if (thirdUrl === null) {
// Step 7, skipping the optional step 5 and 6
assert_not_equals(firstUuid, secondUuid);
resolve();
} else {
window.addEventListener("message", test.step_func(e => {
// Result Step 6
let thirdUuid = e.data;
// Step 7
assert_not_equals(firstUuid, thirdUuid);
resolve();
}), {once: true});
// Step 5
let third_window = window.open(thirdUrl);
test.add_cleanup(third_window.close);
}
}), {once: true});
// Step 3
let second_window = window.open(secondUrl);
test.add_cleanup(second_window.close);
}), {once: true});
// Step 1
let first_window = window.open(firstUrl);
test.add_cleanup(first_window.close);
});
}
promise_test(t => {
return test_cache_clear(t, "response=single_html&cache&clear_first=cache", "response=single_html&cache&clear_first=cache");
}, "clear cache: Document with clear-cache header doesn't get cached");
promise_test(t => {
return test_cache_clear(t, "response=single_html&cache&clear_first=all", "response=single_html&cache&clear_first=all");
}, "clear all: Document with clear-cache header doesn't get cached");
promise_test(t => {
return test_cache_clear(t, "response=html_embed_json&clear=cache", "response=html_embed_json&clear=cache");
}, "clear cache: Fetch on docment with clear-cache header doesn't get cached");
promise_test(t => {
return test_cache_clear(t, "response=html_embed_json&clear=all", "response=html_embed_json&clear=all");
}, "clear all: Fetch on docment with clear-cache header doesn't get cached");
promise_test(t => {
return test_cache_clear(t, "response=html_embed_json", "response=html_embed_json&clear=cache");
}, "clear cache: Previously cached fetch gets cleared");
promise_test(t => {
return test_cache_clear(t, "response=html_embed_json", "response=html_embed_json&clear=all");
}, "clear all: Previously cached fetch gets cleared");
promise_test(t => {
return test_cache_clear(t, "response=html_embed_json", "response=single_html&clear=cache", "response=html_embed_json");
}, "clear cache: Clear fetch on intermediate navigation");
promise_test(t => {
return test_cache_clear(t, "response=html_embed_json", "response=single_html&clear=all", "response=html_embed_json");
}, "clear all: Clear fetch on intermediate navigation");
promise_test(t => {
return test_cache_clear(t, "response=single_html&cache", "response=single_html&clear=cache", "response=single_html&cache");
}, "clear cache: Clear document in intermediate load");
promise_test(t => {
return test_cache_clear(t, "response=single_html&cache", "response=single_html&clear=all", "response=single_html&cache");
}, "clear all: Clear document in intermediate load");
</script>
</body>
</html>