Bug 1267015 - ESLint cleanup of devtools/client/styleinspector/shared/test; r=bgrins

MozReview-Commit-ID: GKnRmlqIBxb

--HG--
extra : rebase_source : 69109deafb0af8113a31832b604208817a224dbb
This commit is contained in:
Patrick Brosset 2016-05-13 10:16:45 +02:00
parent b2488b6603
commit e4149a2ab9
18 changed files with 121 additions and 101 deletions

View file

@ -84,7 +84,6 @@ devtools/client/framework/**
# devtools/client/inspector/shared/*.js files are eslint-clean, so they aren't
# included in the ignore list.
devtools/client/inspector/fonts/**
devtools/client/inspector/shared/test/**
devtools/client/inspector/test/**
devtools/client/inspector/*.js
!devtools/client/inspector/breadcrumbs.js

View file

@ -11,28 +11,25 @@ const TEST_DATA_URI = "data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQA
// Invalid URL still needs to be reachable otherwise getImageDataUrl will
// timeout. DevTools chrome:// URLs aren't content accessible, so use some
// random resource:// URL here.
const INVALID_IMAGE_URI =
"resource://devtools/client/definitions.js";
const INVALID_IMAGE_URI = "resource://devtools/client/definitions.js";
const ERROR_MESSAGE = Services.strings
.createBundle(PROPERTIES_URL)
.GetStringFromName("styleinspector.copyImageDataUrlError");
add_task(function*() {
const PAGE_CONTENT = [
"<style type=\"text/css\">",
" .valid-background {",
" background-image: url(" + TEST_DATA_URI + ");",
" }",
" .invalid-background {",
" background-image: url(" + INVALID_IMAGE_URI + ");",
" }",
"</style>",
"<div class=\"valid-background\">Valid background image</div>",
"<div class=\"invalid-background\">Invalid background image</div>"
].join("\n");
add_task(function* () {
const TEST_URI = `<style type="text/css">
.valid-background {
background-image: url(${TEST_DATA_URI});
}
.invalid-background {
background-image: url(${INVALID_IMAGE_URI});
}
</style>
<div class="valid-background">Valid background image</div>
<div class="invalid-background">Invalid background image</div>`;
yield addTab("data:text/html;charset=utf8," + encodeURIComponent(PAGE_CONTENT));
yield addTab("data:text/html;charset=utf8," + encodeURIComponent(TEST_URI));
yield startTest();
});
@ -42,28 +39,39 @@ function* startTest() {
let {inspector, view} = yield openRuleView();
info("Test valid background image URL in rule view");
yield testCopyUrlToClipboard({view, inspector}, "data-uri", ".valid-background", TEST_DATA_URI);
yield testCopyUrlToClipboard({view, inspector}, "url", ".valid-background", TEST_DATA_URI);
yield testCopyUrlToClipboard({view, inspector}, "data-uri",
".valid-background", TEST_DATA_URI);
yield testCopyUrlToClipboard({view, inspector}, "url",
".valid-background", TEST_DATA_URI);
info("Test invalid background image URL in rue view");
yield testCopyUrlToClipboard({view, inspector}, "data-uri", ".invalid-background", ERROR_MESSAGE);
yield testCopyUrlToClipboard({view, inspector}, "url", ".invalid-background", INVALID_IMAGE_URI);
yield testCopyUrlToClipboard({view, inspector}, "data-uri",
".invalid-background", ERROR_MESSAGE);
yield testCopyUrlToClipboard({view, inspector}, "url",
".invalid-background", INVALID_IMAGE_URI);
info("Opening computed view");
view = selectComputedView(inspector);
info("Test valid background image URL in computed view");
yield testCopyUrlToClipboard({view, inspector}, "data-uri", ".valid-background", TEST_DATA_URI);
yield testCopyUrlToClipboard({view, inspector}, "url", ".valid-background", TEST_DATA_URI);
yield testCopyUrlToClipboard({view, inspector}, "data-uri",
".valid-background", TEST_DATA_URI);
yield testCopyUrlToClipboard({view, inspector}, "url",
".valid-background", TEST_DATA_URI);
info("Test invalid background image URL in computed view");
yield testCopyUrlToClipboard({view, inspector}, "data-uri", ".invalid-background", ERROR_MESSAGE);
yield testCopyUrlToClipboard({view, inspector}, "url", ".invalid-background", INVALID_IMAGE_URI);
yield testCopyUrlToClipboard({view, inspector}, "data-uri",
".invalid-background", ERROR_MESSAGE);
yield testCopyUrlToClipboard({view, inspector}, "url",
".invalid-background", INVALID_IMAGE_URI);
}
function* testCopyUrlToClipboard({view, inspector}, type, selector, expected) {
info("Select node in inspector panel");
yield selectNode(selector, inspector);
info("Retrieve background-image link for selected node in current styleinspector view");
info("Retrieve background-image link for selected node in current " +
"styleinspector view");
let property = getBackgroundImageProperty(view, selector);
let imageLink = property.valueSpan.querySelector(".theme-link");
ok(imageLink, "Background-image link element found");
@ -71,26 +79,36 @@ function* testCopyUrlToClipboard({view, inspector}, type, selector, expected) {
info("Simulate right click on the background-image URL");
let popup = once(view._contextmenu._menupopup, "popupshown");
// Cannot rely on synthesizeMouseAtCenter here. The image URL can be displayed on several lines.
// A click simulated at the exact center may click between the lines and miss the target
// Instead, using the top-left corner of first client rect, with an offset of 2 pixels.
// Cannot rely on synthesizeMouseAtCenter here. The image URL can be displayed
// on several lines. A click simulated at the exact center may click between
// the lines and miss the target. Instead, using the top-left corner of first
// client rect, with an offset of 2 pixels.
let rect = imageLink.getClientRects()[0];
let x = rect.left + 2;
let y = rect.top + 2;
EventUtils.synthesizeMouseAtPoint(x, y, {button: 2, type: "contextmenu"}, getViewWindow(view));
EventUtils.synthesizeMouseAtPoint(x, y, {
button: 2,
type: "contextmenu"
}, getViewWindow(view));
yield popup;
info("Context menu is displayed");
ok(!view._contextmenu.menuitemCopyUrl.hidden, "\"Copy URL\" menu entry is displayed");
ok(!view._contextmenu.menuitemCopyImageDataUrl.hidden, "\"Copy Image Data-URL\" menu entry is displayed");
ok(!view._contextmenu.menuitemCopyUrl.hidden,
"\"Copy URL\" menu entry is displayed");
ok(!view._contextmenu.menuitemCopyImageDataUrl.hidden,
"\"Copy Image Data-URL\" menu entry is displayed");
if (type == "data-uri") {
info("Click Copy Data URI and wait for clipboard");
yield waitForClipboard(() => view._contextmenu.menuitemCopyImageDataUrl.click(), expected);
yield waitForClipboard(() => {
return view._contextmenu.menuitemCopyImageDataUrl.click();
}, expected);
} else {
info("Click Copy URL and wait for clipboard");
yield waitForClipboard(() => view._contextmenu.menuitemCopyUrl.click(), expected);
yield waitForClipboard(() => {
return view._contextmenu.menuitemCopyUrl.click();
}, expected);
}
info("Hide context menu");
@ -101,9 +119,8 @@ function getBackgroundImageProperty(view, selector) {
let isRuleView = view instanceof CssRuleView;
if (isRuleView) {
return getRuleViewProperty(view, selector, "background-image");
} else {
return getComputedViewProperty(view, "background-image");
}
return getComputedViewProperty(view, "background-image");
}
/**

View file

@ -20,7 +20,7 @@ var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(Ci.nsIScriptSecurityManager);
const XUL_PRINCIPAL = ssm.createCodebasePrincipal(XUL_URI, {});
add_task(function*() {
add_task(function* () {
requestLongerTimeout(2);
info("Checking stylesheets on HTML document");

View file

@ -145,7 +145,9 @@ const TEST_DATA = [
},
{
name: "background",
value: "linear-gradient(to right, rgba(183,222,237,1) 0%, rgba(33,180,226,1) 30%, rgba(31,170,217,.5) 44%, #F06 75%, red 100%)",
value: "linear-gradient(to right, rgba(183,222,237,1) 0%, " +
"rgba(33,180,226,1) 30%, rgba(31,170,217,.5) 44%, " +
"#F06 75%, red 100%)",
test: fragment => {
is(countAll(fragment), 10);
let allSwatches = fragment.querySelectorAll("." + COLOR_CLASS);
@ -159,7 +161,8 @@ const TEST_DATA = [
},
{
name: "background",
value: "-moz-radial-gradient(center 45deg, circle closest-side, orange 0%, red 100%)",
value: "-moz-radial-gradient(center 45deg, circle closest-side, " +
"orange 0%, red 100%)",
test: fragment => {
is(countAll(fragment), 6);
let colorSwatches = fragment.querySelectorAll("." + COLOR_CLASS);
@ -207,10 +210,12 @@ const TEST_DATA = [
},
{
name: "background-image",
value: "url(../../../look/at/this/folder/structure/../../red.blue.green.svg )",
value: "url(../../../look/at/this/folder/structure/../" +
"../red.blue.green.svg )",
test: fragment => {
is(countAll(fragment), 1);
is(getUrl(fragment), "../../../look/at/this/folder/structure/../../red.blue.green.svg");
is(getUrl(fragment), "../../../look/at/this/folder/structure/../" +
"../red.blue.green.svg");
}
},
{
@ -290,7 +295,7 @@ const TEST_DATA = [
}
];
add_task(function*() {
add_task(function* () {
let parser = new OutputParser(document);
for (let i = 0; i < TEST_DATA.length; i++) {
let data = TEST_DATA[i];

View file

@ -11,7 +11,7 @@ const TEST_URI = `
<div id="two" style="color:blue;">two</div>
`;
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();

View file

@ -25,7 +25,7 @@ const TEST_URI = `
<div class="test-element">test element</div>
`;
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();

View file

@ -8,7 +8,7 @@
const TEST_URI = "<div class='one'>el 1</div><div class='two'>el 2</div>";
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();
yield selectNode(".one", inspector);

View file

@ -17,7 +17,7 @@ const TEST_URI = `
<div id="testElement">test element</div>
`;
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();
yield selectNode("#testElement", inspector);
@ -109,7 +109,7 @@ function* testExpandedComputedViewProperty(computedView, nodeFront) {
function getPropertyView(computedView, name) {
let propertyView = null;
computedView.propertyViews.some(function(view) {
computedView.propertyViews.some(function (view) {
if (view.name == name) {
propertyView = view;
return true;

View file

@ -15,7 +15,7 @@ const TEST_URI = `
<div id="testElement">test element</div>
`;
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();

View file

@ -17,7 +17,7 @@ const TEST_URI = `
<div></div>
`;
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();
yield selectNode("div", inspector);

View file

@ -17,7 +17,7 @@ const TEST_URI = `
const TYPE = "CssTransformHighlighter";
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();

View file

@ -19,7 +19,7 @@ const TEST_URI = `
var TYPE = "CssTransformHighlighter";
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();
let hs = view.highlighters;

View file

@ -25,7 +25,7 @@ const TEST_URI = `
const TYPE = "CssTransformHighlighter";
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();
@ -34,18 +34,18 @@ add_task(function*() {
isShown: false,
nodeFront: null,
nbOfTimesShown: 0,
show: function(nodeFront) {
show: function (nodeFront) {
this.nodeFront = nodeFront;
this.isShown = true;
this.nbOfTimesShown ++;
return promise.resolve(true);
},
hide: function() {
hide: function () {
this.nodeFront = null;
this.isShown = false;
return promise.resolve();
},
finalize: function() {}
finalize: function () {}
};
// Inject the mock highlighter in the rule-view

View file

@ -27,7 +27,7 @@ const TEST_URI = `
const TYPE = "CssTransformHighlighter";
add_task(function*() {
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();
yield selectNode(".test", inspector);

View file

@ -3,30 +3,26 @@
<html>
<head>
<title>authored sheet test</title>
<style>
#target {
color: chartreuse;
}
</style>
<script>
var gIOService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
.getService(SpecialPowers.Ci.nsIIOService)
var style = "data:text/css,div { background-color: seagreen; }";
var uri = gIOService.newURI(style, null, null);
var windowUtils = SpecialPowers.wrap(window)
.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
.getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
windowUtils.loadSheet(uri, windowUtils.AUTHOR_SHEET);
"use strict";
var gIOService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
.getService(SpecialPowers.Ci.nsIIOService);
var style = "data:text/css,div { background-color: seagreen; }";
var uri = gIOService.newURI(style, null, null);
var windowUtils = SpecialPowers.wrap(window)
.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
.getInterface(SpecialPowers.Ci.nsIDOMWindowUtils);
windowUtils.loadSheet(uri, windowUtils.AUTHOR_SHEET);
</script>
</head>
<body>
<div id="target"> the ocean </div>
<input type=text placeholder=test></input>
<input type=color></input>
<input type=range></input>

View file

@ -1,20 +1,19 @@
<html>
<head>
<title>test</title>
<link href="./doc_content_stylesheet_linked.css" rel="stylesheet" type="text/css">
<script>
/* exported loadCSS */
"use strict";
// Load script.css
function loadCSS() {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
let link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = "./doc_content_stylesheet_script.css";
document.getElementsByTagName('head')[0].appendChild(link);
document.getElementsByTagName("head")[0].appendChild(link);
}
</script>
<style>
table {
border: 1px solid #000;

View file

@ -1,6 +1,7 @@
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* globals addMessageListener, sendAsyncMessage */
"use strict";
@ -10,12 +11,12 @@
// then execute code upon receiving, and immediately send back a message.
// This is so that chrome test code can execute code in content and wait for a
// response this way:
// let response = yield executeInContent(browser, "Test:MessageName", data, true);
// The response message should have the same name "Test:MessageName"
// let response = yield executeInContent(browser, "Test:MsgName", data, true);
// The response message should have the same name "Test:MsgName"
//
// Some listeners do not send a response message back.
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
var {CssLogic} = require("devtools/shared/inspector/css-logic");
@ -30,7 +31,7 @@ var promise = require("promise");
* - {String} name
* @return {String} The value, if found, null otherwise
*/
addMessageListener("Test:GetRulePropertyValue", function(msg) {
addMessageListener("Test:GetRulePropertyValue", function (msg) {
let {name, styleSheetIndex, ruleIndex} = msg.data;
let value = null;
@ -55,7 +56,7 @@ addMessageListener("Test:GetRulePropertyValue", function(msg) {
* @param {Object} objects Expects a 'target' CPOW object
* @return {Array} A list of stylesheet info objects
*/
addMessageListener("Test:GetStyleSheetsInfoForNode", function(msg) {
addMessageListener("Test:GetStyleSheetsInfoForNode", function (msg) {
let target = msg.objects.target;
let sheets = [];
@ -82,10 +83,12 @@ addMessageListener("Test:GetStyleSheetsInfoForNode", function(msg) {
* - {String} name: name of the property
* @return {String} The value, if found, null otherwise
*/
addMessageListener("Test:GetComputedStylePropertyValue", function(msg) {
addMessageListener("Test:GetComputedStylePropertyValue", function (msg) {
let {selector, pseudo, name} = msg.data;
let element = content.document.querySelector(selector);
let value = content.document.defaultView.getComputedStyle(element, pseudo).getPropertyValue(name);
let doc = content.document;
let element = doc.querySelector(selector);
let value = content.getComputedStyle(element, pseudo).getPropertyValue(name);
sendAsyncMessage("Test:GetComputedStylePropertyValue", value);
});
@ -98,7 +101,7 @@ addMessageListener("Test:GetComputedStylePropertyValue", function(msg) {
* - {String} name: name of the property
* - {String} expected: the expected value for property
*/
addMessageListener("Test:WaitForComputedStylePropertyValue", function(msg) {
addMessageListener("Test:WaitForComputedStylePropertyValue", function (msg) {
let {selector, pseudo, name, expected} = msg.data;
let element = content.document.querySelector(selector);
waitForSuccess(() => {
@ -108,10 +111,9 @@ addMessageListener("Test:WaitForComputedStylePropertyValue", function(msg) {
return value === expected;
}).then(() => {
sendAsyncMessage("Test:WaitForComputedStylePropertyValue");
})
});
});
var dumpn = msg => dump(msg + "\n");
/**
@ -125,14 +127,14 @@ var dumpn = msg => dump(msg + "\n");
* @return a promise that resolves when the function returned true or rejects
* if the timeout is reached
*/
function waitForSuccess(validatorFn, name="untitled") {
function waitForSuccess(validatorFn, name = "untitled") {
let def = promise.defer();
function wait(validatorFn) {
if (validatorFn()) {
function wait(fn) {
if (fn()) {
def.resolve();
} else {
setTimeout(() => wait(validatorFn), 200);
setTimeout(() => wait(fn), 200);
}
}
wait(validatorFn);

View file

@ -1,6 +1,7 @@
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* eslint no-unused-vars: [2, {"vars": "local"}] */
/* import-globals-from ../../test/head.js */
"use strict";
@ -77,7 +78,7 @@ registerCleanupFunction(() => {
* script, so they can run on remote targets too.
*/
var _addTab = addTab;
addTab = function(url) {
addTab = function (url) {
return _addTab(url).then(tab => {
info("Loading the helper frame script " + FRAME_SCRIPT_URL);
let browser = tab.linkedBrowser;
@ -125,7 +126,8 @@ function waitForContentMessage(name) {
* @return {Promise} Resolves to the response data if a response is expected,
* immediately resolves otherwise
*/
function executeInContent(name, data={}, objects={}, expectResponse=true) {
function executeInContent(name, data = {}, objects = {},
expectResponse = true) {
info("Sending message " + name + " to content");
let mm = gBrowser.selectedBrowser.messageManager;
@ -184,8 +186,8 @@ function* waitForComputedStyleProperty(selector, pseudo, name, expected) {
*
* @return a promise that resolves to the inplace-editor element when ready
*/
var focusEditableField = Task.async(function*(ruleView, editable, xOffset=1,
yOffset=1, options={}) {
var focusEditableField = Task.async(function* (ruleView, editable, xOffset = 1,
yOffset = 1, options = {}) {
let onFocus = once(editable.parentNode, "focus", true);
info("Clicking on editable field to turn to edit mode");
EventUtils.synthesizeMouse(editable, xOffset, yOffset, options,
@ -211,7 +213,7 @@ var focusEditableField = Task.async(function*(ruleView, editable, xOffset=1,
* @return a promise that resolves when the function returned true or rejects
* if the timeout is reached
*/
function waitForSuccess(validatorFn, name="untitled") {
function waitForSuccess(validatorFn, name = "untitled") {
let def = promise.defer();
function wait(validator) {
@ -236,7 +238,7 @@ function waitForSuccess(validatorFn, name="untitled") {
* The NodeActor that will used to retrieve the dataURL for the
* font family tooltip contents.
*/
var getFontFamilyDataURL = Task.async(function*(font, nodeFront) {
var getFontFamilyDataURL = Task.async(function* (font, nodeFront) {
let fillStyle = (Services.prefs.getCharPref("devtools.theme") === "light") ?
"black" : "white";
@ -372,7 +374,7 @@ function getRuleViewSelectorHighlighterIcon(view, selectorText) {
* - {String} value The expected style value
* The style will be checked like so: getComputedStyle(element)[name] === value
*/
var simulateColorPickerChange = Task.async(function*(ruleView, colorPicker,
var simulateColorPickerChange = Task.async(function* (ruleView, colorPicker,
newRgba, expectedChange) {
let onRuleViewChanged = ruleView.once("ruleview-changed");
info("Getting the spectrum colorpicker object");
@ -447,7 +449,7 @@ function getRuleViewRuleEditor(view, childrenIndex, nodeIndex) {
* @return a promise that resolves to the newly created editor when ready and
* focused
*/
var focusNewRuleViewProperty = Task.async(function*(ruleEditor) {
var focusNewRuleViewProperty = Task.async(function* (ruleEditor) {
info("Clicking on a close ruleEditor brace to start editing a new property");
ruleEditor.closeBrace.scrollIntoView();
let editor = yield focusEditableField(ruleEditor.ruleView,
@ -472,7 +474,7 @@ var focusNewRuleViewProperty = Task.async(function*(ruleEditor) {
* @return a promise that resolves when the new property name has been entered
* and once the value field is focused
*/
var createNewRuleViewProperty = Task.async(function*(ruleEditor, inputValue) {
var createNewRuleViewProperty = Task.async(function* (ruleEditor, inputValue) {
info("Creating a new property editor");
let editor = yield focusNewRuleViewProperty(ruleEditor);
@ -496,7 +498,7 @@ var createNewRuleViewProperty = Task.async(function*(ruleEditor, inputValue) {
* @return a promise that resolves when the rule-view is filtered for the
* search term
*/
var setSearchFilter = Task.async(function*(view, searchValue) {
var setSearchFilter = Task.async(function* (view, searchValue) {
info("Setting filter text to \"" + searchValue + "\"");
let win = view.styleWindow;
let searchField = view.searchField;