--- a/devtools/client/shared/test/browser_key_shortcuts.js
+++ b/devtools/client/shared/test/browser_key_shortcuts.js
@@ -1,11 +1,13 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
var isOSX = Services.appinfo.OS === "Darwin";
add_task(function* () {
let shortcuts = new KeyShortcuts({
window
});
yield testSimple(shortcuts);
@@ -39,68 +41,68 @@ function once(shortcuts, key, listener)
called = true;
listener(key2, event);
done();
};
shortcuts.on(key, onShortcut);
});
}
-function testSimple(shortcuts) {
+function* testSimple(shortcuts) {
info("Test simple key shortcuts");
let onKey = once(shortcuts, "0", (key, event) => {
is(event.key, "0");
// Display another key press to ensure that once() correctly stop listening
EventUtils.synthesizeKey("0", {}, window);
});
EventUtils.synthesizeKey("0", {}, window);
yield onKey;
}
-function testNonLetterCharacter(shortcuts) {
+function* testNonLetterCharacter(shortcuts) {
info("Test non-naive character key shortcuts");
let onKey = once(shortcuts, "[", (key, event) => {
is(event.key, "[");
});
EventUtils.synthesizeKey("[", {}, window);
yield onKey;
}
-function testFunctionKey(shortcuts) {
+function* testFunctionKey(shortcuts) {
info("Test function key shortcuts");
let onKey = once(shortcuts, "F12", (key, event) => {
is(event.key, "F12");
});
EventUtils.synthesizeKey("F12", { keyCode: 123 }, window);
yield onKey;
}
// Plus is special. It's keycode is the one for "=". That's because it requires
// shift to be pressed and is behind "=" key. So it should be considered as a
// character key
-function testPlusCharacter(shortcuts) {
+function* testPlusCharacter(shortcuts) {
info("Test 'Plus' key shortcuts");
let onKey = once(shortcuts, "Plus", (key, event) => {
is(event.key, "+");
});
EventUtils.synthesizeKey("+", { keyCode: 61, shiftKey: true }, window);
yield onKey;
}
// Test they listeners are not mixed up between shortcuts
-function testMixup(shortcuts) {
+function* testMixup(shortcuts) {
info("Test possible listener mixup");
let hitFirst = false, hitSecond = false;
let onFirstKey = once(shortcuts, "0", (key, event) => {
is(event.key, "0");
hitFirst = true;
});
let onSecondKey = once(shortcuts, "Alt+A", (key, event) => {
@@ -125,17 +127,17 @@ function testMixup(shortcuts) {
// Finally dispatch the second shortcut
EventUtils.synthesizeKey("a", { altKey: true }, window);
yield onSecondKey;
ok(hitSecond, "Got the second shortcut notified once it is actually fired");
}
// On azerty keyboard, digits are only available by pressing Shift/Capslock,
// but we accept them even if we omit doing that.
-function testLooseDigits(shortcuts) {
+function* testLooseDigits(shortcuts) {
info("Test Loose digits");
let onKey = once(shortcuts, "0", (key, event) => {
is(event.key, "à");
ok(!event.altKey);
ok(!event.ctrlKey);
ok(!event.metaKey);
ok(!event.shiftKey);
});
@@ -158,17 +160,17 @@ function testLooseDigits(shortcuts) {
EventUtils.synthesizeKey(
"0",
{ keyCode: 48, shiftKey: true },
window);
yield onKey;
}
// Test that shortcuts is notified only when the modifiers match exactly
-function testExactModifiers(shortcuts) {
+function* testExactModifiers(shortcuts) {
info("Test exact modifiers match");
let hit = false;
let onKey = once(shortcuts, "Alt+A", (key, event) => {
is(event.key, "a");
ok(event.altKey);
ok(!event.ctrlKey);
ok(!event.metaKey);
@@ -206,17 +208,17 @@ function testExactModifiers(shortcuts) {
yield onKey;
ok(hit, "Got shortcut notified once it is actually fired");
}
// Some keys are only accessible via shift and listener should also be called
// even if the key didn't explicitely requested Shift modifier.
// For example, `%` on french keyboards is only accessible via Shift.
// Same thing for `@` on US keybords.
-function testLooseShiftModifier(shortcuts) {
+function* testLooseShiftModifier(shortcuts) {
info("Test Loose shift modifier");
let onKey = once(shortcuts, "%", (key, event) => {
is(event.key, "%");
ok(!event.altKey);
ok(!event.ctrlKey);
ok(!event.metaKey);
ok(event.shiftKey);
});
@@ -236,17 +238,17 @@ function testLooseShiftModifier(shortcut
EventUtils.synthesizeKey(
"@",
{ accelKey: false, altKey: false, ctrlKey: false, shiftKey: true},
window);
yield onKey;
}
// But Shift modifier is strict on all letter characters (a to Z)
-function testStrictLetterShiftModifier(shortcuts) {
+function* testStrictLetterShiftModifier(shortcuts) {
info("Test strict shift modifier on letters");
let hitFirst = false;
let onKey = once(shortcuts, "a", (key, event) => {
is(event.key, "a");
ok(!event.altKey);
ok(!event.ctrlKey);
ok(!event.metaKey);
ok(!event.shiftKey);
@@ -268,33 +270,33 @@ function testStrictLetterShiftModifier(s
EventUtils.synthesizeKey(
"a",
{ shiftKey: false},
window);
yield onKey;
}
-function testAltModifier(shortcuts) {
+function* testAltModifier(shortcuts) {
info("Test Alt modifier");
let onKey = once(shortcuts, "Alt+F1", (key, event) => {
is(event.keyCode, window.KeyboardEvent.DOM_VK_F1);
ok(event.altKey);
ok(!event.ctrlKey);
ok(!event.metaKey);
ok(!event.shiftKey);
});
EventUtils.synthesizeKey(
"VK_F1",
{ altKey: true },
window);
yield onKey;
}
-function testCommandOrControlModifier(shortcuts) {
+function* testCommandOrControlModifier(shortcuts) {
info("Test CommandOrControl modifier");
let onKey = once(shortcuts, "CommandOrControl+F1", (key, event) => {
is(event.keyCode, window.KeyboardEvent.DOM_VK_F1);
ok(!event.altKey);
if (isOSX) {
ok(!event.ctrlKey);
ok(event.metaKey);
} else {
@@ -325,17 +327,17 @@ function testCommandOrControlModifier(sh
"VK_F1",
{ ctrlKey: true },
window);
}
yield onKey;
yield onKeyAlias;
}
-function testCtrlModifier(shortcuts) {
+function* testCtrlModifier(shortcuts) {
info("Test Ctrl modifier");
let onKey = once(shortcuts, "Ctrl+F1", (key, event) => {
is(event.keyCode, window.KeyboardEvent.DOM_VK_F1);
ok(!event.altKey);
ok(event.ctrlKey);
ok(!event.metaKey);
ok(!event.shiftKey);
});
@@ -349,17 +351,17 @@ function testCtrlModifier(shortcuts) {
EventUtils.synthesizeKey(
"VK_F1",
{ ctrlKey: true },
window);
yield onKey;
yield onKeyAlias;
}
-function testCmdShiftShortcut(shortcuts) {
+function* testCmdShiftShortcut(shortcuts) {
if (!isOSX) {
// This test is OSX only (Bug 1300458).
return;
}
let onCmdKey = once(shortcuts, "CmdOrCtrl+[", (key, event) => {
is(event.key, "[");
ok(!event.altKey);
@@ -383,17 +385,17 @@ function testCmdShiftShortcut(shortcuts)
"[",
{ metaKey: true },
window);
yield onCmdKey;
yield onCmdShiftKey;
}
-function testTarget() {
+function* testTarget() {
info("Test KeyShortcuts with target argument");
let target = document.createElementNS("http://www.w3.org/1999/xhtml",
"input");
document.documentElement.appendChild(target);
target.focus();
let shortcuts = new KeyShortcuts({