browser/devtools/framework/test/browser_toolbox_highlight.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 let Toolbox = devtools.Toolbox;
     5 let temp = {};
     6 Cu.import("resource://gre/modules/Services.jsm", temp);
     7 let Services = temp.Services;
     8 temp = null;
     9 let toolbox = null;
    11 function test() {
    12   waitForExplicitFinish();
    14   const URL = "data:text/plain;charset=UTF-8,Nothing to see here, move along";
    16   const TOOL_ID_1 = "jsdebugger";
    17   const TOOL_ID_2 = "webconsole";
    19   addTab(URL, () => {
    20     let target = TargetFactory.forTab(gBrowser.selectedTab);
    21     gDevTools.showToolbox(target, TOOL_ID_1, Toolbox.HostType.BOTTOM)
    22              .then(aToolbox => {
    23                 toolbox = aToolbox;
    24                 // select tool 2
    25                 toolbox.selectTool(TOOL_ID_2)
    26                        // and highlight the first one
    27                        .then(highlightTab.bind(null, TOOL_ID_1))
    28                        // to see if it has the proper class.
    29                        .then(checkHighlighted.bind(null, TOOL_ID_1))
    30                        // Now switch back to first tool
    31                        .then(() => toolbox.selectTool(TOOL_ID_1))
    32                        // to check again. But there is no easy way to test if
    33                        // it is showing orange or not.
    34                        .then(checkNoHighlightWhenSelected.bind(null, TOOL_ID_1))
    35                        // Switch to tool 2 again
    36                        .then(() => toolbox.selectTool(TOOL_ID_2))
    37                        // and check again.
    38                        .then(checkHighlighted.bind(null, TOOL_ID_1))
    39                        // Now unhighlight the tool
    40                        .then(unhighlightTab.bind(null, TOOL_ID_1))
    41                        // to see the classes gone.
    42                        .then(checkNoHighlight.bind(null, TOOL_ID_1))
    43                        // Now close the toolbox and exit.
    44                        .then(() => executeSoon(() => {
    45                           toolbox.destroy()
    46                                  .then(() => {
    47                                    toolbox = null;
    48                                    gBrowser.removeCurrentTab();
    49                                    finish();
    50                                  });
    51                         }));
    52               });
    53   });
    54 }
    56 function highlightTab(toolId) {
    57   info("Highlighting tool " + toolId + "'s tab.");
    58   toolbox.highlightTool(toolId);
    59 }
    61 function unhighlightTab(toolId) {
    62   info("Unhighlighting tool " + toolId + "'s tab.");
    63   toolbox.unhighlightTool(toolId);
    64 }
    66 function checkHighlighted(toolId) {
    67   let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
    68   ok(tab.hasAttribute("highlighted"), "The highlighted attribute is present");
    69   ok(!tab.hasAttribute("selected") || tab.getAttribute("selected") != "true",
    70      "The tab is not selected");
    71 }
    73 function checkNoHighlightWhenSelected(toolId) {
    74   let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
    75   ok(tab.hasAttribute("highlighted"), "The highlighted attribute is present");
    76   ok(tab.hasAttribute("selected") && tab.getAttribute("selected") == "true",
    77      "and the tab is selected, so the orange glow will not be present.");
    78 }
    80 function checkNoHighlight(toolId) {
    81   let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId);
    82   ok(!tab.hasAttribute("highlighted"),
    83      "The highlighted attribute is not present");
    84 }

mercurial