From 39993dba214de95a31267b376be877843706a787 Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Tue, 23 Oct 2018 01:13:44 +0000 Subject: [PATCH] Bug 1497447: Add test for connection prompt preference setting. r=jdescottes Depends on D9067 Differential Revision: https://phabricator.services.mozilla.com/D9068 --HG-- extra : moz-landing-system : lando --- .../src/components/ConnectionPromptSetting.js | 2 +- .../test/browser/browser.ini | 1 + ...boutdebugging_connection_prompt_setting.js | 40 +++++++++++++++++++ .../browser_aboutdebugging_navigate.js | 11 ----- .../aboutdebugging-new/test/browser/head.js | 11 +++++ 5 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connection_prompt_setting.js diff --git a/devtools/client/aboutdebugging-new/src/components/ConnectionPromptSetting.js b/devtools/client/aboutdebugging-new/src/components/ConnectionPromptSetting.js index a09c4f96a490..198893cbd62b 100644 --- a/devtools/client/aboutdebugging-new/src/components/ConnectionPromptSetting.js +++ b/devtools/client/aboutdebugging-new/src/components/ConnectionPromptSetting.js @@ -39,7 +39,7 @@ class ConnectionPromptSetting extends PureComponent { }, dom.button( { - className: "default-button", + className: "default-button js-connection-prompt-toggle-button", onClick: () => this.onToggleClick(), }, localizedState diff --git a/devtools/client/aboutdebugging-new/test/browser/browser.ini b/devtools/client/aboutdebugging-new/test/browser/browser.ini index 9c8a3ee1cb85..7291927317b1 100644 --- a/devtools/client/aboutdebugging-new/test/browser/browser.ini +++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini @@ -13,6 +13,7 @@ support-files = [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] diff --git a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connection_prompt_setting.js b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_connection_prompt_setting.js new file mode 100644 index 000000000000..0b96cb90b720 --- /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); +}); diff --git a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js index 6fc686d52b76..d30505e286f3 100644 --- a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js +++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_navigate.js @@ -25,12 +25,6 @@ add_task(async function() { 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 }); @@ -78,8 +72,3 @@ add_task(async function() { 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)); -} diff --git a/devtools/client/aboutdebugging-new/test/browser/head.js b/devtools/client/aboutdebugging-new/test/browser/head.js index 6a9eb3464e38..991960ffc635 100644 --- a/devtools/client/aboutdebugging-new/test/browser/head.js +++ b/devtools/client/aboutdebugging-new/test/browser/head.js @@ -51,6 +51,12 @@ async function openAboutDebugging(page, win) { 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 }; } @@ -71,6 +77,11 @@ async function selectConnectPage(doc) { 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 => {