Bug 1540609: Add a test whether the status of connect button will be reverted after a certain period of time. r=jdescottes
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Thu, 18 Apr 2019 02:54:34 +0000
changeset 469989 b28102014ab9bbf2de762f9a1f0bedbe09768b7e
parent 469988 31bf296dcfcea35e26503ea3594b914163f5a326
child 469990 90a95d56b18df1b2a658dd8b156486e31b3ee0ec
push id83478
push userdakatsuka@mozilla.com
push dateThu, 18 Apr 2019 02:55:46 +0000
treeherderautoland@b28102014ab9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1540609
milestone68.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 1540609: Add a test whether the status of connect button will be reverted after a certain period of time. r=jdescottes Depends on D27645 Differential Revision: https://phabricator.services.mozilla.com/D27646
devtools/client/aboutdebugging-new/src/actions/runtimes.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_connection_state.js
--- a/devtools/client/aboutdebugging-new/src/actions/runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/actions/runtimes.js
@@ -1,14 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+const Services = require("Services");
+
 const Actions = require("./index");
 
 const {
   getAllRuntimes,
   getCurrentRuntime,
   findRuntimeById,
 } = require("../modules/runtimes-state-helper");
 
@@ -70,30 +72,39 @@ function onRemoteDebuggerClientClosed() 
 
 function onMultiE10sUpdated() {
   window.AboutDebugging.store.dispatch(updateMultiE10s());
 }
 
 function connectRuntime(id) {
   return async (dispatch, getState) => {
     dispatch({ type: CONNECT_RUNTIME_START, id });
+
+    // The preferences test-connection-timing-out-delay and test-connection-cancel-delay
+    // don't have a default value but will be overridden during our tests.
+    const connectionTimingOutDelay = Services.prefs.getIntPref(
+      "devtools.aboutdebugging.test-connection-timing-out-delay",
+      CONNECTION_TIMING_OUT_DELAY);
+    const connectionCancelDelay = Services.prefs.getIntPref(
+      "devtools.aboutdebugging.test-connection-cancel-delay", CONNECTION_CANCEL_DELAY);
+
     const connectionNotRespondingTimer = setTimeout(() => {
       // If connecting to the runtime takes time over CONNECTION_TIMING_OUT_DELAY,
       // we assume the connection prompt is showing on the runtime, show a dialog
       // to let user know that.
       dispatch({ type: CONNECT_RUNTIME_NOT_RESPONDING, id });
-    }, CONNECTION_TIMING_OUT_DELAY);
+    }, connectionTimingOutDelay);
     const connectionCancelTimer = setTimeout(() => {
       // Connect button of the runtime will be disabled during connection, but the status
       // continues till the connection was either succeed or failed. This may have a
       // possibility that the disabling continues unless page reloading, user will not be
       // able to click again. To avoid this, revert the connect button status after
       // CONNECTION_CANCEL_DELAY ms.
       dispatch({ type: CONNECT_RUNTIME_CANCEL, id });
-    }, CONNECTION_CANCEL_DELAY);
+    }, connectionCancelDelay);
 
     try {
       const runtime = findRuntimeById(id, getState().runtimes);
       const clientWrapper = await createClientForRuntime(runtime);
 
       const deviceDescription = await clientWrapper.getDeviceDescription();
       const compatibilityReport = await clientWrapper.checkVersionCompatibility();
       const icon = await getRuntimeIcon(deviceDescription.channel);
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_connection_state.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_sidebar_connection_state.js
@@ -3,21 +3,26 @@
 
 "use strict";
 
 const RUNTIME_ID = "test-runtime-id";
 const RUNTIME_NAME = "test runtime name";
 const RUNTIME_DEVICE_NAME = "test device name";
 const RUNTIME_SHORT_NAME = "test short name";
 
+const CONNECTION_TIMING_OUT_DELAY = 1000;
+const CONNECTION_CANCEL_DELAY = 2000;
+
 // Test following connection state tests.
 // * Connect button label and state will change during connecting.
 // * Show error message if connection failed.
 // * Show warninng if connection has been taken time.
 add_task(async function() {
+  await setupPreferences();
+
   const mocks = new Mocks();
 
   const { document, tab } = await openAboutDebugging();
 
   mocks.createUSBRuntime(RUNTIME_ID, {
     name: RUNTIME_NAME,
     deviceName: RUNTIME_DEVICE_NAME,
     shortName: RUNTIME_SHORT_NAME,
@@ -46,21 +51,21 @@ add_task(async function() {
   });
   mocks.runtimeClientFactoryMock.createClientForRuntime = async (runtime) => {
     await resumeConnectionPromise;
     return mocks._clients[runtime.type][runtime.id];
   };
 
   info("Click on the connect button and wait until it disappears");
   connectButton.click();
-  info("Check whether a warning of connection not responding displays after 3sec");
+  info("Check whether a warning of connection not responding displays");
   await waitUntil(() => document.querySelector(".qa-connection-not-responding"));
   ok(document.querySelector(".qa-connection-not-responding"),
      "A warning of connection not responding displays");
-  ok(connectButton.disabled, "State of the connect button displays");
+  ok(connectButton.disabled, "Connect button is disabled");
   ok(connectButton.textContent.startsWith("Connecting"),
      "Label of the connect button changes");
   ok(!document.querySelector(".qa-connection-error"), "Error message disappears");
 
   info("Unblock the connection and check the message and connect button disappear");
   resumeConnection();
   await waitUntil(() => !usbRuntimeSidebarItem.querySelector(".js-connect-button"));
   ok(!document.querySelector(".qa-connection-error"), "Error disappears");
@@ -68,8 +73,70 @@ add_task(async function() {
 
   info("Remove a USB runtime");
   mocks.removeUSBRuntime(RUNTIME_ID);
   mocks.emitUSBUpdate();
   await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
 
   await removeTab(tab);
 });
+
+// Test whether the status of all will be reverted after a certain period of time during
+// waiting connection.
+add_task(async function() {
+  await setupPreferences();
+
+  const mocks = new Mocks();
+
+  const { document, tab } = await openAboutDebugging();
+
+  mocks.createUSBRuntime(RUNTIME_ID, {
+    name: RUNTIME_NAME,
+    deviceName: RUNTIME_DEVICE_NAME,
+    shortName: RUNTIME_SHORT_NAME,
+  });
+  mocks.emitUSBUpdate();
+
+  info("Wait until the USB sidebar item appears");
+  await waitUntil(() => findSidebarItemByText(RUNTIME_DEVICE_NAME, document));
+  const usbRuntimeSidebarItem = findSidebarItemByText(RUNTIME_DEVICE_NAME, document);
+  const connectButton = usbRuntimeSidebarItem.querySelector(".js-connect-button");
+
+  let resumeConnection;
+  const resumeConnectionPromise = new Promise(r => {
+    resumeConnection = r;
+  });
+  mocks.runtimeClientFactoryMock.createClientForRuntime = async (runtime) => {
+    await resumeConnectionPromise;
+    return mocks._clients[runtime.type][runtime.id];
+  };
+
+  info("Click on the connect button and wait until it disappears");
+  connectButton.click();
+  await waitUntil(() => document.querySelector(".qa-connection-not-responding"));
+  info("Check whether the all status will be reverted");
+  await waitUntil(() => !document.querySelector(".qa-connection-not-responding"));
+  ok(document.querySelector(".qa-connection-timeout"),
+     "Connection timeout message displays");
+  ok(!connectButton.disabled, "Connect button is enabled");
+  is(connectButton.textContent, "Connect", "Label of the connect button reverted");
+  ok(!document.querySelector(".qa-connection-error"), "Error message disappears");
+
+  info("Check whether the timeout message disappears");
+  resumeConnection();
+  await waitUntil(() => !document.querySelector(".qa-connection-timeout"));
+
+  info("Remove a USB runtime");
+  mocks.removeUSBRuntime(RUNTIME_ID);
+  mocks.emitUSBUpdate();
+
+  info("Wait until the USB sidebar item disappears");
+  await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
+
+  await removeTab(tab);
+});
+
+async function setupPreferences() {
+  await pushPref("devtools.aboutdebugging.test-connection-timing-out-delay",
+                 CONNECTION_TIMING_OUT_DELAY);
+  await pushPref("devtools.aboutdebugging.test-connection-cancel-delay",
+                 CONNECTION_CANCEL_DELAY);
+}