Bug 1689685 - Ensure docshell/test/navigation/test_scrollRestoration.html works with SHIP-BFCache, r=peterv
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Mon, 29 Mar 2021 14:38:18 +0000
changeset 641146 5e983be8bc9f046fc818c278ba7a452358c1c971
parent 641145 089ac339cd7642cc71227c46b7c448a5f05c81b5
child 641147 8df311a9bec01ebae17ecdf40af0856eb2ef7588
push id15309
push userffxbld-merge
push dateMon, 19 Apr 2021 17:51:21 +0000
treeherdermozilla-beta@842785ce363f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1689685
milestone89.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1689685 - Ensure docshell/test/navigation/test_scrollRestoration.html works with SHIP-BFCache, r=peterv Similarly to the old session history implementation, scroll position needs to be stored in HandleSameDocumentNavigation. The relevant old implementation is couple of lines above the new code in nsDocShell. Differential Revision: https://phabricator.services.mozilla.com/D109756
docshell/base/nsDocShell.cpp
docshell/shistory/SessionHistoryEntry.h
docshell/test/navigation/file_scrollRestoration_part3_nobfcache.html
docshell/test/navigation/mochitest.ini
docshell/test/navigation/test_scrollRestoration.html
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -9042,16 +9042,33 @@ nsresult nsDocShell::HandleSameDocumentN
           // should be inherited from the previous session history entry.
           SetScrollRestorationIsManualOnHistoryEntry(mLSHE,
                                                      scrollRestorationIsManual);
         }
         mLSHE->AdoptBFCacheEntry(mOSHE);
       }
     }
   } else {
+    if (mActiveEntry) {
+      mActiveEntry->SetScrollPosition(scrollPos.x, scrollPos.y);
+      if (mBrowsingContext) {
+        if (XRE_IsParentProcess()) {
+          SessionHistoryEntry* entry =
+              mBrowsingContext->Canonical()->GetActiveSessionHistoryEntry();
+          if (entry) {
+            entry->SetScrollPosition(scrollPos.x, scrollPos.y);
+          }
+        } else {
+          mozilla::Unused << ContentChild::GetSingleton()
+                                 ->SendSessionHistoryEntryScrollPosition(
+                                     mBrowsingContext, scrollPos.x,
+                                     scrollPos.y);
+        }
+      }
+    }
     if (mLoadingEntry) {
       if (!mLoadingEntry->mLoadIsFromSessionHistory) {
         // If we're not doing a history load, scroll restoration
         // should be inherited from the previous session history entry.
         // XXX This needs most probably tweaks once fragment navigation is
         // fixed to work with session-history-in-parent.
         SetScrollRestorationIsManualOnHistoryEntry(nullptr,
                                                    scrollRestorationIsManual);
--- a/docshell/shistory/SessionHistoryEntry.h
+++ b/docshell/shistory/SessionHistoryEntry.h
@@ -71,16 +71,22 @@ class SessionHistoryInfo {
 
   nsIInputStream* GetPostData() const { return mPostData; }
   void SetPostData(nsIInputStream* aPostData) { mPostData = aPostData; }
 
   void GetScrollPosition(int32_t* aScrollPositionX, int32_t* aScrollPositionY) {
     *aScrollPositionX = mScrollPositionX;
     *aScrollPositionY = mScrollPositionY;
   }
+
+  void SetScrollPosition(int32_t aScrollPositionX, int32_t aScrollPositionY) {
+    mScrollPositionX = aScrollPositionX;
+    mScrollPositionY = aScrollPositionY;
+  }
+
   bool GetScrollRestorationIsManual() const {
     return mScrollRestorationIsManual;
   }
   const nsAString& GetTitle() { return mTitle; }
   void SetTitle(const nsAString& aTitle) {
     mTitle = aTitle;
     MaybeUpdateTitleFromURI();
   }
--- a/docshell/test/navigation/file_scrollRestoration_part3_nobfcache.html
+++ b/docshell/test/navigation/file_scrollRestoration_part3_nobfcache.html
@@ -84,17 +84,18 @@
             history.pushState({ state: "state5" }, "state5");
             history.scrollRestoration = "auto";
             document.getElementById("bottom").scrollIntoView();
             assertIsNot.push([Math.round(window.scrollY), 0, "Should have scrolled to 'bottom'."]);
             bc.postMessage({command: "asserts", currentCase, assertIs, assertIsNot});
             bc.postMessage({command: "nextCase"});
             callTest = true;
             nextCase = currentCase + 1;
-            history.back(); // go back to state 4
+            // go back to state 3 (state 4 was removed when state 5 was pushed)
+            history.back();
             break;
           }
           case 6: {
             window.scrollTo(0, 0);
             bc.postMessage({command: "nextCase"});
             callTest = true;
             nextCase = currentCase + 1;
             history.forward();
--- a/docshell/test/navigation/mochitest.ini
+++ b/docshell/test/navigation/mochitest.ini
@@ -126,17 +126,16 @@ skip-if = verify && (os == 'mac') && deb
 [test_sessionhistory_document_write.html]
 [test_sessionhistory_iframe_removal.html]
 support-files = file_sessionhistory_iframe_removal.html
 [test_session_history_entry_cleanup.html]
 [test_fragment_handling_during_load.html]
 [test_nested_frames.html]
 [test_shiftReload_and_pushState.html]
 [test_scrollRestoration.html]
-skip-if = sessionHistoryInParent # It relies on the bfcache
 [test_bug1609475.html]
 [test_bug1300461.html]
 skip-if =
   fission # Bug 1688712
 [test_bug1326251.html]
 skip-if = toolkit == 'android' || sessionHistoryInParent # It relies on the bfcache
 [test_bug1379762.html]
 [test_static_and_dynamic.html]
--- a/docshell/test/navigation/test_scrollRestoration.html
+++ b/docshell/test/navigation/test_scrollRestoration.html
@@ -138,15 +138,18 @@ https://bugzilla.mozilla.org/show_bug.cg
           bc3navigate.postMessage({command: "back"})
           bc3navigate.close();
         }
       }
       window.open("file_scrollRestoration_part3_nobfcache.html", "", "width=360,height=480,noopener");
     }
 
     function runTest() {
-      test1();
+      // If Fission is disabled, the pref is no-op.
+      SpecialPowers.pushPrefEnv({set: [["fission.bfcacheInParent", true]]}, () => {
+        test1();
+      });
     }
 
   </script>
 </pre>
 </body>
 </html>
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -7296,16 +7296,31 @@ ContentParent::RecvSessionHistoryEntrySc
   SessionHistoryEntry* entry =
       aContext.get_canonical()->GetActiveSessionHistoryEntry();
   if (entry) {
     entry->SetScrollRestorationIsManual(aIsManual);
   }
   return IPC_OK();
 }
 
+mozilla::ipc::IPCResult ContentParent::RecvSessionHistoryEntryScrollPosition(
+    const MaybeDiscarded<BrowsingContext>& aContext, const int32_t& aX,
+    const int32_t& aY) {
+  if (aContext.IsNullOrDiscarded()) {
+    return IPC_OK();
+  }
+
+  SessionHistoryEntry* entry =
+      aContext.get_canonical()->GetActiveSessionHistoryEntry();
+  if (entry) {
+    entry->SetScrollPosition(aX, aY);
+  }
+  return IPC_OK();
+}
+
 mozilla::ipc::IPCResult
 ContentParent::RecvSessionHistoryEntryStoreWindowNameInContiguousEntries(
     const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aName) {
   if (aContext.IsNullOrDiscarded()) {
     return IPC_OK();
   }
 
   // Per https://html.spec.whatwg.org/#history-traversal 4.2.1, we need to set
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -1370,16 +1370,20 @@ class ContentParent final
       nsILayoutHistoryState* aState);
 
   mozilla::ipc::IPCResult RecvSessionHistoryEntryTitle(
       const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aTitle);
 
   mozilla::ipc::IPCResult RecvSessionHistoryEntryScrollRestorationIsManual(
       const MaybeDiscarded<BrowsingContext>& aContext, const bool& aIsManual);
 
+  mozilla::ipc::IPCResult RecvSessionHistoryEntryScrollPosition(
+      const MaybeDiscarded<BrowsingContext>& aContext, const int32_t& aX,
+      const int32_t& aY);
+
   mozilla::ipc::IPCResult RecvSessionHistoryEntryCacheKey(
       const MaybeDiscarded<BrowsingContext>& aContext,
       const uint32_t& aCacheKey);
 
   mozilla::ipc::IPCResult
   RecvSessionHistoryEntryStoreWindowNameInContiguousEntries(
       const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aName);
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -951,16 +951,18 @@ parent:
     async SynchronizeLayoutHistoryState(MaybeDiscardedBrowsingContext aContext,
                                         nsILayoutHistoryState aState);
 
     async SessionHistoryEntryTitle(MaybeDiscardedBrowsingContext aContext,
                                    nsString aTitle);
 
     async SessionHistoryEntryScrollRestorationIsManual(MaybeDiscardedBrowsingContext aContext,
                                                        bool aIsManual);
+    async SessionHistoryEntryScrollPosition(MaybeDiscardedBrowsingContext aContext,
+                                            int32_t aX, int32_t aY);
 
     async SessionHistoryEntryCacheKey(MaybeDiscardedBrowsingContext aContext,
                                       uint32_t aCacheKey);
 
     async SessionHistoryEntryStoreWindowNameInContiguousEntries(MaybeDiscardedBrowsingContext aContext,
                                                                 nsString aName);
 
     async GetLoadingSessionHistoryInfoFromParent(MaybeDiscardedBrowsingContext aContext)