Bug 1498892 - Part 2: Add session store test for scroll positions of frames. r=gbrown
authorJan Henning <jh+bugzilla@buttercookie.de>
Mon, 15 Oct 2018 21:11:15 +0000
changeset 489694 8e482a5a51ad99eb7173e1bf1a2410c1a70d6825
parent 489693 fb3685a86f81baeebbf47aabdf2e0f28aa2bf221
child 489695 2c8dd9e9532adcdf00295810aeb389e1708a3a86
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersgbrown
bugs1498892
milestone64.0a1
Bug 1498892 - Part 2: Add session store test for scroll positions of frames. r=gbrown Differential Revision: https://phabricator.services.mozilla.com/D8675
mobile/android/tests/browser/chrome/browser_scrollPositions_sample_frameset.html
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/head.js
mobile/android/tests/browser/chrome/test_session_scroll_position.html
copy from browser/components/sessionstore/test/browser_scrollPositions_sample_frameset.html
copy to mobile/android/tests/browser/chrome/browser_scrollPositions_sample_frameset.html
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -2,16 +2,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
   desktopmode_user_agent.sjs
   devicesearch.xml
   head.js
   head_search.js
   media_playback.html
   session_formdata_sample.html
   simpleservice.xml
   video_controls.html
--- a/mobile/android/tests/browser/chrome/head.js
+++ b/mobile/android/tests/browser/chrome/head.js
@@ -1,33 +1,34 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 function fuzzyEquals(a, b) {
   return (Math.abs(a - b) < 1e-6);
 }
 
-function promiseBrowserEvent(browser, eventType, options) {
+function promiseBrowserEvent(browserOrFrame, eventType, options) {
   return new Promise((resolve) => {
     function handle(event) {
       // Since we'll be redirecting, don't make assumptions about the given URL and the loaded URL
-      if (event.target != browser.contentDocument || event.target.location.href == "about:blank") {
+      if (event.target != (browserOrFrame.contentDocument || browserOrFrame.document) ||
+                          event.target.location.href == "about:blank") {
         info("Skipping spurious '" + eventType + "' event" + " for " + event.target.location.href);
         return;
       }
       info("Received event " + eventType + " from browser");
-      browser.removeEventListener(eventType, handle, true);
+      browserOrFrame.removeEventListener(eventType, handle, true);
       if (options && options.resolveAtNextTick) {
         setTimeout(() => resolve(event), 0);
       } else {
         resolve(event);
       }
     }
 
-    browser.addEventListener(eventType, handle, true);
+    browserOrFrame.addEventListener(eventType, handle, true);
     info("Now waiting for " + eventType + " event from browser");
   });
 }
 
 function promiseTabEvent(container, eventType) {
   return new Promise((resolve) => {
     function handle(event) {
       info("Received event " + eventType + " from container");
--- a/mobile/android/tests/browser/chrome/test_session_scroll_position.html
+++ b/mobile/android/tests/browser/chrome/test_session_scroll_position.html
@@ -1,27 +1,28 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=810981
 https://bugzilla.mozilla.org/show_bug.cgi?id=1282902
 https://bugzilla.mozilla.org/show_bug.cgi?id=1301016
 https://bugzilla.mozilla.org/show_bug.cgi?id=1265818
+https://bugzilla.mozilla.org/show_bug.cgi?id=1498892
 -->
 <head>
   <meta charset="utf-8">
-  <title>Tests for Bug 810981, 1282902, 1301016, 1265818</title>
+  <title>Various scroll position/zoom level tests for the mobile session store</title>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/AddTask.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
   <script type="application/javascript" src="head.js"></script>
   <script type="application/javascript">
 
-  /** Tests for Bug 810981, 1282902, 1301016, 1265818 **/
+  /** Tests for Bug 810981, 1282902, 1301016, 1265818, 1498892 **/
 
   "use strict";
 
   ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
   ChromeUtils.import("resource://gre/modules/Services.jsm");
   ChromeUtils.import("resource://gre/modules/Messaging.jsm");
   ChromeUtils.import("resource://gre/modules/Task.jsm");
 
@@ -29,16 +30,18 @@ https://bugzilla.mozilla.org/show_bug.cg
   let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
   let BrowserApp = chromeWin.BrowserApp;
 
   const BASE = "http://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";
   // 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;
@@ -251,23 +254,88 @@ https://bugzilla.mozilla.org/show_bug.cg
     // Check the scroll position and zoom level.
     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 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;
+        yield promiseBrowserEvent(browser, "pageshow");
+
+        // Move the frameset itself.
+        setScrollPosition(browser, testDataParent);
+        yield promiseTabEvent(browser, "SSTabScrollCaptured");
+        checkScroll(browser, testDataParent);
+
+        // Modify scroll position and zoom level for one frame...
+        setScrollPosition(browser, testData1);
+        yield promiseTabEvent(browser, "SSTabScrollCaptured");
+        checkScroll(browser, testData1);
+
+        // ... and the other.
+        setScrollPosition(browser, testData2);
+        yield promiseTabEvent(browser, "SSTabScrollCaptured");
+        checkScroll(browser, testData2);
+
+        // Remove the tab.
+        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");
+
+    // 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;
+    let scrollParent = promiseBrowserEvent(getFrame(browser, testDataParent), "scroll");
+    let scroll1 = promiseBrowserEvent(getFrame(browser, testData1), "scroll");
+    let scroll2 = promiseBrowserEvent(getFrame(browser, testData2), "scroll");
+    await pageshow;
+    await scrollParent;
+    await scroll1;
+    await scroll2;
+
+    // Check the scroll position and zoom level.
+    checkScroll(browser, testDataParent);
+    checkScroll(browser, testData1);
+    checkScroll(browser, testData2);
+
+    // 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>
 <p id="display"></p>
 <div id="content" style="display: none">
 
 </div>
 <pre id="test">
 </pre>
 </body>
 </html>