Skip to content

Commit

Permalink
[Client Hints] Verify hint availability
Browse files Browse the repository at this point in the history
We want to check whether hints are available in embedded contexts.

Bug: 1399788
Change-Id: Idc4a4f0a7e3266c2cbc57a89fc90df8923f97232
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4089490
Reviewed-by: Ian Clelland <iclelland@chromium.org>
Auto-Submit: Ari Chivukula <arichiv@chromium.org>
Commit-Queue: Ari Chivukula <arichiv@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1084701}
  • Loading branch information
arichiv authored and Chromium LUCI CQ committed Dec 17, 2022
1 parent 9536f16 commit 5faa5aa
Show file tree
Hide file tree
Showing 23 changed files with 483 additions and 0 deletions.
@@ -0,0 +1,37 @@
<!doctype html>
<meta charset=utf-8>
<title>Client Hints: Delegation of hints to cross-origin frames and resources for *</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Here's the set-up for this test:
// Step 1. (Site 1 Window) verify ch-device-memory availability.
// Step 2. (Site 1 Window) set up listener and embed Site 2 Frame.
// Step 3. (Site 2 Frame) verify ch-device-memory availability.
// Step 4. (Site 2 Frame) embeds Site 1 Frame.
// Step 5. (Site 3 Frame) verify ch-device-memory availability.
// Step 6. (Site 1 Window) exit.

promise_test(async (t) => {
// Step 1
let r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 200, "Site 1 fetching Site 1 didn't recieve sec-ch-device-memory");
r = await fetch("https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 200, "Site 1 fetching Site 2 didn't recieve sec-ch-device-memory");
r = await fetch("https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 200, "Site 1 fetching Site 3 didn't recieve sec-ch-device-memory");
// Step 2
const site2Frame = document.createElement("iframe");
site2Frame.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/accept_ch_delegation_to_all_iframe.sub.https.html";
site2Frame.allow = "ch-device-memory *"
document.body.appendChild(site2Frame);
// Step 6
return new Promise(resolve => {
window.addEventListener("message", resolve);
}).then(e => {
assert_equals(e.data, "ch-device-memory is available as expected for all");
});
}, "postMessage: First-Party to Third-Party, Cross-Partition, Same-Origin");
</script>
</body>
@@ -0,0 +1,2 @@
Permissions-Policy: ch-device-memory=(*)
Accept-CH: Sec-CH-Device-Memory
@@ -0,0 +1,36 @@
<!doctype html>
<meta charset=utf-8>
<title>Client Hints: Delegation of hints to cross-origin frames and resources for none</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Here's the set-up for this test:
// Step 1. (Site 1 Window) verify ch-device-memory availability.
// Step 2. (Site 1 Window) set up listener and embed Site 2 Frame.
// Step 3. (Site 2 Frame) verify ch-device-memory availability.
// Step 4. (Site 2 Frame) embeds Site 1 Frame.
// Step 5. (Site 3 Frame) verify ch-device-memory availability.
// Step 6. (Site 1 Window) exit.

promise_test(async (t) => {
// Step 1
let r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 400, "Site 1 fetching Site 1 did recieve sec-ch-device-memory");
r = await fetch("https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 400, "Site 1 fetching Site 2 did recieve sec-ch-device-memory");
r = await fetch("https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 400, "Site 1 fetching Site 3 did recieve sec-ch-device-memory");
// Step 2
const site2Frame = document.createElement("iframe");
site2Frame.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/accept_ch_delegation_to_none_iframe.sub.https.html";
document.body.appendChild(site2Frame);
// Step 6
return new Promise(resolve => {
window.addEventListener("message", resolve);
}).then(e => {
assert_equals(e.data, "ch-device-memory is available as expected for none");
});
}, "postMessage: First-Party to Third-Party, Cross-Partition, Same-Origin");
</script>
</body>
@@ -0,0 +1,2 @@
Permissions-Policy: ch-device-memory=()
Accept-CH: Sec-CH-Device-Memory
@@ -0,0 +1,37 @@
<!doctype html>
<meta charset=utf-8>
<title>Client Hints: Delegation of hints to cross-origin frames and resources for self</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Here's the set-up for this test:
// Step 1. (Site 1 Window) verify ch-device-memory availability.
// Step 2. (Site 1 Window) set up listener and embed Site 2 Frame.
// Step 3. (Site 2 Frame) verify ch-device-memory availability.
// Step 4. (Site 2 Frame) embeds Site 1 Frame.
// Step 5. (Site 3 Frame) verify ch-device-memory availability.
// Step 6. (Site 1 Window) exit.

promise_test(async (t) => {
// Step 1
let r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 200, "Site 1 fetching Site 1 didn't recieve sec-ch-device-memory");
r = await fetch("https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 400, "Site 1 fetching Site 2 did recieve sec-ch-device-memory");
r = await fetch("https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 400, "Site 1 fetching Site 3 did recieve sec-ch-device-memory");
// Step 2
const site2Frame = document.createElement("iframe");
site2Frame.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/accept_ch_delegation_to_self_iframe.sub.https.html";
site2Frame.allow = "ch-device-memory self"
document.body.appendChild(site2Frame);
// Step 6
return new Promise(resolve => {
window.addEventListener("message", resolve);
}).then(e => {
assert_equals(e.data, "ch-device-memory is available as expected for self");
});
}, "postMessage: First-Party to Third-Party, Cross-Partition, Same-Origin");
</script>
</body>
@@ -0,0 +1,2 @@
Permissions-Policy: ch-device-memory=(self)
Accept-CH: Sec-CH-Device-Memory
@@ -0,0 +1,37 @@
<!doctype html>
<meta charset=utf-8>
<title>Client Hints: Delegation of hints to cross-origin frames and resources for some</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Here's the set-up for this test:
// Step 1. (Site 1 Window) verify ch-device-memory availability.
// Step 2. (Site 1 Window) set up listener and embed Site 2 Frame.
// Step 3. (Site 2 Frame) verify ch-device-memory availability.
// Step 4. (Site 2 Frame) embeds Site 1 Frame.
// Step 5. (Site 3 Frame) verify ch-device-memory availability.
// Step 6. (Site 1 Window) exit.

promise_test(async (t) => {
// Step 1
let r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 200, "Site 1 fetching Site 1 didn't recieve sec-ch-device-memory");
r = await fetch("https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 200, "Site 1 fetching Site 2 didn't recieve sec-ch-device-memory");
r = await fetch("https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 400, "Site 1 fetching Site 3 did recieve sec-ch-device-memory");
// Step 2
const site2Frame = document.createElement("iframe");
site2Frame.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/accept_ch_delegation_to_some_iframe.sub.https.html";
site2Frame.allow = "ch-device-memory https://{{hosts[alt][]}}:{{ports[https][0]}}"
document.body.appendChild(site2Frame);
// Step 6
return new Promise(resolve => {
window.addEventListener("message", resolve);
}).then(e => {
assert_equals(e.data, "ch-device-memory is available as expected for some");
});
}, "postMessage: First-Party to Third-Party, Cross-Partition, Same-Origin");
</script>
</body>
@@ -0,0 +1,2 @@
Permissions-Policy: ch-device-memory=("https://{{host}}:{{ports[https][0]}}" "https://{{hosts[alt][]}}:{{ports[https][0]}}")
Accept-CH: Sec-CH-Device-Memory
@@ -0,0 +1,37 @@
<!doctype html>
<meta charset=utf-8>
<title>Client Hints: Delegation of hints to cross-origin frames and resources for src</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Here's the set-up for this test:
// Step 1. (Site 1 Window) verify ch-device-memory availability.
// Step 2. (Site 1 Window) set up listener and embed Site 2 Frame.
// Step 3. (Site 2 Frame) verify ch-device-memory availability.
// Step 4. (Site 2 Frame) embeds Site 1 Frame.
// Step 5. (Site 3 Frame) verify ch-device-memory availability.
// Step 6. (Site 1 Window) exit.

promise_test(async (t) => {
// Step 1
let r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 200, "Site 1 fetching Site 1 didn't recieve sec-ch-device-memory");
r = await fetch("https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 400, "Site 1 fetching Site 2 did recieve sec-ch-device-memory");
r = await fetch("https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
assert_equals(r.status, 400, "Site 1 fetching Site 3 did recieve sec-ch-device-memory");
// Step 2
const site2Frame = document.createElement("iframe");
site2Frame.src = "https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/accept_ch_delegation_to_src_iframe.sub.https.html";
site2Frame.allow = "ch-device-memory src"
document.body.appendChild(site2Frame);
// Step 6
return new Promise(resolve => {
window.addEventListener("message", resolve);
}).then(e => {
assert_equals(e.data, "ch-device-memory is available as expected for src");
});
}, "postMessage: First-Party to Third-Party, Cross-Partition, Same-Origin");
</script>
</body>
@@ -0,0 +1,2 @@
Permissions-Policy: ch-device-memory=(self)
Accept-CH: Sec-CH-Device-Memory
@@ -0,0 +1,32 @@
<!doctype html>
<meta charset=utf-8>
<body>
<script>
async function test() {
// Step 3 (client-hints/inner-delegation/accept_ch_delegation_to_all.sub.https.html)
let r = await fetch("https://{{host}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 2 fetching Site 1 did recieve sec-ch-device-memory";
}
r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status != 200) {
return "Site 2 fetching Site 2 didn't recieve sec-ch-device-memory";
}
r = await fetch("https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 2 fetching Site 3 did recieve sec-ch-device-memory";
}
// Step 4 (client-hints/inner-delegation/accept_ch_delegation_to_all.sub.https.html)
const site3Frame = document.createElement("iframe");
site3Frame.src = "https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/accept_ch_delegation_to_all_iframe_iframe.sub.https.html";
site3Frame.allow = "ch-device-memory *"
document.body.appendChild(site3Frame);
return ""
}
test().then((message) => {
if (message) {
window.top.postMessage(message, "*");
}
});
</script>
</body>
@@ -0,0 +1,23 @@
<!doctype html>
<meta charset=utf-8>
<body>
<script>
async function test() {
// Step 5 (client-hints/inner-delegation/accept_ch_delegation_to_all.sub.https.html)
let r = await fetch("https://{{host}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 3 fetching Site 1 did recieve sec-ch-device-memory";
}
r = await fetch("https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 3 fetching Site 2 did recieve sec-ch-device-memory";
}
r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status != 200) {
return "Site 3 fetching Site 3 didn't recieve sec-ch-device-memory";
}
return "ch-device-memory is available as expected for all"
}
test().then((message) => window.top.postMessage(message, "*"));
</script>
</body>
@@ -0,0 +1,32 @@
<!doctype html>
<meta charset=utf-8>
<body>
<script>
async function test() {
// Step 3 (client-hints/inner-delegation/accept_ch_delegation_to_none.sub.https.html)
let r = await fetch("https://{{host}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 2 fetching Site 1 did recieve sec-ch-device-memory";
}
r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 2 fetching Site 2 did recieve sec-ch-device-memory";
}
r = await fetch("https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 2 fetching Site 3 did recieve sec-ch-device-memory";
}
// Step 4 (client-hints/inner-delegation/accept_ch_delegation_to_none.sub.https.html)
const site3Frame = document.createElement("iframe");
site3Frame.src = "https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/accept_ch_delegation_to_none_iframe_iframe.sub.https.html";
site3Frame.allow = "ch-device-memory none"
document.body.appendChild(site3Frame);
return ""
}
test().then((message) => {
if (message) {
window.top.postMessage(message, "*");
}
});
</script>
</body>
@@ -0,0 +1,23 @@
<!doctype html>
<meta charset=utf-8>
<body>
<script>
async function test() {
// Step 5 (client-hints/inner-delegation/accept_ch_delegation_to_none.sub.https.html)
let r = await fetch("https://{{host}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 3 fetching Site 1 did recieve sec-ch-device-memory";
}
r = await fetch("https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 3 fetching Site 2 did recieve sec-ch-device-memory";
}
r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 3 fetching Site 3 did recieve sec-ch-device-memory";
}
return "ch-device-memory is available as expected for none"
}
test().then((message) => window.top.postMessage(message, "*"));
</script>
</body>
@@ -0,0 +1,32 @@
<!doctype html>
<meta charset=utf-8>
<body>
<script>
async function test() {
// Step 3 (client-hints/inner-delegation/accept_ch_delegation_to_self.sub.https.html)
let r = await fetch("https://{{host}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 2 fetching Site 1 did recieve sec-ch-device-memory";
}
r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 2 fetching Site 2 did recieve sec-ch-device-memory";
}
r = await fetch("https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 2 fetching Site 3 did recieve sec-ch-device-memory";
}
// Step 4 (client-hints/inner-delegation/accept_ch_delegation_to_self.sub.https.html)
const site3Frame = document.createElement("iframe");
site3Frame.src = "https://{{domains[www2]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/accept_ch_delegation_to_self_iframe_iframe.sub.https.html";
site3Frame.allow = "ch-device-memory self"
document.body.appendChild(site3Frame);
return ""
}
test().then((message) => {
if (message) {
window.top.postMessage(message, "*");
}
});
</script>
</body>
@@ -0,0 +1,23 @@
<!doctype html>
<meta charset=utf-8>
<body>
<script>
async function test() {
// Step 5 (client-hints/inner-delegation/accept_ch_delegation_to_self.sub.https.html)
let r = await fetch("https://{{host}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 3 fetching Site 1 did recieve sec-ch-device-memory";
}
r = await fetch("https://{{hosts[alt][]}}:{{ports[https][0]}}/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 3 fetching Site 2 did recieve sec-ch-device-memory";
}
r = await fetch("/client-hints/inner-delegation/resources/was-sec-ch-device-memory-received.py");
if (r.status == 200) {
return "Site 3 fetching Site 3 did recieve sec-ch-device-memory";
}
return "ch-device-memory is available as expected for self"
}
test().then((message) => window.top.postMessage(message, "*"));
</script>
</body>

0 comments on commit 5faa5aa

Please sign in to comment.