Backed out changeset 5f60270bf1bb (bug 1272198) for breaking mochitests
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Wed, 20 Jul 2016 11:32:24 +0200
changeset 345829 ed8e23b5e0c7b739e61173bb180cf3410a306679
parent 345828 e904e18d7dfcd8097f92d44104ca1462fc5d1335
child 345830 ee1973d27f13e5adc7d41a8917c097266ec907b7
child 345835 6d9c0e3bde9e39749ff7dff998f8c9d7c0edd425
child 345850 744232e7c04a6e4c7167822b58163c712feb4719
child 345889 aab8baf2c5f54cf16b69b197094719fc0f0eae23
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1272198
milestone50.0a1
backs out5f60270bf1bbf06e09cf5dc3f35a622da3c4e632
first release with
nightly linux32
ed8e23b5e0c7 / 50.0a1 / 20160720030208 / files
nightly linux64
ed8e23b5e0c7 / 50.0a1 / 20160720030208 / files
nightly mac
ed8e23b5e0c7 / 50.0a1 / 20160720030201 / files
nightly win32
ed8e23b5e0c7 / 50.0a1 / 20160720030208 / files
nightly win64
ed8e23b5e0c7 / 50.0a1 / 20160720030208 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 5f60270bf1bb (bug 1272198) for breaking mochitests
browser/components/extensions/ext-commands.js
browser/components/extensions/test/browser/browser_ext_commands_onCommand.js
--- a/browser/components/extensions/ext-commands.js
+++ b/browser/components/extensions/ext-commands.js
@@ -72,22 +72,20 @@ CommandList.prototype = {
   loadCommandsFromManifest(manifest) {
     let commands = new Map();
     // For Windows, chrome.runtime expects 'win' while chrome.commands
     // expects 'windows'.  We can special case this for now.
     let os = PlatformInfo.os == "win" ? "windows" : PlatformInfo.os;
     for (let name of Object.keys(manifest.commands)) {
       let command = manifest.commands[name];
       let shortcut = command.suggested_key[os] || command.suggested_key.default;
-      if (shortcut) {
-        commands.set(name, {
-          description: command.description,
-          shortcut: shortcut.replace(/\s+/g, ""),
-        });
-      }
+      commands.set(name, {
+        description: command.description,
+        shortcut: shortcut.replace(/\s+/g, ""),
+      });
     }
     return commands;
   },
 
   /**
    * Registers the commands to a document.
    * @param {ChromeWindow} window The XUL window to insert the Keyset.
    */
@@ -121,17 +119,17 @@ CommandList.prototype = {
     // and it is currently ignored when set to the empty string.
     keyElement.setAttribute("oncommand", "//");
 
     /* eslint-disable mozilla/balanced-listeners */
     // We remove all references to the key elements when the extension is shutdown,
     // therefore the listeners for these elements will be garbage collected.
     keyElement.addEventListener("command", (event) => {
       if (name == "_execute_page_action") {
-        let win = event.target.ownerDocument.defaultView;
+        let win = event.target.ownerGlobal;
         pageActionFor(this.extension).triggerAction(win);
       } else {
         this.emit("command", name);
       }
     });
     /* eslint-enable mozilla/balanced-listeners */
 
     return keyElement;
--- a/browser/components/extensions/test/browser/browser_ext_commands_onCommand.js
+++ b/browser/components/extensions/test/browser/browser_ext_commands_onCommand.js
@@ -1,254 +1,98 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-Cu.import("resource://gre/modules/AppConstants.jsm");
-
 add_task(function* test_user_defined_commands() {
-  const testCommands = [
-    // Ctrl Shortcuts
-    {
-      name: "toggle-ctrl-a",
-      shortcut: "Ctrl+A",
-      key: "A",
-      modifiers: {
-        accelKey: true,
-      },
-    },
-    {
-      name: "toggle-ctrl-up",
-      shortcut: "Ctrl+Up",
-      key: "VK_UP",
-      modifiers: {
-        accelKey: true,
-      },
-    },
-    // Alt Shortcuts
-    {
-      name: "toggle-alt-1",
-      shortcut: "Alt+1",
-      key: "1",
-      modifiers: {
-        altKey: true,
-      },
-    },
-    {
-      name: "toggle-alt-a",
-      shortcut: "Alt+A",
-      key: "A",
-      modifiers: {
-        altKey: true,
-      },
-    },
-    {
-      name: "toggle-alt-down",
-      shortcut: "Alt+Down",
-      key: "VK_DOWN",
-      modifiers: {
-        altKey: true,
-      },
-    },
-    // Mac Shortcuts
-    {
-      name: "toggle-command-shift-page-up",
-      shortcutMac: "Command+Shift+PageUp",
-      key: "VK_PAGE_UP",
-      modifiers: {
-        accelKey: true,
-        shiftKey: true,
-      },
-    },
-    {
-      name: "toggle-mac-control-b",
-      shortcut: "Ctrl+B",
-      shortcutMac: "MacCtrl+B",
-      key: "B",
-      modifiers: {
-        ctrlKey: true,
-      },
-    },
-    // Ctrl+Shift Shortcuts
-    {
-      name: "toggle-ctrl-shift-1",
-      shortcut: "Ctrl+Shift+1",
-      key: "1",
-      modifiers: {
-        accelKey: true,
-        shiftKey: true,
-      },
-    },
-    {
-      name: "toggle-ctrl-shift-i",
-      shortcut: "Ctrl+Shift+I",
-      key: "I",
-      modifiers: {
-        accelKey: true,
-        shiftKey: true,
-      },
-    },
-    {
-      name: "toggle-ctrl-shift-left",
-      shortcut: "Ctrl+Shift+Left",
-      key: "VK_LEFT",
-      modifiers: {
-        accelKey: true,
-        shiftKey: true,
-      },
-    },
-    // Alt+Shift Shortcuts
-    {
-      name: "toggle-alt-shift-1",
-      shortcut: "Alt+Shift+1",
-      key: "1",
-      modifiers: {
-        altKey: true,
-        shiftKey: true,
-      },
-    },
-    {
-      name: "toggle-alt-shift-a",
-      shortcut: "Alt+Shift+A",
-      key: "A",
-      modifiers: {
-        altKey: true,
-        shiftKey: true,
-      },
-    },
-    {
-      name: "toggle-alt-shift-right",
-      shortcut: "Alt+Shift+Right",
-      key: "VK_RIGHT",
-      modifiers: {
-        altKey: true,
-        shiftKey: true,
-      },
-    },
-    // Misc Shortcuts
-    {
-      name: "unrecognized-property-name",
-      shortcut: "Alt+Shift+3",
-      key: "3",
-      modifiers: {
-        altKey: true,
-        shiftKey: true,
-      },
-      unrecognized_property: "with-a-random-value",
-    },
-    {
-      name: "spaces-in-shortcut-name",
-      shortcut: "  Alt + Shift + 2  ",
-      key: "2",
-      modifiers: {
-        altKey: true,
-        shiftKey: true,
-      },
-    },
-  ];
-
   // Create a window before the extension is loaded.
   let win1 = yield BrowserTestUtils.openNewBrowserWindow();
   yield BrowserTestUtils.loadURI(win1.gBrowser.selectedBrowser, "about:robots");
   yield BrowserTestUtils.browserLoaded(win1.gBrowser.selectedBrowser);
 
-  let commands = {};
-  let isMac = AppConstants.platform == "macosx";
-  let totalMacOnlyCommands = 0;
-
-  for (let testCommand of testCommands) {
-    let command = {
-      suggested_key: {},
-    };
-
-    if (testCommand.shortcut) {
-      command.suggested_key.default = testCommand.shortcut;
-    }
-
-    if (testCommand.shortcutMac) {
-      command.suggested_key.mac = testCommand.shortcutMac;
-    }
-
-    if (testCommand.shortcutMac && !testCommand.shortcut) {
-      totalMacOnlyCommands++;
-    }
-
-    if (testCommand.unrecognized_property) {
-      command.unrecognized_property = testCommand.unrecognized_property;
-    }
-
-    commands[testCommand.name] = command;
-  }
-
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
-      "commands": commands,
+      "commands": {
+        "toggle-feature-using-alt-shift-3": {
+          "suggested_key": {
+            "default": "Alt+Shift+3",
+          },
+        },
+        "toggle-feature-using-alt-shift-comma": {
+          "suggested_key": {
+            "default": "Alt+Shift+Comma",
+          },
+          "unrecognized_property": "with-a-random-value",
+        },
+        "toggle-feature-with-whitespace-in-suggested-key": {
+          "suggested_key": {
+            "default": "  Alt + Shift + 2  ",
+          },
+        },
+      },
     },
 
     background: function() {
       browser.commands.onCommand.addListener(commandName => {
         browser.test.sendMessage("oncommand", commandName);
       });
       browser.test.sendMessage("ready");
     },
   });
 
+
   SimpleTest.waitForExplicitFinish();
   let waitForConsole = new Promise(resolve => {
     SimpleTest.monitorConsole(resolve, [{
       message: /Reading manifest: Error processing commands.*.unrecognized_property: An unexpected property was found/,
     }]);
   });
 
   yield extension.startup();
   yield extension.awaitMessage("ready");
 
-  function* runTest() {
-    for (let testCommand of testCommands) {
-      if (testCommand.shortcutMac && !isMac) {
-        continue;
-      }
-      EventUtils.synthesizeKey(testCommand.key, testCommand.modifiers);
-      let message = yield extension.awaitMessage("oncommand");
-      is(message, testCommand.name, "Expected onCommand listener to fire with the correct command name");
-    }
-  }
-
   // Create another window after the extension is loaded.
   let win2 = yield BrowserTestUtils.openNewBrowserWindow();
   yield BrowserTestUtils.loadURI(win2.gBrowser.selectedBrowser, "about:config");
   yield BrowserTestUtils.browserLoaded(win2.gBrowser.selectedBrowser);
 
-  let totalTestCommands = Object.keys(testCommands).length;
-  let expectedCommandsRegistered = isMac ? totalTestCommands : totalTestCommands - totalMacOnlyCommands;
-
   // Confirm the keysets have been added to both windows.
   let keysetID = `ext-keyset-id-${makeWidgetId(extension.id)}`;
   let keyset = win1.document.getElementById(keysetID);
   ok(keyset != null, "Expected keyset to exist");
-  is(keyset.childNodes.length, expectedCommandsRegistered, "Expected keyset to have the correct number of children");
+  is(keyset.childNodes.length, 3, "Expected keyset to have 3 children");
 
   keyset = win2.document.getElementById(keysetID);
   ok(keyset != null, "Expected keyset to exist");
-  is(keyset.childNodes.length, expectedCommandsRegistered, "Expected keyset to have the correct number of children");
+  is(keyset.childNodes.length, 3, "Expected keyset to have 3 children");
 
   // Confirm that the commands are registered to both windows.
   yield focusWindow(win1);
-  yield runTest();
+  EventUtils.synthesizeKey("3", {altKey: true, shiftKey: true});
+  let message = yield extension.awaitMessage("oncommand");
+  is(message, "toggle-feature-using-alt-shift-3", "Expected onCommand listener to fire with correct message");
 
   yield focusWindow(win2);
-  yield runTest();
+  EventUtils.synthesizeKey("VK_COMMA", {altKey: true, shiftKey: true});
+  message = yield extension.awaitMessage("oncommand");
+  is(message, "toggle-feature-using-alt-shift-comma", "Expected onCommand listener to fire with correct message");
+
+  EventUtils.synthesizeKey("2", {altKey: true, shiftKey: true});
+  message = yield extension.awaitMessage("oncommand");
+  is(message, "toggle-feature-with-whitespace-in-suggested-key", "Expected onCommand listener to fire with correct message");
 
   yield extension.unload();
 
   // Confirm that the keysets have been removed from both windows after the extension is unloaded.
   keyset = win1.document.getElementById(keysetID);
   is(keyset, null, "Expected keyset to be removed from the window");
 
   keyset = win2.document.getElementById(keysetID);
   is(keyset, null, "Expected keyset to be removed from the window");
 
   yield BrowserTestUtils.closeWindow(win1);
   yield BrowserTestUtils.closeWindow(win2);
 
   SimpleTest.endMonitorConsole();
   yield waitForConsole;
 });
+
+