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