Bug 1477137 - Part 2: Add a test for remove temporary and undo. r=jdescottes
☠☠ backed out by 6ddec20d1e35 ☠ ☠
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Fri, 27 Jul 2018 17:49:28 +0900
changeset 428710 c75f46c67e2733766dc9f2a3b6ac7979b6ef65f7
parent 428709 dd5e331122a911f9bb88e50205de4e2e841073cd
child 428711 060f8e446844e423d93a6dec7ba227725572739c
push id34340
push userdvarga@mozilla.com
push dateFri, 27 Jul 2018 17:37:02 +0000
treeherdermozilla-central@d353b80fd66c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1477137
milestone63.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 1477137 - Part 2: Add a test for remove temporary and undo. r=jdescottes MozReview-Commit-ID: nLjj4gcOrm
devtools/client/aboutdebugging/test/browser.ini
devtools/client/aboutdebugging/test/browser_addons_remove_temporary_and_undo.js
devtools/client/aboutdebugging/test/head.js
--- a/devtools/client/aboutdebugging/test/browser.ini
+++ b/devtools/client/aboutdebugging/test/browser.ini
@@ -34,16 +34,17 @@ tags = webextensions
 [browser_addons_debug_webextension_popup.js]
 skip-if = coverage || (verify && debug) || (debug && os == "linux" && bits == 64) # coverage: Bug 1387827, verify: crashes on shutdown, timeouts linux debug Bug 1299001
 tags = webextensions
 [browser_addons_debugging_initial_state.js]
 [browser_addons_install.js]
 skip-if = verify && debug
 [browser_addons_reload.js]
 [browser_addons_remove.js]
+[browser_addons_remove_temporary_and_undo.js]
 [browser_addons_toggle_debug.js]
 [browser_page_not_found.js]
 [browser_service_workers.js]
 [browser_service_workers_fetch_flag.js]
 skip-if = os == 'mac' # bug 1333759
 [browser_service_workers_multi_content_process.js]
 skip-if = !e10s # This test is only valid in e10s
 [browser_service_workers_not_compatible.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser_addons_remove_temporary_and_undo.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Test for temporary removing and undoing an extension.
+
+add_task(async () => {
+  const addonID = "test-devtools-webextension@mozilla.org";
+  const addonName = "test-devtools-webextension";
+
+  const { document, tab } = await openAboutDebugging("addons");
+  await waitForInitialAddonList(document);
+
+  // Install this add-on, and verify that it appears in the about:debugging UI
+  await installAddon({
+    document,
+    path: "addons/test-devtools-webextension/manifest.json",
+    name: addonName,
+    isWebExtension: true,
+  });
+  ok(getTargetEl(document, addonID), "Add-on is shown");
+
+  info("Uninstall the addon but allow to undo the action " +
+       "(same as when uninstalling from about:addons)");
+  await uninstallAddon({ document, id: addonID, name: addonName, allowUndo: true });
+  await waitUntil(() => !getTargetEl(document, addonID), 100);
+  ok(true, "Add-on is hidden after removal");
+
+  info("Canceling uninstalling to undo");
+  await cancelUninstallAddon({ document, id: addonID, name: addonName });
+  await waitUntil(() => getTargetEl(document, addonID), 100);
+  ok(true, "Add-on re-appeared after undo");
+
+  await uninstallAddon({ document, id: addonID, name: addonName });
+  await closeAboutDebugging(tab);
+});
+
+function getTargetEl(document, id) {
+  return document.querySelector(`[data-addon-id="${id}"]`);
+}
--- a/devtools/client/aboutdebugging/test/head.js
+++ b/devtools/client/aboutdebugging/test/head.js
@@ -200,38 +200,60 @@ async function installAddon({document, p
 
   await onAddonInstalled;
   ok(true, "Addon installed and running its bootstrap.js file");
 
   info("Wait for the addon to appear in the UI");
   await waitUntilAddonContainer(name, document);
 }
 
-async function uninstallAddon({document, id, name}) {
+async function uninstallAddon({document, id, name, allowUndo}) {
   // Now uninstall this addon
   await new Promise(async done => {
     const addon = await AddonManager.getAddonByID(id);
+    const eventName = allowUndo ? "onUninstalling" : "onUninstalled";
     const listener = {
-      onUninstalled: function(uninstalledAddon) {
+      [eventName]: function(uninstalledAddon) {
         if (uninstalledAddon != addon) {
           return;
         }
+
         AddonManager.removeAddonListener(listener);
-
         done();
-      }
+      },
     };
     AddonManager.addAddonListener(listener);
-    addon.uninstall();
+    addon.uninstall(allowUndo);
   });
 
   info("Wait until the addon is removed from about:debugging");
   await waitUntil(() => !getAddonContainer(name, document), 100);
 }
 
+async function cancelUninstallAddon({document, id, name}) {
+  await new Promise(async done => {
+    const addon = await AddonManager.getAddonByID(id);
+    const listener = {
+      onOperationCancelled: function(cancelledAddon) {
+        if (cancelledAddon != addon) {
+          return;
+        }
+
+        AddonManager.removeAddonListener(listener);
+        done();
+      },
+    };
+    AddonManager.addAddonListener(listener);
+    addon.cancelUninstall();
+  });
+
+  info("Wait for the addon to appear in the UI");
+  await waitUntil(() => getAddonContainer(name, document), 100);
+}
+
 function getAddonCount(document) {
   const addonListContainer = getAddonList(document);
   const addonElements = addonListContainer.querySelectorAll(".target");
   return addonElements.length;
 }
 
 /**
  * Returns a promise that will resolve when the add-on list has been updated.