2012-11-30 00:07:59 -08:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
let toolbox;
|
|
|
|
|
|
|
|
function test()
|
|
|
|
{
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab();
|
2012-12-13 05:03:55 -08:00
|
|
|
let target = TargetFactory.forTab(gBrowser.selectedTab);
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
|
|
|
|
gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
|
2012-12-13 05:03:55 -08:00
|
|
|
gDevTools.showToolbox(target).then(testRegister);
|
2012-11-30 00:07:59 -08:00
|
|
|
}, true);
|
|
|
|
|
|
|
|
content.location = "data:text/html,test for dynamically registering and unregistering tools";
|
|
|
|
}
|
|
|
|
|
2012-12-13 05:03:55 -08:00
|
|
|
function testRegister(aToolbox)
|
2012-11-30 00:07:59 -08:00
|
|
|
{
|
2012-12-13 05:03:55 -08:00
|
|
|
toolbox = aToolbox
|
2012-11-30 00:07:59 -08:00
|
|
|
gDevTools.once("tool-registered", toolRegistered);
|
|
|
|
|
|
|
|
gDevTools.registerTool({
|
|
|
|
id: "test-tool",
|
|
|
|
label: "Test Tool",
|
|
|
|
isTargetSupported: function() true,
|
|
|
|
build: function() {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function toolRegistered(event, toolId)
|
|
|
|
{
|
|
|
|
is(toolId, "test-tool", "tool-registered event handler sent tool id");
|
|
|
|
|
2013-01-11 04:16:31 -08:00
|
|
|
ok(gDevTools.getToolDefinitionMap().has(toolId), "tool added to map");
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
// test that it appeared in the UI
|
|
|
|
let doc = toolbox.frame.contentDocument;
|
|
|
|
let tab = doc.getElementById("toolbox-tab-" + toolId);
|
|
|
|
ok(tab, "new tool's tab exists in toolbox UI");
|
|
|
|
|
|
|
|
let panel = doc.getElementById("toolbox-panel-" + toolId);
|
|
|
|
ok(panel, "new tool's panel exists in toolbox UI");
|
|
|
|
|
|
|
|
for (let win of getAllBrowserWindows()) {
|
|
|
|
let command = win.document.getElementById("Tools:" + toolId);
|
|
|
|
ok(command, "command for new tool added to every browser window");
|
2013-01-04 16:21:27 -08:00
|
|
|
let menuitem = win.document.getElementById("menuitem_" + toolId);
|
|
|
|
ok(menuitem, "menu item of new tool added to every browser window");
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// then unregister it
|
|
|
|
testUnregister();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAllBrowserWindows() {
|
|
|
|
let wins = [];
|
|
|
|
let enumerator = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
wins.push(enumerator.getNext());
|
|
|
|
}
|
|
|
|
return wins;
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUnregister()
|
|
|
|
{
|
|
|
|
gDevTools.once("tool-unregistered", toolUnregistered);
|
|
|
|
|
|
|
|
gDevTools.unregisterTool("test-tool");
|
|
|
|
}
|
|
|
|
|
2013-04-19 06:44:38 -07:00
|
|
|
function toolUnregistered(event, toolDefinition)
|
2012-11-30 00:07:59 -08:00
|
|
|
{
|
2013-04-19 06:44:38 -07:00
|
|
|
let toolId = toolDefinition.id;
|
2012-11-30 00:07:59 -08:00
|
|
|
is(toolId, "test-tool", "tool-unregistered event handler sent tool id");
|
|
|
|
|
2013-01-11 04:16:31 -08:00
|
|
|
ok(!gDevTools.getToolDefinitionMap().has(toolId), "tool removed from map");
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
// test that it disappeared from the UI
|
|
|
|
let doc = toolbox.frame.contentDocument;
|
|
|
|
let tab = doc.getElementById("toolbox-tab-" + toolId);
|
|
|
|
ok(!tab, "tool's tab was removed from the toolbox UI");
|
|
|
|
|
|
|
|
let panel = doc.getElementById("toolbox-panel-" + toolId);
|
|
|
|
ok(!panel, "tool's panel was removed from toolbox UI");
|
|
|
|
|
|
|
|
for (let win of getAllBrowserWindows()) {
|
|
|
|
let command = win.document.getElementById("Tools:" + toolId);
|
|
|
|
ok(!command, "command removed from every browser window");
|
2013-01-04 16:21:27 -08:00
|
|
|
let menuitem = win.document.getElementById("menuitem_" + toolId);
|
|
|
|
ok(!menuitem, "menu item removed from every browser window");
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup()
|
|
|
|
{
|
|
|
|
toolbox.destroy();
|
|
|
|
toolbox = null;
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
finish();
|
|
|
|
}
|