forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1072208 - Implement new events for ToolSidebar. r=bgrins
- Loading branch information
1 parent
337d4c2
commit 76cc624
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
browser/devtools/framework/test/browser_toolbox_sidebar_events.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* Any copyright is dedicated to the Public Domain. | ||
* http://creativecommons.org/publicdomain/zero/1.0/ */ | ||
|
||
function test() { | ||
const Cu = Components.utils; | ||
const { ToolSidebar } = devtools.require("devtools/framework/sidebar"); | ||
|
||
const toolURL = "data:text/xml;charset=utf8,<?xml version='1.0'?>" + | ||
"<?xml-stylesheet href='chrome://browser/skin/devtools/common.css' type='text/css'?>" + | ||
"<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>" + | ||
"<hbox flex='1'><description flex='1'>foo</description><splitter class='devtools-side-splitter'/>" + | ||
"<tabbox flex='1' id='sidebar' class='devtools-sidebar-tabs'><tabs/><tabpanels flex='1'/></tabbox>" + | ||
"</hbox>" + | ||
"</window>"; | ||
|
||
const tab1URL = "data:text/html;charset=utf8,<title>1</title><p>1</p>"; | ||
|
||
let collectedEvents = []; | ||
|
||
let toolDefinition = { | ||
id: "testTool1072208", | ||
visibilityswitch: "devtools.testTool1072208.enabled", | ||
url: toolURL, | ||
label: "Test tool", | ||
isTargetSupported: function() true, | ||
build: function(iframeWindow, toolbox) { | ||
let deferred = promise.defer(); | ||
executeSoon(() => { | ||
deferred.resolve({ | ||
target: toolbox.target, | ||
toolbox: toolbox, | ||
isReady: true, | ||
destroy: function(){}, | ||
panelDoc: iframeWindow.document, | ||
}); | ||
}); | ||
return deferred.promise; | ||
}, | ||
}; | ||
|
||
gDevTools.registerTool(toolDefinition); | ||
|
||
addTab("about:blank").then(function(aTab) { | ||
let target = TargetFactory.forTab(aTab); | ||
gDevTools.showToolbox(target, toolDefinition.id).then(function(toolbox) { | ||
let panel = toolbox.getPanel(toolDefinition.id); | ||
ok(true, "Tool open"); | ||
|
||
panel.once("sidebar-created", function(event, id) { | ||
collectedEvents.push(event); | ||
}); | ||
|
||
panel.once("sidebar-destroyed", function(event, id) { | ||
collectedEvents.push(event); | ||
}); | ||
|
||
let tabbox = panel.panelDoc.getElementById("sidebar"); | ||
panel.sidebar = new ToolSidebar(tabbox, panel, "testbug1072208", true); | ||
|
||
panel.sidebar.once("show", function(event, id) { | ||
collectedEvents.push(event); | ||
}); | ||
|
||
panel.sidebar.once("hide", function(event, id) { | ||
collectedEvents.push(event); | ||
}); | ||
|
||
panel.sidebar.once("tab1-selected", () => finishUp(panel)); | ||
panel.sidebar.addTab("tab1", tab1URL, true); | ||
panel.sidebar.show(); | ||
}).then(null, console.error); | ||
}); | ||
|
||
function finishUp(panel) { | ||
panel.sidebar.hide(); | ||
panel.sidebar.destroy(); | ||
|
||
let events = collectedEvents.join(":"); | ||
is(events, "sidebar-created:show:hide:sidebar-destroyed", | ||
"Found the right amount of collected events."); | ||
|
||
gDevTools.unregisterTool(toolDefinition.id); | ||
gBrowser.removeCurrentTab(); | ||
|
||
executeSoon(function() { | ||
finish(); | ||
}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters