Bug 483330: use new domWindowUtils getter to avoid flushing layout when getting scroll position during session store data collection, r=zeniko
authorGavin Sharp <gavin@mozilla.com>
Mon, 30 Mar 2009 14:32:19 -0400
changeset 26725 6b1294a055389efb562a17e770817160b5ab1dd4
parent 26724 395e11e49392d29f127523f353380ade2187010b
child 26731 71fa70c0e3486516a133055640299c969436e123
push id6195
push usergsharp@mozilla.com
push dateMon, 30 Mar 2009 18:32:38 +0000
treeherdermozilla-central@6b1294a05538 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszeniko
bugs483330
milestone1.9.2a1pre
Bug 483330: use new domWindowUtils getter to avoid flushing layout when getting scroll position during session store data collection, r=zeniko
browser/components/sessionstore/src/nsSessionStore.js
browser/components/sessionstore/test/browser/Makefile.in
browser/components/sessionstore/test/browser/browser_483330.js
--- a/browser/components/sessionstore/src/nsSessionStore.js
+++ b/browser/components/sessionstore/src/nsSessionStore.js
@@ -1330,17 +1330,24 @@ SessionStoreService.prototype = {
           let _this = this;
           aContent.addEventListener("keypress", function(aEvent) {
             _this.saveStateDelayed(aWindow, 3000);
           }, true);
         }
         aData.innerHTML = aContent.document.body.innerHTML;
       }
     }
-    aData.scroll = aContent.scrollX + "," + aContent.scrollY;
+
+    // get scroll position from nsIDOMWindowUtils, since it allows avoiding a
+    // flush of layout
+    let domWindowUtils = aContent.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsIDOMWindowUtils);
+    let scrollX = {}, scrollY = {};
+    domWindowUtils.getScrollXY(false, scrollX, scrollY);
+    aData.scroll = scrollX.value + "," + scrollY.value;
   },
 
   /**
    * determine the title of the currently enabled style sheet (if any)
    * and recurse through the frameset if necessary
    * @param   aContent is a frame reference
    * @returns the title style sheet determined to be enabled (empty string if none)
    */
--- a/browser/components/sessionstore/test/browser/Makefile.in
+++ b/browser/components/sessionstore/test/browser/Makefile.in
@@ -73,12 +73,13 @@ include $(topsrcdir)/config/rules.mk
 	browser_464199.js \
 	browser_465215.js \
 	browser_465223.js \
 	browser_466937.js \
 	browser_466937_sample.html \
 	browser_476161.js \
 	browser_476161_sample.html \
 	browser_480893.js \
+	browser_483330.js \
 	$(NULL)
 
 libs:: $(_BROWSER_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser/browser_483330.js
@@ -0,0 +1,39 @@
+function test() {
+  /** Test for Bug 483330 **/
+
+  // test setup
+  let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
+  waitForExplicitFinish();
+
+  let tab = gBrowser.addTab();
+  gBrowser.selectedTab = tab;
+
+  let browser = tab.linkedBrowser;
+  browser.addEventListener("load", function loadListener(e) {
+    browser.removeEventListener("load", arguments.callee, false);
+
+    // Scroll the content document
+    browser.contentWindow.scrollTo(1100, 1200);
+    is(browser.contentWindow.scrollX, 1100, "scrolled horizontally");
+    is(browser.contentWindow.scrollY, 1200, "scrolled vertically");
+
+    gBrowser.removeTab(tab);
+
+    let newTab = ss.undoCloseTab(window, 0);
+    newTab.addEventListener("SSTabRestored", function tabRestored(e) {
+      newTab.removeEventListener("SSTabRestored", arguments.callee, false);
+
+      let newBrowser = newTab.linkedBrowser;
+
+      // check that the scroll position was restored
+      is(newBrowser.contentWindow.scrollX, 1100, "still scrolled horizontally");
+      is(newBrowser.contentWindow.scrollY, 1200, "still scrolled vertically");
+
+      gBrowser.removeTab(newTab);
+
+      finish();
+    }, true);
+  }, true);
+
+  browser.loadURI("data:text/html,<body style='width: 100000px; height: 100000px;'><p>top</p></body>");
+}