Skip to content

Commit

Permalink
[ResourceTiming]: Migrate redirects(.sub).html WPT
Browse files Browse the repository at this point in the history
This change updates the redirects.sub.html WPT to follow the new style
and structure we've been introducing in the linked bug.

Bug: 1171767
Change-Id: I28bb746d01872b7ba4585750d86fc4d5a8d9af9b
GithubIssue: w3c/resource-timing#254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2774478
Reviewed-by: Yoav Weiss <[email protected]>
Commit-Queue: Tom McKee <[email protected]>
Cr-Commit-Position: refs/heads/master@{#864435}
GitOrigin-RevId: baa9e3c1b188ea693609dbbc11600fa5c9159f65
  • Loading branch information
tommckee1 authored and copybara-github committed Mar 18, 2021
1 parent 2835135 commit 5e9fc8b
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 80 deletions.
20 changes: 0 additions & 20 deletions blink/web_tests/external/wpt/resource-timing/entry-attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,6 @@
<script src="resources/resource-loaders.js"></script>
<script src="resources/entry-invariants.js"></script>
<script>

// Given a resource-loader and a PerformanceResourceTiming validator, loads a
// resource and validates the resulting entry.
const attribute_test = (load_resource, validate, test_label) => {
promise_test(
async () => {
// Clear out everything that isn't the one ResourceTiming entry under test.
performance.clearResourceTimings();

await load_resource();

const entry_list = performance.getEntriesByType("resource");
if (entry_list.length != 1) {
throw new Error(`There should be one entry for one resource (found ${entry_list.length})`);
}

validate(entry_list[0]);
}, test_label);
}

attribute_test(
() => load.image("resources/fake_responses.py#hash=1"),
entry => {
Expand Down
61 changes: 61 additions & 0 deletions blink/web_tests/external/wpt/resource-timing/redirects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing: resources fetched through same-origin redirects</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<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 src="/common/get-host-info.sub.js"></script>
<script src="resources/resource-loaders.js"></script>
<script src="resources/entry-invariants.js"></script>
<script>
const {HTTPS_NOTSAMESITE_ORIGIN} = get_host_info();
const redirect_url = `/common/redirect.py`;
const url_prefix = `${redirect_url}?location=/resource-timing/resources/`;
const https_url_prefix = `${redirect_url}?location=${HTTPS_NOTSAMESITE_ORIGIN}/resource-timing/resources/`;

attribute_test(
() => load.stylesheet(url_prefix + "resource_timing_test0.css"),
invariants.assert_same_origin_redirected_resource,
"Verify attributes of a redirected stylesheet's PerformanceResourceTiming");

attribute_test(
() => load.image(url_prefix + "blue.png"),
invariants.assert_same_origin_redirected_resource,
"Verify attributes of a redirected image's PerformanceResourceTiming");

attribute_test(
() => load.iframe(url_prefix + "blank_page_green.html"),
invariants.assert_same_origin_redirected_resource,
"Verify attributes of a redirected iframe's PerformanceResourceTiming");

attribute_test(
() => load.script(url_prefix + "empty_script.js"),
invariants.assert_same_origin_redirected_resource,
"Verify attributes of a redirected script's PerformanceResourceTiming");

attribute_test(
() => load.xhr_sync(url_prefix + "blank_page_green.htm?id=xhr"),
invariants.assert_same_origin_redirected_resource,
"Verify attributes of a redirected synchronous XMLHttpRequest's " +
"PerformanceResourceTiming");

attribute_test(
() => load.xhr_sync(https_url_prefix + "blank_page_green.htm?id=xhr"),
invariants.assert_cross_origin_redirected_resource,
"Verify attributes of a synchronous XMLHttpRequest's " +
"PerformanceResourceTiming where the initial HTTP request is redirected " +
"to a cross-origin HTTPS resource."
);

</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates that, when a fetching resources that encounter
same-origin redirects, attributes of the PerformanceResourceTiming entry
conform to the specification.</p>
</body>
</html>
60 changes: 0 additions & 60 deletions blink/web_tests/external/wpt/resource-timing/redirects.sub.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,50 @@ const invariants = {
"domainLookupEnd",
"connectStart",
]);
},

// Asserts that attributes of the given PerformanceResourceTiming entry match
// what the spec dictates for any resource fetched over HTTPS through a
// cross-origin redirect.
// (e.g. GET http://remote.com/foo => 304 Location: https://remote.com/foo)
assert_cross_origin_redirected_resource: entry => {
assert_zeroed_(entry, [
"redirectStart",
"redirectEnd",
"domainLookupStart",
"domainLookupEnd",
"connectStart",
"connectEnd",
"secureConnectionStart",
"requestStart",
"responseStart",
]);

assert_positive_(entry, [
"fetchStart",
"responseEnd",
]);
}
};

// Given a resource-loader and a PerformanceResourceTiming validator, loads a
// resource and validates the resulting entry.
const attribute_test = (load_resource, validate, test_label) => {
promise_test(
async () => {
// Clear out everything that isn't the one ResourceTiming entry under test.
performance.clearResourceTimings();

await load_resource();

const entry_list = performance.getEntriesByType("resource");
if (entry_list.length != 1) {
const names = entry_list
.map(e => e.name)
.join(", ");
throw new Error(`There should be one entry for one resource (found ${entry_list.length}: ${names})`);
}

validate(entry_list[0]);
}, test_label);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,56 @@ const load = {
return document.fonts.ready.then(() => {
document.body.removeChild(div);
});
},

// Returns a promise that settles once the given path has been fetched as a
// stylesheet resource.
stylesheet: async path => {
const link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = path;

const loaded = new Promise(resolve => {
link.onload = link.onerror = resolve;
});

document.head.appendChild(link);
await loaded;
document.head.removeChild(link);
},

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

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

// Returns a promise that settles once the given path has been fetched
// through a synchronous XMLHttpRequest.
xhr_sync: async path => {
const xhr = new XMLHttpRequest;
xhr.open("GET", path, /* async = */ false);
xhr.send();
}
};

0 comments on commit 5e9fc8b

Please sign in to comment.