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.

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

mercurial