1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/framework/test/browser_toolbox_highlight.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let Toolbox = devtools.Toolbox; 1.8 +let temp = {}; 1.9 +Cu.import("resource://gre/modules/Services.jsm", temp); 1.10 +let Services = temp.Services; 1.11 +temp = null; 1.12 +let toolbox = null; 1.13 + 1.14 +function test() { 1.15 + waitForExplicitFinish(); 1.16 + 1.17 + const URL = "data:text/plain;charset=UTF-8,Nothing to see here, move along"; 1.18 + 1.19 + const TOOL_ID_1 = "jsdebugger"; 1.20 + const TOOL_ID_2 = "webconsole"; 1.21 + 1.22 + addTab(URL, () => { 1.23 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.24 + gDevTools.showToolbox(target, TOOL_ID_1, Toolbox.HostType.BOTTOM) 1.25 + .then(aToolbox => { 1.26 + toolbox = aToolbox; 1.27 + // select tool 2 1.28 + toolbox.selectTool(TOOL_ID_2) 1.29 + // and highlight the first one 1.30 + .then(highlightTab.bind(null, TOOL_ID_1)) 1.31 + // to see if it has the proper class. 1.32 + .then(checkHighlighted.bind(null, TOOL_ID_1)) 1.33 + // Now switch back to first tool 1.34 + .then(() => toolbox.selectTool(TOOL_ID_1)) 1.35 + // to check again. But there is no easy way to test if 1.36 + // it is showing orange or not. 1.37 + .then(checkNoHighlightWhenSelected.bind(null, TOOL_ID_1)) 1.38 + // Switch to tool 2 again 1.39 + .then(() => toolbox.selectTool(TOOL_ID_2)) 1.40 + // and check again. 1.41 + .then(checkHighlighted.bind(null, TOOL_ID_1)) 1.42 + // Now unhighlight the tool 1.43 + .then(unhighlightTab.bind(null, TOOL_ID_1)) 1.44 + // to see the classes gone. 1.45 + .then(checkNoHighlight.bind(null, TOOL_ID_1)) 1.46 + // Now close the toolbox and exit. 1.47 + .then(() => executeSoon(() => { 1.48 + toolbox.destroy() 1.49 + .then(() => { 1.50 + toolbox = null; 1.51 + gBrowser.removeCurrentTab(); 1.52 + finish(); 1.53 + }); 1.54 + })); 1.55 + }); 1.56 + }); 1.57 +} 1.58 + 1.59 +function highlightTab(toolId) { 1.60 + info("Highlighting tool " + toolId + "'s tab."); 1.61 + toolbox.highlightTool(toolId); 1.62 +} 1.63 + 1.64 +function unhighlightTab(toolId) { 1.65 + info("Unhighlighting tool " + toolId + "'s tab."); 1.66 + toolbox.unhighlightTool(toolId); 1.67 +} 1.68 + 1.69 +function checkHighlighted(toolId) { 1.70 + let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId); 1.71 + ok(tab.hasAttribute("highlighted"), "The highlighted attribute is present"); 1.72 + ok(!tab.hasAttribute("selected") || tab.getAttribute("selected") != "true", 1.73 + "The tab is not selected"); 1.74 +} 1.75 + 1.76 +function checkNoHighlightWhenSelected(toolId) { 1.77 + let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId); 1.78 + ok(tab.hasAttribute("highlighted"), "The highlighted attribute is present"); 1.79 + ok(tab.hasAttribute("selected") && tab.getAttribute("selected") == "true", 1.80 + "and the tab is selected, so the orange glow will not be present."); 1.81 +} 1.82 + 1.83 +function checkNoHighlight(toolId) { 1.84 + let tab = toolbox.doc.getElementById("toolbox-tab-" + toolId); 1.85 + ok(!tab.hasAttribute("highlighted"), 1.86 + "The highlighted attribute is not present"); 1.87 +}