Bug 1301016 - Part 2 - Test scroll position restoring on reader mode pages. r=ahunt
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 11 Sep 2016 16:03:26 +0200
changeset 344703 4e6337f61e6bd54479e6460fa92d27250415758f
parent 344702 43e595bc39d597b1da6e6d4399acd23651bfd90d
child 344704 45c948de0bea73609bcdeef13f0b4a60bce18761
push id8
push userfmarier@mozilla.com
push dateThu, 15 Sep 2016 05:23:20 +0000
reviewersahunt
bugs1301016
milestone51.0a1
Bug 1301016 - Part 2 - Test scroll position restoring on reader mode pages. r=ahunt MozReview-Commit-ID: D36u8kUD67g
mobile/android/tests/browser/chrome/test_session_scroll_position.html
--- a/mobile/android/tests/browser/chrome/test_session_scroll_position.html
+++ b/mobile/android/tests/browser/chrome/test_session_scroll_position.html
@@ -29,16 +29,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 
   // Track the tabs where the tests are happening.
   let tabScroll;
 
   // Use something with enough content to allow for scrolling.
   const URL = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article_mobile.html";
   // Something to test the zoom level scaling on rotation with.
   const URL_desktop = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article.html";
+  // Reader mode URL
+  const URL_reader = "about:reader?url=http%3A%2F%2Fexample.org%2Fchrome%2Fmobile%2Fandroid%2Ftests%2Fbrowser%2Fchrome%2Fbasic_article_mobile.html";
 
   function dispatchUIEvent(browser, type) {
     let event = browser.contentDocument.createEvent("UIEvents");
     event.initUIEvent(type, true, false, browser.contentDocument.defaultView, 0);
     browser.dispatchEvent(event);
   }
 
   function setScrollPosition(browser, x, y) {
@@ -104,16 +106,71 @@ https://bugzilla.mozilla.org/show_bug.cg
     utils.getScrollXY(false, scrollX, scrollY);
     is(scrollX.value, SCROLL_X, "scrollX restored correctly");
     is(scrollY.value, SCROLL_Y, "scrollY restored correctly");
 
     // Remove the tab.
     BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
   });
 
+  add_task(function* test_sessionStoreScrollPositionReaderMode() {
+    const SCROLL_X = 0;
+    const SCROLL_Y = 44;
+
+    chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+    let BrowserApp = chromeWin.BrowserApp;
+
+    // Creates a tab, sets a scroll position and closes the tab.
+    function createAndRemoveReaderTab() {
+      return Task.spawn(function () {
+        // Create a new tab.
+        tabScroll = BrowserApp.addTab(URL_reader);
+        let browser = tabScroll.browser;
+        yield promiseBrowserEvent(browser, "AboutReaderContentReady");
+
+        // Modify scroll position.
+        setScrollPosition(browser, SCROLL_X, SCROLL_Y);
+        yield promiseTabEvent(browser, "SSTabScrollCaptured");
+
+        // Check that we've actually scrolled.
+        let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+        let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+        let scrollX = {}, scrollY = {};
+        utils.getScrollXY(false, scrollX, scrollY);
+        is(scrollX.value, SCROLL_X, "scrollX set correctly");
+        is(scrollY.value, SCROLL_Y, "scrollY set correctly");
+
+        // Remove the tab.
+        BrowserApp.closeTab(tabScroll);
+        yield promiseTabEvent(browser, "SSTabCloseProcessed");
+      });
+    }
+
+    yield createAndRemoveReaderTab();
+    let state = ss.getClosedTabs(chromeWin);
+    let [{scrolldata}] = state;
+    is(scrolldata.scroll, SCROLL_X + "," + SCROLL_Y, "stored scroll position is correct");
+
+    // Restore the closed tab.
+    let closedTabData = ss.getClosedTabs(chromeWin)[0];
+    let browser = ss.undoCloseTab(chromeWin, closedTabData);
+    yield promiseBrowserEvent(browser, "AboutReaderContentReady");
+
+    // Check the scroll position.
+    let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+    let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+    let scrollX = {}, scrollY = {};
+    utils.getScrollXY(false, scrollX, scrollY);
+    is(scrollX.value, SCROLL_X, "scrollX restored correctly");
+    is(scrollY.value, SCROLL_Y, "scrollY restored correctly");
+
+    // Remove the tab.
+    BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+  });
+
   add_task(function* test_sessionStoreZoomLevel() {
     const ZOOM = 4.2;
     const SCROLL_X = 42;
     const SCROLL_Y = 42;
 
     chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
     let BrowserApp = chromeWin.BrowserApp;