|
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, secondTime = false, |
|
7 reverse = false, nextKey = null, prevKey = null; |
|
8 |
|
9 function test() { |
|
10 waitForExplicitFinish(); |
|
11 |
|
12 addTab("about:blank", function() { |
|
13 let target = TargetFactory.forTab(gBrowser.selectedTab); |
|
14 idIndex = 0; |
|
15 |
|
16 target.makeRemote().then(() => { |
|
17 toolIDs = gDevTools.getToolDefinitionArray() |
|
18 .filter(def => def.isTargetSupported(target)) |
|
19 .map(def => def.id); |
|
20 gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.BOTTOM) |
|
21 .then(testShortcuts); |
|
22 }); |
|
23 }); |
|
24 } |
|
25 |
|
26 function testShortcuts(aToolbox, aIndex) { |
|
27 if (aIndex == toolIDs.length) { |
|
28 aIndex = 0; |
|
29 if (secondTime) { |
|
30 secondTime = false; |
|
31 reverse = true; |
|
32 aIndex = toolIDs.length - 2; |
|
33 } |
|
34 else { |
|
35 secondTime = true; |
|
36 } |
|
37 } |
|
38 else if (aIndex == -1) { |
|
39 aIndex = toolIDs.length - 1; |
|
40 if (secondTime) { |
|
41 tidyUp(); |
|
42 return; |
|
43 } |
|
44 secondTime = true; |
|
45 } |
|
46 |
|
47 toolbox = aToolbox; |
|
48 if (!nextKey) { |
|
49 nextKey = toolbox.doc.getElementById("toolbox-next-tool-key") |
|
50 .getAttribute("key"); |
|
51 prevKey = toolbox.doc.getElementById("toolbox-previous-tool-key") |
|
52 .getAttribute("key"); |
|
53 } |
|
54 info("Toolbox fired a `ready` event"); |
|
55 |
|
56 toolbox.once("select", onSelect); |
|
57 |
|
58 if (aIndex != null) { |
|
59 // This if block is to allow the call of onSelect without shortcut press for |
|
60 // the first time. That happens because on opening of toolbox, one tool gets |
|
61 // selected atleast. |
|
62 |
|
63 let key = (reverse ? prevKey: nextKey); |
|
64 let modifiers = { |
|
65 accelKey: true |
|
66 }; |
|
67 idIndex = aIndex; |
|
68 info("Testing shortcut to switch to tool " + aIndex + ":" + toolIDs[aIndex] + |
|
69 " using key " + key); |
|
70 EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView); |
|
71 } |
|
72 } |
|
73 |
|
74 function onSelect(event, id) { |
|
75 info("toolbox-select event from " + id); |
|
76 |
|
77 is(toolIDs.indexOf(id), idIndex, |
|
78 "Correct tool is selected on pressing the shortcut for " + id); |
|
79 // Execute soon to reset the stack trace. |
|
80 executeSoon(() => { |
|
81 testShortcuts(toolbox, idIndex + (reverse ? -1: 1)); |
|
82 }); |
|
83 } |
|
84 |
|
85 function tidyUp() { |
|
86 toolbox.destroy().then(function() { |
|
87 gBrowser.removeCurrentTab(); |
|
88 |
|
89 toolbox = toolIDs = idIndex = Toolbox = secondTime = reverse = nextKey = |
|
90 prevKey = null; |
|
91 finish(); |
|
92 }); |
|
93 } |