Wed, 31 Dec 2014 06:09:35 +0100
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 | // Tests devtools API |
michael@0 | 5 | |
michael@0 | 6 | const Cu = Components.utils; |
michael@0 | 7 | const toolId = "test-tool"; |
michael@0 | 8 | |
michael@0 | 9 | let tempScope = {}; |
michael@0 | 10 | Cu.import("resource://gre/modules/devtools/event-emitter.js", tempScope); |
michael@0 | 11 | let EventEmitter = tempScope.EventEmitter; |
michael@0 | 12 | |
michael@0 | 13 | function test() { |
michael@0 | 14 | addTab("about:blank", function(aBrowser, aTab) { |
michael@0 | 15 | runTests(aTab); |
michael@0 | 16 | }); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function runTests(aTab) { |
michael@0 | 20 | let toolDefinition = { |
michael@0 | 21 | id: toolId, |
michael@0 | 22 | isTargetSupported: function() true, |
michael@0 | 23 | visibilityswitch: "devtools.test-tool.enabled", |
michael@0 | 24 | url: "about:blank", |
michael@0 | 25 | label: "someLabel", |
michael@0 | 26 | build: function(iframeWindow, toolbox) { |
michael@0 | 27 | let panel = new DevToolPanel(iframeWindow, toolbox); |
michael@0 | 28 | return panel.open(); |
michael@0 | 29 | }, |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | ok(gDevTools, "gDevTools exists"); |
michael@0 | 33 | is(gDevTools.getToolDefinitionMap().has(toolId), false, |
michael@0 | 34 | "The tool is not registered"); |
michael@0 | 35 | |
michael@0 | 36 | gDevTools.registerTool(toolDefinition); |
michael@0 | 37 | is(gDevTools.getToolDefinitionMap().has(toolId), true, |
michael@0 | 38 | "The tool is registered"); |
michael@0 | 39 | |
michael@0 | 40 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 41 | gDevTools.showToolbox(target, toolId).then(function(toolbox) { |
michael@0 | 42 | is(toolbox.target, target, "toolbox target is correct"); |
michael@0 | 43 | is(toolbox._host.hostTab, gBrowser.selectedTab, "toolbox host is correct"); |
michael@0 | 44 | continueTests(toolbox); |
michael@0 | 45 | }).then(null, console.error); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function continueTests(toolbox, panel) { |
michael@0 | 49 | ok(toolbox.getCurrentPanel(), "panel value is correct"); |
michael@0 | 50 | is(toolbox.currentToolId, toolId, "toolbox _currentToolId is correct"); |
michael@0 | 51 | |
michael@0 | 52 | ok(!toolbox.doc.getElementById("toolbox-tab-" + toolId).hasAttribute("icon-invertable"), |
michael@0 | 53 | "The tool tab does not have the invertable attribute"); |
michael@0 | 54 | |
michael@0 | 55 | ok(toolbox.doc.getElementById("toolbox-tab-inspector").hasAttribute("icon-invertable"), |
michael@0 | 56 | "The builtin tool tabs do have the invertable attribute"); |
michael@0 | 57 | |
michael@0 | 58 | let toolDefinitions = gDevTools.getToolDefinitionMap(); |
michael@0 | 59 | is(toolDefinitions.has(toolId), true, "The tool is in gDevTools"); |
michael@0 | 60 | |
michael@0 | 61 | let toolDefinition = toolDefinitions.get(toolId); |
michael@0 | 62 | is(toolDefinition.id, toolId, "toolDefinition id is correct"); |
michael@0 | 63 | |
michael@0 | 64 | gDevTools.unregisterTool(toolId); |
michael@0 | 65 | is(gDevTools.getToolDefinitionMap().has(toolId), false, |
michael@0 | 66 | "The tool is no longer registered"); |
michael@0 | 67 | |
michael@0 | 68 | toolbox.destroy().then(function() { |
michael@0 | 69 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 70 | ok(gDevTools._toolboxes.get(target) == null, "gDevTools doesn't know about target"); |
michael@0 | 71 | ok(toolbox._target == null, "toolbox doesn't know about target."); |
michael@0 | 72 | |
michael@0 | 73 | finishUp(); |
michael@0 | 74 | }).then(null, console.error); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function finishUp() { |
michael@0 | 78 | tempScope = null; |
michael@0 | 79 | gBrowser.removeCurrentTab(); |
michael@0 | 80 | finish(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * When a Toolbox is started it creates a DevToolPanel for each of the tools |
michael@0 | 85 | * by calling toolDefinition.build(). The returned object should |
michael@0 | 86 | * at least implement these functions. They will be used by the ToolBox. |
michael@0 | 87 | * |
michael@0 | 88 | * There may be no benefit in doing this as an abstract type, but if nothing |
michael@0 | 89 | * else gives us a place to write documentation. |
michael@0 | 90 | */ |
michael@0 | 91 | function DevToolPanel(iframeWindow, toolbox) { |
michael@0 | 92 | EventEmitter.decorate(this); |
michael@0 | 93 | |
michael@0 | 94 | this._toolbox = toolbox; |
michael@0 | 95 | |
michael@0 | 96 | /*let doc = iframeWindow.document |
michael@0 | 97 | let label = doc.createElement("label"); |
michael@0 | 98 | let textNode = doc.createTextNode("Some Tool"); |
michael@0 | 99 | |
michael@0 | 100 | label.appendChild(textNode); |
michael@0 | 101 | doc.body.appendChild(label);*/ |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | DevToolPanel.prototype = { |
michael@0 | 105 | open: function() { |
michael@0 | 106 | let deferred = promise.defer(); |
michael@0 | 107 | |
michael@0 | 108 | executeSoon(function() { |
michael@0 | 109 | this._isReady = true; |
michael@0 | 110 | this.emit("ready"); |
michael@0 | 111 | deferred.resolve(this); |
michael@0 | 112 | }.bind(this)); |
michael@0 | 113 | |
michael@0 | 114 | return deferred.promise; |
michael@0 | 115 | }, |
michael@0 | 116 | |
michael@0 | 117 | get target() this._toolbox.target, |
michael@0 | 118 | |
michael@0 | 119 | get toolbox() this._toolbox, |
michael@0 | 120 | |
michael@0 | 121 | get isReady() this._isReady, |
michael@0 | 122 | |
michael@0 | 123 | _isReady: false, |
michael@0 | 124 | |
michael@0 | 125 | destroy: function DTI_destroy() { |
michael@0 | 126 | return promise.defer(null); |
michael@0 | 127 | }, |
michael@0 | 128 | }; |