Skip to content

Commit

Permalink
[resource-timing] Improve object related tests and timeouts
Browse files Browse the repository at this point in the history
This CL applies the following improvements to resource-timing's tests:
* Removes console logging
* Remove spurious timeout logs when no timeouts occur
* Deflake Firefox by ensuring delays of over 1ms happen between measured
timestamps.

Bug: 1408635
Change-Id: Ifb706e01c510a16cdcae6aca7ae7aa64944dbc4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4187177
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Yoav Weiss <yoavweiss@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096682}
  • Loading branch information
Yoav Weiss authored and Chromium LUCI CQ committed Jan 25, 2023
1 parent e56b210 commit 5257021
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 625 deletions.
2 changes: 0 additions & 2 deletions third_party/blink/web_tests/external/wpt/lint.ignore
Expand Up @@ -116,8 +116,6 @@ CONSOLE: service-workers/service-worker/navigation-redirect.https.html
CONSOLE: service-workers/service-worker/resources/clients-get-other-origin.html
CONSOLE: webrtc/tools/*
CONSOLE: webaudio/resources/audit.js:41
CONSOLE: resource-timing/resources/resource-loaders.js
CONSOLE: resource-timing/resources/entry-invariants.js

# use of console in a public library - annotation-model ensures
# it is not actually used
Expand Down
Expand Up @@ -19,13 +19,19 @@
const blank_page = `/resource-timing/resources/blank_page_green.htm`;
const destUrl = `/common/slow-redirect.py?delay=${delay}&location=${REMOTE_ORIGIN}/${blank_page}`;

const timeBefore = performance.now()
attribute_test(load.iframe, destUrl, entry => {
assert_equals(entry.startTime, entry.fetchStart, 'startTime and fetchStart should be equal');
assert_greater_than(entry.startTime, timeBefore, 'startTime and fetchStart should be greater than the time before fetching');
// See https://github.com/w3c/resource-timing/issues/264
assert_less_than(Math.round(entry.startTime - timeBefore), delay * 1000, 'startTime should not expose redirect delays');
}, "Verify that cross-origin resources don't implicitly expose their redirect timings")
const timeBefore = performance.now();
(async () => {
// Wait 10 ms, to ensure the difference between startTime and timeBefore is
// larger than 1 ms, to avoid flakiness in browsers that clamp timestamps to
// 1 ms.
await new Promise(r => step_timeout(r, 10));
attribute_test(load.iframe, destUrl, entry => {
assert_equals(entry.startTime, entry.fetchStart, 'startTime and fetchStart should be equal');
assert_greater_than(entry.startTime, timeBefore, 'startTime and fetchStart should be greater than the time before fetching');
// See https://github.com/w3c/resource-timing/issues/264
assert_less_than(Math.round(entry.startTime - timeBefore), delay * 1000, 'startTime should not expose redirect delays');
}, "Verify that cross-origin resources don't implicitly expose their redirect timings")
})();

</script>
</body>
Expand Down
Expand Up @@ -23,13 +23,19 @@
}
const destUrl = `/common/slow-redirect.py?delay=${delay}&location=${REMOTE_ORIGIN}${not_found_page}`;

const timeBefore = performance.now()
attribute_test(load_null_object, destUrl, entry => {
assert_equals(entry.startTime, entry.fetchStart, 'startTime and fetchStart should be equal');
assert_greater_than(entry.startTime, timeBefore, 'startTime and fetchStart should be greater than the time before fetching');
// See https://github.com/w3c/resource-timing/issues/264
assert_less_than(Math.round(entry.startTime - timeBefore), delay * 1000, 'startTime should not expose redirect delays');
}, "Verify that cross-origin object resources don't implicitly expose their redirect timings")
const timeBefore = performance.now();
(async () => {
// Wait 10 ms, to ensure the difference between startTime and timeBefore is
// larger than 1 ms, to avoid flakiness in browsers that clamp timestamps to
// 1 ms.
await new Promise(r => step_timeout(r, 10));
attribute_test(load_null_object, destUrl, entry => {
assert_equals(entry.startTime, entry.fetchStart, 'startTime and fetchStart should be equal');
assert_greater_than(entry.startTime, timeBefore, 'startTime and fetchStart should be greater than the time before fetching');
// See https://github.com/w3c/resource-timing/issues/264
assert_less_than(Math.round(entry.startTime - timeBefore), delay * 1000, 'startTime should not expose redirect delays');
}, "Verify that cross-origin object resources don't implicitly expose their redirect timings")
})();

</script>
</body>
Expand Down
@@ -1,3 +1,19 @@
const await_with_timeout = async (delay, message, promise, cleanup = ()=>{}) => {
let timeout_id;
const timeout = new Promise((_, reject) => {
timeout_id = step_timeout(() =>
reject(new DOMException(message, "TimeoutError")), delay)
});
let result = null;
try {
result = await Promise.race([promise, timeout]);
clearTimeout(timeout_id);
} finally {
cleanup();
}
return result;
};

// Asserts that the given attributes are present in 'entry' and hold equal
// values.
const assert_all_equal_ = (entry, attributes) => {
Expand Down Expand Up @@ -451,12 +467,10 @@ const attribute_test_internal = (loader, path, validator, run_test, test_label)
});

await loader(path, validator);
const timeout = new Promise(r => step_timeout(() => {
console.log("Timeout was reached before entry fired");
r(null);
}, 2000));
const entry = await Promise.race([loaded_entry, timeout]);
assert_not_equals(entry, null, 'No entry was recieved');
const entry = await await_with_timeout(2000,
"Timeout was reached before entry fired",
loaded_entry);
assert_not_equals(entry, null, 'No entry was received');
run_test(entry);
}, test_label);
};
Expand Down
Expand Up @@ -135,20 +135,19 @@ const load = {
// object.
object: async (path, type) => {
const object = document.createElement("object");
const loaded = new Promise(resolve => {
const object_load_settled = new Promise(resolve => {
object.onload = object.onerror = resolve;
});
object.data = load.cache_bust(path);
if (type) {
object.type = type;
}
document.body.appendChild(object);
const timeout = new Promise(r => step_timeout(() => {
console.log("Timeout was reached before load or error events fired");
r();
}, 2000));
await Promise.race([loaded, timeout]);
document.body.removeChild(object);
await await_with_timeout(2000,
"Timeout was reached before load or error events fired",
object_load_settled,
() => { document.body.removeChild(object) }
);
},

// Returns a promise that settles once the given path has been fetched
Expand Down
Expand Up @@ -24,6 +24,10 @@
return load.object(path, "image/png");
}

const load_frame_object = async path => {
return load.object(path, "text/html");
}

const load_null_object = async path => {
return load.object(path, null);
}
Expand All @@ -38,6 +42,7 @@
load.xhr_async,
load.iframe,
load_image_object,
load_frame_object,
load_null_object
]) {
for(const status of status_codes) {
Expand Down Expand Up @@ -88,6 +93,7 @@
load.stylesheet,
load.iframe,
load_image_object,
load_frame_object,
load_null_object
]) {
for(const tao of [false, true]) {
Expand All @@ -113,6 +119,7 @@
// Same-Origin => Cross-Origin => Same-Origin => Same-Origin redirect chain
for(const loader of [
load.iframe,
load_frame_object,
load_null_object
]) {
for(const status of status_codes) {
Expand All @@ -136,6 +143,7 @@
// Response status for iframes is exposed for same origin redirects
for(const loader of [
load.iframe,
load_frame_object,
load_null_object
]) {
for(const status of status_codes) {
Expand Down

0 comments on commit 5257021

Please sign in to comment.