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 nested-context resource-timing tests #13823

Merged
merged 13 commits into from
Mar 13, 2019
1 change: 1 addition & 0 deletions lint.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ SET TIMEOUT: payment-request/allowpaymentrequest/setting-allowpaymentrequest-tim
SET TIMEOUT: preload/single-download-preload.html
SET TIMEOUT: resize-observer/resources/iframe.html
SET TIMEOUT: resource-timing/resources/iframe-TAO*
SET TIMEOUT: resource-timing/resources/nested-contexts.js
SET TIMEOUT: screen-orientation/onchange-event.html
SET TIMEOUT: secure-contexts/basic-popup-and-iframe-tests.https.js
SET TIMEOUT: service-workers/cache-storage/script-tests/cache-abort.js
Expand Down
30 changes: 30 additions & 0 deletions resource-timing/nested-context-navigations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing embed navigate - back button navigation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/nested-contexts.js"></script>
<script>
open_test_window("resources/embed-navigate-back.html", "Test that embed navigations are not observable by the parent, even after history navigations by the parent");
open_test_window("resources/embed-navigate-back.html?crossorigin", "Test that crossorigin embed navigations are not observable by the parent, even after history navigations by the parent");
open_test_window("resources/embed-navigate.html", "Test that embed navigations are not observable by the parent");
open_test_window("resources/embed-navigate.html?crossorigin", "Test that crossorigin embed navigations are not observable by the parent");
open_test_window("resources/embed-refresh.html", "Test that embed refreshes are not observable by the parent");
open_test_window("resources/embed-refresh.html?crossorigin", "Test that crossorigin embed refreshes are not observable by the parent");
open_test_window("resources/iframe-navigate-back.html", "Test that iframe navigations are not observable by the parent, even after history navigations by the parent");
open_test_window("resources/iframe-navigate-back.html?crossorigin", "Test that crossorigin iframe navigations are not observable by the parent, even after history navigations by the parent");
open_test_window("resources/iframe-navigate.html", "Test that iframe navigations are not observable by the parent");
open_test_window("resources/iframe-navigate.html?crossorigin", "Test that crossorigin iframe navigations are not observable by the parent");
open_test_window("resources/iframe-refresh.html", "Test that iframe refreshes are not observable by the parent");
open_test_window("resources/iframe-refresh.html?crossorigin", "Test that crossorigin iframe refreshes are not observable by the parent");
open_test_window("resources/object-navigate-back.html", "Test that object navigations are not observable by the parent, even after history navigations by the parent");
open_test_window("resources/object-navigate-back.html?crossorigin", "Test that crossorigin object navigations are not observable by the parent, even after history navigations by the parent");
open_test_window("resources/object-navigate.html", "Test that object navigations are not observable by the parent");
open_test_window("resources/object-navigate.html?crossorigin", "Test that crossorigin object navigations are not observable by the parent");
open_test_window("resources/object-refresh.html", "Test that object refreshes are not observable by the parent");
open_test_window("resources/object-refresh.html?crossorigin", "Test that crossorigin object refreshes are not observable by the parent");
</script>

12 changes: 12 additions & 0 deletions resource-timing/resources/document-navigated.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
navigated document!
<script>
top.postMessage("navigated", "*");
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions resource-timing/resources/document-refreshed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
Refreshed document!
<script>
top.postMessage("refreshed", "*");
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions resource-timing/resources/document-that-navigates.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script>
location.href="document-navigated.html";
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions resource-timing/resources/document-that-refreshes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0;document-refreshed.html">
</head>
<body></body>
</html>
14 changes: 14 additions & 0 deletions resource-timing/resources/embed-navigate-back.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing embed navigate - back button navigation</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_back_navigation("embed-navigate-back.html");
</script>
<embed type="text/html">
<script>
document.getElementsByTagName("embed")[0].src = pre_navigate_url;
</script>
15 changes: 15 additions & 0 deletions resource-timing/resources/embed-navigate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing embed navigate</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_navigate_test();
</script>
<div id=log></div>
<embed type="text/html">
<script>
document.getElementsByTagName("embed")[0].src = pre_navigate_url;
</script>
15 changes: 15 additions & 0 deletions resource-timing/resources/embed-refresh.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing embed refresh</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_refresh_test();
</script>
<div id=log></div>
<embed type="text/html">
<script>
document.getElementsByTagName("embed")[0].src = pre_refresh_url;
</script>
14 changes: 14 additions & 0 deletions resource-timing/resources/iframe-navigate-back.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing iframe navigate - back button navigation</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_back_navigation("iframe-navigate-back.html");
</script>
<iframe></iframe>
<script>
document.getElementsByTagName("iframe")[0].src = pre_navigate_url;
</script>
15 changes: 15 additions & 0 deletions resource-timing/resources/iframe-navigate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing iframe navigate</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_navigate_test();
</script>
<div id=log></div>
<iframe></iframe>
<script>
document.getElementsByTagName("iframe")[0].src = pre_navigate_url;
</script>
15 changes: 15 additions & 0 deletions resource-timing/resources/iframe-refresh.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing iframe refresh</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_refresh_test();
</script>
<div id=log></div>
<iframe></iframe>
<script>
document.getElementsByTagName("iframe")[0].src = pre_refresh_url;
</script>
7 changes: 7 additions & 0 deletions resource-timing/resources/navigate_back.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>
window.onload = function() {history.back();}
</script>
95 changes: 95 additions & 0 deletions resource-timing/resources/nested-contexts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
let destination = location;
if (location.search == "?crossorigin") {
host_info = get_host_info()
yoavweiss marked this conversation as resolved.
Show resolved Hide resolved
destination = location.protocol + "//" + host_info["REMOTE_HOST"] + ":" + location.port;
Copy link
Contributor

Choose a reason for hiding this comment

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

As a followup, it might be good to have not-samesite tests here too, just to test the cross-process case. hostinfo does not expose NOTSAMESITE_HOST at the moment, so that would need to get fixed too... I filed #15819 on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

But this test is already cross-origin between localhost and some other host, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC, @bzbarsky was asking for cross-origin and cross-site tests (so using hosts that have different domains)

Copy link
Contributor

Choose a reason for hiding this comment

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

Right but this test is both cross-origin and cross-site if runs from localhost. Maybe what's missing is same-site cross-origin?

Copy link
Contributor

@bzbarsky bzbarsky Feb 8, 2022

Choose a reason for hiding this comment

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

This test does not normally run "from localhost". It runs from one of the defined test hosts in the test configuration. Specifically, from whatever {{host}} expands to. Depends on the harness what that is, but it's generally not localhost, but something more like web-platform.test or wpt.live or whatnot, depending on the test runner configuration.

Copy link
Contributor

@bzbarsky bzbarsky Feb 8, 2022

Choose a reason for hiding this comment

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

And for details, see the get_host_info function's implementation and ORIGINAL_HOST and REMOTE_HOST and NOTSAMESITE_HOST in there. It has provisions for what to do if running from localhost, but also provisions for what to do in other cases. So yes, when running from localhost the test is testing the cross-site case and can't test the same-site cross-origin case at all.... which is why you should not be running these tests from localhost: a bunch of them will fail due to the lack of an available same-site cross-origin host in that setup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. I wasn't aware of these details. Thanks!

}

