Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
54 changes: 54 additions & 0 deletions html/partitioning/ancestor-chain-partitioning.sub.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
async function getResultPromise(key) {
return new Promise((resolve) => {
window.addEventListener("message", (event) => {
if (event.data?.type != "result" || event.data?.key != key) {
return;
}
resolve(event.data.value);
});
});
}
localStorage.setItem("aba", "unpartitioned");
localStorage.setItem("aaa", "unpartitioned");
localStorage.setItem("aa-sw-redir", "unpartitioned");
let resultDataABA = getResultPromise("aba");
let resultDataAAA = getResultPromise("aaa");
let resultDataAASW = getResultPromise("aa-sw-redir");
</script>
<iframe src="//{{hosts[alt][www]}}:{{ports[https][0]}}{{location[path]}}/../resources/middle-frame.sub.html?key=aba"></iframe>
<iframe src="//{{hosts[][]}}:{{ports[https][0]}}{{location[path]}}/../resources/middle-frame.sub.html?key=aaa"></iframe>
<iframe id="aa-sw-redir"></iframe>
<script>
promise_test(async function() {
let value = await resultDataABA;
assert_equals(value, null, "Expected partitioned data in A(B(A)) nested frame");
localStorage.removeItem("aba");
}, "Expected partitioned data in A(B(A)) nested frame")

promise_test(async function() {
let value = await resultDataAAA;
assert_equals(value, "unpartitioned", "Expected unpartitioned data in A(A(A)) nested frame");
localStorage.removeItem("aaa");
}, "Expected unpartitioned data in A(A(A)) nested frame")

promise_test(async function() {
let registration = await navigator.serviceWorker.register("./resources/intercepting-worker.sub.js");
this.add_cleanup(async function() {
await registration.unregister();
});

let innerFrame = document.getElementById("aa-sw-redir");
innerFrame.src ="//{{hosts[][]}}:{{ports[https][0]}}{{location[path]}}/../resources/post-storage.html?key=aa-sw-redir&intercept";

let value = await resultDataAASW;
assert_equals(value, "unpartitioned", "Expected unpartitioned data in same-origin subframe redirected by service worker");

localStorage.removeItem("aa-sw-redir");
}, "Expected unpartitioned data in same-origin subframe redirected by service worker")
</script>
11 changes: 11 additions & 0 deletions html/partitioning/resources/intercepting-worker.sub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
self.addEventListener("fetch", (event) => {
let url = new URL(event.request.url);
if (url.searchParams.has("intercept")) {
if (url.hostname == "{{hosts[][]}}") {
url.hostname = "{{hosts[alt][www]}}"
} else {
url.hostname = "{{hosts[][]}}";
}
return event.respondWith(fetch(url));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this is doing the CORS thing whatwg/html#11540 (comment) discusses. Or is this testing something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was trying to validate that the request vs response partition behavior. I was going to do it with top-level sandboxing, but the sandbox blocks localStorage, so I went this way. I can do a cookie-lookup in a sandboxed-partitioned context if that helps.

Adding the CORS headers here though.

}
});
15 changes: 15 additions & 0 deletions html/partitioning/resources/middle-frame.sub.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<body>
<iframe id="innerFrame"></iframe>
<script>
window.addEventListener("message", (event) => {
if (event.data?.type != "result") {
return;
}
parent.postMessage(event.data, "*");
});
let innerFrame = document.getElementById("innerFrame");
innerFrame.src ="//{{hosts[][]}}:{{ports[https][0]}}{{location[path]}}/../../resources/post-storage.html{{location[query]}}";
</script>
15 changes: 15 additions & 0 deletions html/partitioning/resources/popup.sub.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<body>
<iframe id="innerFrame"></iframe>
<script>
window.addEventListener("message", (event) => {
if (event.data?.type != "result") {
return;
}
window.opener.postMessage(event.data, "*");
});
let innerFrame = document.getElementById("innerFrame");
innerFrame.src ="//{{hosts[alt][www]}}:{{ports[https][0]}}{{location[path]}}/../../resources/post-storage.html{{location[query]}}";
</script>
17 changes: 17 additions & 0 deletions html/partitioning/resources/post-storage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<body>
<script>
const urlParams = new URLSearchParams(window.location.search);
let key = urlParams.get("key");
let result = localStorage.getItem(key);
if (urlParams.has("store")) {
localStorage.setItem(key, urlParams.get("store"));
}
parent.postMessage({
type: "result",
value: result,
key,
}, "*");
</script>