michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests devtools API michael@0: michael@0: const Cu = Components.utils; michael@0: michael@0: let toolbox, target; michael@0: michael@0: let tempScope = {}; michael@0: michael@0: function test() { michael@0: addTab("about:blank", function(aBrowser, aTab) { michael@0: target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: loadWebConsole(aTab).then(function() { michael@0: console.log('loaded'); michael@0: }, console.error); michael@0: }); michael@0: } michael@0: michael@0: function loadWebConsole(aTab) { michael@0: ok(gDevTools, "gDevTools exists"); michael@0: michael@0: return gDevTools.showToolbox(target, "webconsole").then(function(aToolbox) { michael@0: toolbox = aToolbox; michael@0: checkToolLoading(); michael@0: }, console.error); michael@0: } michael@0: michael@0: function checkToolLoading() { michael@0: is(toolbox.currentToolId, "webconsole", "The web console is selected"); michael@0: ok(toolbox.isReady, "toolbox is ready") michael@0: michael@0: selectAndCheckById("jsdebugger").then(function() { michael@0: selectAndCheckById("styleeditor").then(function() { michael@0: testToggle(); michael@0: }); michael@0: }, console.error); michael@0: } michael@0: michael@0: function selectAndCheckById(id) { michael@0: let doc = toolbox.frame.contentDocument; michael@0: michael@0: return toolbox.selectTool(id).then(function() { michael@0: let tab = doc.getElementById("toolbox-tab-" + id); michael@0: is(tab.hasAttribute("selected"), true, "The " + id + " tab is selected"); michael@0: }); michael@0: } michael@0: michael@0: function testToggle() { michael@0: toolbox.once("destroyed", function() { michael@0: // Cannot reuse a target after it's destroyed. michael@0: target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.showToolbox(target, "styleeditor").then(function(aToolbox) { michael@0: toolbox = aToolbox; michael@0: is(toolbox.currentToolId, "styleeditor", "The style editor is selected"); michael@0: finishUp(); michael@0: }); michael@0: }.bind(this)); michael@0: michael@0: toolbox.destroy(); michael@0: } michael@0: michael@0: function finishUp() { michael@0: toolbox.destroy().then(function() { michael@0: toolbox = null; michael@0: target = null; michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }); michael@0: }