Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional Web Platform Tests for the Split Cache #24075

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions fetch/http-cache/resources/split-origin-popup-with-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTTP Cache - helper</title>
<meta name="help" href="https://fetch.spec.whatwg.org/#http-cache-partitions">
<meta name="timeout" content="normal">
<script src="/resources/testharness.js"></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script>
const host = get_host_info();

// Create iframe that is same-origin to the opener.
var iframe = document.createElement("iframe");
iframe.src = host.HTTP_ORIGIN + window.location.pathname.replace(/\/[^\/]*$/, '/') + "split-origin-popup.html";
document.body.appendChild(iframe);

window.addEventListener("message", function listener(event) {
if (event.origin !== host.HTTP_ORIGIN) {
// Ignore messages not from the iframe or opener
return;
} else if (typeof(event.data) === "object") {
// This message came from the opener, pass it on to the iframe
iframe.contentWindow.postMessage(event.data, host.HTTP_ORIGIN);
} else if (typeof(event.data) === "string") {
// This message came from the iframe, pass it on to the opener
window.opener.postMessage(event.data, host.HTTP_ORIGIN);
}
})
</script>
</body>
</html>
22 changes: 17 additions & 5 deletions fetch/http-cache/split-cache.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
<script>
const host = get_host_info();

// We run this entire test twice: first with a same-origin then with a cross-origin popup
function performFullTest(is_same_origin_test) {
// We run this entire test four times, varying the following two booleans:
// - is_same_origin_test, which controls whether the popup is same-origin.
// - load_resource_in_iframe, which controls whether the popup loads the
// resource in an iframe or the mainframe. Note that the iframe is always
// same-origin to the opener.
function performFullTest(is_same_origin_test, load_resource_in_iframe) {
const POPUP_HTTP_ORIGIN = is_same_origin_test ? host.HTTP_ORIGIN : host.HTTP_NOTSAMESITE_ORIGIN
const LOCAL_HTTP_ORIGIN = host.HTTP_ORIGIN

Expand All @@ -40,6 +44,9 @@
],
// If the popup's request was a cache hit, we would only expect 2
// requests to the server. If it was a cache miss, we would expect 3.
// load_resource_in_iframe does not affect the expectation as, even
// though the iframe (if present) is same-origin, we expect a cache miss
// when the popup's mainframe is a different origin.
expected_response_headers: [
["server-request-count", is_same_origin_test ? "2" : "3"]
],
Expand All @@ -61,7 +68,10 @@

function popup_fetch() {
return new Promise(function(resolve, reject) {
var win = window.open(popupBaseURL + "resources/split-origin-popup.html")
var relativeUrl = load_resource_in_iframe
? "resources/split-origin-popup-with-iframe.html"
: "resources/split-origin-popup.html";
var win = window.open(popupBaseURL + relativeUrl);

// Post a message to initiate the popup's request and give the necessary
// information. Posted repeatedly to account for dropped messages as the
Expand Down Expand Up @@ -111,8 +121,10 @@
promise_test(() => local_fetch().then(popup_fetch).then(local_fetch2).then(check_server_info))
}

performFullTest(true);
performFullTest(false);
performFullTest(true, true);
performFullTest(false, true);
performFullTest(true, false);
performFullTest(false, false);
</script>
</body>
</html>