Bug 1531057 - Add a test to check that session history respects the layout scroll range. r=JanH a=test-only
authorBotond Ballo <botond@mozilla.com>
Wed, 27 Mar 2019 20:20:05 +0000
changeset 525934 e2f09a8bd87cb38405446b594058104f0c694561
parent 525933 3e71adc4ab1dfcbabeb559613924b755391e08d1
child 525935 086b3323f453fb39d9c965b5f2a2aec018352698
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJanH, test-only
bugs1531057
milestone67.0
Bug 1531057 - Add a test to check that session history respects the layout scroll range. r=JanH a=test-only Differential Revision: https://phabricator.services.mozilla.com/D23753
mobile/android/tests/browser/chrome/browser_scrollPositions_sample_small.html
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/test_session_scroll_position.html
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/browser_scrollPositions_sample_small.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>browser_scrollPositions_sample_small.html</title>
+  </head>
+  <!-- Make the page short enough that it doesn't have a layout scroll range.
+       In the absence of an explicit minimum-scale, the minimum scale defaults
+       to 0.25, which means the layout viewport will be expanded to up to 4x
+       the screen size. So, this assumes the screen size is at least
+       250x250. -->
+  <body style='width: 1000px; height: 1000px;'>top</body>
+</html>
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -3,16 +3,17 @@ skip-if = os != 'android'
 support-files =
   audio.ogg
   basic_article.html
   basic_article_mobile.html
   basic_article_mobile_2x.html
   browser_scrollPositions_sample.html
   browser_scrollPositions_sample2.html
   browser_scrollPositions_sample_frameset.html
+  browser_scrollPositions_sample_small.html
   desktopmode_user_agent.sjs
   devicesearch.xml
   head.js
   head_scroll.js
   head_search.js
   media_playback.html
   session_formdata_sample.html
   simpleservice.xml
--- a/mobile/android/tests/browser/chrome/test_session_scroll_position.html
+++ b/mobile/android/tests/browser/chrome/test_session_scroll_position.html
@@ -27,22 +27,26 @@ https://bugzilla.mozilla.org/show_bug.cg
   ChromeUtils.import("resource://gre/modules/Messaging.jsm");
   const {Task} = ChromeUtils.import("resource://testing-common/Task.jsm");
 
   // The chrome window and friends.
   let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
   let BrowserApp = chromeWin.BrowserApp;
 
   const BASE = "http://example.org/chrome/mobile/android/tests/browser/chrome/";
+  const BASE2 = "http://test1.example.org/chrome/mobile/android/tests/browser/chrome/";
   // Use something with ample space for scrolling and zooming.
   const URL = BASE + "browser_scrollPositions_sample.html";
   // Same content but under a different URL, so we have something to navigate to and from.
   const URL2 = BASE + "browser_scrollPositions_sample2.html";
   // Test nested scrolling with frames.
   const URL_FRAMESET = BASE + "browser_scrollPositions_sample_frameset.html";
+  // Smaller page, which has no layout scroll range.
+  const URL_SMALL = BASE + "browser_scrollPositions_sample_small.html";
+  const URL_SMALL2 = BASE2 + "browser_scrollPositions_sample_small.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";
 
   // Randomized set of scroll positions and zoom factors we will use in this test.
   const SCROLL_X = Math.round(100 * (1 + Math.random()));
   const SCROLL_Y = Math.round(200 * (1 + Math.random()));
   const ZOOM = 1 + 0.5 * Math.random();
 
@@ -283,16 +287,99 @@ https://bugzilla.mozilla.org/show_bug.cg
     checkScroll(browser, testDataParent);
     checkScroll(browser, testData1);
     checkScroll(browser, testData2);
 
     // Remove the tab.
     BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
   });
 
+  add_task(async function test_sessionHistoryRespectsLayoutScrollRange() {
+    let zoom = 2.0;
+    let testData = {x: 100, y: 100, zoom};
+    // Creates a tab, sets a scroll position and zoom level and closes the tab.
+    function createAndRemoveTab() {
+      return Task.spawn(function* () {
+        // Create a new tab.
+        tabScroll = BrowserApp.addTab(URL_SMALL);
+        let browser = tabScroll.browser;
+        yield promiseBrowserEvent(browser, "pageshow");
+
+        // Modify scroll position and zoom level.
+        setScrollPosition(browser, testData);
+        yield promiseVisualScrollEvent(browser);
+
+        // Check that we've actually scrolled and zoomed.
+        checkScroll(browser, testData);
+
+        // Check that the layout scroll position hasn't changed,
+        // as the page has no layout scroll range.
+        is(browser.contentWindow.scrollX, 0, "Layout scrolling should not have occurred");
+        is(browser.contentWindow.scrollY, 0, "Layout scrolling should not have occurred");
+
+        // Navigate to a different page and scroll/zoom there as well.
+        browser.loadURI(URL_SMALL2);
+        yield promiseBrowserEvent(browser, "pageshow");
+
+        setScrollPosition(browser, testData);
+        yield promiseVisualScrollEvent(browser);
+
+        checkScroll(browser, testData);
+
+        // Check that the layout scroll range is respected.
+        is(browser.contentWindow.scrollX, 0, "Layout scroll range should be respected");
+        is(browser.contentWindow.scrollY, 0, "Layout scroll range should be respected");
+
+        // Remove the tab.
+        BrowserApp.closeTab(tabScroll);
+        yield promiseTabEvent(browser, "SSTabCloseProcessed");
+      });
+    }
+
+    await createAndRemoveTab();
+    let state = ss.getClosedTabs(chromeWin);
+    let [{scrolldata}] = state;
+    is(scrolldata.scroll, getScrollString(testData), "stored scroll position is correct");
+    ok(fuzzyEquals(scrolldata.zoom.resolution, zoom), "stored zoom level is correct");
+
+    // Restore the closed tab.
+    let closedTabData = ss.getClosedTabs(chromeWin)[0];
+    let browser = ss.undoCloseTab(chromeWin, closedTabData);
+    let pageshow = promiseBrowserEvent(browser, "pageshow");
+    let scroll = promiseVisualScrollEvent(browser);
+    await pageshow;
+    await scroll;
+
+    // Check the scroll position and zoom level.
+    checkScroll(browser, testData);
+    
+    // Check that the layout scroll range is still respected.
+    // TODO: This should start passing after bug 1516056 is fixed.
+    todo_is(browser.contentWindow.scrollX, 0, "Layout scroll range should be respected");
+    todo_is(browser.contentWindow.scrollY, 0, "Layout scroll range should be respected");
+
+    // Now go back in history and check that the scroll position
+    // is restored there as well.
+    is(browser.canGoBack, true, "can go back");
+    pageshow = promiseBrowserEvent(browser, "pageshow");
+    scroll = promiseVisualScrollEvent(browser);
+    browser.goBack();
+    await pageshow;
+    await scroll;
+
+    checkScroll(browser, testData);
+
+    // Check that the layout scroll range is still respected.
+    is(browser.contentWindow.scrollX, 0, "Layout scroll range should be respected");
+    is(browser.contentWindow.scrollY, 0, "Layout scroll range should be respected");
+
+    // Remove the tab.
+    BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+  });
+
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=810981">Mozilla Bug 810981</a>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1282902">Mozilla Bug 1282902</a>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1301016">Mozilla Bug 1301016</a>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1265818">Mozilla Bug 1265818</a>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1498892">Mozilla Bug 1498892</a>