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

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

var toolbox = null;

function test() {
  const URL = "data:text/plain;charset=UTF-8,Nothing to see here, move along";

  const TOOL_ID_1 = "jsdebugger";
  const TOOL_ID_2 = "webconsole";

  addTab(URL).then(() => {
    let target = TargetFactory.forTab(gBrowser.selectedTab);
    gDevTools.showToolbox(target, TOOL_ID_1, Toolbox.HostType.BOTTOM)
             .then(aToolbox => {
               toolbox = aToolbox;
                // select tool 2
               toolbox.selectTool(TOOL_ID_2)
                       // and highlight the first one
                       .then(highlightTab.bind(null, TOOL_ID_1))
                       // to see if it has the proper class.
                       .then(checkHighlighted.bind(null, TOOL_ID_1))
                       // Now switch back to first tool
                       .then(() => toolbox.selectTool(TOOL_ID_1))
                       // to check again. But there is no easy way to test if
                       // it is showing orange or not.
                       .then(checkNoHighlightWhenSelected.bind(null, TOOL_ID_1))
                       // Switch to tool 2 again
                       .then(() => toolbox.selectTool(TOOL_ID_2))
                       // and check again.
                       .then(checkHighlighted.bind(null, TOOL_ID_1))
                       // Now unhighlight the tool
                       .then(unhighlightTab.bind(null, TOOL_ID_1))
                       // to see the classes gone.
                       .then(checkNoHighlight.bind(null, TOOL_ID_1))
                       // Now close the toolbox and exit.
                       .then(() => executeSoon(() => {
                         toolbox.destroy()
                                 .then(() => {
                                   toolbox = null;
                                   gBrowser.removeCurrentTab();
                                   finish();
                                 });
                       }));
             });
  });
}

function highlightTab(toolId) {
  info("Highlighting tool " + toolId + "'s tab.");
  toolbox.highlightTool(toolId);
}

function unhighlightTab(toolId) {
  info("Unhighlighting tool " + toolId + "'s tab.");
  toolbox.unhighlightTool(toolId);
}

function checkHighlighted(toolId) {
  let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
  ok(tab.hasAttribute("highlighted"), "The highlighted attribute is present");
  ok(!tab.hasAttribute("selected") || tab.getAttribute("selected") != "true",
     "The tab is not selected");
}

function checkNoHighlightWhenSelected(toolId) {
  let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
  ok(tab.hasAttribute("highlighted"), "The highlighted attribute is present");
  ok(tab.hasAttribute("selected") && tab.getAttribute("selected") == "true",
     "and the tab is selected, so the orange glow will not be present.");
}

function checkNoHighlight(toolId) {
  let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
  ok(!tab.hasAttribute("highlighted"),
     "The highlighted attribute is not present");
}