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.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     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
     7 function test()
     8 {
     9   waitForExplicitFinish();
    11   let doc;
    12   let node;
    13   let inspector;
    14   let keysetMap = { };
    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);
    24   content.location = "data:text/html,<html><head><title>Test for the " +
    25                      "highlighter keybindings</title></head><body>" +
    26                      "<h1>Keybindings!</h1></body></html>";
    28   function buildDevtoolsKeysetMap(keyset) {
    29     [].forEach.call(keyset.querySelectorAll("key"), function(key) {
    31       if (!key.getAttribute("key")) {
    32         return;
    33       }
    35       let modifiers = key.getAttribute("modifiers");
    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   }
    54   function setupKeyBindingsTest()
    55   {
    56     for (let win of gDevToolsBrowser._trackedBrowserWindows) {
    57       buildDevtoolsKeysetMap(win.document.getElementById("devtoolsKeyset"));
    58     }
    60     gDevTools.once("toolbox-ready", (e, toolbox) => {
    61       inspectorShouldBeOpenAndHighlighting(toolbox.getCurrentPanel(), toolbox)
    62     });
    64     keysetMap.inspector.synthesizeKey();
    65   }
    67   function inspectorShouldBeOpenAndHighlighting(aInspector, aToolbox)
    68   {
    69     is (aToolbox.currentToolId, "inspector", "Correct tool has been loaded");
    71     aToolbox.once("picker-started", () => {
    72       ok(true, "picker-started event received, highlighter started");
    73       keysetMap.inspector.synthesizeKey();
    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   }
    85   function webconsoleShouldBeSelected(aToolbox, panel)
    86   {
    87       is (aToolbox.currentToolId, "webconsole");
    89       aToolbox.once("jsdebugger-ready", (e, panel) => {
    90         jsdebuggerShouldBeSelected(aToolbox, panel);
    91       });
    92       keysetMap.jsdebugger.synthesizeKey();
    93   }
    95   function jsdebuggerShouldBeSelected(aToolbox, panel)
    96   {
    97       is (aToolbox.currentToolId, "jsdebugger");
    99       aToolbox.once("netmonitor-ready", (e, panel) => {
   100         netmonitorShouldBeSelected(aToolbox, panel);
   101       });
   103       keysetMap.netmonitor.synthesizeKey();
   104   }
   106   function netmonitorShouldBeSelected(aToolbox, panel)
   107   {
   108       is (aToolbox.currentToolId, "netmonitor");
   109       finishUp();
   110   }
   112   function finishUp() {
   113     doc = node = inspector = keysetMap = null;
   114     gBrowser.removeCurrentTab();
   115     finish();
   116   }
   117 }

mercurial