Bug 1499239 - Use a smaller scroll range for the frameset. r=gbrown
authorJan Henning <jh+bugzilla@buttercookie.de>
Tue, 16 Oct 2018 20:12:20 +0000
changeset 489885 de6fb9a3d7a5dcf98798c833994c68f2ac83526c
parent 489884 4c98e1b28c388eed1ce835038f570cc0169ef389
child 489886 943c165146e677a243702a51d5d9f3a5cfe163ba
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersgbrown
bugs1499239
milestone64.0a1
Bug 1499239 - Use a smaller scroll range for the frameset. r=gbrown The size of the frameset on the emulator is smaller than I expected, so we can't scroll the full range of SCROLL_Y even when we've zoomed in somewhat. Because SCROLL_Y has a maximum of 400 and the scroll got truncated to 292, we divide the number in half. So we don't have to generate yet another hard-coded scroll string for this case, we switch to generating them on the fly from the test data for the respective sub test. Differential Revision: https://phabricator.services.mozilla.com/D8894
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
@@ -38,23 +38,20 @@ https://bugzilla.mozilla.org/show_bug.cg
   // Test nested scrolling with frames.
   const URL_FRAMESET = BASE + "browser_scrollPositions_sample_frameset.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 SCROLL_STR = SCROLL_X + "," + SCROLL_Y;
-  const SCROLL_STR_Y_ONLY = 0 + "," + SCROLL_Y;
   const ZOOM = 1 + 0.5 * Math.random();
 
   const SCROLL2_X = Math.round(300 * (1 + Math.random()));
   const SCROLL2_Y = Math.round(400 * (1 + Math.random()));
-  const SCROLL2_STR = SCROLL2_X + "," + SCROLL2_Y;
   const ZOOM2 = 1.5 + 0.5 * Math.random();
 
   function getFrame(browser, data) {
     let frame = browser.contentWindow;
     if (data.hasOwnProperty("frame")) {
       frame = browser.contentWindow.frames[data.frame];
     }
     return frame;
@@ -85,16 +82,23 @@ https://bugzilla.mozilla.org/show_bug.cg
     if (data.hasOwnProperty("y")) {
       is(actualY.value, y, "scrollY set correctly");
     }
     if (data.hasOwnProperty("zoom")) {
       ok(fuzzyEquals(actualZoom.value, zoom), "zoom set correctly");
     }
   }
 
+  function getScrollString(data) {
+    let {x, y} = data;
+    x = x || 0;
+    y = y || 0;
+    return x + "," + y;
+  }
+
   // Track the tabs where the tests are happening.
   let tabScroll;
 
   function cleanupTabs() {
     if (tabScroll) {
       BrowserApp.closeTab(tabScroll);
       tabScroll = null;
     }
@@ -127,17 +131,17 @@ https://bugzilla.mozilla.org/show_bug.cg
         BrowserApp.closeTab(tabScroll);
         yield promiseTabEvent(browser, "SSTabCloseProcessed");
       });
     }
 
     await createAndRemoveReaderTab();
     let state = ss.getClosedTabs(chromeWin);
     let [{scrolldata}] = state;
-    is(scrolldata.scroll, SCROLL_STR_Y_ONLY, "stored scroll position is correct");
+    is(scrolldata.scroll, getScrollString(testData), "stored scroll position is correct");
 
     // Restore the closed tab.
     let closedTabData = ss.getClosedTabs(chromeWin)[0];
     let browser = ss.undoCloseTab(chromeWin, closedTabData);
     await promiseBrowserEvent(browser, "AboutReaderContentReady");
 
     // Check the scroll position.
     checkScroll(browser, testData);
@@ -177,17 +181,17 @@ https://bugzilla.mozilla.org/show_bug.cg
         BrowserApp.closeTab(tabScroll);
         yield promiseTabEvent(browser, "SSTabCloseProcessed");
       });
     }
 
     await createAndRemoveTab();
     let state = ss.getClosedTabs(chromeWin);
     let [{scrolldata}] = state;
-    is(scrolldata.scroll, SCROLL2_STR, "stored scroll position is correct");
+    is(scrolldata.scroll, getScrollString(testData2), "stored scroll position is correct");
     ok(fuzzyEquals(scrolldata.zoom.resolution, ZOOM2), "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 = promiseBrowserEvent(browser, "scroll");
     await pageshow;
@@ -232,17 +236,17 @@ https://bugzilla.mozilla.org/show_bug.cg
         BrowserApp.closeTab(tabScroll);
         yield promiseTabEvent(browser, "SSTabCloseProcessed");
       });
     }
 
     await createAndRemoveTab();
     let state = ss.getClosedTabs(chromeWin);
     let [{scrolldata}] = state;
-    is(scrolldata.scroll, SCROLL_STR, "stored scroll position is correct");
+    is(scrolldata.scroll, getScrollString(testData), "stored scroll position is correct");
     ok(fuzzyEquals(scrolldata.zoom.resolution, ZOOM), "stored zoom level is correct");
 
     // Pretend the zoom level was originally saved on a rotated device.
     let closedTabData = ss.getClosedTabs(chromeWin)[0];
     let displayWidth = scrolldata.zoom.displaySize.width;
     let displayHeight = scrolldata.zoom.displaySize.height;
     closedTabData.scrolldata.zoom.displaySize.width = displayHeight;
     closedTabData.scrolldata.zoom.displaySize.height = displayWidth;
@@ -255,17 +259,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     testData.zoom = ZOOM * displayWidth / displayHeight;
     checkScroll(browser, testData);
 
     // Remove the tab.
     BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
   });
 
   add_task(async function test_sessionStoreScrollPositionForFrames() {
-    let testDataParent = {x: 0, y: SCROLL_Y, zoom: 2.0};
+    let testDataParent = {x: 0, y: Math.round(SCROLL_Y / 2), zoom: 2.0};
     let testData1 = {x: SCROLL_X, y: SCROLL_Y, frame: 0};
     let testData2 = {x: SCROLL2_X, y: SCROLL2_Y, frame: 1};
     // 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_FRAMESET);
         let browser = tabScroll.browser;
@@ -290,19 +294,19 @@ https://bugzilla.mozilla.org/show_bug.cg
         BrowserApp.closeTab(tabScroll);
         yield promiseTabEvent(browser, "SSTabCloseProcessed");
       });
     }
 
     await createAndRemoveTab();
     let state = ss.getClosedTabs(chromeWin);
     let [{scrolldata}] = state;
-    is(scrolldata.scroll, SCROLL_STR_Y_ONLY, "stored scroll position for frameset is correct");
-    is(scrolldata.children[0].scroll, SCROLL_STR, "stored scroll position for frame 1 is correct");
-    is(scrolldata.children[1].scroll, SCROLL2_STR, "stored scroll position for frame 2 is correct");
+    is(scrolldata.scroll, getScrollString(testDataParent), "stored scroll position for frameset is correct");
+    is(scrolldata.children[0].scroll, getScrollString(testData1), "stored scroll position for frame 1 is correct");
+    is(scrolldata.children[1].scroll, getScrollString(testData2), "stored scroll position for frame 2 is correct");
 
     // Restore the closed tab.
     let closedTabData = ss.getClosedTabs(chromeWin)[0];
     let browser = ss.undoCloseTab(chromeWin, closedTabData);
     let pageshow = promiseBrowserEvent(browser, "pageshow");
     // We can't add event listeners for the frames until we're sure that they've actually loaded.
     let load = promiseBrowserEvent(browser, "load");
     await load;