Bug 1459711: Ensure that navigation.performance.type is 2 when restoring a document from the session history. r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D39551

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Will Hawkins 2019-07-29 20:28:38 +00:00
parent 16912a4087
commit bfcfe34e57
6 changed files with 87 additions and 0 deletions

View File

@ -8075,6 +8075,11 @@ nsresult nsDocShell::RestoreFromHistory() {
// restart the timers for the window and all of the child frames.
privWinInner->Resume();
// Now that we have found the inner window of the page restored
// from the history, we have to make sure that
// performance.navigation.type is 2.
privWinInner->GetPerformance()->GetDOMTiming()->NotifyRestoreStart();
// Restore the refresh URI list. The refresh timers will be restarted
// when EndPageLoad() is called.
mRefreshURIList = refreshURIList;

View File

@ -54,6 +54,7 @@ support-files =
file_bug1375833.html
file_bug1375833-frame1.html
file_bug1375833-frame2.html
test_bug145971.html
[test_bug13871.html]
fail-if = fission
@ -82,6 +83,7 @@ fail-if = fission
[test_reserved.html]
fail-if = fission
skip-if = (toolkit == 'android') || (debug && e10s) || (os == 'mac' && os_version == '10.14') #too slow on Android 4.3 aws only; bug 1030403; bug 1263213 for debug e10s, macosx1014 due to 1548821
[test_performance_navigation.html]
[test_sessionhistory.html]
skip-if =
toolkit == 'android' || # RANDOM on android

View File

@ -0,0 +1,28 @@
<html>
<head>
<script>
let pass = false;
let initialLoad = false;
function checkNavigationTypeEquals2() {
if (performance.navigation.type == 2) {
pass = true;
}
testDone();
}
function testDone() {
opener.ok(pass, "Bug 145971: Navigation type does not equal 2 when restoring document from session history.");
opener.nextTest();
window.close();
}
function test() {
window.onpageshow = checkNavigationTypeEquals2;
window.location.href = 'goback.html';
}
</script>
</head>
<body onload="setTimeout(test, 0);">
Testing bug 145971.
</body>
</html>

View File

@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=
-->
<head>
<title>Test for Bug </title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="nextTest()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug **/
var testFiles =
[ "test_bug145971.html"
];
var testWindow;
function nextTest_() {
if (testFiles.length) {
let nextFile = testFiles.shift();
info("Running " + nextFile);
testWindow = window.open(nextFile, "", "width=360,height=480");
} else {
SimpleTest.finish();
}
}
function nextTest() {
setTimeout(nextTest_, 0);
}
</script>
</pre>
</body>
</html>

View File

@ -87,6 +87,10 @@ void nsDOMNavigationTiming::NotifyFetchStart(nsIURI* aURI,
mLoadedURI = aURI;
}
void nsDOMNavigationTiming::NotifyRestoreStart() {
mNavigationType = TYPE_BACK_FORWARD;
}
void nsDOMNavigationTiming::NotifyBeforeUnload() {
mBeforeUnloadStart = TimeStamp::Now();
}

View File

@ -122,6 +122,10 @@ class nsDOMNavigationTiming final : public mozilla::RelativeTimeline {
void NotifyNavigationStart(DocShellState aDocShellState);
void NotifyFetchStart(nsIURI* aURI, Type aNavigationType);
// A restoration occurs when the document is loaded from the
// bfcache. This method sets the appropriate parameters of the
// navigation timing object in this case.
void NotifyRestoreStart();
void NotifyBeforeUnload();
void NotifyUnloadAccepted(nsIURI* aOldURI);
void NotifyUnloadEventStart();