Miscellaneous lazification and cleanups in devtools framework code (bug 986841). r=dcamp

This commit is contained in:
Panos Astithas 2014-04-03 11:19:42 +03:00
parent 8ac9209bc4
commit 1ed8b5fa5c
3 changed files with 24 additions and 28 deletions

View File

@ -6,20 +6,15 @@ let doc = null, toolbox = null, panelWin = null, modifiedPrefs = [];
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
let target = TargetFactory.forTab(gBrowser.selectedTab);
gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
gDevTools.showToolbox(target)
.then(testSelectTool)
.then(testOptionsShortcut)
.then(testOptions)
.then(testToggleTools)
.then(cleanup, errorHandler);
}, true);
content.location = "data:text/html;charset=utf8,test for dynamically registering and unregistering tools";
const URL = "data:text/html;charset=utf8,test for dynamically registering and unregistering tools";
Task.spawn(function* () {
let { target } = yield addTab(URL);
let toolbox = yield gDevTools.showToolbox(target);
yield testSelectTool(toolbox);
yield testOptionsShortcut();
yield testOptions();
yield testToggleTools();
}).then(cleanup, errorHandler);
}
function testSelectTool(aToolbox) {
@ -39,17 +34,18 @@ function testSelectTool(aToolbox) {
function testOptionsShortcut() {
let deferred = promise.defer();
toolbox.once("options-selected", (event, tool) => {
ok(true, "Toolbox selected via shortcut key");
deferred.resolve(tool);
});
toolbox.selectTool("webconsole")
.then(() => synthesizeKeyFromKeyTag("toolbox-options-key", doc));
.then(() => synthesizeKeyFromKeyTag("toolbox-options-key", doc))
.then(() => {
ok(true, "Toolbox selected via shortcut key");
deferred.resolve();
});
return deferred.promise;
}
function testOptions(tool) {
function testOptions() {
let tool = toolbox.getPanel("options");
panelWin = tool.panelWin;
let prefNodes = tool.panelDoc.querySelectorAll("checkbox[data-pref]");
@ -105,10 +101,10 @@ function testToggleTools() {
let toolNodes = panelWin.document.querySelectorAll("#default-tools-box > checkbox:not([unsupported])");
let enabledTools = Array.prototype.filter.call(toolNodes, node => node.checked);
let toggleableTools = gDevTools.getDefaultTools().filter(tool=>tool.visibilityswitch);
let toggleableTools = gDevTools.getDefaultTools().filter(tool => tool.visibilityswitch);
for (let node of toolNodes) {
let id = node.getAttribute("id");
ok (toggleableTools.some(tool=>tool.id === id),
ok (toggleableTools.some(tool => tool.id === id),
"There should be a toggle checkbox for: " + id);
}

View File

@ -7,7 +7,7 @@ let TargetFactory = gDevTools.TargetFactory;
let tempScope = {};
Components.utils.import("resource://gre/modules/devtools/Console.jsm", tempScope);
let console = tempScope.console;
Components.utils.import("resource://gre/modules/commonjs/sdk/core/promise.js", tempScope);
Components.utils.import("resource://gre/modules/Promise.jsm", tempScope);
let promise = tempScope.Promise;
let {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});

View File

@ -5,11 +5,9 @@
"use strict";
const {Cu, Cc, Ci} = require("chrome");
const EventEmitter = require("devtools/toolkit/event-emitter");
const {Promise: promise} = require("resource://gre/modules/Promise.jsm");
const Services = require("Services");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource:///modules/devtools/gDevTools.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "gDevTools", "resource:///modules/devtools/gDevTools.jsm");
exports.OptionsPanel = OptionsPanel;
@ -38,6 +36,7 @@ function OptionsPanel(iframeWindow, toolbox) {
this.toolbox = toolbox;
this.isReady = false;
const EventEmitter = require("devtools/toolkit/event-emitter");
EventEmitter.decorate(this);
}
@ -158,8 +157,9 @@ OptionsPanel.prototype = {
// Populating the default tools lists
let toggleableTools = gDevTools.getDefaultTools().filter(tool => {
return tool.visibilityswitch
return tool.visibilityswitch;
});
for (let tool of toggleableTools) {
defaultToolsBox.appendChild(createToolCheckbox(tool));
}