From 104fe2c9974f8de860634a82edd54afc5cc09f83 Mon Sep 17 00:00:00 2001 From: Samael Wang Date: Fri, 30 Sep 2016 11:55:10 +0800 Subject: [PATCH] Bug 1300461 - UpdateIndex on LOAD_NORMAL_REPLACE, ReplaceEntry at requestedIndex when available. r=smaug --HG-- extra : rebase_source : 9bb3c7488a1785ee5c4106b8e024555f31b3220c --- docshell/base/nsDocShell.cpp | 18 ++++-- docshell/test/navigation/file_bug1300461.html | 63 +++++++++++++++++++ .../test/navigation/file_bug1300461_back.html | 31 +++++++++ .../navigation/file_bug1300461_redirect.html | 10 +++ .../file_bug1300461_redirect.html^headers^ | 2 + docshell/test/navigation/mochitest.ini | 6 +- .../test/navigation/test_sessionhistory.html | 5 +- 7 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 docshell/test/navigation/file_bug1300461.html create mode 100644 docshell/test/navigation/file_bug1300461_back.html create mode 100644 docshell/test/navigation/file_bug1300461_redirect.html create mode 100644 docshell/test/navigation/file_bug1300461_redirect.html^headers^ diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 7288de9bb256..2d946e680fc3 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -11691,9 +11691,12 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel, AddURIVisit(aURI, referrer, previousURI, previousFlags, responseStatus); } - // If this was a history load or a refresh, - // update the index in SH. - if (rootSH && (mLoadType & (LOAD_CMD_HISTORY | LOAD_CMD_RELOAD))) { + // If this was a history load or a refresh, or it was a history load but + // later changed to LOAD_NORMAL_REPLACE due to redirection, update the index + // in session history. + if (rootSH && + ((mLoadType & (LOAD_CMD_HISTORY | LOAD_CMD_RELOAD)) || + mLoadType == LOAD_NORMAL_REPLACE)) { nsCOMPtr shInternal(do_QueryInterface(rootSH)); if (shInternal) { rootSH->GetIndex(&mPreviousTransIndex); @@ -12329,9 +12332,14 @@ nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel, // This is the root docshell bool addToSHistory = !LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY); if (!addToSHistory) { - // Replace current entry in session history. + // Replace current entry in session history; If the requested index is + // valid, it indicates the loading was triggered by a history load, and + // we should replace the entry at requested index instead. int32_t index = 0; - mSessionHistory->GetIndex(&index); + mSessionHistory->GetRequestedIndex(&index); + if (index == -1) { + mSessionHistory->GetIndex(&index); + } nsCOMPtr shPrivate = do_QueryInterface(mSessionHistory); // Replace the current entry with the new entry diff --git a/docshell/test/navigation/file_bug1300461.html b/docshell/test/navigation/file_bug1300461.html new file mode 100644 index 000000000000..1ba935046d7d --- /dev/null +++ b/docshell/test/navigation/file_bug1300461.html @@ -0,0 +1,63 @@ + + + + + Bug 1300461 + + + + + diff --git a/docshell/test/navigation/file_bug1300461_back.html b/docshell/test/navigation/file_bug1300461_back.html new file mode 100644 index 000000000000..7b187742faeb --- /dev/null +++ b/docshell/test/navigation/file_bug1300461_back.html @@ -0,0 +1,31 @@ + + + + + Bug 1300461 + + + + + + diff --git a/docshell/test/navigation/file_bug1300461_redirect.html b/docshell/test/navigation/file_bug1300461_redirect.html new file mode 100644 index 000000000000..979530c5cf5d --- /dev/null +++ b/docshell/test/navigation/file_bug1300461_redirect.html @@ -0,0 +1,10 @@ + + + + + Bug 1300461 + + + Redirect to file_bug1300461_back.html. + + diff --git a/docshell/test/navigation/file_bug1300461_redirect.html^headers^ b/docshell/test/navigation/file_bug1300461_redirect.html^headers^ new file mode 100644 index 000000000000..241b8918264e --- /dev/null +++ b/docshell/test/navigation/file_bug1300461_redirect.html^headers^ @@ -0,0 +1,2 @@ +HTTP 301 Moved Permanently +Location: file_bug1300461_back.html diff --git a/docshell/test/navigation/mochitest.ini b/docshell/test/navigation/mochitest.ini index 9a807adeeadf..4000944db612 100644 --- a/docshell/test/navigation/mochitest.ini +++ b/docshell/test/navigation/mochitest.ini @@ -32,7 +32,11 @@ support-files = file_triggeringprincipal_iframe_iframe_window_open_frame_a.html file_triggeringprincipal_iframe_iframe_window_open_frame_b.html file_triggeringprincipal_iframe_iframe_window_open_frame_a_nav.html - + file_bug1300461.html + file_bug1300461_redirect.html + file_bug1300461_redirect.html^headers^ + file_bug1300461_back.html + [test_bug13871.html] skip-if = buildapp == 'b2g' || buildapp == 'mulet' || toolkit == 'android' #RANDOM # Bug 1136180 disabled on B2G Desktop and Mulet for intermittent failures [test_bug270414.html] diff --git a/docshell/test/navigation/test_sessionhistory.html b/docshell/test/navigation/test_sessionhistory.html index e4c0d18419ef..452271a41f23 100644 --- a/docshell/test/navigation/test_sessionhistory.html +++ b/docshell/test/navigation/test_sessionhistory.html @@ -30,7 +30,8 @@ var testFiles = "file_fragment_handling_during_load.html", "file_nested_frames.html", "file_shiftReload_and_pushState.html", - "file_scrollRestoration.html" + "file_scrollRestoration.html", + "file_bug1300461.html" ]; var testCount = 0; // Used by the test files. @@ -42,7 +43,7 @@ function nextTest_() { if (testFiles.length) { testCount = 0; testWindow = window.open(testFiles.shift(), "", "width=300,height=300"); - testWindow.onunload = function () { } //XXX + testWindow.onunload = function () { } // to prevent bfcache } else { SimpleTest.finish(); }