diff --git a/testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/document-state.tentative.https.html b/testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/document-state.https.html similarity index 67% rename from testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/document-state.tentative.https.html rename to testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/document-state.https.html index d0e629f631245..609ce9b850369 100644 --- a/testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/document-state.tentative.https.html +++ b/testing/web-platform/tests/html/browsers/browsing-the-web/history-traversal/document-state.https.html @@ -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()");