summaryrefslogtreecommitdiff
path: root/toolkit/devtools/framework/test/browser_toolbox_window_shortcuts.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2016-10-16 19:34:53 -0400
committerMatt A. Tobin <email@mattatobin.com>2016-10-16 19:34:53 -0400
commit81805ce3f63e2e4a799bd54f174083c58a9b5640 (patch)
tree6e13374b213ac9b2ae74c25d8aac875faf71fdd0 /toolkit/devtools/framework/test/browser_toolbox_window_shortcuts.js
parent28c8da71bf521bb3ee76f27b8a241919e24b7cd5 (diff)
downloadpalemoon-gre-81805ce3f63e2e4a799bd54f174083c58a9b5640.tar.gz
Move Mozilla DevTools to Platform - Part 3: Merge the browser/devtools and toolkit/devtools adjusting for directory collisions
Diffstat (limited to 'toolkit/devtools/framework/test/browser_toolbox_window_shortcuts.js')
-rw-r--r--toolkit/devtools/framework/test/browser_toolbox_window_shortcuts.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/toolkit/devtools/framework/test/browser_toolbox_window_shortcuts.js b/toolkit/devtools/framework/test/browser_toolbox_window_shortcuts.js
new file mode 100644
index 000000000..bd7248bab
--- /dev/null
+++ b/toolkit/devtools/framework/test/browser_toolbox_window_shortcuts.js
@@ -0,0 +1,80 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+let Toolbox = devtools.Toolbox;
+
+let toolbox, toolIDs, idIndex, modifiedPrefs = [];
+
+function test() {
+ addTab("about:blank").then(function() {
+ toolIDs = [];
+ for (let [id, definition] of gDevTools._tools) {
+ if (definition.key) {
+ toolIDs.push(id);
+
+ // Enable disabled tools
+ let pref = definition.visibilityswitch, prefValue;
+ try {
+ prefValue = Services.prefs.getBoolPref(pref);
+ } catch (e) {
+ continue;
+ }
+ if (!prefValue) {
+ modifiedPrefs.push(pref);
+ Services.prefs.setBoolPref(pref, true);
+ }
+ }
+ }
+ let target = TargetFactory.forTab(gBrowser.selectedTab);
+ idIndex = 0;
+ gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.WINDOW)
+ .then(testShortcuts);
+ });
+}
+
+function testShortcuts(aToolbox, aIndex) {
+ if (aIndex === undefined) {
+ aIndex = 1;
+ } else if (aIndex == toolIDs.length) {
+ tidyUp();
+ return;
+ }
+
+ toolbox = aToolbox;
+ info("Toolbox fired a `ready` event");
+
+ toolbox.once("select", selectCB);
+
+ let key = gDevTools._tools.get(toolIDs[aIndex]).key;
+ let toolModifiers = gDevTools._tools.get(toolIDs[aIndex]).modifiers;
+ let modifiers = {
+ accelKey: toolModifiers.contains("accel"),
+ altKey: toolModifiers.contains("alt"),
+ shiftKey: toolModifiers.contains("shift"),
+ };
+ idIndex = aIndex;
+ info("Testing shortcut for tool " + aIndex + ":" + toolIDs[aIndex] +
+ " using key " + key);
+ EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView.parent);
+}
+
+function selectCB(event, id) {
+ info("toolbox-select event from " + id);
+
+ is(toolIDs.indexOf(id), idIndex,
+ "Correct tool is selected on pressing the shortcut for " + id);
+
+ testShortcuts(toolbox, idIndex + 1);
+}
+
+function tidyUp() {
+ toolbox.destroy().then(function() {
+ gBrowser.removeCurrentTab();
+
+ for (let pref of modifiedPrefs) {
+ Services.prefs.clearUserPref(pref);
+ }
+ toolbox = toolIDs = idIndex = modifiedPrefs = Toolbox = null;
+ finish();
+ });
+}