browser/devtools/framework/test/browser_toolbox_window_shortcuts.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:2b46e7906f13
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 let Toolbox = devtools.Toolbox;
5
6 let toolbox, toolIDs, idIndex, modifiedPrefs = [];
7
8 function test() {
9 waitForExplicitFinish();
10
11 if (window.navigator.userAgent.indexOf("Mac OS X 10.8") != -1 ||
12 window.navigator.userAgent.indexOf("Windows NT 5.1") != -1) {
13 info("Skipping Mac OSX 10.8 and Windows xp, see bug 838069");
14 finish();
15 return;
16 }
17 addTab("about:blank", function() {
18 toolIDs = [];
19 for (let [id, definition] of gDevTools._tools) {
20 if (definition.key) {
21 toolIDs.push(id);
22
23 // Enable disabled tools
24 let pref = definition.visibilityswitch, prefValue;
25 try {
26 prefValue = Services.prefs.getBoolPref(pref);
27 } catch (e) {
28 continue;
29 }
30 if (!prefValue) {
31 modifiedPrefs.push(pref);
32 Services.prefs.setBoolPref(pref, true);
33 }
34 }
35 }
36 let target = TargetFactory.forTab(gBrowser.selectedTab);
37 idIndex = 0;
38 gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.WINDOW)
39 .then(testShortcuts);
40 });
41 }
42
43 function testShortcuts(aToolbox, aIndex) {
44 if (aIndex == toolIDs.length) {
45 tidyUp();
46 return;
47 }
48
49 toolbox = aToolbox;
50 info("Toolbox fired a `ready` event");
51
52 toolbox.once("select", selectCB);
53
54 if (aIndex != null) {
55 // This if block is to allow the call of selectCB without shortcut press for
56 // the first time. That happens because on opening of toolbox, one tool gets
57 // selected atleast.
58
59 let key = gDevTools._tools.get(toolIDs[aIndex]).key;
60 let toolModifiers = gDevTools._tools.get(toolIDs[aIndex]).modifiers;
61 let modifiers = {
62 accelKey: toolModifiers.contains("accel"),
63 altKey: toolModifiers.contains("alt"),
64 shiftKey: toolModifiers.contains("shift"),
65 };
66 idIndex = aIndex;
67 info("Testing shortcut for tool " + aIndex + ":" + toolIDs[aIndex] +
68 " using key " + key);
69 EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView.parent);
70 }
71 }
72
73 function selectCB(event, id) {
74 info("toolbox-select event from " + id);
75
76 is(toolIDs.indexOf(id), idIndex,
77 "Correct tool is selected on pressing the shortcut for " + id);
78
79 testShortcuts(toolbox, idIndex + 1);
80 }
81
82 function tidyUp() {
83 toolbox.destroy().then(function() {
84 gBrowser.removeCurrentTab();
85
86 for (let pref of modifiedPrefs) {
87 Services.prefs.clearUserPref(pref);
88 }
89 toolbox = toolIDs = idIndex = modifiedPrefs = Toolbox = null;
90 finish();
91 });
92 }

mercurial