Bug 1488500 - Add test for temporary extension install error;r=daisuke
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 07 Dec 2018 15:59:03 +0000
changeset 449688 8b2231ca82cdc24af258d660f7219558bcbe7221
parent 449687 11412ab473bc033509ceef42326eecaec4ec18c1
child 449689 48a91a80b4df0c4beafbb651c2b187f8a78b5462
push id35182
push usercbrindusan@mozilla.com
push dateMon, 10 Dec 2018 22:02:24 +0000
treeherdermozilla-central@773061bafdd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke
bugs1488500
milestone65.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 1488500 - Add test for temporary extension install error;r=daisuke Depends on D12571 Differential Revision: https://phabricator.services.mozilla.com/D12572
devtools/client/aboutdebugging-new/src/components/shared/ErrorMessage.js
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_temporary_addon_install_error.js
devtools/client/aboutdebugging-new/test/browser/head-addons-script.js
devtools/client/aboutdebugging-new/test/browser/resources/bad-extension/manifest.json
--- a/devtools/client/aboutdebugging-new/src/components/shared/ErrorMessage.js
+++ b/devtools/client/aboutdebugging-new/src/components/shared/ErrorMessage.js
@@ -23,17 +23,17 @@ class ErrorMessage extends PureComponent
       // Should match a valid localized string key.
       errorDescriptionKey: PropTypes.string.isRequired,
     };
   }
 
   render() {
     return dom.div(
       {
-        className: "error-message",
+        className: "error-message js-error-message",
       },
       dom.div(
         {
           className: "error-message__header",
         },
         dom.img(
           {
             // Temporary image chosen to match error container in about:addons.
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -6,16 +6,17 @@ prefs =
   # ensure consistent test behavior by always setting this to false.
   devtools.aboutdebugging.showSystemAddons=false
 support-files =
   debug-target-pane_collapsibilities_head.js
   head-addons-script.js
   head-mocks.js
   head.js
   mocks/*
+  resources/bad-extension/*
   resources/test-adb-extension/*
   resources/test-temporary-extension/*
   test-tab-favicons.html
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/shared-redux-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
 
 [browser_aboutdebugging_addons_remote_runtime.js]
@@ -38,11 +39,12 @@ skip-if = (os == 'linux' && bits == 32) 
 [browser_aboutdebugging_sidebar_usb_runtime_connect.js]
 [browser_aboutdebugging_sidebar_usb_runtime_refresh.js]
 [browser_aboutdebugging_sidebar_usb_status.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_stop_adb.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_system_addons.js]
 [browser_aboutdebugging_tab_favicons.js]
+[browser_aboutdebugging_temporary_addon_install_error.js]
 [browser_aboutdebugging_thisfirefox.js]
 [browser_aboutdebugging_thisfirefox_runtime_info.js]
 [browser_aboutdebugging_thisfirefox_worker_inspection.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_temporary_addon_install_error.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* import-globals-from head-addons-script.js */
+
+"use strict";
+
+// Load addons helpers
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "head-addons-script.js", this);
+
+/**
+ * Test that the installation error messages are displayed when installing temporary
+ * extensions.
+ */
+
+const BAD_EXTENSION_PATH = "resources/bad-extension/manifest.json";
+const EXTENSION_PATH = "resources/test-temporary-extension/manifest.json";
+const EXTENSION_NAME = "test-temporary-extension";
+
+add_task(async function() {
+  const { document, tab } = await openAboutDebugging();
+
+  info("Install a bad extension");
+  // Do not use installTemporaryAddon here since the install will fail.
+  prepareMockFilePicker(BAD_EXTENSION_PATH);
+  document.querySelector(".js-temporary-extension-install-button").click();
+
+  info("Wait until the install error message appears");
+  await waitUntil(() => document.querySelector(".js-error-message"));
+  const installError = document.querySelector(".js-error-message");
+  ok(installError.textContent.includes("JSON.parse: unexpected keyword"),
+    "The expected installation error is displayed: " + installError.textContent);
+
+  info("Install a valid extension to make the message disappear");
+  await installTemporaryExtension(EXTENSION_PATH, EXTENSION_NAME, document);
+
+  info("Wait until the error message disappears");
+  await waitUntil(() => !document.querySelector(".js-error-message"));
+
+  info("Wait for the temporary addon to be displayed as a debug target");
+  await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, document));
+
+  await removeTemporaryExtension(EXTENSION_NAME, document);
+
+  await removeTab(tab);
+});
--- a/devtools/client/aboutdebugging-new/test/browser/head-addons-script.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head-addons-script.js
@@ -1,11 +1,12 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 /* import-globals-from ../../../shared/test/shared-head.js */
+/* import-globals-from head.js */
 
 "use strict";
 
 const { Management } = ChromeUtils.import("resource://gre/modules/Extension.jsm", {});
 
 function getSupportsFile(path) {
   const cr = Cc["@mozilla.org/chrome/chrome-registry;1"]
     .getService(Ci.nsIChromeRegistry);
@@ -16,20 +17,17 @@ function getSupportsFile(path) {
 
 /**
  * Install a temporary extension at the provided path, with the provided name.
  * Will use a mock file picker to select the file.
  */
 // eslint-disable-next-line no-unused-vars
 async function installTemporaryExtension(path, name, document) {
   // Mock the file picker to select a test addon
-  const MockFilePicker = SpecialPowers.MockFilePicker;
-  MockFilePicker.init(window);
-  const file = getSupportsFile(path);
-  MockFilePicker.setFiles([file.file]);
+  prepareMockFilePicker(path);
 
   const onAddonInstalled = new Promise(done => {
     Management.on("startup", function listener(event, extension) {
       if (extension.name != name) {
         return;
       }
 
       Management.off("startup", listener);
@@ -38,8 +36,24 @@ async function installTemporaryExtension
   });
 
   // Trigger the file picker by clicking on the button
   document.querySelector(".js-temporary-extension-install-button").click();
 
   info("Wait for addon to be installed");
   await onAddonInstalled;
 }
+
+async function removeTemporaryExtension(name, document) {
+  info(`Remove the temporary extension with name: '${name}'`);
+  const temporaryExtensionItem = findDebugTargetByText(name, document);
+  temporaryExtensionItem.querySelector(".js-temporary-extension-remove-button").click();
+
+  info("Wait until the debug target item disappears");
+  await waitUntil(() => !findDebugTargetByText(name, document));
+}
+
+function prepareMockFilePicker(path) {
+  // Mock the file picker to select a test addon
+  const MockFilePicker = SpecialPowers.MockFilePicker;
+  MockFilePicker.init(window);
+  MockFilePicker.setFiles([getSupportsFile(path).file]);
+}
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/resources/bad-extension/manifest.json
@@ -0,0 +1,1 @@
+this is not valid json