Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 let Toolbox = devtools.Toolbox;
6 let toolbox, toolIDs, idIndex, modifiedPrefs = [];
8 function test() {
9 waitForExplicitFinish();
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);
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 }
43 function testShortcuts(aToolbox, aIndex) {
44 if (aIndex == toolIDs.length) {
45 tidyUp();
46 return;
47 }
49 toolbox = aToolbox;
50 info("Toolbox fired a `ready` event");
52 toolbox.once("select", selectCB);
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.
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 }
73 function selectCB(event, id) {
74 info("toolbox-select event from " + id);
76 is(toolIDs.indexOf(id), idIndex,
77 "Correct tool is selected on pressing the shortcut for " + id);
79 testShortcuts(toolbox, idIndex + 1);
80 }
82 function tidyUp() {
83 toolbox.destroy().then(function() {
84 gBrowser.removeCurrentTab();
86 for (let pref of modifiedPrefs) {
87 Services.prefs.clearUserPref(pref);
88 }
89 toolbox = toolIDs = idIndex = modifiedPrefs = Toolbox = null;
90 finish();
91 });
92 }