Bug 1500350: Add a test for extension debug setting. r=jdescottes,ladybenko
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Tue, 19 Feb 2019 01:18:05 +0000
changeset 459838 dd4aa59c6a12
parent 459837 ef94872bfd12
child 459839 1e97c3573ce6
child 459888 6d375c8210ff
push id35576
push userbtara@mozilla.com
push dateTue, 19 Feb 2019 09:46:27 +0000
treeherdermozilla-central@dd4aa59c6a12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes, ladybenko
bugs1500350
milestone67.0a1
first release with
nightly linux32
dd4aa59c6a12 / 67.0a1 / 20190219094627 / files
nightly linux64
dd4aa59c6a12 / 67.0a1 / 20190219094627 / files
nightly mac
dd4aa59c6a12 / 67.0a1 / 20190219094627 / files
nightly win32
dd4aa59c6a12 / 67.0a1 / 20190219094627 / files
nightly win64
dd4aa59c6a12 / 67.0a1 / 20190219094627 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1500350: Add a test for extension debug setting. r=jdescottes,ladybenko Depends on D18199 Differential Revision: https://phabricator.services.mozilla.com/D18200
devtools/client/aboutdebugging-new/src/components/ExtensionDebugSetting.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_debug_setting_thisfirefox.js
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_debug_setting_usb.js
--- a/devtools/client/aboutdebugging-new/src/components/ExtensionDebugSetting.js
+++ b/devtools/client/aboutdebugging-new/src/components/ExtensionDebugSetting.js
@@ -32,17 +32,17 @@ class ExtensionDebugSetting extends Pure
 
   renderCheckbox() {
     const { extensionDebugEnabled } = this.props;
 
     return dom.input(
       {
         type: "checkbox",
         id: "extension-debug-setting-input",
-        className: "default-checkbox",
+        className: "default-checkbox  js-extension-debug-checkbox",
         checked: extensionDebugEnabled,
         onChange: () => this.onToggle(),
       }
     );
   }
 
   renderLabel() {
     return Localized(
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -28,16 +28,18 @@ support-files =
 tags = webextensions
 [browser_aboutdebugging_addons_debug_inspector.js]
 tags = webextensions
 [browser_aboutdebugging_addons_debug_nobg.js]
 tags = webextensions
 [browser_aboutdebugging_addons_debug_popup.js]
 skip-if = (verify && debug) || (debug && os == "linux" && bits == 64) # verify: crashes on shutdown, timeouts linux debug Bug 1299001
 tags = webextensions
+[browser_aboutdebugging_addons_debug_setting_thisfirefox.js]
+[browser_aboutdebugging_addons_debug_setting_usb.js]
 [browser_aboutdebugging_addons_manifest_url.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_addons_remote_runtime.js]
 [browser_aboutdebugging_addons_temporary_addon_buttons.js]
 skip-if = (os == 'win') # On windows the AddonManager locks the XPI file loaded as a temporary extension and we can not test the reload of the extension.
 [browser_aboutdebugging_addons_temporary_id_message.js]
 [browser_aboutdebugging_addons_temporary_install_error.js]
 [browser_aboutdebugging_addons_warnings.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_debug_setting_thisfirefox.js
@@ -0,0 +1,110 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-collapsibilities.js", this);
+
+const TEMPORARY_EXTENSION_ID = "test-devtools-webextension@mozilla.org";
+const TEMPORARY_EXTENSION_NAME = "test-devtools-webextension";
+const REGULAR_EXTENSION_ID = "packaged-extension@tests";
+const REGULAR_EXTENSION_NAME = "Packaged extension";
+
+const TEST_DATA = [
+  {
+    chromeEnabled: false,
+    debuggerRemoteEnable: false,
+    isEnabledAtInitial: false,
+  }, {
+    chromeEnabled: false,
+    debuggerRemoteEnable: true,
+    isEnabledAtInitial: false,
+  }, {
+    chromeEnabled: true,
+    debuggerRemoteEnable: false,
+    isEnabledAtInitial: false,
+  }, {
+    chromeEnabled: true,
+    debuggerRemoteEnable: true,
+    isEnabledAtInitial: true,
+  },
+];
+
+/**
+ * Check the state of extension debug setting checkbox, inspect buttons and prefs on
+ * this-firefox at initializing and after toggling.
+ */
+add_task(async function() {
+  info("Force all debug target panes to be expanded");
+  prepareCollapsibilitiesTest();
+
+  for (const testData of TEST_DATA) {
+    await testState(testData);
+  }
+});
+
+async function testState({ chromeEnabled, debuggerRemoteEnable, isEnabledAtInitial }) {
+  info(`Test for chromeEnabled: ${ chromeEnabled }, ` +
+       `debuggerRemoteEnable:${ debuggerRemoteEnable }`);
+
+  info("Set initial state for test");
+  await pushPref("devtools.chrome.enabled", chromeEnabled);
+  await pushPref("devtools.debugger.remote-enabled", debuggerRemoteEnable);
+
+  const { document, tab, window } = await openAboutDebugging();
+  await selectThisFirefoxPage(document, window.AboutDebugging.store);
+  await installExtensions(document);
+
+  info("Check the status of extension debug setting checkbox and inspect buttons");
+  const checkbox = document.querySelector(".js-extension-debug-checkbox");
+  ok(checkbox, "Extension debug setting checkbox exists");
+  is(checkbox.checked, isEnabledAtInitial, "The state of checkbox is correct");
+  assertInspectButtons(isEnabledAtInitial, document);
+
+  info("Check the status after toggling checkbox");
+  checkbox.click();
+  await waitUntil(() => checkbox.checked !== isEnabledAtInitial);
+  ok(true, "The state of checkbox is changed correctly after toggling");
+  assertPreferences(!isEnabledAtInitial);
+  assertInspectButtons(!isEnabledAtInitial, document);
+
+  await uninstallExtensions(document);
+  await removeTab(tab);
+}
+
+function assertPreferences(expected) {
+  for (const pref of ["devtools.chrome.enabled", "devtools.debugger.remote-enabled"]) {
+    is(Services.prefs.getBoolPref(pref), expected, `${ pref } should be ${expected}`);
+  }
+}
+
+function assertInspectButtons(shouldBeEnabled, document) {
+  assertInspectButtonsOnCategory(shouldBeEnabled, "Temporary Extensions", document);
+  assertInspectButtonsOnCategory(shouldBeEnabled, "Extensions", document);
+  // Inspect button on Tabs category should be always enabled.
+  assertInspectButtonsOnCategory(true, "Tabs", document);
+}
+
+function assertInspectButtonsOnCategory(shouldBeEnabled, category, document) {
+  const pane = getDebugTargetPane(category, document);
+  const buttons = pane.querySelectorAll(".js-debug-target-inspect-button");
+  ok([...buttons].every(b => b.disabled !== shouldBeEnabled),
+     `disabled attribute should be ${ !shouldBeEnabled } on ${ category }`);
+}
+
+async function installExtensions(document) {
+  await installTemporaryExtensionFromXPI({
+    id: TEMPORARY_EXTENSION_ID,
+    name: TEMPORARY_EXTENSION_NAME,
+  }, document);
+
+  await installRegularExtension("resources/packaged-extension/packaged-extension.xpi");
+}
+
+async function uninstallExtensions(document) {
+  await removeTemporaryExtension(TEMPORARY_EXTENSION_NAME, document);
+  await removeExtension(REGULAR_EXTENSION_ID, REGULAR_EXTENSION_NAME, document);
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_addons_debug_setting_usb.js
@@ -0,0 +1,41 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-collapsibilities.js", this);
+
+/**
+ * Check extension debug setting on USB runtime.
+ */
+add_task(async function() {
+  info("Force all debug target panes to be expanded");
+  prepareCollapsibilitiesTest();
+
+  info("Set initial state for test");
+  await pushPref("devtools.debugger.remote-enabled", false);
+
+  // Setup USB devices mocks
+  const mocks = new Mocks();
+  const usbRuntime = mocks.createUSBRuntime("1337id", {
+    deviceName: "Fancy Phone",
+    name: "Lorem ipsum",
+  });
+  const extension = { name: "Test extension name", debuggable: true };
+  usbRuntime.listAddons = () => [extension];
+
+  const { document, tab, window } = await openAboutDebugging();
+  await selectThisFirefoxPage(document, window.AboutDebugging.store);
+  mocks.emitUSBUpdate();
+
+  info("Check the status of extension debug setting checkbox and inspect buttons");
+  await connectToRuntime("Fancy Phone", document);
+  await selectRuntime("Fancy Phone", "Lorem ipsum", document);
+  ok(!document.querySelector(".js-extension-debug-checkbox"),
+     "Extension debug setting checkbox should not exist");
+  const buttons = document.querySelectorAll(".js-debug-target-inspect-button");
+  ok([...buttons].every(b => !b.disabled), "All inspect buttons should be enabled");
+
+  await removeTab(tab);
+});