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: const toolId = "test-tool"; michael@0: michael@0: let tempScope = {}; michael@0: Cu.import("resource://gre/modules/devtools/event-emitter.js", tempScope); michael@0: let EventEmitter = tempScope.EventEmitter; michael@0: michael@0: function test() { michael@0: addTab("about:blank", function(aBrowser, aTab) { michael@0: runTests(aTab); michael@0: }); michael@0: } michael@0: michael@0: function runTests(aTab) { michael@0: let toolDefinition = { michael@0: id: toolId, michael@0: isTargetSupported: function() true, michael@0: visibilityswitch: "devtools.test-tool.enabled", michael@0: url: "about:blank", michael@0: label: "someLabel", michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new DevToolPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: }, michael@0: }; michael@0: michael@0: ok(gDevTools, "gDevTools exists"); michael@0: is(gDevTools.getToolDefinitionMap().has(toolId), false, michael@0: "The tool is not registered"); michael@0: michael@0: gDevTools.registerTool(toolDefinition); michael@0: is(gDevTools.getToolDefinitionMap().has(toolId), true, michael@0: "The tool is registered"); michael@0: michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.showToolbox(target, toolId).then(function(toolbox) { michael@0: is(toolbox.target, target, "toolbox target is correct"); michael@0: is(toolbox._host.hostTab, gBrowser.selectedTab, "toolbox host is correct"); michael@0: continueTests(toolbox); michael@0: }).then(null, console.error); michael@0: } michael@0: michael@0: function continueTests(toolbox, panel) { michael@0: ok(toolbox.getCurrentPanel(), "panel value is correct"); michael@0: is(toolbox.currentToolId, toolId, "toolbox _currentToolId is correct"); michael@0: michael@0: ok(!toolbox.doc.getElementById("toolbox-tab-" + toolId).hasAttribute("icon-invertable"), michael@0: "The tool tab does not have the invertable attribute"); michael@0: michael@0: ok(toolbox.doc.getElementById("toolbox-tab-inspector").hasAttribute("icon-invertable"), michael@0: "The builtin tool tabs do have the invertable attribute"); michael@0: michael@0: let toolDefinitions = gDevTools.getToolDefinitionMap(); michael@0: is(toolDefinitions.has(toolId), true, "The tool is in gDevTools"); michael@0: michael@0: let toolDefinition = toolDefinitions.get(toolId); michael@0: is(toolDefinition.id, toolId, "toolDefinition id is correct"); michael@0: michael@0: gDevTools.unregisterTool(toolId); michael@0: is(gDevTools.getToolDefinitionMap().has(toolId), false, michael@0: "The tool is no longer registered"); michael@0: michael@0: toolbox.destroy().then(function() { michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: ok(gDevTools._toolboxes.get(target) == null, "gDevTools doesn't know about target"); michael@0: ok(toolbox._target == null, "toolbox doesn't know about target."); michael@0: michael@0: finishUp(); michael@0: }).then(null, console.error); michael@0: } michael@0: michael@0: function finishUp() { michael@0: tempScope = null; michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: } michael@0: michael@0: /** michael@0: * When a Toolbox is started it creates a DevToolPanel for each of the tools michael@0: * by calling toolDefinition.build(). The returned object should michael@0: * at least implement these functions. They will be used by the ToolBox. michael@0: * michael@0: * There may be no benefit in doing this as an abstract type, but if nothing michael@0: * else gives us a place to write documentation. michael@0: */ michael@0: function DevToolPanel(iframeWindow, toolbox) { michael@0: EventEmitter.decorate(this); michael@0: michael@0: this._toolbox = toolbox; michael@0: michael@0: /*let doc = iframeWindow.document michael@0: let label = doc.createElement("label"); michael@0: let textNode = doc.createTextNode("Some Tool"); michael@0: michael@0: label.appendChild(textNode); michael@0: doc.body.appendChild(label);*/ michael@0: } michael@0: michael@0: DevToolPanel.prototype = { michael@0: open: function() { michael@0: let deferred = promise.defer(); michael@0: michael@0: executeSoon(function() { michael@0: this._isReady = true; michael@0: this.emit("ready"); michael@0: deferred.resolve(this); michael@0: }.bind(this)); michael@0: michael@0: return deferred.promise; michael@0: }, michael@0: michael@0: get target() this._toolbox.target, michael@0: michael@0: get toolbox() this._toolbox, michael@0: michael@0: get isReady() this._isReady, michael@0: michael@0: _isReady: false, michael@0: michael@0: destroy: function DTI_destroy() { michael@0: return promise.defer(null); michael@0: }, michael@0: };