summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_keybindings_01.js
blob: 4e4effb070c53c2a8b37bd79da78ba9735eff466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests that the keybindings for opening and closing the inspector work as expected
// Can probably make this a shared test that tests all of the tools global keybindings
const TEST_URL = "data:text/html,<html><head><title>Test for the " +
                 "highlighter keybindings</title></head><body>" +
                 "<h1>Keybindings!</h1></body></html>"
function test()
{
  waitForExplicitFinish();

  let doc;
  let node;
  let inspector;
  let keysetMap = { };

  addTab(TEST_URL).then(function () {
    doc = content.document;
    node = doc.querySelector("h1");
    waitForFocus(setupKeyBindingsTest);
  });

  function buildDevtoolsKeysetMap(keyset) {
    [].forEach.call(keyset.querySelectorAll("key"), function (key) {

      if (!key.getAttribute("key")) {
        return;
      }

      let modifiers = key.getAttribute("modifiers");

      keysetMap[key.id.split("_")[1]] = {
        key: key.getAttribute("key"),
        modifiers: modifiers,
        modifierOpt: {
          shiftKey: modifiers.match("shift"),
          ctrlKey: modifiers.match("ctrl"),
          altKey: modifiers.match("alt"),
          metaKey: modifiers.match("meta"),
          accelKey: modifiers.match("accel")
        },
        synthesizeKey: function () {
          EventUtils.synthesizeKey(this.key, this.modifierOpt);
        }
      };
    });
  }

  function setupKeyBindingsTest()
  {
    for (let win of gDevToolsBrowser._trackedBrowserWindows) {
      buildDevtoolsKeysetMap(win.document.getElementById("devtoolsKeyset"));
    }

    gDevTools.once("toolbox-ready", (e, toolbox) => {
      inspectorShouldBeOpenAndHighlighting(toolbox.getCurrentPanel(), toolbox);
    });

    keysetMap.inspector.synthesizeKey();
  }

  function inspectorShouldBeOpenAndHighlighting(aInspector, aToolbox)
  {
    is(aToolbox.currentToolId, "inspector", "Correct tool has been loaded");

    aToolbox.once("picker-started", () => {
      ok(true, "picker-started event received, highlighter started");
      keysetMap.inspector.synthesizeKey();

      aToolbox.once("picker-stopped", () => {
        ok(true, "picker-stopped event received, highlighter stopped");
        gDevTools.once("select-tool-command", () => {
          webconsoleShouldBeSelected(aToolbox);
        });
        keysetMap.webconsole.synthesizeKey();
      });
    });
  }

  function webconsoleShouldBeSelected(aToolbox)
  {
    is(aToolbox.currentToolId, "webconsole", "webconsole should be selected.");

    gDevTools.once("select-tool-command", () => {
      jsdebuggerShouldBeSelected(aToolbox);
    });
    keysetMap.jsdebugger.synthesizeKey();
  }

  function jsdebuggerShouldBeSelected(aToolbox)
  {
    is(aToolbox.currentToolId, "jsdebugger", "jsdebugger should be selected.");

    gDevTools.once("select-tool-command", () => {
      netmonitorShouldBeSelected(aToolbox);
    });

    keysetMap.netmonitor.synthesizeKey();
  }

  function netmonitorShouldBeSelected(aToolbox, panel)
  {
    is(aToolbox.currentToolId, "netmonitor", "netmonitor should be selected.");
    finishUp();
  }

  function finishUp() {
    doc = node = inspector = keysetMap = null;
    gBrowser.removeCurrentTab();
    finish();
  }
}