michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let Toolbox = devtools.Toolbox; michael@0: michael@0: let toolbox, toolIDs, idIndex, secondTime = false, michael@0: reverse = false, nextKey = null, prevKey = null; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: addTab("about:blank", function() { michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: idIndex = 0; michael@0: michael@0: target.makeRemote().then(() => { michael@0: toolIDs = gDevTools.getToolDefinitionArray() michael@0: .filter(def => def.isTargetSupported(target)) michael@0: .map(def => def.id); michael@0: gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.BOTTOM) michael@0: .then(testShortcuts); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function testShortcuts(aToolbox, aIndex) { michael@0: if (aIndex == toolIDs.length) { michael@0: aIndex = 0; michael@0: if (secondTime) { michael@0: secondTime = false; michael@0: reverse = true; michael@0: aIndex = toolIDs.length - 2; michael@0: } michael@0: else { michael@0: secondTime = true; michael@0: } michael@0: } michael@0: else if (aIndex == -1) { michael@0: aIndex = toolIDs.length - 1; michael@0: if (secondTime) { michael@0: tidyUp(); michael@0: return; michael@0: } michael@0: secondTime = true; michael@0: } michael@0: michael@0: toolbox = aToolbox; michael@0: if (!nextKey) { michael@0: nextKey = toolbox.doc.getElementById("toolbox-next-tool-key") michael@0: .getAttribute("key"); michael@0: prevKey = toolbox.doc.getElementById("toolbox-previous-tool-key") michael@0: .getAttribute("key"); michael@0: } michael@0: info("Toolbox fired a `ready` event"); michael@0: michael@0: toolbox.once("select", onSelect); michael@0: michael@0: if (aIndex != null) { michael@0: // This if block is to allow the call of onSelect without shortcut press for michael@0: // the first time. That happens because on opening of toolbox, one tool gets michael@0: // selected atleast. michael@0: michael@0: let key = (reverse ? prevKey: nextKey); michael@0: let modifiers = { michael@0: accelKey: true michael@0: }; michael@0: idIndex = aIndex; michael@0: info("Testing shortcut to switch to tool " + aIndex + ":" + toolIDs[aIndex] + michael@0: " using key " + key); michael@0: EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView); michael@0: } michael@0: } michael@0: michael@0: function onSelect(event, id) { michael@0: info("toolbox-select event from " + id); michael@0: michael@0: is(toolIDs.indexOf(id), idIndex, michael@0: "Correct tool is selected on pressing the shortcut for " + id); michael@0: // Execute soon to reset the stack trace. michael@0: executeSoon(() => { michael@0: testShortcuts(toolbox, idIndex + (reverse ? -1: 1)); michael@0: }); michael@0: } michael@0: michael@0: function tidyUp() { michael@0: toolbox.destroy().then(function() { michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: toolbox = toolIDs = idIndex = Toolbox = secondTime = reverse = nextKey = michael@0: prevKey = null; michael@0: finish(); michael@0: }); michael@0: }