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 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | let toolbox; |
michael@0 | 6 | |
michael@0 | 7 | function test() |
michael@0 | 8 | { |
michael@0 | 9 | waitForExplicitFinish(); |
michael@0 | 10 | |
michael@0 | 11 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 12 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 13 | |
michael@0 | 14 | gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { |
michael@0 | 15 | gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); |
michael@0 | 16 | gDevTools.showToolbox(target).then(testRegister); |
michael@0 | 17 | }, true); |
michael@0 | 18 | |
michael@0 | 19 | content.location = "data:text/html,test for dynamically registering and unregistering tools"; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function testRegister(aToolbox) |
michael@0 | 23 | { |
michael@0 | 24 | toolbox = aToolbox |
michael@0 | 25 | gDevTools.once("tool-registered", toolRegistered); |
michael@0 | 26 | |
michael@0 | 27 | gDevTools.registerTool({ |
michael@0 | 28 | id: "test-tool", |
michael@0 | 29 | label: "Test Tool", |
michael@0 | 30 | inMenu: true, |
michael@0 | 31 | isTargetSupported: function() true, |
michael@0 | 32 | build: function() {} |
michael@0 | 33 | }); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function toolRegistered(event, toolId) |
michael@0 | 37 | { |
michael@0 | 38 | is(toolId, "test-tool", "tool-registered event handler sent tool id"); |
michael@0 | 39 | |
michael@0 | 40 | ok(gDevTools.getToolDefinitionMap().has(toolId), "tool added to map"); |
michael@0 | 41 | |
michael@0 | 42 | // test that it appeared in the UI |
michael@0 | 43 | let doc = toolbox.frame.contentDocument; |
michael@0 | 44 | let tab = doc.getElementById("toolbox-tab-" + toolId); |
michael@0 | 45 | ok(tab, "new tool's tab exists in toolbox UI"); |
michael@0 | 46 | |
michael@0 | 47 | let panel = doc.getElementById("toolbox-panel-" + toolId); |
michael@0 | 48 | ok(panel, "new tool's panel exists in toolbox UI"); |
michael@0 | 49 | |
michael@0 | 50 | for (let win of getAllBrowserWindows()) { |
michael@0 | 51 | let command = win.document.getElementById("Tools:" + toolId); |
michael@0 | 52 | ok(command, "command for new tool added to every browser window"); |
michael@0 | 53 | let menuitem = win.document.getElementById("menuitem_" + toolId); |
michael@0 | 54 | ok(menuitem, "menu item of new tool added to every browser window"); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // then unregister it |
michael@0 | 58 | testUnregister(); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function getAllBrowserWindows() { |
michael@0 | 62 | let wins = []; |
michael@0 | 63 | let enumerator = Services.wm.getEnumerator("navigator:browser"); |
michael@0 | 64 | while (enumerator.hasMoreElements()) { |
michael@0 | 65 | wins.push(enumerator.getNext()); |
michael@0 | 66 | } |
michael@0 | 67 | return wins; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function testUnregister() |
michael@0 | 71 | { |
michael@0 | 72 | gDevTools.once("tool-unregistered", toolUnregistered); |
michael@0 | 73 | |
michael@0 | 74 | gDevTools.unregisterTool("test-tool"); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function toolUnregistered(event, toolDefinition) |
michael@0 | 78 | { |
michael@0 | 79 | let toolId = toolDefinition.id; |
michael@0 | 80 | is(toolId, "test-tool", "tool-unregistered event handler sent tool id"); |
michael@0 | 81 | |
michael@0 | 82 | ok(!gDevTools.getToolDefinitionMap().has(toolId), "tool removed from map"); |
michael@0 | 83 | |
michael@0 | 84 | // test that it disappeared from the UI |
michael@0 | 85 | let doc = toolbox.frame.contentDocument; |
michael@0 | 86 | let tab = doc.getElementById("toolbox-tab-" + toolId); |
michael@0 | 87 | ok(!tab, "tool's tab was removed from the toolbox UI"); |
michael@0 | 88 | |
michael@0 | 89 | let panel = doc.getElementById("toolbox-panel-" + toolId); |
michael@0 | 90 | ok(!panel, "tool's panel was removed from toolbox UI"); |
michael@0 | 91 | |
michael@0 | 92 | for (let win of getAllBrowserWindows()) { |
michael@0 | 93 | let command = win.document.getElementById("Tools:" + toolId); |
michael@0 | 94 | ok(!command, "command removed from every browser window"); |
michael@0 | 95 | let menuitem = win.document.getElementById("menuitem_" + toolId); |
michael@0 | 96 | ok(!menuitem, "menu item removed from every browser window"); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | cleanup(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function cleanup() |
michael@0 | 103 | { |
michael@0 | 104 | toolbox.destroy(); |
michael@0 | 105 | toolbox = null; |
michael@0 | 106 | gBrowser.removeCurrentTab(); |
michael@0 | 107 | finish(); |
michael@0 | 108 | } |