Bug 1498812 - Part 3: Move scroll position test helper functions into separate file. r=mikedeboer
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 11 Jan 2019 20:21:06 +0000
changeset 510650 bf744ce7867af3c2548b1ec10233692f11f1ecf9
parent 510649 bbbb9e3c793d7f9ea29e24aa23b46ee2d7e2b49d
child 510651 7b00521b6f3176cb88698b4773d9be13f0e54b2e
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1498812
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1498812 - Part 3: Move scroll position test helper functions into separate file. r=mikedeboer ... so it can be shared across multiple test files. Also make slightly more use of modern JS features for destructuring objects etc. Differential Revision: https://phabricator.services.mozilla.com/D15684
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/head.js
mobile/android/tests/browser/chrome/head_scroll.js
mobile/android/tests/browser/chrome/test_session_scroll_position.html
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -6,16 +6,17 @@ support-files =
   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_scroll.js
   head_search.js
   media_playback.html
   session_formdata_sample.html
   simpleservice.xml
   video_controls.html
   video_discovery.html
   video_discovery.sjs
   web_channel.html
--- a/mobile/android/tests/browser/chrome/head.js
+++ b/mobile/android/tests/browser/chrome/head.js
@@ -1,15 +1,11 @@
 /* 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(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 != (browserOrFrame.contentDocument || browserOrFrame.document) ||
                           event.target.location.href == "about:blank") {
         info("Skipping spurious '" + eventType + "' event" + " for " + event.target.location.href);
         return;
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/head_scroll.js
@@ -0,0 +1,48 @@
+/* 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 getFrame(browser, { frame = null }) {
+  let window;
+  if (frame !== null) {
+    window = browser.contentWindow.frames[frame];
+  } else {
+    window = browser.contentWindow;
+  }
+  return window;
+}
+
+function setScrollPosition(browser,
+                           { x = 0, y = 0, zoom = 0, frame }) {
+  let window = getFrame(browser, {frame});
+  if (zoom) {
+    browser.contentWindow.windowUtils.setResolutionAndScaleTo(zoom);
+  }
+  window.scrollTo(x, y);
+}
+
+function checkScroll(browser, data) {
+  let {x, y, zoom} = data;
+  let utils = getFrame(browser, data).windowUtils;
+
+  let actualX = {}, actualY = {};
+  let actualZoom = utils.getResolution();
+  utils.getScrollXY(false, actualX, actualY);
+
+  if (data.hasOwnProperty("x")) {
+    is(actualX.value, x, "scrollX set correctly");
+  }
+  if (data.hasOwnProperty("y")) {
+    is(actualY.value, y, "scrollY set correctly");
+  }
+  if (zoom) {
+    ok(fuzzyEquals(actualZoom, zoom), "zoom set correctly");
+  }
+}
+
+function getScrollString({ x = 0, y = 0 }) {
+  return x + "," + y;
+}
--- a/mobile/android/tests/browser/chrome/test_session_scroll_position.html
+++ b/mobile/android/tests/browser/chrome/test_session_scroll_position.html
@@ -10,16 +10,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <head>
   <meta charset="utf-8">
   <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" src="head_scroll.js"></script>
   <script type="application/javascript">
 
   /** Tests for Bug 810981, 1282902, 1301016, 1265818, 1498892 **/
 
   "use strict";
 
   ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
   ChromeUtils.import("resource://gre/modules/Services.jsm");
@@ -44,61 +45,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   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();
 
   const SCROLL2_X = Math.round(300 * (1 + Math.random()));
   const SCROLL2_Y = Math.round(400 * (1 + Math.random()));
   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;
-  }
-
-  function setScrollPosition(browser, data) {
-    let {x, y, zoom} = data;
-    x = x || 0;
-    y = y || 0;
-    let frame = getFrame(browser, data);
-    if (data.hasOwnProperty("zoom")) {
-      browser.contentWindow.windowUtils.setResolutionAndScaleTo(zoom);
-    }
-    frame.scrollTo(x, y);
-  }
-
-  function checkScroll(browser, data) {
-    let {x, y, zoom} = data;
-    let utils = getFrame(browser, data).windowUtils;
-
-    let actualX = {}, actualY = {};
-    let actualZoom = utils.getResolution();
-    utils.getScrollXY(false, actualX, actualY);
-
-    if (data.hasOwnProperty("x")) {
-      is(actualX.value, x, "scrollX set correctly");
-    }
-    if (data.hasOwnProperty("y")) {
-      is(actualY.value, y, "scrollY set correctly");
-    }
-    if (data.hasOwnProperty("zoom")) {
-      ok(fuzzyEquals(actualZoom, 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;
     }