Bug 1398297 - Reload RDM when disabling touch. r=gl
authorJ. Ryan Stinnett <jryans@gmail.com>
Fri, 08 Sep 2017 15:09:22 -0500
changeset 429549 3f4c7db71dc24cd682dac0e3612c464ee1c0c029
parent 429548 c33c05b5d47d306a2a7eeeca4a17aa48aa14f35f
child 429550 1a31654a23d3949e405d7a25d8061c7d41ae6d7b
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1398297
milestone57.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 1398297 - Reload RDM when disabling touch. r=gl MozReview-Commit-ID: ILdfxs5SXfH
devtools/client/responsive.html/manager.js
devtools/client/responsive.html/test/browser/browser_touch_device.js
devtools/client/responsive.html/test/browser/browser_touch_simulation.js
devtools/client/responsive.html/test/browser/head.js
--- a/devtools/client/responsive.html/manager.js
+++ b/devtools/client/responsive.html/manager.js
@@ -491,16 +491,18 @@ ResponsiveUI.prototype = {
   onChangePixelRatio(event) {
     let { pixelRatio } = event.data;
     this.updateDPPX(pixelRatio);
   },
 
   onChangeTouchSimulation(event) {
     let { enabled } = event.data;
     this.updateTouchSimulation(enabled);
+    // Used by tests
+    this.emit("touch-simulation-changed");
   },
 
   onContentResize(event) {
     let { width, height } = event.data;
     this.emit("content-resize", {
       width,
       height,
     });
@@ -545,23 +547,24 @@ ResponsiveUI.prototype = {
     if (!userAgent) {
       yield this.emulationFront.clearUserAgentOverride();
       return;
     }
     yield this.emulationFront.setUserAgentOverride(userAgent);
   }),
 
   updateTouchSimulation: Task.async(function* (enabled) {
-    if (!enabled) {
-      yield this.emulationFront.clearTouchEventsOverride();
-      return;
+    let reloadNeeded;
+    if (enabled) {
+      reloadNeeded = yield this.emulationFront.setTouchEventsOverride(
+        Ci.nsIDocShell.TOUCHEVENTS_OVERRIDE_ENABLED
+      );
+    } else {
+      reloadNeeded = yield this.emulationFront.clearTouchEventsOverride();
     }
-    let reloadNeeded = yield this.emulationFront.setTouchEventsOverride(
-      Ci.nsIDocShell.TOUCHEVENTS_OVERRIDE_ENABLED
-    );
     if (reloadNeeded) {
       this.getViewportBrowser().reload();
     }
   }),
 
   /**
    * Helper for tests. Assumes a single viewport for now.
    */
--- a/devtools/client/responsive.html/test/browser/browser_touch_device.js
+++ b/devtools/client/responsive.html/test/browser/browser_touch_device.js
@@ -25,16 +25,17 @@ addDeviceForTest(testDevice);
 addRDMTask(TEST_URL, function* ({ ui, manager }) {
   yield waitStartup(ui);
 
   yield testDefaults(ui);
   yield testChangingDevice(ui);
   yield testResizingViewport(ui, true, false);
   yield testEnableTouchSimulation(ui);
   yield testResizingViewport(ui, false, true);
+  yield testDisableTouchSimulation(ui);
 });
 
 function* waitStartup(ui) {
   let { store } = ui.toolWindow;
 
   // Wait until the viewport has been added and the device list has been loaded
   yield waitUntilState(store, state => state.viewports.length == 1
     && state.devices.listState == Types.deviceListState.LOADED);
@@ -51,27 +52,37 @@ function* testChangingDevice(ui) {
   info("Test Changing Device");
 
   yield selectDevice(ui, testDevice.name);
   yield waitForViewportResizeTo(ui, testDevice.width, testDevice.height);
   yield testTouchEventsOverride(ui, true);
   testViewportDeviceSelectLabel(ui, testDevice.name);
 }
 
-function* testResizingViewport(ui, device, expected) {
-  info(`Test resizing the viewport, device ${device}, expected ${expected}`);
+function* testResizingViewport(ui, device, touch) {
+  info(`Test resizing the viewport, device ${device}, touch ${touch}`);
 
-  let deviceRemoved = once(ui, "device-removed");
+  let deviceRemoved;
+  if (device) {
+    deviceRemoved = once(ui, "device-removed");
+  }
   yield testViewportResize(ui, ".viewport-vertical-resize-handle",
     [-10, -10], [testDevice.width, testDevice.height - 10], [0, -10], ui);
   if (device) {
     yield deviceRemoved;
   }
-  yield testTouchEventsOverride(ui, expected);
+  yield testTouchEventsOverride(ui, touch);
   testViewportDeviceSelectLabel(ui, "no device selected");
 }
 
 function* testEnableTouchSimulation(ui) {
   info("Test enabling touch simulation via button");
 
-  yield enableTouchSimulation(ui);
+  yield toggleTouchSimulation(ui);
   yield testTouchEventsOverride(ui, true);
 }
+
+function* testDisableTouchSimulation(ui) {
+  info("Test disabling touch simulation via button");
+
+  yield toggleTouchSimulation(ui);
+  yield testTouchEventsOverride(ui, false);
+}
--- a/devtools/client/responsive.html/test/browser/browser_touch_simulation.js
+++ b/devtools/client/responsive.html/test/browser/browser_touch_simulation.js
@@ -6,17 +6,17 @@
 // Test global touch simulation button
 
 const TEST_URL = `${URL_ROOT}touch.html`;
 const PREF_DOM_META_VIEWPORT_ENABLED = "dom.meta-viewport.enabled";
 
 addRDMTask(TEST_URL, function* ({ ui }) {
   yield waitBootstrap(ui);
   yield testWithNoTouch(ui);
-  yield enableTouchSimulation(ui);
+  yield toggleTouchSimulation(ui);
   yield testWithTouch(ui);
   yield testWithMetaViewportEnabled(ui);
   yield testWithMetaViewportDisabled(ui);
   testTouchButton(ui);
 });
 
 function* testWithNoTouch(ui) {
   yield injectEventUtils(ui);
--- a/devtools/client/responsive.html/test/browser/head.js
+++ b/devtools/client/responsive.html/test/browser/head.js
@@ -364,22 +364,23 @@ function* testTouchEventsOverride(ui, ex
 function testViewportDeviceSelectLabel(ui, expected) {
   info("Test viewport's device select label");
 
   let select = ui.toolWindow.document.querySelector(".viewport-device-selector");
   is(select.selectedOptions[0].textContent, expected,
      `Device Select value should be: ${expected}`);
 }
 
-function* enableTouchSimulation(ui) {
+function* toggleTouchSimulation(ui) {
   let { document } = ui.toolWindow;
   let touchButton = document.querySelector("#global-touch-simulation-button");
+  let changed = once(ui, "touch-simulation-changed");
   let loaded = waitForViewportLoad(ui);
   touchButton.click();
-  yield loaded;
+  yield Promise.all([ changed, loaded ]);
 }
 
 function* testUserAgent(ui, expected) {
   let ua = yield ContentTask.spawn(ui.getViewportBrowser(), {}, function* () {
     return content.navigator.userAgent;
   });
   is(ua, expected, `UA should be set to ${expected}`);
 }