Bug 1245776 - part3: import shared/test/head in styleeditor/test/head;r=gl
5 tests of the styleeditor suite are importing shared/test/head.
Now that this also includes shared-head.js, it conflicts with the existing
styleeditor head file.
For now, the import was moved to the head, so it's always imported.
The tests have been updated accordingly.
Should file a follow-up to split the inspector test suites head files in a
head.js + helpers.js (see commandline/test). It should be possible to
include helpers in other tests without impact on the test lifecycle.
MozReview-Commit-ID: BU3LiEr0UtZ
--- a/devtools/client/inspector/shared/test/head.js
+++ b/devtools/client/inspector/shared/test/head.js
@@ -34,17 +34,17 @@ registerCleanupFunction(() => {
* (the instance of the current toolbox, or inspector panel for instance).
*
* Most of these functions are async too and return promises.
*
* All tests should follow the following pattern:
*
* add_task(function*() {
* yield addTab(TEST_URI);
- * let {toolbox, inspector, view} = yield openInspector();
+ * let {toolbox, inspector} = yield openInspector();
* inspector.sidebar.select(viewId);
* let view = inspector[viewId].view;
* yield selectNode("#test", inspector);
* yield someAsyncTestFunction(view);
* });
*
* add_task is the way to define the testcase in the test file. It accepts
* a single generator-function argument.
--- a/devtools/client/styleeditor/test/browser_styleeditor_filesave.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_filesave.js
@@ -3,19 +3,16 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that 'Save' function works.
const TESTCASE_URI_HTML = TEST_BASE_HTTP + "simple.html";
const TESTCASE_URI_CSS = TEST_BASE_HTTP + "simple.css";
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-
var tempScope = {};
Components.utils.import("resource://gre/modules/FileUtils.jsm", tempScope);
Components.utils.import("resource://gre/modules/NetUtil.jsm", tempScope);
var FileUtils = tempScope.FileUtils;
var NetUtil = tempScope.NetUtil;
add_task(function* () {
let htmlFile = yield copy(TESTCASE_URI_HTML, "simple.html");
--- a/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_links.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_media_sidebar_links.js
@@ -41,17 +41,17 @@ function testNumberOfLinks(editor) {
is(conditions[3].querySelectorAll(responsiveModeToggleClass).length, 2,
"There should be 2 responsive mode links in the media rule");
}
function* testMediaLink(editor, tab, ui, itemIndex, type, value) {
let sidebar = editor.details.querySelector(".stylesheet-sidebar");
let conditions = sidebar.querySelectorAll(".media-rule-condition");
- let onMediaChange = once("media-list-changed", ui);
+ let onMediaChange = once(ui, "media-list-changed");
let onContentResize = waitForResizeTo(ResponsiveUIManager, type, value);
info("Launching responsive mode");
conditions[itemIndex].querySelector(responsiveModeToggleClass).click();
ResponsiveUIManager.getResponsiveUIForTab(tab).transitionsEnabled = false;
info("Waiting for the @media list to update");
@@ -66,18 +66,18 @@ function* testMediaLink(editor, tab, ui,
let dimension = (yield getSizing())[type];
is(dimension, value, `${type} should be properly set.`);
}
function* closeRDM(tab, ui) {
info("Closing responsive mode");
ResponsiveUIManager.toggle(window, tab);
- let onMediaChange = once("media-list-changed", ui);
- yield once("off", ResponsiveUIManager);
+ let onMediaChange = once(ui, "media-list-changed");
+ yield once(ResponsiveUIManager, "off");
yield onMediaChange;
ok(!ResponsiveUIManager.isActiveForTab(tab),
"Responsive mode should no longer be active.");
}
function doFinalChecks(editor) {
let sidebar = editor.details.querySelector(".stylesheet-sidebar");
let conditions = sidebar.querySelectorAll(".media-rule-condition");
@@ -110,24 +110,16 @@ function* getSizing() {
return {
width: content.innerWidth,
height: content.innerHeight
};
});
return sizing;
}
-function once(event, target) {
- let deferred = promise.defer();
- target.once(event, () => {
- deferred.resolve();
- });
- return deferred.promise;
-}
-
function openEditor(editor) {
getLinkFor(editor).click();
return editor.getSourceEditor();
}
function getLinkFor(editor) {
return editor.summary.querySelector(".stylesheet-name");
--- a/devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_sourcemap_watching.js
@@ -10,19 +10,16 @@ const TESTCASE_URI_REG_CSS = TEST_BASE_H
const TESTCASE_URI_SCSS = TEST_BASE_HTTP + "sourcemap-sass/sourcemaps.scss";
const TESTCASE_URI_MAP = TEST_BASE_HTTP + "sourcemap-css/sourcemaps.css.map";
const TESTCASE_SCSS_NAME = "sourcemaps.scss";
const TRANSITIONS_PREF = "devtools.styleeditor.transitions";
const CSS_TEXT = "* { color: blue }";
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-
const {FileUtils} = Components.utils.import("resource://gre/modules/FileUtils.jsm", {});
const {NetUtil} = Components.utils.import("resource://gre/modules/NetUtil.jsm", {});
add_task(function* () {
yield new Promise(resolve => {
SpecialPowers.pushPrefEnv({"set": [
[TRANSITIONS_PREF, false]
]}, resolve);
--- a/devtools/client/styleeditor/test/browser_styleeditor_sync.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_sync.js
@@ -1,19 +1,16 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that changes in the style inspector are synchronized into the
// style editor.
-/* import-globals-from ../../inspector/shared/test/head.js */
-Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/inspector/shared/test/head.js", this);
-
const TESTCASE_URI = TEST_BASE_HTTP + "sync.html";
const expectedText = `
body {
border-width: 15px;
/*! color: red; */
}
--- a/devtools/client/styleeditor/test/browser_styleeditor_syncAddRule.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncAddRule.js
@@ -1,18 +1,15 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that adding a new rule is synced to the style editor.
-/* import-globals-from ../../inspector/shared/test/head.js */
-Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/inspector/shared/test/head.js", this);
-
const TESTCASE_URI = TEST_BASE_HTTP + "sync.html";
const expectedText = `
#testid {
}`;
add_task(function* () {
yield addTab(TESTCASE_URI);
--- a/devtools/client/styleeditor/test/browser_styleeditor_syncAlreadyOpen.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncAlreadyOpen.js
@@ -1,46 +1,43 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that changes in the style inspector are synchronized into the
// style editor.
-/* import-globals-from ../../inspector/shared/test/head.js */
-Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/inspector/shared/test/head.js", this);
-
const TESTCASE_URI = TEST_BASE_HTTP + "sync.html";
const expectedText = `
body {
border-width: 15px;
color: red;
}
#testid {
/*! font-size: 4em; */
}
`;
add_task(function* () {
yield addTab(TESTCASE_URI);
- let { inspector, view } = yield openRuleView();
+ let { inspector, view, toolbox } = yield openRuleView();
// In this test, make sure the style editor is open before making
// changes in the inspector.
let { ui } = yield openStyleEditor();
let editor = yield ui.editors[0].getSourceEditor();
let onEditorChange = promise.defer();
editor.sourceEditor.on("change", onEditorChange.resolve);
- yield openRuleView();
+ yield toolbox.getPanel("inspector");
yield selectNode("#testid", inspector);
let ruleEditor = getRuleViewRuleEditor(view, 1);
// Disable the "font-size" property.
let propEditor = ruleEditor.rule.textProps[0].editor;
let onModification = view.once("ruleview-changed");
propEditor.enable.click();
yield onModification;
--- a/devtools/client/styleeditor/test/browser_styleeditor_syncEditSelector.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncEditSelector.js
@@ -1,19 +1,16 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that changes in the style inspector are synchronized into the
// style editor.
-/* import-globals-from ../../inspector/shared/test/head.js */
-Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/inspector/shared/test/head.js", this);
-
const TESTCASE_URI = TEST_BASE_HTTP + "sync.html";
const expectedText = `
body {
border-width: 15px;
color: red;
}
--- a/devtools/client/styleeditor/test/browser_styleeditor_syncIntoRuleView.js
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncIntoRuleView.js
@@ -1,19 +1,16 @@
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that changes in the style editor are synchronized into the
// style inspector.
-/* import-globals-from ../../inspector/shared/test/head.js */
-Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/client/inspector/shared/test/head.js", this);
-
const TEST_URI = `
<style type='text/css'>
div { background-color: seagreen; }
</style>
<div id='testid' class='testclass'>Styled Node</div>
`;
const TESTCASE_CSS_SOURCE = "#testid { color: chartreuse; }";
--- a/devtools/client/styleeditor/test/head.js
+++ b/devtools/client/styleeditor/test/head.js
@@ -1,53 +1,47 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* All top-level definitions here are exports. */
/* eslint no-unused-vars: [2, {"vars": "local"}] */
"use strict";
+/* import-globals-from ../../inspector/shared/test/head.js */
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/devtools/client/inspector/shared/test/head.js", this);
+
const TEST_BASE = "chrome://mochitests/content/browser/devtools/client/styleeditor/test/";
const TEST_BASE_HTTP = "http://example.com/browser/devtools/client/styleeditor/test/";
const TEST_BASE_HTTPS = "https://example.com/browser/devtools/client/styleeditor/test/";
const TEST_HOST = "mochi.test:8888";
-var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
-var {TargetFactory} = require("devtools/client/framework/target");
-var promise = require("promise");
-var DevToolsUtils = require("devtools/shared/DevToolsUtils");
-
-DevToolsUtils.testing = true;
-SimpleTest.registerCleanupFunction(() => {
- DevToolsUtils.testing = false;
-});
-
/**
* Add a new test tab in the browser and load the given url.
* @param {String} url The url to be loaded in the new tab
* @param {Window} win The window to add the tab to (default: current window).
* @return a promise that resolves to the tab object when the url is loaded
*/
-function addTab(url, win) {
+var addTab = function(url, win) {
info("Adding a new tab with URL: '" + url + "'");
let def = promise.defer();
let targetWindow = win || window;
let targetBrowser = targetWindow.gBrowser;
let tab = targetBrowser.selectedTab = targetBrowser.addTab(url);
targetBrowser.selectedBrowser.addEventListener("load", function onload() {
targetBrowser.selectedBrowser.removeEventListener("load", onload, true);
info("URL '" + url + "' loading complete");
def.resolve(tab);
}, true);
return def.promise;
-}
+};
/**
* Navigate the currently selected tab to a new URL and wait for it to load.
* @param {String} url The url to be loaded in the current tab.
* @return a promise that resolves when the page has fully loaded.
*/
var navigateTo = Task.async(function* (url) {
info(`Navigating to ${url}`);
@@ -74,25 +68,16 @@ var reloadPageAndWaitForStyleSheets = Ta
info("Reloading the page.");
let onReset = ui.once("stylesheets-reset");
let browser = gBrowser.selectedBrowser;
yield ContentTask.spawn(browser, null, "() => content.location.reload()");
yield onReset;
});
-registerCleanupFunction(function* () {
- while (gBrowser.tabs.length > 1) {
- let target = TargetFactory.forTab(gBrowser.selectedTab);
- yield gDevTools.closeToolbox(target);
-
- gBrowser.removeCurrentTab();
- }
-});
-
/**
* Open the style editor for the current tab.
*/
var openStyleEditor = Task.async(function* (tab) {
if (!tab) {
tab = gBrowser.selectedTab;
}
let target = TargetFactory.forTab(tab);
@@ -120,17 +105,17 @@ var openStyleEditorForURL = Task.async(f
*
* @param {String} selector
* The selector used to obtain the element.
* @param {String} pseudo
* pseudo id to query, or null.
* @param {String} name
* name of the property.
*/
-function* getComputedStyleProperty(args) {
+var getComputedStyleProperty = function* (args) {
return yield ContentTask.spawn(gBrowser.selectedBrowser, args,
function({selector, pseudo, name}) {
let element = content.document.querySelector(selector);
let style = content.getComputedStyle(element, pseudo);
return style.getPropertyValue(name);
}
);
-}
+};