diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 492246ef394b..8025adb2d19f 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -2910,12 +2910,21 @@ void BrowsingContext::DidSet(FieldIndex) { nsDocShell::Cast(mDocShell)->MaybeDisconnectChildListenersOnPageHide(); } - PreOrderWalk([&](BrowsingContext* aContext) { - nsCOMPtr shell = aContext->GetDocShell(); - if (shell) { - nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(!isInBFCache); - } - }); + if (isInBFCache) { + PreOrderWalk([&](BrowsingContext* aContext) { + nsCOMPtr shell = aContext->GetDocShell(); + if (shell) { + nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(false); + } + }); + } else { + PostOrderWalk([&](BrowsingContext* aContext) { + nsCOMPtr shell = aContext->GetDocShell(); + if (shell) { + nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(true); + } + }); + } if (isInBFCache) { PreOrderWalk([&](BrowsingContext* aContext) { diff --git a/docshell/test/mochitest/file_bug1740516_1.html b/docshell/test/mochitest/file_bug1740516_1.html new file mode 100644 index 000000000000..cf3a54027bd3 --- /dev/null +++ b/docshell/test/mochitest/file_bug1740516_1.html @@ -0,0 +1,29 @@ + + + + + + + + + + diff --git a/docshell/test/mochitest/file_bug1740516_1_inner.html b/docshell/test/mochitest/file_bug1740516_1_inner.html new file mode 100644 index 000000000000..159c6bde5aec --- /dev/null +++ b/docshell/test/mochitest/file_bug1740516_1_inner.html @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/docshell/test/mochitest/file_bug1740516_2.html b/docshell/test/mochitest/file_bug1740516_2.html new file mode 100644 index 000000000000..2dc714feef0c --- /dev/null +++ b/docshell/test/mochitest/file_bug1740516_2.html @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/docshell/test/mochitest/mochitest.ini b/docshell/test/mochitest/mochitest.ini index 1501867d613e..c65697074052 100644 --- a/docshell/test/mochitest/mochitest.ini +++ b/docshell/test/mochitest/mochitest.ini @@ -112,6 +112,11 @@ support-files = file_bug675587.html [test_bug1729662.html] support-files = file_bug1729662.html +[test_bug1740516.html] +support-files = + file_bug1740516_1.html + file_bug1740516_1_inner.html + file_bug1740516_2.html [test_close_onpagehide_by_history_back.html] [test_close_onpagehide_by_window_close.html] [test_compressed_multipart.html] diff --git a/docshell/test/mochitest/test_bug1740516.html b/docshell/test/mochitest/test_bug1740516.html new file mode 100644 index 000000000000..dba7e8c2aa96 --- /dev/null +++ b/docshell/test/mochitest/test_bug1740516.html @@ -0,0 +1,76 @@ + + + + + Test pageshow event order for iframe + + + + + +

+ +

+
+