browser/devtools/framework/test/browser_keybindings.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial