Bug 1497447: Add test for connection prompt preference setting. r=jdescottes
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Tue, 23 Oct 2018 01:13:44 +0000
changeset 490899 c92898803b7ea3460832f1d0548f973ed070cdbd
parent 490898 9ea7d4eba90f391f32164969ddc2d17b1cb84f40
child 490900 7efdeaeffda83a4440e180fc46c40c36cd79decb
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjdescottes
bugs1497447
milestone65.0a1
Bug 1497447: Add test for connection prompt preference setting. r=jdescottes Depends on D9067 Differential Revision: https://phabricator.services.mozilla.com/D9068
devtools/client/aboutdebugging-new/src/components/ConnectionPromptSetting.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connection_prompt_setting.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js
devtools/client/aboutdebugging-new/test/browser/head.js
--- a/devtools/client/aboutdebugging-new/src/components/ConnectionPromptSetting.js
+++ b/devtools/client/aboutdebugging-new/src/components/ConnectionPromptSetting.js
@@ -34,17 +34,17 @@ class ConnectionPromptSetting extends Pu
                              : "about-debugging-connection-prompt-enable-button";
 
     return Localized(
       {
         id: localizedState,
       },
       dom.button(
         {
-          className: "default-button",
+          className: "default-button js-connection-prompt-toggle-button",
           onClick: () => this.onToggleClick(),
         },
         localizedState
       )
     );
   }
 }
 
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -8,16 +8,17 @@ support-files =
   resources/test-adb-extension/*
   resources/test-temporary-extension/*
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
 
 [browser_aboutdebugging_connect_networklocations.js]
 [browser_aboutdebugging_connect_toggle_usb_devices.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
+[browser_aboutdebugging_connection_prompt_setting.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
 [browser_aboutdebugging_debug-target-pane_empty.js]
 [browser_aboutdebugging_navigate.js]
 [browser_aboutdebugging_sidebar_network_runtimes.js]
 [browser_aboutdebugging_sidebar_usb_status.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_thisfirefox.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connection_prompt_setting.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Check whether can toggle enable/disable connection prompt setting.
+ */
+add_task(async function() {
+  info("Set initial state for test");
+  await pushPref("devtools.debugger.prompt-connection", true);
+
+  const { document, tab } = await openAboutDebugging();
+
+  info("Check whether connection prompt toggle button exists");
+  const connectionPromptToggleButton =
+    document.querySelector(".js-connection-prompt-toggle-button");
+  ok(connectionPromptToggleButton, "Toggle button existed");
+  await waitUntil(() => connectionPromptToggleButton.textContent.includes("Disable"));
+
+  info("Click on the toggle button");
+  connectionPromptToggleButton.click();
+  info("Wait until the toggle button text is updated");
+  await waitUntil(() => connectionPromptToggleButton.textContent.includes("Enable"));
+  info("Check the preference");
+  is(Services.prefs.getBoolPref("devtools.debugger.prompt-connection"),
+     false,
+     "The preference should be updated");
+
+  info("Click on the toggle button again");
+  connectionPromptToggleButton.click();
+  info("Wait until the toggle button text is updated");
+  await waitUntil(() => connectionPromptToggleButton.textContent.includes("Disable"));
+  info("Check the preference");
+  is(Services.prefs.getBoolPref("devtools.debugger.prompt-connection"),
+     true,
+     "The preference should be updated");
+
+  await removeTab(tab);
+});
--- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js
@@ -20,22 +20,16 @@ add_task(async function() {
   const connectSidebarItem = findSidebarItemByText("Connect", document);
   ok(connectSidebarItem, "Found the Connect sidebar item");
 
   const thisFirefoxSidebarItem = findSidebarItemByText("This Firefox", document);
   ok(thisFirefoxSidebarItem, "Found the ThisFirefox sidebar item");
   ok(isSidebarItemSelected(thisFirefoxSidebarItem),
     "ThisFirefox sidebar item is selected by default");
 
-  // Wait until the about:debugging target is visible in the tab list
-  // Otherwise, we might have a race condition where TAB1 is discovered by the initial
-  // listTabs from the watchRuntime action, instead of being discovered after the
-  // TAB_UPDATED event. See analysis in Bug 1493968.
-  await waitUntil(() => findDebugTargetByText("about:debugging", document));
-
   info("Open a new background tab TAB1");
   const backgroundTab1 = await addTab(TAB_URL_1, { background: true });
 
   info("Wait for the tab to appear in the debug targets with the correct name");
   await waitUntil(() => findDebugTargetByText("TAB1", document));
 
   info("Click on the Connect item in the sidebar");
   connectSidebarItem.click();
@@ -73,13 +67,8 @@ add_task(async function() {
   await waitUntil(() => !findDebugTargetByText("TAB2", document));
 
   await removeTab(tab);
 });
 
 function isSidebarItemSelected(item) {
   return item.classList.contains("js-sidebar-item-selected");
 }
-
-function findDebugTargetByText(text, document) {
-  const targets = [...document.querySelectorAll(".js-debug-target-item")];
-  return targets.find(target => target.textContent.includes(text));
-}
--- a/devtools/client/aboutdebugging-new/test/browser/head.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head.js
@@ -46,16 +46,22 @@ async function openAboutDebugging(page, 
   const window = browser.contentWindow;
 
   info("Wait until the main about debugging container is available");
   await waitUntil(() => document.querySelector(".app"));
 
   info("Wait until the client connection was established");
   await waitUntil(() => document.querySelector(".js-runtime-page"));
 
+  // Wait until the about:debugging target is visible in the tab list
+  // Otherwise, we might have a race condition where TAB1 is discovered by the initial
+  // listTabs from the watchRuntime action, instead of being discovered after the
+  // TAB_UPDATED event. See analysis in Bug 1493968.
+  await waitUntil(() => findDebugTargetByText("about:debugging", document));
+
   return { tab, document, window };
 }
 
 /**
  * Navigate to the Connect page. Resolves when the Connect page is rendered.
  */
 async function selectConnectPage(doc) {
   const sidebarItems = doc.querySelectorAll(".js-sidebar-item");
@@ -66,14 +72,19 @@ async function selectConnectPage(doc) {
 
   info("Click on the Connect item in the sidebar");
   connectSidebarItem.click();
 
   info("Wait until Connect page is displayed");
   await waitUntil(() => doc.querySelector(".js-connect-page"));
 }
 
+function findDebugTargetByText(text, document) {
+  const targets = [...document.querySelectorAll(".js-debug-target-item")];
+  return targets.find(target => target.textContent.includes(text));
+}
+
 function findSidebarItemByText(text, document) {
   const sidebarItems = document.querySelectorAll(".js-sidebar-item");
   return [...sidebarItems].find(element => {
     return element.textContent.includes(text);
   });
 }