Bug 1246514 - Fix eslint errors in files touched in this bug. r=bgrins

MozReview-Commit-ID: LSs3NUsMXLN

--HG--
extra : rebase_source : 24572d2d23b63e36f4664a4c20dfce847da4c37c
This commit is contained in:
Nicolas Chevobbe 2016-03-11 22:23:53 +01:00
Родитель abb431e0ca
Коммит b94e8a4b94
4 изменённых файлов: 95 добавлений и 68 удалений

Просмотреть файл

@ -3,13 +3,17 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* import-globals-from shared-head.js */
"use strict";
// Tests that changing preferences in the options panel updates the prefs
// and toggles appropriate things in the toolbox.
var doc = null, toolbox = null, panelWin = null, modifiedPrefs = [];
add_task(function*() {
const URL = "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";
registerNewTool();
let tab = yield addTab(URL);
let target = TargetFactory.forTab(tab);
@ -41,7 +45,7 @@ function registerNewTool() {
}
function* testSelectTool() {
info ("Checking to make sure that the options panel can be selected.");
info("Checking to make sure that the options panel can be selected.");
let onceSelected = toolbox.once("options-selected");
toolbox.selectTool("options");
@ -50,7 +54,7 @@ function* testSelectTool() {
}
function* testOptionsShortcut() {
info ("Selecting another tool, then reselecting options panel with keyboard.");
info("Selecting another tool, then reselecting options panel with keyboard.");
yield toolbox.selectTool("webconsole");
is(toolbox.currentToolId, "webconsole", "webconsole is selected");
@ -114,7 +118,7 @@ function* testSelect(select) {
gDevTools.once("pref-changed", (event, data) => {
if (data.pref == pref) {
ok(true, "Correct pref was changed");
is (GetPref(pref), option.value, "Preference been switched for " + pref);
is(GetPref(pref), option.value, "Preference been switched for " + pref);
} else {
ok(false, "Pref " + pref + " was not changed correctly");
}
@ -168,7 +172,7 @@ function* testToggleTools() {
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);
}
@ -199,9 +203,9 @@ function* testToggleTools() {
// Toggle first, middle, and last tools to ensure that toolbox tabs are
// inserted in order
let firstTool = toolNodes[0],
middleTool = toolNodes[(toolNodes.length / 2) | 0],
lastTool = toolNodes[toolNodes.length - 1];
let firstTool = toolNodes[0];
let middleTool = toolNodes[(toolNodes.length / 2) | 0];
let lastTool = toolNodes[toolNodes.length - 1];
yield toggleTool(firstTool);
yield toggleTool(firstTool);
@ -215,11 +219,12 @@ function* toggleTool(node) {
let deferred = promise.defer();
let toolId = node.getAttribute("id");
let onRegistrationChange;
if (node.checked) {
gDevTools.once("tool-unregistered", checkUnregistered.bind(null, toolId, deferred));
gDevTools.once("tool-unregistered",
checkUnregistered.bind(null, toolId, deferred));
} else {
gDevTools.once("tool-registered", checkRegistered.bind(null, toolId, deferred));
gDevTools.once("tool-registered",
checkRegistered.bind(null, toolId, deferred));
}
node.scrollIntoView();
EventUtils.synthesizeMouseAtCenter(node, {}, panelWin);
@ -231,7 +236,8 @@ function checkUnregistered(toolId, deferred, event, data) {
if (data.id == toolId) {
ok(true, "Correct tool removed");
// checking tab on the toolbox
ok(!doc.getElementById("toolbox-tab-" + toolId), "Tab removed for " + toolId);
ok(!doc.getElementById("toolbox-tab-" + toolId),
"Tab removed for " + toolId);
} else {
ok(false, "Something went wrong, " + toolId + " was not unregistered");
}

Просмотреть файл

@ -3,6 +3,9 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* import-globals-from shared-head.js */
"use strict";
var doc = null, toolbox = null, panelWin = null, modifiedPrefs = [];
function test() {
@ -18,20 +21,21 @@ function test() {
.then(cleanup, errorHandler);
}, true);
content.location = "data:text/html;charset=utf8,test for dynamically registering and unregistering tools";
content.location = "data:text/html;charset=utf8,test for dynamically " +
"registering and unregistering tools";
}
function testPrefsAreRespectedWhenReopeningToolbox() {
let deferred = promise.defer();
let target = TargetFactory.forTab(gBrowser.selectedTab);
info ("Closing toolbox to test after reopening");
info("Closing toolbox to test after reopening");
gDevTools.closeToolbox(target).then(() => {
let target = TargetFactory.forTab(gBrowser.selectedTab);
gDevTools.showToolbox(target)
let tabTarget = TargetFactory.forTab(gBrowser.selectedTab);
gDevTools.showToolbox(tabTarget)
.then(testSelectTool)
.then(() => {
info ("Toolbox has been reopened. Checking UI state.");
info("Toolbox has been reopened. Checking UI state.");
testPreferenceAndUIStateIsConsistent();
deferred.resolve();
});
@ -40,11 +44,11 @@ function testPrefsAreRespectedWhenReopeningToolbox() {
return deferred.promise;
}
function testSelectTool(aToolbox) {
function testSelectTool(devtoolsToolbox) {
let deferred = promise.defer();
info ("Selecting the options panel");
info("Selecting the options panel");
toolbox = aToolbox;
toolbox = devtoolsToolbox;
doc = toolbox.doc;
toolbox.once("options-selected", (event, tool) => {
ok(true, "Options panel selected via selectTool method");
@ -57,51 +61,61 @@ function testSelectTool(aToolbox) {
}
function testPreferenceAndUIStateIsConsistent() {
let checkNodes = [...panelWin.document.querySelectorAll("#enabled-toolbox-buttons-box input[type=checkbox]")];
let checkNodes = [...panelWin.document.querySelectorAll(
"#enabled-toolbox-buttons-box input[type=checkbox]")];
let toolboxButtonNodes = [...doc.querySelectorAll(".command-button")];
toolboxButtonNodes.push(doc.getElementById("command-button-frames"));
let toggleableTools = toolbox.toolboxButtons;
// The noautohide button is only displayed in the browser toolbox
toggleableTools = toggleableTools.filter(tool => tool.id != "command-button-noautohide");
toggleableTools = toggleableTools.filter(
tool => tool.id != "command-button-noautohide");
for (let tool of toggleableTools) {
let isVisible = getBoolPref(tool.visibilityswitch);
let button = toolboxButtonNodes.filter(button => button.id === tool.id)[0];
is (!button.hasAttribute("hidden"), isVisible, "Button visibility matches pref for " + tool.id);
let button = toolboxButtonNodes.filter(
toolboxButton => toolboxButton.id === tool.id)[0];
is(!button.hasAttribute("hidden"), isVisible,
"Button visibility matches pref for " + tool.id);
let check = checkNodes.filter(node=>node.id === tool.id)[0];
is (check.checked, isVisible, "Checkbox should be selected based on current pref for " + tool.id);
let check = checkNodes.filter(node => node.id === tool.id)[0];
is(check.checked, isVisible,
"Checkbox should be selected based on current pref for " + tool.id);
}
}
function testToggleToolboxButtons() {
let checkNodes = [...panelWin.document.querySelectorAll("#enabled-toolbox-buttons-box input[type=checkbox]")];
let checkNodes = [...panelWin.document.querySelectorAll(
"#enabled-toolbox-buttons-box input[type=checkbox]")];
let toolboxButtonNodes = [...doc.querySelectorAll(".command-button")];
let toggleableTools = toolbox.toolboxButtons;
// The noautohide button is only displayed in the browser toolbox
toggleableTools = toggleableTools.filter(tool => tool.id != "command-button-noautohide");
toolboxButtonNodes = toolboxButtonNodes.filter(btn => btn.id != "command-button-noautohide");
toggleableTools = toggleableTools.filter(
tool => tool.id != "command-button-noautohide");
toolboxButtonNodes = toolboxButtonNodes.filter(
btn => btn.id != "command-button-noautohide");
is (checkNodes.length, toggleableTools.length, "All of the buttons are toggleable." );
is (checkNodes.length, toolboxButtonNodes.length, "All of the DOM buttons are toggleable." );
is(checkNodes.length, toggleableTools.length,
"All of the buttons are toggleable.");
is(checkNodes.length, toolboxButtonNodes.length,
"All of the DOM buttons are toggleable.");
for (let tool of toggleableTools) {
let id = tool.id;
let matchedCheckboxes = checkNodes.filter(node=>node.id === id);
let matchedButtons = toolboxButtonNodes.filter(button=>button.id === id);
is (matchedCheckboxes.length, 1,
let matchedCheckboxes = checkNodes.filter(node => node.id === id);
let matchedButtons = toolboxButtonNodes.filter(button => button.id === id);
is(matchedCheckboxes.length, 1,
"There should be a single toggle checkbox for: " + id);
is (matchedButtons.length, 1,
is(matchedButtons.length, 1,
"There should be a DOM button for: " + id);
is (matchedButtons[0], tool.button,
is(matchedButtons[0], tool.button,
"DOM buttons should match for: " + id);
is (matchedCheckboxes[0].nextSibling.textContent, tool.label,
is(matchedCheckboxes[0].nextSibling.textContent, tool.label,
"The label for checkbox matches the tool definition.");
is (matchedButtons[0].getAttribute("tooltiptext"), tool.label,
is(matchedButtons[0].getAttribute("tooltiptext"), tool.label,
"The tooltip for button matches the tool definition.");
}
@ -113,7 +127,8 @@ function testToggleToolboxButtons() {
// Try checking each checkbox, making sure that it changes the preference
for (let node of checkNodes) {
let tool = toggleableTools.filter(tool=>tool.id === node.id)[0];
let tool = toggleableTools.filter(
toggleableTool => toggleableTool.id === node.id)[0];
let isVisible = getBoolPref(tool.visibilityswitch);
testPreferenceAndUIStateIsConsistent();
@ -122,8 +137,9 @@ function testToggleToolboxButtons() {
let isVisibleAfterClick = getBoolPref(tool.visibilityswitch);
is (isVisible, !isVisibleAfterClick,
"Clicking on the node should have toggled visibility preference for " + tool.visibilityswitch);
is(isVisible, !isVisibleAfterClick,
"Clicking on the node should have toggled visibility preference for " +
tool.visibilityswitch);
}
return promise.resolve();

Просмотреть файл

@ -3,6 +3,9 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* import-globals-from shared-head.js */
"use strict";
// Test for dynamically registering and unregistering themes
const CHROME_URL = "chrome://mochitests/content/browser/devtools/client/framework/test/";
@ -14,8 +17,8 @@ add_task(function* themeRegistration() {
toolbox = yield gDevTools.showToolbox(target, "options");
let themeId = yield new Promise(resolve => {
gDevTools.once("theme-registered", (e, themeId) => {
resolve(themeId);
gDevTools.once("theme-registered", (e, registeredThemeId) => {
resolve(registeredThemeId);
});
gDevTools.registerTheme({
@ -79,7 +82,8 @@ add_task(function* themeUnregistration() {
gDevTools.unregisterTheme("test-theme");
yield onUnRegisteredTheme;
ok(!gDevTools.getThemeDefinitionMap().has("test-theme"), "theme removed from map");
ok(!gDevTools.getThemeDefinitionMap().has("test-theme"),
"theme removed from map");
let panelWin = toolbox.getCurrentPanel().panelWin;
let doc = panelWin.frameElement.contentDocument;

Просмотреть файл

@ -6,7 +6,7 @@
"use strict";
const {Cu, Cc, Ci} = require("chrome");
const {Cu} = require("chrome");
const Services = require("Services");
const promise = require("promise");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
@ -17,15 +17,14 @@ exports.OptionsPanel = OptionsPanel;
XPCOMUtils.defineLazyGetter(this, "l10n", function() {
let bundle = Services.strings.createBundle("chrome://devtools/locale/toolbox.properties");
let l10n = function(aName, ...aArgs) {
let l10n = function(name, ...aArgs) {
try {
if (aArgs.length == 0) {
return bundle.GetStringFromName(aName);
} else {
return bundle.formatStringFromName(aName, aArgs, aArgs.length);
return bundle.GetStringFromName(name);
}
return bundle.formatStringFromName(name, aArgs, aArgs.length);
} catch (ex) {
Services.console.logStringMessage("Error reading '" + aName + "'");
Services.console.logStringMessage("Error reading '" + name + "'");
}
};
return l10n;
@ -67,7 +66,6 @@ function InfallibleGetBoolPref(key) {
}
}
/**
* Represents the Options Panel in the Toolbox.
*/
@ -83,7 +81,8 @@ function OptionsPanel(iframeWindow, toolbox) {
this._themeUnregistered = this._themeUnregistered.bind(this);
this._disableJSClicked = this._disableJSClicked.bind(this);
this.disableJSNode = this.panelDoc.getElementById("devtools-disable-javascript");
this.disableJSNode = this.panelDoc.getElementById(
"devtools-disable-javascript");
this._addListeners();
@ -130,8 +129,7 @@ OptionsPanel.prototype = {
let cbx = this.panelDoc.getElementById("devtools-disable-cache");
cbx.checked = cacheDisabled;
}
else if (data.pref === "devtools.theme") {
} else if (data.pref === "devtools.theme") {
this.updateCurrentTheme();
}
},
@ -158,8 +156,10 @@ OptionsPanel.prototype = {
this.toolbox.setToolboxButtonsVisibility.bind(this.toolbox);
let onCheckboxClick = (checkbox) => {
let toolDefinition = toggleableButtons.filter(tool => tool.id === checkbox.id)[0];
Services.prefs.setBoolPref(toolDefinition.visibilityswitch, checkbox.checked);
let toolDefinition = toggleableButtons.filter(
toggleableButton => toggleableButton.id === checkbox.id)[0];
Services.prefs.setBoolPref(
toolDefinition.visibilityswitch, checkbox.checked);
setToolboxButtonsVisibility();
};
@ -192,8 +192,10 @@ OptionsPanel.prototype = {
setupToolsList: function() {
let defaultToolsBox = this.panelDoc.getElementById("default-tools-box");
let additionalToolsBox = this.panelDoc.getElementById("additional-tools-box");
let toolsNotSupportedLabel = this.panelDoc.getElementById("tools-not-supported-label");
let additionalToolsBox = this.panelDoc.getElementById(
"additional-tools-box");
let toolsNotSupportedLabel = this.panelDoc.getElementById(
"tools-not-supported-label");
let atleastOneToolNotSupported = false;
let onCheckboxClick = function(id) {
@ -202,8 +204,7 @@ OptionsPanel.prototype = {
Services.prefs.setBoolPref(toolDefinition.visibilityswitch, this.checked);
if (this.checked) {
gDevTools.emit("tool-registered", id);
}
else {
} else {
gDevTools.emit("tool-unregistered", toolDefinition);
}
};
@ -218,8 +219,7 @@ OptionsPanel.prototype = {
let checkboxSpanLabel = this.panelDoc.createElement("span");
if (tool.isTargetSupported(this.target)) {
checkboxSpanLabel.textContent = tool.label;
}
else {
} else {
atleastOneToolNotSupported = true;
checkboxSpanLabel.textContent = l10n(
"options.toolNotSupportedMarker", tool.label);
@ -347,12 +347,13 @@ OptionsPanel.prototype = {
}
if (this.target.activeTab) {
return this.target.client.attachTab(this.target.activeTab._actor).then(([response, client]) => {
this._origJavascriptEnabled = !response.javascriptEnabled;
this.disableJSNode.checked = this._origJavascriptEnabled;
this.disableJSNode.addEventListener("click",
this._disableJSClicked, false);
});
return this.target.client.attachTab(this.target.activeTab._actor)
.then(([response, client]) => {
this._origJavascriptEnabled = !response.javascriptEnabled;
this.disableJSNode.checked = this._origJavascriptEnabled;
this.disableJSNode.addEventListener("click",
this._disableJSClicked, false);
});
}
this.disableJSNode.hidden = true;
},