Skip to content

Commit

Permalink
Bug 1831752 [wpt PR 39878] - Add location.reload() document state tes…
Browse files Browse the repository at this point in the history
…t, a=testonly

Automatic update from web-platform-tests
Add location.reload() document state test

This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

R=domenicchromium.org

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <domenicchromium.org>
Auto-Submit: Dominic Farolino <domchromium.org>
Reviewed-by: Domenic Denicola <domenicchromium.org>
Cr-Commit-Position: refs/heads/main{#1145759}

--

wpt-commits: d9c2152bab4d2933e38c8df3c95d967c40809f8c
wpt-pr: 39878

UltraBlame original commit: 2342752e35cc28fc870b3576d5d7a22b9f92e7fd
  • Loading branch information
marco-c committed May 31, 2023
1 parent 2377159 commit 6e492b3
Showing 1 changed file with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,50 @@
'Same-origin forward history navigation to a document whose original ' +
'initiator was cross-site ends up with document.referrer that is the ' +
'original cross-site initiator');
}, "A navigation's initiator origin and referrer are stored in the document state");
}, "A navigation's initiator origin and referrer are stored in the document " +
"state and used in the document repopulation case");

// This test is similar to the above, but instead of testing for the true
// history entry -> document state -> document repopulation case, we stay on [B]
// (the document who was navigated to from [A]) and run `location.reload()` to
// confirm that the initiator information from the [A] -> [B] navigation is used
// when reloading [B], not [B]'s own same-origin information.
promise_test(async t => {
const rcHelper = new RemoteContextHelper();
const A = await rcHelper.addWindow();

const originA = new URL(await A.executeScript(() => location.href)).origin;

// Create B on a new origin.
const B = await A.navigateToNew({
origin: 'HTTPS_NOTSAMESITE_ORIGIN',
});

const originB = new URL(await B.executeScript(() => location.href)).origin;
assert_not_equals(originA, originB, 'Contexts A and B are cross-origin');

// Reload B.
await B.navigate(() => {
location.reload();
}, []);

const secFetchSite = await B.executeScript(() => window.requestHeaders['sec-fetch-site']);
const referrer = await B.executeScript(() => window.requestHeaders['referer']);
const documentReferrer = await B.executeScript(() => document.referrer);

assert_equals(secFetchSite, 'cross-site',
'Same-origin forward history navigation to a document whose original ' +
'initiator was cross-site, ends up with Sec-Fetch-Dest: cross-site ' +
'header');
assert_equals(referrer, originA + '/',
'Same-origin forward history navigation to a document whose original ' +
'initiator was cross-site ends up with the Referer header that is the ' +
'original cross-site initiator');
assert_equals(documentReferrer, originA + '/',
'Same-origin forward history navigation to a document whose original ' +
'initiator was cross-site ends up with document.referrer that is the ' +
'original cross-site initiator');
}, "A navigation's initiator origin and referrer are stored in the document " +
"state and used on location.reload()");
</script>
</body>

0 comments on commit 6e492b3

Please sign in to comment.