const pre_navigate_url = new URL("/resource-timing/resources/document-that-navigates.html", destination).href;
const post_navigate_url = new URL("/resource-timing/resources/document-navigated.html", destination).href;
const pre_refresh_url = new URL("/resource-timing/resources/document-that-refreshes.html", destination).href;
const post_refresh_url = new URL("/resource-timing/resources/document-refreshed.html", destination).href;

function setup_navigate_or_refresh(type, pre, post) {
function verify_document_navigate_not_observable() {
let entries = performance.getEntriesByType("resource");
let found_first_document = false;
for (entry of entries) {
if (entry.name == pre) {
found_first_document = true;
}
if (entry.name == post) {
opener.postMessage("FAIL - " + type + " document should not be observable", "*");
return;
}
}
if (!found_first_document) {
opener.postMessage("FAIL - initial document should be observable", "*");
return;
}
opener.postMessage("PASS", "*");
}
window.addEventListener("message", e=>{
if (e.data == type) {
verify_document_navigate_not_observable();
}
});
}

function setup_navigate_test() {
setup_navigate_or_refresh("navigated", pre_navigate_url, post_navigate_url);
}

function setup_refresh_test() {
setup_navigate_or_refresh("refreshed", pre_refresh_url, post_refresh_url);
}

function setup_back_navigation(pushed_url) {
function verify_document_navigate_not_observable() {
let entries = performance.getEntriesByType("resource");
let found_first_document = false;
for (entry of entries) {
if (entry.name == pre_navigate_url) {
found_first_document = true;
}
if (entry.name == post_navigate_url) {
opener.postMessage("FAIL - navigated document exposed", "*");
return;
}
}
if (!found_first_document) {
opener.postMessage("FAIL - first document not exposed", "*");
return;
}
opener.postMessage("PASS", "*");
}
window.addEventListener("message", e=>{
if (e.data == "navigated") {
if (sessionStorage.navigated) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might have been good to document somewhere the tight coupling between this and the exact test-serialization behavior we get from using promise_test for everything, thus ensuring that we never touch sessionStorage from two different tests in a racy way.

delete sessionStorage.navigated;
verify_document_navigate_not_observable();
} else {
sessionStorage.navigated = true;
setTimeout(() => {
history.pushState({}, "", pushed_url);
location.href="navigate_back.html";
}, 0);
}
}
});
}

function open_test_window(url, message) {
promise_test(() => {
return new Promise((resolve, reject) => {
let openee = window.open(url);
addEventListener("message", e => {
openee.close();
if (e.data == "PASS") {
resolve();
} else {
reject(e.data);
}
});
});
}, message);
}
14 changes: 14 additions & 0 deletions resource-timing/resources/object-navigate-back.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing object navigate - back button navigation</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_back_navigation("object-navigate-back.html");
</script>
<object></object>
<script>
document.getElementsByTagName("object")[0].data = pre_navigate_url;
</script>
15 changes: 15 additions & 0 deletions resource-timing/resources/object-navigate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing object navigate</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_navigate_test();
</script>
<div id=log></div>
<object></object>
<script>
document.getElementsByTagName("object")[0].data = pre_navigate_url;
</script>
15 changes: 15 additions & 0 deletions resource-timing/resources/object-refresh.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing object refresh</title>
<script src="/common/get-host-info.sub.js"></script>
<script src="nested-contexts.js"></script>
<script>
setup_refresh_test();
</script>
<div id=log></div>
<object></object>
<script>
document.getElementsByTagName("object")[0].data = pre_refresh_url;
</script>