From 18b3aefc0a292043481ecfbbf1daf2c2a5ddd32f Mon Sep 17 00:00:00 2001 From: Tom McKee Date: Fri, 19 Mar 2021 22:09:51 +0000 Subject: [PATCH] Bug 1699559 [wpt PR 28140] - [ResourceTiming]: Migrate redirects(.sub).html WPT, a=testonly Automatic update from web-platform-tests [ResourceTiming]: Migrate redirects(.sub).html WPT 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: https://github.com/w3c/resource-timing/issues/254 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2774478 Reviewed-by: Yoav Weiss Commit-Queue: Tom McKee Cr-Commit-Position: refs/heads/master@{#864435} -- wpt-commits: 44d236ef8f04fadab87ce3ca8e5dd7d62708e90b wpt-pr: 28140 --- .../resource-timing/entry-attributes.html | 20 ------ .../tests/resource-timing/redirects.html | 61 +++++++++++++++++++ .../tests/resource-timing/redirects.sub.html | 60 ------------------ .../resources/entry-invariants.js | 45 ++++++++++++++ .../resources/resource-loaders.js | 51 ++++++++++++++++ 5 files changed, 157 insertions(+), 80 deletions(-) create mode 100644 testing/web-platform/tests/resource-timing/redirects.html delete mode 100644 testing/web-platform/tests/resource-timing/redirects.sub.html diff --git a/testing/web-platform/tests/resource-timing/entry-attributes.html b/testing/web-platform/tests/resource-timing/entry-attributes.html index e667c638dd4d..1115b7f56f72 100644 --- a/testing/web-platform/tests/resource-timing/entry-attributes.html +++ b/testing/web-platform/tests/resource-timing/entry-attributes.html @@ -9,26 +9,6 @@ + + + + + + + +

Description

+

This test validates that, when a fetching resources that encounter +same-origin redirects, attributes of the PerformanceResourceTiming entry +conform to the specification.

+ + diff --git a/testing/web-platform/tests/resource-timing/redirects.sub.html b/testing/web-platform/tests/resource-timing/redirects.sub.html deleted file mode 100644 index d3d4f75c817d..000000000000 --- a/testing/web-platform/tests/resource-timing/redirects.sub.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - -Resource Timing redirect names - - - - - - - - - -

Description

-

This test validates that redirects do not alter the URL.

-
- - - diff --git a/testing/web-platform/tests/resource-timing/resources/entry-invariants.js b/testing/web-platform/tests/resource-timing/resources/entry-invariants.js index 26701ee757e9..51d94e3a9d71 100644 --- a/testing/web-platform/tests/resource-timing/resources/entry-invariants.js +++ b/testing/web-platform/tests/resource-timing/resources/entry-invariants.js @@ -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); +} diff --git a/testing/web-platform/tests/resource-timing/resources/resource-loaders.js b/testing/web-platform/tests/resource-timing/resources/resource-loaders.js index 1d20d71209c7..c5754d1df53b 100644 --- a/testing/web-platform/tests/resource-timing/resources/resource-loaders.js +++ b/testing/web-platform/tests/resource-timing/resources/resource-loaders.js @@ -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(); } };