browser/devtools/framework/test/browser_keybindings.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:bd1c6118c1c3
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 // Tests that the keybindings for opening and closing the inspector work as expected
5 // Can probably make this a shared test that tests all of the tools global keybindings
6
7 function test()
8 {
9 waitForExplicitFinish();
10
11 let doc;
12 let node;
13 let inspector;
14 let keysetMap = { };
15
16 gBrowser.selectedTab = gBrowser.addTab();
17 gBrowser.selectedBrowser.addEventListener("load", function onload() {
18 gBrowser.selectedBrowser.removeEventListener("load", onload, true);
19 doc = content.document;
20 node = doc.querySelector("h1");
21 waitForFocus(setupKeyBindingsTest, content);
22 }, true);
23
24 content.location = "data:text/html,<html><head><title>Test for the " +
25 "highlighter keybindings</title></head><body>" +
26 "<h1>Keybindings!</h1></body></html>";
27
28 function buildDevtoolsKeysetMap(keyset) {
29 [].forEach.call(keyset.querySelectorAll("key"), function(key) {
30
31 if (!key.getAttribute("key")) {
32 return;
33 }
34
35 let modifiers = key.getAttribute("modifiers");
36
37 keysetMap[key.id.split("_")[1]] = {
38 key: key.getAttribute("key"),
39 modifiers: modifiers,
40 modifierOpt: {
41 shiftKey: modifiers.match("shift"),
42 ctrlKey: modifiers.match("ctrl"),
43 altKey: modifiers.match("alt"),
44 metaKey: modifiers.match("meta"),
45 accelKey: modifiers.match("accel")
46 },
47 synthesizeKey: function() {
48 EventUtils.synthesizeKey(this.key, this.modifierOpt);
49 }
50 }
51 });
52 }
53
54 function setupKeyBindingsTest()
55 {
56 for (let win of gDevToolsBrowser._trackedBrowserWindows) {
57 buildDevtoolsKeysetMap(win.document.getElementById("devtoolsKeyset"));
58 }
59
60 gDevTools.once("toolbox-ready", (e, toolbox) => {
61 inspectorShouldBeOpenAndHighlighting(toolbox.getCurrentPanel(), toolbox)
62 });
63
64 keysetMap.inspector.synthesizeKey();
65 }
66
67 function inspectorShouldBeOpenAndHighlighting(aInspector, aToolbox)
68 {
69 is (aToolbox.currentToolId, "inspector", "Correct tool has been loaded");
70
71 aToolbox.once("picker-started", () => {
72 ok(true, "picker-started event received, highlighter started");
73 keysetMap.inspector.synthesizeKey();
74
75 aToolbox.once("picker-stopped", () => {
76 ok(true, "picker-stopped event received, highlighter stopped");
77 aToolbox.once("webconsole-ready", (e, panel) => {
78 webconsoleShouldBeSelected(aToolbox, panel);
79 });
80 keysetMap.webconsole.synthesizeKey();
81 });
82 });
83 }
84
85 function webconsoleShouldBeSelected(aToolbox, panel)
86 {
87 is (aToolbox.currentToolId, "webconsole");
88
89 aToolbox.once("jsdebugger-ready", (e, panel) => {
90 jsdebuggerShouldBeSelected(aToolbox, panel);
91 });
92 keysetMap.jsdebugger.synthesizeKey();
93 }
94
95 function jsdebuggerShouldBeSelected(aToolbox, panel)
96 {
97 is (aToolbox.currentToolId, "jsdebugger");
98
99 aToolbox.once("netmonitor-ready", (e, panel) => {
100 netmonitorShouldBeSelected(aToolbox, panel);
101 });
102
103 keysetMap.netmonitor.synthesizeKey();
104 }
105
106 function netmonitorShouldBeSelected(aToolbox, panel)
107 {
108 is (aToolbox.currentToolId, "netmonitor");
109 finishUp();
110 }
111
112 function finishUp() {
113 doc = node = inspector = keysetMap = null;
114 gBrowser.removeCurrentTab();
115 finish();
116 }
117 }

mercurial