browser/devtools/framework/test/browser_keybindings.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/framework/test/browser_keybindings.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Tests that the keybindings for opening and closing the inspector work as expected
     1.8 +// Can probably make this a shared test that tests all of the tools global keybindings
     1.9 +
    1.10 +function test()
    1.11 +{
    1.12 +  waitForExplicitFinish();
    1.13 +
    1.14 +  let doc;
    1.15 +  let node;
    1.16 +  let inspector;
    1.17 +  let keysetMap = { };
    1.18 +
    1.19 +  gBrowser.selectedTab = gBrowser.addTab();
    1.20 +  gBrowser.selectedBrowser.addEventListener("load", function onload() {
    1.21 +    gBrowser.selectedBrowser.removeEventListener("load", onload, true);
    1.22 +    doc = content.document;
    1.23 +    node = doc.querySelector("h1");
    1.24 +    waitForFocus(setupKeyBindingsTest, content);
    1.25 +  }, true);
    1.26 +
    1.27 +  content.location = "data:text/html,<html><head><title>Test for the " +
    1.28 +                     "highlighter keybindings</title></head><body>" +
    1.29 +                     "<h1>Keybindings!</h1></body></html>";
    1.30 +
    1.31 +  function buildDevtoolsKeysetMap(keyset) {
    1.32 +    [].forEach.call(keyset.querySelectorAll("key"), function(key) {
    1.33 +
    1.34 +      if (!key.getAttribute("key")) {
    1.35 +        return;
    1.36 +      }
    1.37 +
    1.38 +      let modifiers = key.getAttribute("modifiers");
    1.39 +
    1.40 +      keysetMap[key.id.split("_")[1]] = {
    1.41 +        key: key.getAttribute("key"),
    1.42 +        modifiers: modifiers,
    1.43 +        modifierOpt: {
    1.44 +          shiftKey: modifiers.match("shift"),
    1.45 +          ctrlKey: modifiers.match("ctrl"),
    1.46 +          altKey: modifiers.match("alt"),
    1.47 +          metaKey: modifiers.match("meta"),
    1.48 +          accelKey: modifiers.match("accel")
    1.49 +        },
    1.50 +        synthesizeKey: function() {
    1.51 +          EventUtils.synthesizeKey(this.key, this.modifierOpt);
    1.52 +        }
    1.53 +      }
    1.54 +    });
    1.55 +  }
    1.56 +
    1.57 +  function setupKeyBindingsTest()
    1.58 +  {
    1.59 +    for (let win of gDevToolsBrowser._trackedBrowserWindows) {
    1.60 +      buildDevtoolsKeysetMap(win.document.getElementById("devtoolsKeyset"));
    1.61 +    }
    1.62 +
    1.63 +    gDevTools.once("toolbox-ready", (e, toolbox) => {
    1.64 +      inspectorShouldBeOpenAndHighlighting(toolbox.getCurrentPanel(), toolbox)
    1.65 +    });
    1.66 +
    1.67 +    keysetMap.inspector.synthesizeKey();
    1.68 +  }
    1.69 +
    1.70 +  function inspectorShouldBeOpenAndHighlighting(aInspector, aToolbox)
    1.71 +  {
    1.72 +    is (aToolbox.currentToolId, "inspector", "Correct tool has been loaded");
    1.73 +
    1.74 +    aToolbox.once("picker-started", () => {
    1.75 +      ok(true, "picker-started event received, highlighter started");
    1.76 +      keysetMap.inspector.synthesizeKey();
    1.77 +
    1.78 +      aToolbox.once("picker-stopped", () => {
    1.79 +        ok(true, "picker-stopped event received, highlighter stopped");
    1.80 +        aToolbox.once("webconsole-ready", (e, panel) => {
    1.81 +          webconsoleShouldBeSelected(aToolbox, panel);
    1.82 +        });
    1.83 +        keysetMap.webconsole.synthesizeKey();
    1.84 +      });
    1.85 +    });
    1.86 +  }
    1.87 +
    1.88 +  function webconsoleShouldBeSelected(aToolbox, panel)
    1.89 +  {
    1.90 +      is (aToolbox.currentToolId, "webconsole");
    1.91 +
    1.92 +      aToolbox.once("jsdebugger-ready", (e, panel) => {
    1.93 +        jsdebuggerShouldBeSelected(aToolbox, panel);
    1.94 +      });
    1.95 +      keysetMap.jsdebugger.synthesizeKey();
    1.96 +  }
    1.97 +
    1.98 +  function jsdebuggerShouldBeSelected(aToolbox, panel)
    1.99 +  {
   1.100 +      is (aToolbox.currentToolId, "jsdebugger");
   1.101 +
   1.102 +      aToolbox.once("netmonitor-ready", (e, panel) => {
   1.103 +        netmonitorShouldBeSelected(aToolbox, panel);
   1.104 +      });
   1.105 +
   1.106 +      keysetMap.netmonitor.synthesizeKey();
   1.107 +  }
   1.108 +
   1.109 +  function netmonitorShouldBeSelected(aToolbox, panel)
   1.110 +  {
   1.111 +      is (aToolbox.currentToolId, "netmonitor");
   1.112 +      finishUp();
   1.113 +  }
   1.114 +
   1.115 +  function finishUp() {
   1.116 +    doc = node = inspector = keysetMap = null;
   1.117 +    gBrowser.removeCurrentTab();
   1.118 +    finish();
   1.119 +  }
   1.120 +}

mercurial