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