Bug 1551563 - Hide hidden/builtin extensions in shortcuts view r=mstriemer,mixedpuppy,kmag
authorRob Wu <rob@robwu.nl>
Thu, 30 May 2019 22:44:48 +0000
changeset 476323 9a811a4d134d5e6e7d17457271d19c5ebc4891af
parent 476322 6e43b0f4322b717606c2b14bd55d9c2958a1f7c7
child 476324 e2ec538a2cd8bd0c9bee7dc2e460da090ba80eb1
push id36092
push userarchaeopteryx@coole-files.de
push dateFri, 31 May 2019 17:03:46 +0000
treeherdermozilla-central@8384972e1f6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer, mixedpuppy, kmag
bugs1551563
milestone69.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 1551563 - Hide hidden/builtin extensions in shortcuts view r=mstriemer,mixedpuppy,kmag 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();
+});