Bug 1162848 - Use a single synthesizeKeyFromKeyTag helper for mochitest-devtools;r=jryans

--HG--
extra : commitid : 45zZOTo938D
This commit is contained in:
Brian Grinstead 2015-10-21 15:05:13 -07:00
parent 7852a87430
commit e21883e698
6 changed files with 22 additions and 69 deletions

View File

@ -52,18 +52,18 @@ function* testOptionsShortcut() {
yield toolbox.selectTool("webconsole");
is(toolbox.currentToolId, "webconsole", "webconsole is selected");
synthesizeKeyFromKeyTag("toolbox-options-key", doc);
synthesizeKeyFromKeyTag(doc.getElementById("toolbox-options-key"));
is(toolbox.currentToolId, "options", "Toolbox selected via shortcut key (1)");
synthesizeKeyFromKeyTag("toolbox-options-key", doc);
synthesizeKeyFromKeyTag(doc.getElementById("toolbox-options-key"));
is(toolbox.currentToolId, "webconsole", "webconsole is selected (1)");
yield toolbox.selectTool("webconsole");
is(toolbox.currentToolId, "webconsole", "webconsole is selected");
synthesizeKeyFromKeyTag("toolbox-options-key2", doc);
synthesizeKeyFromKeyTag(doc.getElementById("toolbox-options-key2"));
is(toolbox.currentToolId, "options", "Toolbox selected via shortcut key (2)");
synthesizeKeyFromKeyTag("toolbox-options-key", doc);
synthesizeKeyFromKeyTag(doc.getElementById("toolbox-options-key"));
is(toolbox.currentToolId, "webconsole", "webconsole is reselected (2)");
synthesizeKeyFromKeyTag("toolbox-options-key2", doc);
synthesizeKeyFromKeyTag(doc.getElementById("toolbox-options-key2"));
is(toolbox.currentToolId, "options", "Toolbox selected via shortcut key (2)");
}

View File

@ -97,9 +97,8 @@ function removeTab(tab) {
});
}
function synthesizeKeyFromKeyTag(aKeyId, document) {
let key = document.getElementById(aKeyId);
isnot(key, null, "Successfully retrieved the <key> node");
function synthesizeKeyFromKeyTag(key) {
is(key && key.tagName, "key", "Successfully retrieved the <key> node");
let modifiersAttr = key.getAttribute("modifiers");
@ -113,13 +112,14 @@ function synthesizeKeyFromKeyTag(aKeyId, document) {
isnot(name, null, "Successfully retrieved keycode/key");
let modifiers = {
shiftKey: modifiersAttr.match("shift"),
ctrlKey: modifiersAttr.match("ctrl"),
altKey: modifiersAttr.match("alt"),
metaKey: modifiersAttr.match("meta"),
accelKey: modifiersAttr.match("accel")
shiftKey: !!modifiersAttr.match("shift"),
ctrlKey: !!modifiersAttr.match("control"),
altKey: !!modifiersAttr.match("alt"),
metaKey: !!modifiersAttr.match("meta"),
accelKey: !!modifiersAttr.match("accel")
};
info("Synthesizing key " + name + " " + JSON.stringify(modifiers));
EventUtils.synthesizeKey(name, modifiers);
}

View File

@ -27,7 +27,7 @@ function test() {
let mgr = ResponsiveUI.ResponsiveUIManager;
synthesizeKeyFromKeyTag("key_responsiveUI");
synthesizeKeyFromKeyTag(document.getElementById("key_responsiveUI"));
yield once(mgr, "on");

View File

@ -24,29 +24,13 @@ function test() {
return testOnePreset(instance.menulist.firstChild.childNodes.length - 4);
}
function synthesizeKeyFromKeyTag(aKeyId) {
let key = document.getElementById(aKeyId);
isnot(key, null, "Successfully retrieved the <key> node");
let name = null;
if (key.getAttribute("keycode"))
name = key.getAttribute("keycode");
else if (key.getAttribute("key"))
name = key.getAttribute("key");
isnot(name, null, "Successfully retrieved keycode/key");
key.doCommand();
}
Task.spawn(function*() {
yield addTab("data:text/html;charset=utf8,test custom presets in responsive mode");
let mgr = ResponsiveUI.ResponsiveUIManager;
synthesizeKeyFromKeyTag("key_responsiveUI");
synthesizeKeyFromKeyTag(document.getElementById("key_responsiveUI"));
yield once(mgr, "on");
@ -107,7 +91,7 @@ function test() {
// Let's wait next loop to stop it.
yield nextTick();
synthesizeKeyFromKeyTag("key_responsiveUI");
synthesizeKeyFromKeyTag(document.getElementById("key_responsiveUI"));
yield once(mgr, "on");
@ -140,7 +124,7 @@ function test() {
instance.close();
yield once(mgr, "off");
synthesizeKeyFromKeyTag("key_responsiveUI");
synthesizeKeyFromKeyTag(document.getElementById("key_responsiveUI"));
info("waiting for responsive mode to turn on");
yield once(mgr, "on");

View File

@ -3,10 +3,8 @@
"use strict";
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {TargetFactory} = require("devtools/client/framework/target");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var promise = require("promise");
// shared-head.js handles imports, constants, and utility functions
Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js", this);
// Import the GCLI test helper
var testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
@ -184,32 +182,6 @@ function wait(ms) {
return def.promise;
}
function synthesizeKeyFromKeyTag(aKeyId) {
let key = document.getElementById(aKeyId);
isnot(key, null, "Successfully retrieved the <key> node");
let modifiersAttr = key.getAttribute("modifiers");
let name = null;
if (key.getAttribute("keycode"))
name = key.getAttribute("keycode");
else if (key.getAttribute("key"))
name = key.getAttribute("key");
isnot(name, null, "Successfully retrieved keycode/key");
let modifiers = {
shiftKey: modifiersAttr.match("shift"),
ctrlKey: modifiersAttr.match("ctrl"),
altKey: modifiersAttr.match("alt"),
metaKey: modifiersAttr.match("meta"),
accelKey: modifiersAttr.match("accel")
}
EventUtils.synthesizeKey(name, modifiers);
}
function nextTick() {
let def = promise.defer();
executeSoon(() => def.resolve())

View File

@ -5,15 +5,12 @@
"use strict";
var {gDevTools} = Cu.import("resource://devtools/client/framework/gDevTools.jsm", {});
var {console} = Cu.import("resource://gre/modules/Console.jsm", {});
// shared-head.js handles imports, constants, and utility functions
Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/framework/test/shared-head.js", this);
var {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var promise = require("promise");
var {TargetFactory} = require("devtools/client/framework/target");
var {Utils: WebConsoleUtils} = require("devtools/shared/webconsole/utils");
var {Messages} = require("devtools/client/webconsole/console-output");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
const asyncStorage = require("devtools/shared/async-storage");
// Services.prefs.setBoolPref("devtools.debugger.log", true);