Bug 1551563 - Move shortcut test to own file r=mstriemer,mixedpuppy a=jcristau
authorRob Wu <rob@robwu.nl>
Thu, 30 May 2019 22:32:52 +0000
changeset 536629 fe605c689819fc0ca9aa629f1557d796b0c979b8
parent 536628 d31cfde1fa7b466aa2d4fd14a5740e430ab588c4
child 536630 5532b4c4315e32dcdef0f656db1fffc4cfad4367
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer, mixedpuppy, jcristau
bugs1551563, 1522757
milestone68.0
Bug 1551563 - Move shortcut test to own file r=mstriemer,mixedpuppy a=jcristau In bug 1522757, a new test was added to verify that extensions without shortcuts were hidden in the shortcut view, and shown in a list of extensions without shortcuts. The test was inserted in an existing test that did not have anything to do with the change. In the next patch, I am going to add similar tests, so the test logic was moved to a separate file. Differential Revision: https://phabricator.services.mozilla.com/D31794
toolkit/mozapps/extensions/test/browser/browser.ini
toolkit/mozapps/extensions/test/browser/browser_manage_shortcuts.js
toolkit/mozapps/extensions/test/browser/browser_manage_shortcuts_hidden.js
--- a/toolkit/mozapps/extensions/test/browser/browser.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser.ini
@@ -96,16 +96,17 @@ skip-if = os == 'mac' || os == 'linux' #
 [browser_installssl.js]
 skip-if = verify
 [browser_interaction_telemetry.js]
 [browser_langpack_signing.js]
 [browser_legacy.js]
 [browser_legacy_pre57.js]
 [browser_list.js]
 [browser_manage_shortcuts.js]
+[browser_manage_shortcuts_hidden.js]
 [browser_manualupdates.js]
 [browser_pluginprefs.js]
 [browser_pluginprefs_is_not_disabled.js]
 [browser_plugin_enabled_state_locked.js]
 [browser_recentupdates.js]
 [browser_reinstall.js]
 [browser_sorting.js]
 [browser_sorting_plugins.js]
--- a/toolkit/mozapps/extensions/test/browser/browser_manage_shortcuts.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_manage_shortcuts.js
@@ -52,34 +52,16 @@ add_task(async function testUpdatingComm
       browser.test.sendMessage("ready");
     },
     useAddonManager: "temporary",
   });
 
   await extension.startup();
   await extension.awaitMessage("ready");
 
-  let extension2 = ExtensionTestUtils.loadExtension({
-    manifest: {
-      browser_specific_settings: {
-        gecko: {
-          id: "addons@noShorcut",
-        },
-      },
-      name: "no shortcut addon",
-    },
-    background() {
-      browser.test.sendMessage("ready");
-    },
-    useAddonManager: "temporary",
-  });
-
-  await extension2.startup();
-  await extension2.awaitMessage("ready");
-
   async function checkShortcut(name, key, modifiers) {
     EventUtils.synthesizeKey(key, modifiers);
     let message = await extension.awaitMessage("oncommand");
     is(message, name, `Expected onCommand listener to fire with the correct name: ${name}`);
   }
 
   // Check that the original shortcuts work.
   await checkShortcut("commandOne", "7", {shiftKey: true, altKey: true});
@@ -156,32 +138,18 @@ add_task(async function testUpdatingComm
     } else {
       is(label.textContent, value, "The textContent is set");
     }
   }
   checkLabel("commandOne", "commandOne");
   checkLabel("commandTwo", "Command Two!");
   checkLabel("_execute_browser_action", "shortcuts-browserAction");
 
-  // Check there is only 1 shortcut card.
-  let shortcutAddonsList = doc.querySelectorAll(".shortcut");
-  is(shortcutAddonsList.length, 1, "There is only 1 addon card with shortcut");
-
-  // Check there is unordered list of shortcut-less addons.
-  let noShortcutAddonsList = doc.querySelector(".shortcuts-no-commands-list");
-  ok(noShortcutAddonsList, "There is an unordered list of addons without shortcuts");
-
-  // Check there is shortcut-less addon in the list.
-  let addon = noShortcutAddonsList.querySelector(`[addon-id="addons@noShorcut"]`);
-  ok(addon, "There is addon without shortcut in unordered list");
-  is(addon.textContent, "no shortcut addon", "The add-on's name is set in the list");
-
   await closeView();
   await extension.unload();
-  await extension2.unload();
 });
 
 async function startExtensionWithCommands(numCommands) {
   let commands = {};
 
   for (let i = 0; i < numCommands; i++) {
     commands[`command-${i}`] = {};
   }
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_manage_shortcuts_hidden.js
@@ -0,0 +1,70 @@
+/* eslint max-len: ["error", 80] */
+"use strict";
+
+async function loadShortcutsView() {
+  let managerWin = await open_manager(null);
+  managerWin.gViewController.loadView("addons://shortcuts/shortcuts");
+  await wait_for_view_load(managerWin);
+  return managerWin.document.getElementById("shortcuts-view").contentDocument;
+}
+
+async function closeShortcutsView(doc) {
+  let managerWin = doc.defaultView.parent;
+  await close_manager(managerWin);
+}
+
+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}"]`);
+}
+
+function getNoShortcutListItem(doc, extension) {
+  let {id} = extension;
+  let li = doc.querySelector(`.shortcuts-no-commands-list [addon-id="${id}"]`);
+  return li && li.textContent;
+}
+
+add_task(async function extension_with_shortcuts() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      name: "shortcut addon",
+      commands: {
+        theShortcut: {},
+      },
+    },
+    useAddonManager: "temporary",
+  });
+  await extension.startup();
+  let doc = await loadShortcutsView();
+
+  ok(getShortcutByName(doc, extension, "theShortcut"),
+     "Extension with shortcuts should have a card");
+  is(getNoShortcutListItem(doc, extension), null,
+     "Extension with shortcuts should not be listed");
+
+  await closeShortcutsView(doc);
+  await extension.unload();
+});
+
+add_task(async function extension_without_shortcuts() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      name: "no shortcut addon",
+    },
+    useAddonManager: "temporary",
+  });
+  await extension.startup();
+  let doc = await loadShortcutsView();
+
+  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();
+});