michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests that the keybindings for opening and closing the inspector work as expected michael@0: // Can probably make this a shared test that tests all of the tools global keybindings michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: let doc; michael@0: let node; michael@0: let inspector; michael@0: let keysetMap = { }; michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", function onload() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onload, true); michael@0: doc = content.document; michael@0: node = doc.querySelector("h1"); michael@0: waitForFocus(setupKeyBindingsTest, content); michael@0: }, true); michael@0: michael@0: content.location = "data:text/html,Test for the " + michael@0: "highlighter keybindings" + michael@0: "

Keybindings!

"; michael@0: michael@0: function buildDevtoolsKeysetMap(keyset) { michael@0: [].forEach.call(keyset.querySelectorAll("key"), function(key) { michael@0: michael@0: if (!key.getAttribute("key")) { michael@0: return; michael@0: } michael@0: michael@0: let modifiers = key.getAttribute("modifiers"); michael@0: michael@0: keysetMap[key.id.split("_")[1]] = { michael@0: key: key.getAttribute("key"), michael@0: modifiers: modifiers, michael@0: modifierOpt: { michael@0: shiftKey: modifiers.match("shift"), michael@0: ctrlKey: modifiers.match("ctrl"), michael@0: altKey: modifiers.match("alt"), michael@0: metaKey: modifiers.match("meta"), michael@0: accelKey: modifiers.match("accel") michael@0: }, michael@0: synthesizeKey: function() { michael@0: EventUtils.synthesizeKey(this.key, this.modifierOpt); michael@0: } michael@0: } michael@0: }); michael@0: } michael@0: michael@0: function setupKeyBindingsTest() michael@0: { michael@0: for (let win of gDevToolsBrowser._trackedBrowserWindows) { michael@0: buildDevtoolsKeysetMap(win.document.getElementById("devtoolsKeyset")); michael@0: } michael@0: michael@0: gDevTools.once("toolbox-ready", (e, toolbox) => { michael@0: inspectorShouldBeOpenAndHighlighting(toolbox.getCurrentPanel(), toolbox) michael@0: }); michael@0: michael@0: keysetMap.inspector.synthesizeKey(); michael@0: } michael@0: michael@0: function inspectorShouldBeOpenAndHighlighting(aInspector, aToolbox) michael@0: { michael@0: is (aToolbox.currentToolId, "inspector", "Correct tool has been loaded"); michael@0: michael@0: aToolbox.once("picker-started", () => { michael@0: ok(true, "picker-started event received, highlighter started"); michael@0: keysetMap.inspector.synthesizeKey(); michael@0: michael@0: aToolbox.once("picker-stopped", () => { michael@0: ok(true, "picker-stopped event received, highlighter stopped"); michael@0: aToolbox.once("webconsole-ready", (e, panel) => { michael@0: webconsoleShouldBeSelected(aToolbox, panel); michael@0: }); michael@0: keysetMap.webconsole.synthesizeKey(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function webconsoleShouldBeSelected(aToolbox, panel) michael@0: { michael@0: is (aToolbox.currentToolId, "webconsole"); michael@0: michael@0: aToolbox.once("jsdebugger-ready", (e, panel) => { michael@0: jsdebuggerShouldBeSelected(aToolbox, panel); michael@0: }); michael@0: keysetMap.jsdebugger.synthesizeKey(); michael@0: } michael@0: michael@0: function jsdebuggerShouldBeSelected(aToolbox, panel) michael@0: { michael@0: is (aToolbox.currentToolId, "jsdebugger"); michael@0: michael@0: aToolbox.once("netmonitor-ready", (e, panel) => { michael@0: netmonitorShouldBeSelected(aToolbox, panel); michael@0: }); michael@0: michael@0: keysetMap.netmonitor.synthesizeKey(); michael@0: } michael@0: michael@0: function netmonitorShouldBeSelected(aToolbox, panel) michael@0: { michael@0: is (aToolbox.currentToolId, "netmonitor"); michael@0: finishUp(); michael@0: } michael@0: michael@0: function finishUp() { michael@0: doc = node = inspector = keysetMap = null; michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: }