Bug 1551563 - Hide hidden/builtin extensions in shortcuts view r=mstriemer,mixedpuppy,kmag a=jcristau
authorRob Wu <rob@robwu.nl>
Thu, 30 May 2019 22:44:48 +0000
changeset 533563 5532b4c4315e32dcdef0f656db1fffc4cfad4367
parent 533562 fe605c689819fc0ca9aa629f1557d796b0c979b8
child 533564 e87602ae8d9f91280a079e72d47cedd9a394abcb
push id11360
push usermalexandru@mozilla.com
push dateMon, 03 Jun 2019 14:33:27 +0000
treeherdermozilla-beta@fa85a070d833 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer, mixedpuppy, kmag, jcristau
bugs1551563
milestone68.0
Bug 1551563 - Hide hidden/builtin extensions in shortcuts view r=mstriemer,mixedpuppy,kmag a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D31795
toolkit/mozapps/extensions/content/shortcuts.js
toolkit/mozapps/extensions/test/browser/browser_manage_shortcuts_hidden.js
--- a/toolkit/mozapps/extensions/content/shortcuts.js
+++ b/toolkit/mozapps/extensions/content/shortcuts.js
@@ -411,17 +411,17 @@ async function renderAddons(addons) {
               firstHiddenInput.focus();
             }
           }
         });
         card.appendChild(row);
       }
 
       frag.appendChild(card);
-    } else {
+    } else if (!addon.hidden) {
       noShortcutAddons.push({ id: addon.id, name: addon.name });
     }
   }
 
   if (noShortcutAddons.length > 0) {
     frag.appendChild(renderNoShortcutAddons(noShortcutAddons));
   }
 
--- a/toolkit/mozapps/extensions/test/browser/browser_manage_shortcuts_hidden.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_manage_shortcuts_hidden.js
@@ -8,16 +8,38 @@ async function loadShortcutsView() {
   return managerWin.document.getElementById("shortcuts-view").contentDocument;
 }
 
 async function closeShortcutsView(doc) {
   let managerWin = doc.defaultView.parent;
   await close_manager(managerWin);
 }
 
+async function registerAndStartExtension(mockProvider, ext) {
+  // Shortcuts are registered when an extension is started, so we need to load
+  // and start an extension.
+  let extension = ExtensionTestUtils.loadExtension(ext);
+  await extension.startup();
+
+  // Extensions only appear in the add-on manager when they are registered with
+  // the add-on manager, e.g. by passing "useAddonManager" to `loadExtension`.
+  // "useAddonManager" can however not be used, because the resulting add-ons
+  // are unsigned, and only add-ons with privileged signatures can be hidden.
+  mockProvider.createAddons([{
+    id: extension.id,
+    name: ext.manifest.name,
+    type: "extension",
+    version: "1",
+    // We use MockProvider because the "hidden" property cannot
+    // be set when "useAddonManager" is passed to loadExtension.
+    hidden: ext.manifest.hidden,
+  }]);
+  return extension;
+}
+
 function getShortcutCard(doc, extension) {
   return doc.querySelector(`.shortcut[addon-id="${extension.id}"]`);
 }
 
 function getShortcutByName(doc, extension, name) {
   let card = getShortcutCard(doc, extension);
   return card && card.querySelector(`.shortcut-input[name="${name}"]`);
 }
@@ -63,8 +85,45 @@ add_task(async function extension_withou
   is(getShortcutCard(doc, extension), null,
      "Extension without shortcuts should not have a card");
   is(getNoShortcutListItem(doc, extension), "no shortcut addon",
      "The add-on's name is set in the list");
 
   await closeShortcutsView(doc);
   await extension.unload();
 });
+
+// Hidden add-ons without shortcuts should be hidden,
+// but their card should be shown if there is a shortcut.
+add_task(async function hidden_extension() {
+  let mockProvider = new MockProvider();
+  let hiddenExt1 = await registerAndStartExtension(mockProvider, {
+    manifest: {
+      name: "hidden with shortcuts",
+      hidden: true,
+      commands: {
+        hiddenShortcut: {},
+      },
+    },
+  });
+  let hiddenExt2 = await registerAndStartExtension(mockProvider, {
+    manifest: {
+      name: "hidden without shortcuts",
+      hidden: true,
+    },
+  });
+
+  let doc = await loadShortcutsView();
+
+  ok(getShortcutByName(doc, hiddenExt1, "hiddenShortcut"),
+     "Hidden extension with shortcuts should have a card");
+
+  is(getShortcutCard(doc, hiddenExt2), null,
+     "Hidden extension without shortcuts should not have a card");
+  is(getNoShortcutListItem(doc, hiddenExt2), null,
+     "Hidden extension without shortcuts should not be listed");
+
+  await closeShortcutsView(doc);
+  await hiddenExt1.unload();
+  await hiddenExt2.unload();
+
+  mockProvider.unregister();
+});