Bug 1504659 Part 2: Add tests of viewport RDM scroll behavior, with and without touch simulation. r=gl
☠☠ backed out by 38b4e8f428f7 ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Wed, 05 Dec 2018 02:48:46 +0000
changeset 508590 bcebb3fd72d3cec5ce1cb7478d7f7aeb3cffca09
parent 508589 1dbe3852e298dd4bc918c3139ee8ef2ee4e1da96
child 508591 38b4e8f428f7f41feca673ee8833733f27a37460
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1504659
milestone65.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 1504659 Part 2: Add tests of viewport RDM scroll behavior, with and without touch simulation. r=gl Differential Revision: https://phabricator.services.mozilla.com/D13174
devtools/client/responsive.html/test/browser/browser.ini
devtools/client/responsive.html/test/browser/browser_scroll.js
devtools/client/responsive.html/test/browser/head.js
devtools/client/responsive.html/test/unit/test_resize_viewport.js
--- a/devtools/client/responsive.html/test/browser/browser.ini
+++ b/devtools/client/responsive.html/test/browser/browser.ini
@@ -47,16 +47,17 @@ tags = devtools webextensions
 skip-if = true # Bug 1413765
 [browser_network_throttling.js]
 [browser_page_state.js]
 [browser_permission_doorhanger.js]
 tags = devtools geolocation
 skip-if = true # Bug 1413765
 [browser_preloaded_newtab.js]
 [browser_screenshot_button.js]
+[browser_scroll.js]
 [browser_state_restore.js]
 [browser_tab_close.js]
 [browser_tab_remoteness_change.js]
 [browser_target_blank.js]
 [browser_telemetry_activate_rdm.js]
 [browser_toolbox_computed_view.js]
 [browser_toolbox_rule_view.js]
 [browser_toolbox_rule_view_reload.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/responsive.html/test/browser/browser_scroll.js
@@ -0,0 +1,66 @@
+/* Any copyright is dedicated to the Public Domain.
+http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * This test is checking that keyboard scrolling of content in RDM
+ * behaves correctly, both with and without touch simulation enabled.
+ */
+
+const TEST_URL = "data:text/html;charset=utf-8," +
+  "<div style=\"background:blue; width:200px; height:200px\"></div>";
+
+addRDMTask(TEST_URL, async function({ ui, manager }) {
+  info("Turning off keyboard APZ for this test.");
+  await SpecialPowers.pushPrefEnv({
+    set: [["apz.keyboard.enabled", false]],
+  });
+
+  await setViewportSize(ui, manager, 100, 100);
+  const browser = ui.getViewportBrowser();
+
+  info("Setting focus on the browser.");
+  browser.focus();
+
+  info("Testing scroll behavior with touch simulation OFF.");
+  await testScrollingOfContent(ui);
+
+  // Run the tests again with touch simulation on.
+  const reloadNeeded = await ui.updateTouchSimulation(true);
+  if (reloadNeeded) {
+    info("Reload is needed -- waiting for it.");
+    const reload = waitForViewportLoad(ui);
+    browser.reload();
+    await reload;
+
+    await ContentTask.spawn(browser, null, () => {
+      content.scrollTo(0, 0);
+    });
+  }
+
+  info("Testing scroll behavior with touch simulation ON.");
+  await testScrollingOfContent(ui);
+});
+
+async function testScrollingOfContent(ui) {
+  let x, y;
+  let scroll;
+
+  info("Checking initial scroll conditions.");
+  ({x, y} = await getViewportScroll(ui));
+  is(x, 0, "Content should load with scrollX 0.");
+  is(y, 0, "Content should load with scrollY 0.");
+
+  scroll = waitForViewportScroll(ui);
+  EventUtils.synthesizeKey("KEY_ArrowDown");
+  await scroll;
+  ({x, y} = await getViewportScroll(ui));
+  isnot(y, 0, "Down arrow key should scroll down by at least some amount.");
+
+  scroll = waitForViewportScroll(ui);
+  EventUtils.synthesizeKey("KEY_ArrowRight");
+  await scroll;
+  ({x, y} = await getViewportScroll(ui));
+  isnot(x, 0, "Right arrow key should scroll right by at least some amount.");
+}
--- a/devtools/client/responsive.html/test/browser/head.js
+++ b/devtools/client/responsive.html/test/browser/head.js
@@ -327,16 +327,23 @@ function getSessionHistory(browser) {
 
 function getContentSize(ui) {
   return spawnViewportTask(ui, {}, () => ({
     width: content.screen.width,
     height: content.screen.height,
   }));
 }
 
+function getViewportScroll(ui) {
+  return spawnViewportTask(ui, {}, () => ({
+    x: content.scrollX,
+    y: content.scrollY,
+  }));
+}
+
 async function waitForPageShow(browser) {
   const tab = gBrowser.getTabForBrowser(browser);
   const ui = ResponsiveUIManager.getResponsiveUIForTab(tab);
   if (ui) {
     browser = ui.getViewportBrowser();
   }
   info("Waiting for pageshow from " + (ui ? "responsive" : "regular") + " browser");
   // Need to wait an extra tick after pageshow to ensure everyone is up-to-date,
@@ -344,16 +351,20 @@ async function waitForPageShow(browser) 
   await BrowserTestUtils.waitForContentEvent(browser, "pageshow");
   return waitForTick();
 }
 
 function waitForViewportLoad(ui) {
   return BrowserTestUtils.waitForContentEvent(ui.getViewportBrowser(), "load", true);
 }
 
+function waitForViewportScroll(ui) {
+  return BrowserTestUtils.waitForContentEvent(ui.getViewportBrowser(), "scroll", true);
+}
+
 function load(browser, url) {
   const loaded = BrowserTestUtils.browserLoaded(browser, false, url);
   BrowserTestUtils.loadURI(browser, url);
   return loaded;
 }
 
 function back(browser) {
   const shown = waitForPageShow(browser);
--- a/devtools/client/responsive.html/test/unit/test_resize_viewport.js
+++ b/devtools/client/responsive.html/test/unit/test_resize_viewport.js
@@ -2,20 +2,28 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test resizing the viewport.
 
 const { addViewport, resizeViewport } =
   require("devtools/client/responsive.html/actions/viewports");
+const { toggleTouchSimulation } = require("devtools/client/responsive.html/actions/ui");
 
 add_task(async function() {
   const store = Store();
   const { getState, dispatch } = store;
 
   dispatch(addViewport());
   dispatch(resizeViewport(0, 500, 500));
 
-  const viewport = getState().viewports[0];
+  let viewport = getState().viewports[0];
   equal(viewport.width, 500, "Resized width of 500");
   equal(viewport.height, 500, "Resized height of 500");
+
+  dispatch(toggleTouchSimulation(true));
+  dispatch(resizeViewport(0, 400, 400));
+
+  viewport = getState().viewports[0];
+  equal(viewport.width, 400, "Resized width of 400 (with touch simulation on)");
+  equal(viewport.height, 400, "Resized height of 400 (with touch simulation on)");
 });