diff options
-rw-r--r-- | docshell/test/navigation/file_bug1379762-1.html | 32 | ||||
-rw-r--r-- | docshell/test/navigation/file_bug1379762-2.html | 43 | ||||
-rw-r--r-- | docshell/test/navigation/mochitest.ini | 1 | ||||
-rw-r--r-- | docshell/test/navigation/test_sessionhistory.html | 4 | ||||
-rw-r--r-- | layout/base/nsDocumentViewer.cpp | 15 | ||||
-rw-r--r-- | layout/base/nsPresContext.cpp | 13 |
6 files changed, 102 insertions, 6 deletions
diff --git a/docshell/test/navigation/file_bug1379762-1.html b/docshell/test/navigation/file_bug1379762-1.html new file mode 100644 index 000000000..e8cd8b30b --- /dev/null +++ b/docshell/test/navigation/file_bug1379762-1.html @@ -0,0 +1,32 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>Bug 1379762</title> + </head> + <img srcset> <!-- This tries to add load blockers during bfcache restoration --> + <script> + onunload = null; // enable bfcache + opener.is(opener.testCount, 0, + "We should only run once; otherwise the loadCount variable makes no sense"); + var loadCount = 0; + onpageshow = function() { + ++opener.testCount; + if (opener.testCount == 1) { + // Navigate forward and then back. + setTimeout(function() { location = "goback.html"; }, 0); + } else if (opener.testCount == 2) { + // Do this async so our load event gets a chance to fire if it plans to + // do it. + setTimeout(function() { + opener.nextTest(); + window.close(); + }); + } + }; + onload = function() { + ++loadCount; + opener.is(loadCount, 1, "Should only get one onload"); + } + </script> +</html> diff --git a/docshell/test/navigation/file_bug1379762-2.html b/docshell/test/navigation/file_bug1379762-2.html new file mode 100644 index 000000000..86033cb2e --- /dev/null +++ b/docshell/test/navigation/file_bug1379762-2.html @@ -0,0 +1,43 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>Bug 1379762</title> + </head> + <script type="text/just-data"> + onunload = null; // enable bfcache + ++opener.testCount; + onpageshow = function(e) { + opener.ok(!e.persisted, "Pageshow should not be coming from bfcache " + opener.testCount); + } + if (opener.testCount == 1) { + onload = function () { + setTimeout(function() { + document.write(testScript); + }, 0); + } + } else if (opener.testCount == 2) { + // Do this async, just in case. + setTimeout(function() { + history.back(); + }, 0); + } else if (opener.testCount == 3) { + // Do this async, just in case. + setTimeout(function() { + history.forward(); + }, 0); + } else if (opener.testCount == 4) { + onload = function() { + opener.nextTest(); + window.close(); + } + } + </script> + <script> + var data = document.querySelector("script[type='text/just-data']").textContent; + // Store the string that does all out work in a global variable, so we can + // get at it later. + var testScript = "<script>" + data + "</" + "script>"; + document.write(testScript); + </script> +</html> diff --git a/docshell/test/navigation/mochitest.ini b/docshell/test/navigation/mochitest.ini index 1b5f33c7f..8cff81ad1 100644 --- a/docshell/test/navigation/mochitest.ini +++ b/docshell/test/navigation/mochitest.ini @@ -59,6 +59,7 @@ skip-if = (toolkit == 'android') || (!debug && (os == 'mac' || os == 'win')) # B skip-if = (toolkit == 'android') || (debug && e10s) #too slow on Android 4.3 aws only; bug 1030403; bug 1263213 for debug e10s [test_sessionhistory.html] skip-if = toolkit == 'android' #RANDOM +support-files = file_bug1379762-1.html file_bug1379762-2.html [test_sibling-matching-parent.html] [test_sibling-off-domain.html] [test_triggeringprincipal_frame_nav.html] diff --git a/docshell/test/navigation/test_sessionhistory.html b/docshell/test/navigation/test_sessionhistory.html index 452271a41..10b0cbcaf 100644 --- a/docshell/test/navigation/test_sessionhistory.html +++ b/docshell/test/navigation/test_sessionhistory.html @@ -31,7 +31,9 @@ var testFiles = "file_nested_frames.html", "file_shiftReload_and_pushState.html", "file_scrollRestoration.html", - "file_bug1300461.html" + "file_bug1300461.html", + "file_bug1379762-1.html", + "file_bug1379762-2.html", ]; var testCount = 0; // Used by the test files. diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 137efb3cd..7b8734928 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -1012,7 +1012,13 @@ nsDocumentViewer::LoadComplete(nsresult aStatus) nsIDocShell *docShell = window->GetDocShell(); NS_ENSURE_TRUE(docShell, NS_ERROR_UNEXPECTED); - docShell->GetRestoringDocument(&restoring); + // Unfortunately, docShell->GetRestoringDocument() might no longer be set + // correctly. In particular, it can be false by now if someone took it upon + // themselves to block onload from inside restoration and unblock it later. + // But we can detect the restoring case very simply: by whether our + // document's readyState is COMPLETE. + restoring = (mDocument->GetReadyStateEnum() == + nsIDocument::READYSTATE_COMPLETE); if (!restoring) { NS_ASSERTION(mDocument->IsXULDocument() || // readyState for XUL is bogus mDocument->GetReadyStateEnum() == @@ -1023,6 +1029,13 @@ nsDocumentViewer::LoadComplete(nsresult aStatus) nsIDocument::READYSTATE_UNINITIALIZED && NS_IsAboutBlank(mDocument->GetDocumentURI())), "Bad readystate"); +#ifdef DEBUG + bool docShellThinksWeAreRestoring; + docShell->GetRestoringDocument(&docShellThinksWeAreRestoring); + MOZ_ASSERT(!docShellThinksWeAreRestoring, + "How can docshell think we are restoring if we don't have a " + "READYSTATE_COMPLETE document?"); +#endif // DEBUG nsCOMPtr<nsIDocument> d = mDocument; mDocument->SetReadyStateInternal(nsIDocument::READYSTATE_COMPLETE); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 4a54a8432..3106ff386 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1307,10 +1307,15 @@ nsPresContext::SetFullZoom(float aZoom) void nsPresContext::SetOverrideDPPX(float aDPPX) { - mOverrideDPPX = aDPPX; - - if (HasCachedStyleData()) { - MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0)); + // SetOverrideDPPX is called during navigations, including history + // traversals. In that case, it's typically called with our current value, + // and we don't need to actually do anything. + if (aDPPX != mOverrideDPPX) { + mOverrideDPPX = aDPPX; + + if (HasCachedStyleData()) { + MediaFeatureValuesChanged(nsRestyleHint(0), nsChangeHint(0)); + } } } |