Skip to content

Commit

Permalink
[resource timing] Improve document.domain tests (reland)
Browse files Browse the repository at this point in the history
This CL is a fixed up reland of [1], which was reverted due to a rename
in entry-invariants.js that it was relying on.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2878852

Bug: 1171767, 1208054
Change-Id: I436bf6973e4399d142ce45e77c07f26d0e7e1cd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2888667
Reviewed-by: Tom McKee <[email protected]>
Commit-Queue: Yoav Weiss <[email protected]>
Cr-Commit-Position: refs/heads/master@{#881945}
  • Loading branch information
Yoav Weiss authored and chromium-wpt-export-bot committed May 12, 2021
1 parent f0f68ba commit 1afbd7a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 56 deletions.
1 change: 1 addition & 0 deletions common/get-host-info.sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function get_host_info() {
HTTPS_ORIGIN_WITH_CREDS: 'https://foo:bar@' + ORIGINAL_HOST + HTTPS_PORT_ELIDED,
HTTP_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + ORIGINAL_HOST + HTTP_PORT2_ELIDED,
REMOTE_ORIGIN: PROTOCOL + "//" + REMOTE_HOST + PORT_ELIDED,
OTHER_ORIGIN: PROTOCOL + "//" + OTHER_HOST + PORT_ELIDED,
HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + HTTP_PORT_ELIDED,
HTTP_NOTSAMESITE_ORIGIN: 'http://' + NOTSAMESITE_HOST + HTTP_PORT_ELIDED,
HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + REMOTE_HOST + HTTP_PORT2_ELIDED,
Expand Down
15 changes: 0 additions & 15 deletions resource-timing/document-domain-no-impact-loader.sub.html

This file was deleted.

16 changes: 16 additions & 0 deletions resource-timing/document-domain-no-impact-opener.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
// Open a document on one of hosts on the web-platform test domain, so that
// document.domain will set a valid domain, turning the frame into a
// cross-origin frame.
const {OTHER_ORIGIN} = get_host_info();
const openee = window.open(OTHER_ORIGIN +
"/resource-timing/resources/document-domain-no-impact.html");
fetch_tests_from_window(openee);
</script>
28 changes: 28 additions & 0 deletions resource-timing/resources/document-domain-no-impact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="resource-loaders.js"></script>
<script src="entry-invariants.js"></script>
<body>
<script>
const path = location.origin +
"/resource-timing/resources/iframe-setdomain.sub.html";
attribute_test_with_validator(load.iframe, path,
el => {
try {
el.contentWindow.document;
throw new Error("iframe document.domain was not set");
} catch(error) {
if (error.name != "SecurityError") {
throw(error);
}
}
},
invariants.assert_tao_pass_no_redirect,
"test that document.domain being set doesn't have an impact on the " +
"resource timing entry."
);
</script>

33 changes: 0 additions & 33 deletions resource-timing/resources/document-domain-no-impact.sub.html

This file was deleted.

24 changes: 17 additions & 7 deletions resource-timing/resources/entry-invariants.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ const invariants = {
}
};

// Given a resource-loader, a path (a relative path or absolute URL), and a
// PerformanceResourceTiming validator, applies the loader to the resource path
// and applies the validator to the resulting PerformanceResourceTiming entry.
const attribute_test = (loader, path, validate, test_label) => {
const attribute_test_internal = (loader, path, validator, run_test, test_label) => {
promise_test(
async () => {
let loaded_entry = new Promise((resolve, reject) => {
Expand All @@ -190,8 +187,21 @@ const attribute_test = (loader, path, validate, test_label) => {
}).observe({"type": "resource"});
});

await loader(path);
await loader(path, validator);
const entry = await(loaded_entry);
validate(entry);
run_test(entry);
}, test_label);
}
};

// Given a resource-loader, a path (a relative path or absolute URL), and a
// PerformanceResourceTiming test, applies the loader to the resource path
// and tests the resulting PerformanceResourceTiming entry.
const attribute_test = (loader, path, run_test, test_label) => {
attribute_test_internal(loader, path, () => {}, run_test, test_label);
};

// Similar to attribute test, but on top of that, validates the added element,
// to ensure the test does what it intends to do.
const attribute_test_with_validator = (loader, path, validator, run_test, test_label) => {
attribute_test_internal(loader, path, validator, run_test, test_label);
};
5 changes: 4 additions & 1 deletion resource-timing/resources/resource-loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ const load = {

// Returns a promise that settles once the given path has been fetched as an
// iframe.
iframe: async path => {
iframe: async (path, validator) => {
const frame = document.createElement("iframe");
const loaded = new Promise(resolve => {
frame.onload = frame.onerror = resolve;
});
frame.src = load.cache_bust(path);
document.body.appendChild(frame);
await loaded;
if (validator instanceof Function) {
validator(frame);
}
document.body.removeChild(frame);
},

Expand Down

0 comments on commit 1afbd7a

Please sign in to comment.