1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/framework/test/browser_toolbox_select_event.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 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; 1.8 + 1.9 +function test() { 1.10 + addTab("about:blank", function() { 1.11 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.12 + gDevTools.showToolbox(target, "webconsole").then(testSelect); 1.13 + }); 1.14 +} 1.15 + 1.16 +let called = { 1.17 + inspector: false, 1.18 + webconsole: false, 1.19 + styleeditor: false, 1.20 + //jsdebugger: false, 1.21 +} 1.22 + 1.23 +function testSelect(aToolbox) { 1.24 + toolbox = aToolbox; 1.25 + 1.26 + info("Toolbox fired a `ready` event"); 1.27 + 1.28 + toolbox.on("select", selectCB); 1.29 + 1.30 + toolbox.selectTool("inspector"); 1.31 + toolbox.selectTool("webconsole"); 1.32 + toolbox.selectTool("styleeditor"); 1.33 + //toolbox.selectTool("jsdebugger"); 1.34 +} 1.35 + 1.36 +function selectCB(event, id) { 1.37 + called[id] = true; 1.38 + info("toolbox-select event from " + id); 1.39 + 1.40 + for (let tool in called) { 1.41 + if (!called[tool]) { 1.42 + return; 1.43 + } 1.44 + } 1.45 + 1.46 + ok(true, "All the tools fired a 'select event'"); 1.47 + toolbox.off("select", selectCB); 1.48 + 1.49 + reselect(); 1.50 +} 1.51 + 1.52 +function reselect() { 1.53 + for (let tool in called) { 1.54 + called[tool] = false; 1.55 + } 1.56 + 1.57 + toolbox.once("inspector-selected", function() { 1.58 + tidyUpIfAllCalled("inspector"); 1.59 + }); 1.60 + 1.61 + toolbox.once("webconsole-selected", function() { 1.62 + tidyUpIfAllCalled("webconsole"); 1.63 + }); 1.64 + 1.65 + /* 1.66 + toolbox.once("jsdebugger-selected", function() { 1.67 + tidyUpIfAllCalled("jsdebugger"); 1.68 + }); 1.69 + */ 1.70 + 1.71 + toolbox.once("styleeditor-selected", function() { 1.72 + tidyUpIfAllCalled("styleeditor"); 1.73 + }); 1.74 + 1.75 + toolbox.selectTool("inspector"); 1.76 + toolbox.selectTool("webconsole"); 1.77 + toolbox.selectTool("styleeditor"); 1.78 + //toolbox.selectTool("jsdebugger"); 1.79 +} 1.80 + 1.81 +function tidyUpIfAllCalled(id) { 1.82 + called[id] = true; 1.83 + info("select event from " + id); 1.84 + 1.85 + for (let tool in called) { 1.86 + if (!called[tool]) { 1.87 + return; 1.88 + } 1.89 + } 1.90 + 1.91 + ok(true, "All the tools fired a {id}-selected event"); 1.92 + tidyUp(); 1.93 +} 1.94 + 1.95 +function tidyUp() { 1.96 + toolbox.destroy(); 1.97 + gBrowser.removeCurrentTab(); 1.98 + 1.99 + toolbox = null; 1.100 + finish(); 1.101 +}