Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | |
michael@0 | 8 | let toolbox, target; |
michael@0 | 9 | |
michael@0 | 10 | let tempScope = {}; |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | addTab("about:blank", function(aBrowser, aTab) { |
michael@0 | 14 | target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 15 | loadWebConsole(aTab).then(function() { |
michael@0 | 16 | console.log('loaded'); |
michael@0 | 17 | }, console.error); |
michael@0 | 18 | }); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function loadWebConsole(aTab) { |
michael@0 | 22 | ok(gDevTools, "gDevTools exists"); |
michael@0 | 23 | |
michael@0 | 24 | return gDevTools.showToolbox(target, "webconsole").then(function(aToolbox) { |
michael@0 | 25 | toolbox = aToolbox; |
michael@0 | 26 | checkToolLoading(); |
michael@0 | 27 | }, console.error); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function checkToolLoading() { |
michael@0 | 31 | is(toolbox.currentToolId, "webconsole", "The web console is selected"); |
michael@0 | 32 | ok(toolbox.isReady, "toolbox is ready") |
michael@0 | 33 | |
michael@0 | 34 | selectAndCheckById("jsdebugger").then(function() { |
michael@0 | 35 | selectAndCheckById("styleeditor").then(function() { |
michael@0 | 36 | testToggle(); |
michael@0 | 37 | }); |
michael@0 | 38 | }, console.error); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function selectAndCheckById(id) { |
michael@0 | 42 | let doc = toolbox.frame.contentDocument; |
michael@0 | 43 | |
michael@0 | 44 | return toolbox.selectTool(id).then(function() { |
michael@0 | 45 | let tab = doc.getElementById("toolbox-tab-" + id); |
michael@0 | 46 | is(tab.hasAttribute("selected"), true, "The " + id + " tab is selected"); |
michael@0 | 47 | }); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function testToggle() { |
michael@0 | 51 | toolbox.once("destroyed", function() { |
michael@0 | 52 | // Cannot reuse a target after it's destroyed. |
michael@0 | 53 | target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 54 | gDevTools.showToolbox(target, "styleeditor").then(function(aToolbox) { |
michael@0 | 55 | toolbox = aToolbox; |
michael@0 | 56 | is(toolbox.currentToolId, "styleeditor", "The style editor is selected"); |
michael@0 | 57 | finishUp(); |
michael@0 | 58 | }); |
michael@0 | 59 | }.bind(this)); |
michael@0 | 60 | |
michael@0 | 61 | toolbox.destroy(); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function finishUp() { |
michael@0 | 65 | toolbox.destroy().then(function() { |
michael@0 | 66 | toolbox = null; |
michael@0 | 67 | target = null; |
michael@0 | 68 | gBrowser.removeCurrentTab(); |
michael@0 | 69 | finish(); |
michael@0 | 70 | }); |
michael@0 | 71 | } |