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 | function test() { |
michael@0 | 5 | const Cu = Components.utils; |
michael@0 | 6 | let {ToolSidebar} = devtools.require("devtools/framework/sidebar"); |
michael@0 | 7 | |
michael@0 | 8 | const toolURL = "data:text/xml;charset=utf8,<?xml version='1.0'?>" + |
michael@0 | 9 | "<?xml-stylesheet href='chrome://browser/skin/devtools/common.css' type='text/css'?>" + |
michael@0 | 10 | "<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>" + |
michael@0 | 11 | "<hbox flex='1'><description flex='1'>foo</description><splitter class='devtools-side-splitter'/>" + |
michael@0 | 12 | "<tabbox flex='1' id='sidebar' class='devtools-sidebar-tabs'><tabs/><tabpanels flex='1'/></tabbox>" + |
michael@0 | 13 | "</hbox>" + |
michael@0 | 14 | "</window>"; |
michael@0 | 15 | |
michael@0 | 16 | const tab1URL = "data:text/html;charset=utf8,<title>1</title><p>1</p>"; |
michael@0 | 17 | const tab2URL = "data:text/html;charset=utf8,<title>2</title><p>2</p>"; |
michael@0 | 18 | const tab3URL = "data:text/html;charset=utf8,<title>3</title><p>3</p>"; |
michael@0 | 19 | |
michael@0 | 20 | let panelDoc; |
michael@0 | 21 | let tab1Selected = false; |
michael@0 | 22 | let registeredTabs = {}; |
michael@0 | 23 | let readyTabs = {}; |
michael@0 | 24 | |
michael@0 | 25 | let toolDefinition = { |
michael@0 | 26 | id: "fakeTool4242", |
michael@0 | 27 | visibilityswitch: "devtools.fakeTool4242.enabled", |
michael@0 | 28 | url: toolURL, |
michael@0 | 29 | label: "FAKE TOOL!!!", |
michael@0 | 30 | isTargetSupported: function() true, |
michael@0 | 31 | build: function(iframeWindow, toolbox) { |
michael@0 | 32 | let deferred = promise.defer(); |
michael@0 | 33 | executeSoon(function() { |
michael@0 | 34 | deferred.resolve({ |
michael@0 | 35 | target: toolbox.target, |
michael@0 | 36 | toolbox: toolbox, |
michael@0 | 37 | isReady: true, |
michael@0 | 38 | destroy: function(){}, |
michael@0 | 39 | panelDoc: iframeWindow.document, |
michael@0 | 40 | }); |
michael@0 | 41 | }.bind(this)); |
michael@0 | 42 | return deferred.promise; |
michael@0 | 43 | }, |
michael@0 | 44 | }; |
michael@0 | 45 | |
michael@0 | 46 | gDevTools.registerTool(toolDefinition); |
michael@0 | 47 | |
michael@0 | 48 | addTab("about:blank", function(aBrowser, aTab) { |
michael@0 | 49 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 50 | gDevTools.showToolbox(target, toolDefinition.id).then(function(toolbox) { |
michael@0 | 51 | let panel = toolbox.getPanel(toolDefinition.id); |
michael@0 | 52 | ok(true, "Tool open"); |
michael@0 | 53 | |
michael@0 | 54 | let tabbox = panel.panelDoc.getElementById("sidebar"); |
michael@0 | 55 | panel.sidebar = new ToolSidebar(tabbox, panel, "testbug865688", true); |
michael@0 | 56 | |
michael@0 | 57 | panel.sidebar.on("new-tab-registered", function(event, id) { |
michael@0 | 58 | registeredTabs[id] = true; |
michael@0 | 59 | }); |
michael@0 | 60 | |
michael@0 | 61 | panel.sidebar.once("tab1-ready", function(event) { |
michael@0 | 62 | info(event); |
michael@0 | 63 | readyTabs.tab1 = true; |
michael@0 | 64 | allTabsReady(panel); |
michael@0 | 65 | }); |
michael@0 | 66 | |
michael@0 | 67 | panel.sidebar.once("tab2-ready", function(event) { |
michael@0 | 68 | info(event); |
michael@0 | 69 | readyTabs.tab2 = true; |
michael@0 | 70 | allTabsReady(panel); |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | panel.sidebar.once("tab3-ready", function(event) { |
michael@0 | 74 | info(event); |
michael@0 | 75 | readyTabs.tab3 = true; |
michael@0 | 76 | allTabsReady(panel); |
michael@0 | 77 | }); |
michael@0 | 78 | |
michael@0 | 79 | panel.sidebar.once("tab1-selected", function(event) { |
michael@0 | 80 | info(event); |
michael@0 | 81 | tab1Selected = true; |
michael@0 | 82 | allTabsReady(panel); |
michael@0 | 83 | }); |
michael@0 | 84 | |
michael@0 | 85 | panel.sidebar.addTab("tab1", tab1URL, true); |
michael@0 | 86 | panel.sidebar.addTab("tab2", tab2URL); |
michael@0 | 87 | panel.sidebar.addTab("tab3", tab3URL); |
michael@0 | 88 | |
michael@0 | 89 | panel.sidebar.show(); |
michael@0 | 90 | }).then(null, console.error); |
michael@0 | 91 | }); |
michael@0 | 92 | |
michael@0 | 93 | function allTabsReady(panel) { |
michael@0 | 94 | if (!tab1Selected || !readyTabs.tab1 || !readyTabs.tab2 || !readyTabs.tab3) { |
michael@0 | 95 | return; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | ok(registeredTabs.tab1, "tab1 registered"); |
michael@0 | 99 | ok(registeredTabs.tab2, "tab2 registered"); |
michael@0 | 100 | ok(registeredTabs.tab3, "tab3 registered"); |
michael@0 | 101 | ok(readyTabs.tab1, "tab1 ready"); |
michael@0 | 102 | ok(readyTabs.tab2, "tab2 ready"); |
michael@0 | 103 | ok(readyTabs.tab3, "tab3 ready"); |
michael@0 | 104 | |
michael@0 | 105 | let tabs = panel.sidebar._tabbox.querySelectorAll("tab"); |
michael@0 | 106 | let panels = panel.sidebar._tabbox.querySelectorAll("tabpanel"); |
michael@0 | 107 | let label = 1; |
michael@0 | 108 | for (let tab of tabs) { |
michael@0 | 109 | is(tab.getAttribute("label"), label++, "Tab has the right title"); |
michael@0 | 110 | } |
michael@0 | 111 | is(label, 4, "Found the right amount of tabs."); |
michael@0 | 112 | is(panel.sidebar._tabbox.selectedPanel, panels[0], "First tab is selected"); |
michael@0 | 113 | ok(panel.sidebar.getCurrentTabID(), "tab1", "getCurrentTabID() is correct"); |
michael@0 | 114 | |
michael@0 | 115 | panel.sidebar.once("tab1-unselected", function() { |
michael@0 | 116 | ok(true, "received 'unselected' event"); |
michael@0 | 117 | panel.sidebar.once("tab2-selected", function() { |
michael@0 | 118 | ok(true, "received 'selected' event"); |
michael@0 | 119 | panel.sidebar.hide(); |
michael@0 | 120 | is(panel.sidebar._tabbox.getAttribute("hidden"), "true", "Sidebar hidden"); |
michael@0 | 121 | is(panel.sidebar.getWindowForTab("tab1").location.href, tab1URL, "Window is accessible"); |
michael@0 | 122 | testWidth(panel); |
michael@0 | 123 | }); |
michael@0 | 124 | }); |
michael@0 | 125 | |
michael@0 | 126 | panel.sidebar.select("tab2"); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | function testWidth(panel) { |
michael@0 | 130 | let tabbox = panel.panelDoc.getElementById("sidebar"); |
michael@0 | 131 | tabbox.width = 420; |
michael@0 | 132 | panel.sidebar.destroy().then(function() { |
michael@0 | 133 | tabbox.width = 0; |
michael@0 | 134 | panel.sidebar = new ToolSidebar(tabbox, panel, "testbug865688", true); |
michael@0 | 135 | panel.sidebar.show(); |
michael@0 | 136 | is(panel.panelDoc.getElementById("sidebar").width, 420, "Width restored") |
michael@0 | 137 | finishUp(panel); |
michael@0 | 138 | }); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | function finishUp(panel) { |
michael@0 | 142 | panel.sidebar.destroy(); |
michael@0 | 143 | gDevTools.unregisterTool(toolDefinition.id); |
michael@0 | 144 | |
michael@0 | 145 | executeSoon(function() { |
michael@0 | 146 | gBrowser.removeCurrentTab(); |
michael@0 | 147 | finish(); |
michael@0 | 148 | }); |
michael@0 | 149 | } |
michael@0 | 150 | } |