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, modifiedPrefs = []; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: if (window.navigator.userAgent.indexOf("Mac OS X 10.8") != -1 || michael@0: window.navigator.userAgent.indexOf("Windows NT 5.1") != -1) { michael@0: info("Skipping Mac OSX 10.8 and Windows xp, see bug 838069"); michael@0: finish(); michael@0: return; michael@0: } michael@0: addTab("about:blank", function() { michael@0: toolIDs = []; michael@0: for (let [id, definition] of gDevTools._tools) { michael@0: if (definition.key) { michael@0: toolIDs.push(id); michael@0: michael@0: // Enable disabled tools michael@0: let pref = definition.visibilityswitch, prefValue; michael@0: try { michael@0: prefValue = Services.prefs.getBoolPref(pref); michael@0: } catch (e) { michael@0: continue; michael@0: } michael@0: if (!prefValue) { michael@0: modifiedPrefs.push(pref); michael@0: Services.prefs.setBoolPref(pref, true); michael@0: } michael@0: } michael@0: } michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: idIndex = 0; michael@0: gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.WINDOW) michael@0: .then(testShortcuts); michael@0: }); michael@0: } michael@0: michael@0: function testShortcuts(aToolbox, aIndex) { michael@0: if (aIndex == toolIDs.length) { michael@0: tidyUp(); michael@0: return; michael@0: } michael@0: michael@0: toolbox = aToolbox; michael@0: info("Toolbox fired a `ready` event"); michael@0: michael@0: toolbox.once("select", selectCB); michael@0: michael@0: if (aIndex != null) { michael@0: // This if block is to allow the call of selectCB 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 = gDevTools._tools.get(toolIDs[aIndex]).key; michael@0: let toolModifiers = gDevTools._tools.get(toolIDs[aIndex]).modifiers; michael@0: let modifiers = { michael@0: accelKey: toolModifiers.contains("accel"), michael@0: altKey: toolModifiers.contains("alt"), michael@0: shiftKey: toolModifiers.contains("shift"), michael@0: }; michael@0: idIndex = aIndex; michael@0: info("Testing shortcut for tool " + aIndex + ":" + toolIDs[aIndex] + michael@0: " using key " + key); michael@0: EventUtils.synthesizeKey(key, modifiers, toolbox.doc.defaultView.parent); michael@0: } michael@0: } michael@0: michael@0: function selectCB(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: michael@0: testShortcuts(toolbox, idIndex + 1); michael@0: } michael@0: michael@0: function tidyUp() { michael@0: toolbox.destroy().then(function() { michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: for (let pref of modifiedPrefs) { michael@0: Services.prefs.clearUserPref(pref); michael@0: } michael@0: toolbox = toolIDs = idIndex = modifiedPrefs = Toolbox = null; michael@0: finish(); michael@0: }); michael@0: }