Skip to content

Commit

Permalink
[resource-timing] Fix negative duration case
Browse files Browse the repository at this point in the history
Bug: 1157818
Change-Id: Ie5e75ccb239735f3500f8763e4d9255eba2056e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592792
Commit-Queue: Yoav Weiss <yoavweiss@chromium.org>
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841159}
  • Loading branch information
Yoav Weiss authored and chromium-wpt-export-bot committed Jan 7, 2021
1 parent 188bf17 commit d9a933a
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 2 deletions.
1 change: 1 addition & 0 deletions fonts/Ahem.ttf.headers
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Access-Control-Allow-Origin: *
Cache-Control: max-age=3600
Timing-Allow-Origin: *
1 change: 1 addition & 0 deletions lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ MISSING DEPENDENCY: webxr/resources/webxr_util.js

# Tests that are false positives for using Ahem as a system font
AHEM SYSTEM FONT: acid/acid3/test.html
AHEM SYSTEM FONT: resource-timing/font-timestamps.html
AHEM SYSTEM FONT: resource-timing/resources/all_resource_types.htm
AHEM SYSTEM FONT: resource-timing/resources/iframe-reload-TAO.sub.html
AHEM SYSTEM FONT: html/canvas/element/drawing-text-to-the-canvas/2d.text.measure.fontBoundingBox.ahem.html
Expand Down
65 changes: 65 additions & 0 deletions resource-timing/fetch-cross-origin-redirect.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test cross-origin fetch redirects have the right values.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
const run_test = async (t, url, cross_origin) => {
// Set up PerformanceObserver
const href = new URL(url).href;
const setPerformanceObserver = new Promise(resolve => {
const po = new PerformanceObserver(resolve);
po.observe({type: "resource"});
});

// Fetch the resource
await fetch(href, {mode: "no-cors", credentials: "include" });

// Wait for an entry
const timeout = new Promise(resolve => t.step_timeout(resolve, 1000));
const list = await Promise.race([setPerformanceObserver, timeout]);
assert_equals(typeof(list), "object", "No iframe entry was fired");
const entries = list.getEntriesByName(url);
assert_equals(entries.length, 1);

// Test entry values
const entry = entries[0];
if (cross_origin) {
assert_equals(entry.redirectStart, 0, "redirectStart should be 0 in cross-origin redirect.");
assert_equals(entry.redirectEnd, 0, "redirectEnd should be 0 in cross-origin redirect.");
assert_equals(entry.domainLookupStart, 0, "domainLookupStart should be 0 in cross-origin redirect.");
assert_equals(entry.domainLookupEnd, 0, "domainLookupEnd should be 0 in cross-origin redirect.");
assert_equals(entry.connectStart, 0, "connectStart should be 0 in cross-origin redirect.");
assert_equals(entry.connectEnd, 0, "connectEnd should be 0 in cross-origin redirect.");
assert_equals(entry.requestStart, 0, "requestStart should be 0 in cross-origin redirect.");
assert_equals(entry.responseStart, 0, "responseStart should be 0 in cross-origin redirect.");
assert_equals(entry.secureConnectionStart, 0, "secureConnectionStart should be 0 in cross-origin redirect.");
} else {
assert_greater_than(entry.redirectStart, 0, "redirectStart should be more than 0 in same-origin redirect.");
assert_greater_than(entry.redirectEnd, 0, "redirectEnd should be more than 0 in same-origin redirect.");
assert_greater_than(entry.domainLookupStart, 0, "domainLookupStart should be more than 0 in same-origin redirect.");
assert_greater_than(entry.domainLookupEnd, 0, "domainLookupEnd should be more than 0 in same-origin redirect.");
assert_greater_than(entry.connectStart, 0, "connectStart should be more than 0 in same-origin redirect.");
assert_greater_than(entry.connectEnd, 0, "connectEnd should be more than 0 in same-origin redirect.");
assert_greater_than(entry.requestStart, 0, "requestStart should be more than 0 in same-origin redirect.");
assert_greater_than(entry.responseStart, 0, "responseStart should be more than 0 in same-origin redirect.");
assert_greater_than(entry.secureConnectionStart, 0, "secureConnectionStart should be more than 0 in same-origin redirect.");
}
assert_greater_than(entry.fetchStart, 0, "fetchStart should be greater than 0 in redirects.");
assert_greater_than(entry.responseEnd, 0, "responseEnd should be greater than 0 in redirects.");
assert_greater_than(entry.duration, 0, "duration should be greater than 0 in redirects.");
assert_greater_than(entry.responseEnd, entry.fetchStart, "responseEnd should be greater than fetchStart in redirects.");
}

