summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_tabsswitch_shortcuts.js
blob: f8f49c07111e95a42ec988a989c06b117d094f71 (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

requestLongerTimeout(2);

var {Toolbox} = require("devtools/client/framework/toolbox");

const {LocalizationHelper} = require("devtools/shared/l10n");
const L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties");

add_task(function* () {
  let tab = yield addTab("about:blank");
  let target = TargetFactory.forTab(tab);
  yield target.makeRemote();

  let toolIDs = gDevTools.getToolDefinitionArray()
                         .filter(def => def.isTargetSupported(target))
                         .map(def => def.id);

  let toolbox = yield gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.BOTTOM);
  let nextShortcut = L10N.getStr("toolbox.nextTool.key");
  let prevShortcut = L10N.getStr("toolbox.previousTool.key");

  // Iterate over all tools, starting from options to netmonitor, in normal
  // order.
  for (let i = 1; i < toolIDs.length; i++) {
    yield testShortcuts(toolbox, i, nextShortcut, toolIDs);
  }

  // Iterate again, in the same order, starting from netmonitor (so next one is
  // 0: options).
  for (let i = 0; i < toolIDs.length; i++) {
    yield testShortcuts(toolbox, i, nextShortcut, toolIDs);
  }

  // Iterate over all tools in reverse order, starting from netmonitor to
  // options.
  for (let i = toolIDs.length - 2; i >= 0; i--) {
    yield testShortcuts(toolbox, i, prevShortcut, toolIDs);
  }

  // Iterate again, in reverse order again, starting from options (so next one
  // is length-1: netmonitor).
  for (let i = toolIDs.length - 1; i >= 0; i--) {
    yield testShortcuts(toolbox, i, prevShortcut, toolIDs);
  }

  yield toolbox.destroy();
  gBrowser.removeCurrentTab();
});

function* testShortcuts(toolbox, index, shortcut, toolIDs) {
  info("Testing shortcut to switch to tool " + index + ":" + toolIDs[index] +
       " using shortcut " + shortcut);

  let onToolSelected = toolbox.once("select");
  synthesizeKeyShortcut(shortcut);
  let id = yield onToolSelected;

  info("toolbox-select event from " + id);

  is(toolIDs.indexOf(id), index,
     "Correct tool is selected on pressing the shortcut for " + id);
}