diff --git a/devtools/client/aboutdebugging-new/src/components/RuntimePage.js b/devtools/client/aboutdebugging-new/src/components/RuntimePage.js index 35318f6a8476..4543ba8c206d 100644 --- a/devtools/client/aboutdebugging-new/src/components/RuntimePage.js +++ b/devtools/client/aboutdebugging-new/src/components/RuntimePage.js @@ -25,7 +25,7 @@ const TemporaryExtensionInstaller = const WorkerDetail = createFactory(require("./debugtarget/WorkerDetail")); const Actions = require("../actions/index"); -const { DEBUG_TARGET_PANE, PAGE_TYPES } = require("../constants"); +const { DEBUG_TARGET_PANE, PAGE_TYPES, RUNTIMES } = require("../constants"); const { getCurrentConnectionPromptSetting, @@ -98,6 +98,7 @@ class RuntimePage extends PureComponent { dispatch, installedExtensions, otherWorkers, + runtimeId, runtimeInfo, serviceWorkers, sharedWorkers, @@ -111,12 +112,17 @@ class RuntimePage extends PureComponent { return null; } + // do not show the connection prompt setting in 'This Firefox' + const shallShowPromptSetting = runtimeId !== RUNTIMES.THIS_FIREFOX; + return dom.article( { className: "page js-runtime-page", }, RuntimeInfo(runtimeInfo), - this.renderConnectionPromptSetting(), + shallShowPromptSetting + ? this.renderConnectionPromptSetting() + : null, isSupportedDebugTargetPane(runtimeInfo.type, DEBUG_TARGET_PANE.TEMPORARY_EXTENSION) ? TemporaryExtensionInstaller({ dispatch }) : null, diff --git a/devtools/client/aboutdebugging-new/test/browser/browser.ini b/devtools/client/aboutdebugging-new/test/browser/browser.ini index 19d3a39284a0..dd6993e80549 100644 --- a/devtools/client/aboutdebugging-new/test/browser/browser.ini +++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini @@ -31,6 +31,7 @@ skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug [browser_aboutdebugging_navigate.js] [browser_aboutdebugging_persist_connection.js] [browser_aboutdebugging_routes.js] +[browser_aboutdebugging_runtime_connection-prompt.js] [browser_aboutdebugging_select_network_runtime.js] [browser_aboutdebugging_sidebar_network_runtimes.js] [browser_aboutdebugging_sidebar_usb_runtime.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 index 0b96cb90b720..b707e9ab6ef9 100644 --- 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 @@ -3,38 +3,55 @@ "use strict"; +/* import-globals-from head-mocks.js */ +Services.scriptloader.loadSubScript( + CHROME_URL_ROOT + "head-mocks.js", this); + /** * Check whether can toggle enable/disable connection prompt setting. */ add_task(async function() { + // enable USB devices mocks + const mocks = new Mocks(); + const runtime = mocks.createUSBRuntime("1337id", { + deviceName: "Fancy Phone", + name: "Lorem ipsum", + }); + info("Set initial state for test"); await pushPref("devtools.debugger.prompt-connection", true); + // open a remote runtime page const { document, tab } = await openAboutDebugging(); + mocks.emitUSBUpdate(); + await connectToRuntime("Fancy Phone", document); + await selectRuntime("Fancy Phone", "Lorem ipsum", document); + info("Check whether connection prompt toggle button exists"); - const connectionPromptToggleButton = + let connectionPromptToggleButton = document.querySelector(".js-connection-prompt-toggle-button"); ok(connectionPromptToggleButton, "Toggle button existed"); - await waitUntil(() => connectionPromptToggleButton.textContent.includes("Disable")); + ok(connectionPromptToggleButton.textContent.includes("Disable"), + "Toggle button shows 'Disable'"); info("Click on the toggle button"); + connectionPromptToggleButton = + document.querySelector(".js-connection-prompt-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"); + const disabledPref = runtime.getPreference("devtools.debugger.prompt-connection"); + is(disabledPref, 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"); + const enabledPref = runtime.getPreference("devtools.debugger.prompt-connection"); + is(enabledPref, true, "The preference should be updated"); await removeTab(tab); }); diff --git a/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_runtime_connection-prompt.js b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_runtime_connection-prompt.js new file mode 100644 index 000000000000..cbff24909941 --- /dev/null +++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_runtime_connection-prompt.js @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/* import-globals-from head-mocks.js */ +Services.scriptloader.loadSubScript( + CHROME_URL_ROOT + "head-mocks.js", this); + +/** + * Test that remote runtimes show the connection prompt, + * but it's hidden in 'This Firefox' + */ +add_task(async function() { + // enable USB devices mocks + const mocks = new Mocks(); + mocks.createUSBRuntime("1337id", { + deviceName: "Fancy Phone", + name: "Lorem ipsum", + }); + + const { document, tab } = await openAboutDebugging(); + + info("Checking This Firefox"); + ok(!document.querySelector(".js-connection-prompt-toggle-button"), + "This Firefox does not contain the connection prompt button"); + + info("Checking a USB runtime"); + mocks.emitUSBUpdate(); + await connectToRuntime("Fancy Phone", document); + await selectRuntime("Fancy Phone", "Lorem ipsum", document); + ok(!!document.querySelector(".js-connection-prompt-toggle-button"), + "Runtime contains the connection prompt button"); + + await removeTab(tab); +}); diff --git a/devtools/client/aboutdebugging-new/test/browser/mocks/head-client-wrapper-mock.js b/devtools/client/aboutdebugging-new/test/browser/mocks/head-client-wrapper-mock.js index 5f904e73b89e..175a27039b0d 100644 --- a/devtools/client/aboutdebugging-new/test/browser/mocks/head-client-wrapper-mock.js +++ b/devtools/client/aboutdebugging-new/test/browser/mocks/head-client-wrapper-mock.js @@ -26,6 +26,7 @@ function createClientMock() { // add a reference to the internal event emitter so that consumers can fire client // events. _eventEmitter: eventEmitter, + _preferences: {}, addOneTimeListener: (evt, listener) => { eventEmitter.once(evt, listener); }, @@ -55,7 +56,10 @@ function createClientMock() { // no-op getDeviceDescription: () => {}, // Return default preference value or null if no match. - getPreference: (prefName) => { + getPreference: function(prefName) { + if (prefName in this._preferences) { + return this._preferences[prefName]; + } if (prefName in DEFAULT_PREFERENCES) { return DEFAULT_PREFERENCES[prefName]; } @@ -71,8 +75,10 @@ function createClientMock() { serviceWorkers: [], sharedWorkers: [], }), - // no-op - setPreference: () => {}, + // stores the preference locally (doesn't update about:config) + setPreference: function(prefName, value) { + this._preferences[prefName] = value; + }, }; }