const {REMOTE_ORIGIN, ORIGIN} = get_host_info();
const redirect = "/common/redirect.py?location=" + "/resource-timing/resources/blank_page_green.htm";
const cross_origin_redirect = REMOTE_ORIGIN + redirect;
const same_origin_redirect = ORIGIN + redirect;
promise_test(t => {
return run_test(t, cross_origin_redirect, true);
}, "Test fetch for a cross-origin redirect URL");
promise_test(t => {
return run_test(t, same_origin_redirect, false);
}, "Test fetch for a same-origin redirect URL");
</script>
62 changes: 62 additions & 0 deletions resource-timing/font-timestamps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test cross-origin fetch redirects have the right values.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<body>
<script>
const load_font = url => {
document.body.innerHTML = `
<style>
@font-face {
font-family: ahem;
src: url('${url}');
}
</style>
<div style="font-family: ahem;">This fetches ahem font.</div>
`;
return document.fonts.ready;
};

const run_test = async (t, url) => {
// Set up PerformanceObserver
const href = new URL(url).href;
const setPerformanceObserver = new Promise(resolve => {
const po = new PerformanceObserver(resolve);
po.observe({type: "resource"});
});

// Load the font resource and wait for it to be fetched.
await load_font(href);

// Wait for an entry
const timeout = new Promise(resolve => t.step_timeout(resolve, 3000));
const list = await Promise.race([setPerformanceObserver, timeout]);
assert_equals(typeof(list), "object", "No iframe entry was fired");
const entries = list.getEntriesByName(url);
assert_equals(entries.length, 1);

// Test entry values
const entry = entries[0];
assert_greater_than(entry.fetchStart, 0, "fetchStart should be greater than 0 in redirects.");
assert_greater_than_equal(entry.domainLookupStart, entry.fetchStart, "domainLookupStart should be more than 0 in same-origin redirect.");
assert_greater_than_equal(entry.domainLookupEnd, entry.domainLookupStart, "domainLookupEnd should be more than 0 in same-origin redirect.");
assert_greater_than_equal(entry.connectStart, entry.domainLookupEnd, "connectStart should be more than 0 in same-origin redirect.");
assert_greater_than_equal(entry.secureConnectionStart, entry.connectStart, "secureConnectionStart should be more than 0 in same-origin redirect.");
assert_greater_than_equal(entry.connectEnd, entry.secureConnectionStart, "connectEnd should be more than 0 in same-origin redirect.");
assert_greater_than_equal(entry.requestStart, entry.connectEnd, "requestStart should be more than 0 in same-origin redirect.");
assert_greater_than_equal(entry.responseStart, entry.requestStart, "responseStart should be more than 0 in same-origin redirect.");
assert_greater_than_equal(entry.responseEnd, entry.responseStart, "responseEnd should be greater than 0 in redirects.");
assert_greater_than_equal(entry.duration, 0, "duration should be greater than 0 in redirects.");
}

const {HTTPS_REMOTE_ORIGIN} = get_host_info();
promise_test(t => {
return run_test(t, HTTPS_REMOTE_ORIGIN + "/fonts/Ahem.ttf");
}, "Test a font's timestamps");

promise_test(t => {
return run_test(t, HTTPS_REMOTE_ORIGIN + "/resource-timing/resources/cors-ahem.py?pipe=trickle(d1)");
}, "Test a font's timestamps with delays");
</script>
1 change: 1 addition & 0 deletions resource-timing/iframe-failed-commit.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
assert_equals(typeof(list), "object", "No iframe entry was fired");
const entries = list.getEntriesByName(url);
assert_equals(entries.length, 1);
assert_greater_than(entries[0].duration, 0, "Duration greater than 0");
}

const {REMOTE_ORIGIN, ORIGINAL_HOST, HTTPS_PORT} = get_host_info();
Expand Down
1 change: 1 addition & 0 deletions resource-timing/resource_timing_cross_origin_redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
test_equals(entry.secureConnectionStart, 0, 'secureConnectionStart should be 0 in cross-origin redirect.');
test_greater_than(entry.fetchStart, 0, 'fetchStart should be greater than 0 in cross-origin redirect.');
test_greater_than(entry.responseEnd, 0, 'responseEnd should be greater than 0 in cross-origin redirect.');
test_greater_than(entry.responseEnd, entry.fetchStart, 'responseEnd should be greater than fetchStart in cross-origin redirect.');
done();
}
</script>
Expand Down
8 changes: 6 additions & 2 deletions resource-timing/status-codes-create-entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
window.addEventListener("load", t.step_func_done(() => {
const images = document.getElementsByTagName("img");
for (let img of images) {
assert_greater_than(performance.getEntriesByName(img.src).length, 0, img.src);
const entries = performance.getEntriesByName(img.src);
assert_greater_than(entries.length, 0, img.src);
assert_greater_than(entries[0].duration, 0, img.src);
}
const scripts = document.getElementsByTagName("script");
let noSrcScriptFound = false;
for (let script of scripts) {
if (script.src) {
assert_greater_than(performance.getEntriesByName(script.src).length, 0, script.src);
const entries = performance.getEntriesByName(script.src);
assert_greater_than(entries.length, 0, script.src);
assert_greater_than(entries[0].duration, 0, script.src);
} else {
// Ignore this script, which has no src value. There should only be one such script.
assert_false(noSrcScriptFound);
Expand Down

0 comments on commit d9a933a

Please sign in to comment.