Bug 1504659 Part 3: Add tests of viewport RDM scroll behavior, with and without touch simulation. r=gl
☠☠ backed out by 28bcc4da3092 ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Wed, 16 Jan 2019 17:12:00 +0000
changeset 514104 0818e2b1f2c5510247c02330eb81051b04f935cc
parent 514103 bd806b413342b92dba5f91bd91b8f8ed2986b613
child 514105 229ed2090371d4bddb1948c219e63d35767bf792
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1504659
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 1504659 Part 3: 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
@@ -49,16 +49,17 @@ skip-if = true # Bug 1413765
 [browser_page_state.js]
 [browser_page_style.js]
 [browser_permission_doorhanger.js]
 tags = devtools geolocation
 skip-if = true # Bug 1413765
 [browser_preloaded_newtab.js]
 [browser_prompts.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,75 @@
+/* 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 scroll;
+
+  info("Checking initial scroll conditions.");
+  const viewportScroll = await getViewportScroll(ui);
+  is(viewportScroll.x, 0, "Content should load with scrollX 0.");
+  is(viewportScroll.y, 0, "Content should load with scrollY 0.");
+
+  /**
+   * Here we're going to send off some arrow key events to trigger scrolling.
+   * What we would like to be able to do is to await the scroll event and then
+   * check the scroll position to confirm the amount of scrolling that has
+   * happened. Unfortunately, APZ makes the scrolling happen asynchronously on
+   * the compositor thread, and it's very difficult to await the end state of
+   * the APZ animation -- see the tests in /gfx/layers/apz/test/mochitest for
+   * an example. For our purposes, it's sufficient to test that the scroll
+   * event is fired at all, and not worry about the amount of scrolling that
+   * has occurred at the time of the event. If the key events don't trigger
+   * scrolling, then no event will be fired and the test will time out.
+   */
+  scroll = waitForViewportScroll(ui);
+  EventUtils.synthesizeKey("KEY_ArrowDown");
+  await scroll;
+  info("Scroll event was fired after arrow key down.");
+
+  scroll = waitForViewportScroll(ui);
+  EventUtils.synthesizeKey("KEY_ArrowRight");
+  await scroll;
+  info("Scroll event was fired after arrow key right.");
+}
--- 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)");
 });