Commit 2d090a27 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

[WPT/referrer-policy] Call getRequestURLs() for each subtest

Previously, getRequestURLs(), PolicyDelivery/Subresouce
object creation etc. were done once per test HTML file and
reused among multiple subtests.

This CL introduces invokeScenario() that does these things and
calls invokeScenario() for each subtest, and thus
calls getRequestURLs() for each subtest.

This removes hacky modifications to `subresource.url`
in 4K-referrer-length-related subtests to avoid cache hit.
Also this makes subresource URLs unique for
srcdoc-related subtests (previously the same image URL
was used).

Bug: 906850
Change-Id: I894a902338a90526678b70d01857103f46984189
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1723013
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690288}
parent b8deeb50
......@@ -51,6 +51,41 @@ function stripUrlForUseAsReferrer(url) {
return url.replace(/#.*$/, "");
}
function invokeScenario(scenario, sourceContextList) {
const originTypeConversion = {
"same-origin-http": "same-http",
"same-origin-https": "same-https",
"cross-origin-http": "cross-http",
"cross-origin-https": "cross-https"
};
const urls = getRequestURLs(
scenario.subresource,
originTypeConversion[scenario.origin + '-' + scenario.target_protocol],
scenario.redirection);
const deliveryTypeConversion = {
"attr-referrer": "attr",
"rel-noreferrer": "rel-noref",
// Other delivery methods such as "http-rp" are ignored here because
// they are already applied to the main document by generator.py.
};
/** @type {PolicyDelivery} */
const delivery = {
deliveryType: deliveryTypeConversion[scenario.delivery_method],
key: "referrerPolicy",
value: scenario.referrer_policy};
/** @type {Subresource} */
const subresource = {
subresourceType: scenario.subresource,
url: urls.testUrl,
policyDeliveries: [delivery]
};
return invokeRequest(subresource, sourceContextList || []);
}
function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
// Pass and skip rest of the test if browser does not support fetch.
if (scenario.subresource == "fetch-request" && !window.fetch) {
......@@ -66,17 +101,6 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
// This check is A NOOP in release.
sanityChecker.checkScenario(scenario);
const originTypeConversion = {
"same-origin-http": "same-http",
"same-origin-https": "same-https",
"cross-origin-http": "cross-http",
"cross-origin-https": "cross-https"
};
const urls = getRequestURLs(
scenario.subresource,
originTypeConversion[scenario.origin + '-' + scenario.target_protocol],
scenario.redirection);
const referrerUrlResolver = {
"omitted": function(sourceUrl) {
return undefined;
......@@ -89,15 +113,16 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
}
};
const checkResult = (expectedReferrerUrl, result) => {
// Check if the result is in valid format. NOOP in release.
sanityChecker.checkSubresourceResult(scenario, urls.testUrl, result);
const checkResult = (expectation, result) => {
let currentURL = location.toString();
const expectedReferrerUrl =
referrerUrlResolver[expectation](currentURL);
// Check the reported URL.
assert_equals(result.referrer,
expectedReferrerUrl,
"Reported Referrer URL is '" +
scenario.referrer_url + "'.");
expectation + "'.");
assert_equals(result.headers.referer,
expectedReferrerUrl,
"Reported Referrer URL from HTTP header is '" +
......@@ -105,30 +130,6 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
};
function runTest() {
const deliveryTypeConversion = {
"attr-referrer": "attr",
"rel-noreferrer": "rel-noref",
// Other delivery methods such as "http-rp" are ignored here because
// they are already applied to the main document by generator.py.
};
/** @type {PolicyDelivery} */
const delivery = {
deliveryType: deliveryTypeConversion[scenario.delivery_method],
key: "referrerPolicy",
value: scenario.referrer_policy};
/** @type {Subresource} */
const subresource = {
subresourceType: scenario.subresource,
url: urls.testUrl,
policyDeliveries: [delivery]
};
let currentURL = location.toString();
const expectedReferrer =
referrerUrlResolver[scenario.referrer_url](currentURL);
function historyBackPromise(t, scenario) {
history.back();
return new Promise(resolve => {
......@@ -148,43 +149,37 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
// Request in the top-level document.
promise_test(_ => {
return invokeRequest(subresource, [])
.then(result => checkResult(expectedReferrer, result));
return invokeScenario(scenario)
.then(result => checkResult(scenario.referrer_url, result));
}, testDescription);
// `Referer` headers with length over 4k are culled down to an origin, so, let's test around
// that boundary for tests that would otherwise return the complete URL.
// `Referer` headers with length over 4k are culled down to an origin, so,
// let's test around that boundary for tests that would otherwise return
// the complete URL.
// Different subresource URLs are used because getRequestURLs() is called
// for each sub test which returns a unique URL.
if (scenario.referrer_url == "stripped-referrer") {
promise_test(t => {
history.pushState(null, null, "/");
history.replaceState(null, null, "A".repeat(4096 - location.href.length - 1));
const expectedReferrer = location.href;
// Ensure that we don't load the same URL as the previous test.
subresource.url += "&-1";
return invokeRequest(subresource, [])
.then(result => checkResult(location.href, result))
return invokeScenario(scenario)
.then(result => checkResult(scenario.referrer_url, result))
.finally(_ => historyBackPromise(t, scenario));
}, "`Referer` header with length < 4k is not stripped to an origin.");
promise_test(t => {
history.pushState(null, null, "/");
history.replaceState(null, null, "A".repeat(4096 - location.href.length));
const expectedReferrer = location.href;
// Ensure that we don't load the same URL as the previous test.
subresource.url += "&0";
return invokeRequest(subresource, [])
.then(result => checkResult(expectedReferrer, result))
return invokeScenario(scenario)
.then(result => checkResult(scenario.referrer_url, result))
.finally(_ => historyBackPromise(t, scenario));
}, "`Referer` header with length == 4k is not stripped to an origin.");
promise_test(t => {
const originString = referrerUrlResolver["origin"](currentURL);
history.pushState(null, null, "/");
history.replaceState(null, null, "A".repeat(4096 - location.href.length + 1));
// Ensure that we don't load the same URL as the previous test.
subresource.url += "&+1";
return invokeRequest(subresource, [])
.then(result => checkResult(originString, result))
return invokeScenario(scenario)
.then(result => checkResult("origin", result))
.finally(_ => historyBackPromise(t, scenario));
}, "`Referer` header with length > 4k is stripped to an origin.");
}
......@@ -202,8 +197,8 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
/** @type {Array<SourceContext>} */
const sourceContextList = [{sourceContextType: "srcdoc"}];
return invokeRequest(subresource, sourceContextList)
.then(result => checkResult(expectedReferrer, result));
return invokeScenario(scenario, sourceContextList)
.then(result => checkResult(scenario.referrer_url, result));
}, testDescription + " (srcdoc iframe inherits parent)");
// Request in a `srcdoc` frame with its own referrer policy to
......@@ -214,16 +209,14 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
const overridingPolicy =
scenario.referrer_policy === "no-referrer" ? "unsafe-url"
: "no-referrer";
const overrridingExpectedReferrer =
referrerUrlResolver[overridingPolicy === "no-referrer"
? "omitted"
: "stripped-referrer"](location.toString());
const overrridingExpectation =
overridingPolicy === "no-referrer" ? "omitted"
: "stripped-referrer";
/** @type {Subresource} */
const subresourceWithoutDelivery = {
subresourceType: scenario.subresource,
url: urls.testUrl
};
const scenarioWithoutDelivery = Object.assign({}, scenario);
// Omit policy deliveries applied to subresource requests.
// This is hacky method but will be removed soon.
scenarioWithoutDelivery.delivery_method = null;
// <iframe srcdoc> with overriding <meta> referrerPolicy.
/** @type {Array<SourceContext>} */
......@@ -234,8 +227,8 @@ function ReferrerPolicyTestCase(scenario, testDescription, sanityChecker) {
value: overridingPolicy}]
}];
return invokeRequest(subresourceWithoutDelivery, sourceContextList)
.then(result => checkResult(overrridingExpectedReferrer, result));
return invokeScenario(scenarioWithoutDelivery, sourceContextList)
.then(result => checkResult(overrridingExpectation, result));
}, testDescription + " (overridden by srcdoc iframe)");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment