blob: b8d3371a4a92165f421db765a92595e63cebd195 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing: PerformanceResourceTiming attributes</title>
<link rel="help" href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// Returns a promise that settles once the given path has been fetched.
function load_image(path) {
return new Promise(resolve => {
const img = new Image();
img.onload = img.onerror = resolve;
img.src = path;
});
}
function assert_ordered(entry, attributes) {
let before = attributes[0];
attributes.slice(1).forEach(after => {
assert_greater_than_equal(entry[after], entry[before],
`${after} should be greater than ${before}`);
before = after;
});
}
function assert_zeroed(entry, attributes) {
attributes.forEach(attribute => {
assert_equals(entry[attribute], 0, `${attribute} should be 0`);
});
}
function assert_not_negative(entry, attributes) {
attributes.forEach(attribute => {
assert_greater_than_equal(entry[attribute], 0,
`${attribute} should be greater than or equal to 0`);
});
}
function assert_positive(entry, attributes) {
attributes.forEach(attribute => {
assert_greater_than(entry[attribute], 0,
`${attribute} should be greater than 0`);
});
}
function assert_http_resource(entry) {
assert_ordered(entry, [
"fetchStart",
"domainLookupStart",
"domainLookupEnd",
"connectStart",
"connectEnd",
"requestStart",
"responseStart",
"responseEnd",
]);
assert_zeroed(entry, [
"workerStart",
"secureConnectionStart",
"redirectStart",
"redirectEnd",
]);
assert_not_negative(entry, [
"duration",
]);
assert_positive(entry, [
"fetchStart",
"transferSize",
"encodedBodySize",
"decodedBodySize",
]);
}
promise_test(async () => {
// Clean up entries from scripts includes.
performance.clearResourceTimings();
await load_image("resources/fake_responses.py#hash=1");
const entry_list = performance.getEntriesByType("resource");
if (entry_list.length != 1) {
throw new Error("There should be one entry for one resource");
}
const entry = entry_list[0];
assert_true(entry.name.includes('#hash=1'),
"There should be a hash in the resource name");
assert_http_resource(entry);
}, "URL fragments should be present in the 'name' attribute");
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates that PerformanceResourceTiming entries' attributes are
populated with the correct values.</p>
</body>
</html>