Bug 1246677 - 5 - Get rid of 'content' in ruleview test files
MozReview-Commit-ID: Af07cexjJOv
--- a/devtools/client/inspector/rules/test/browser_rules_add-rule_01.js
+++ b/devtools/client/inspector/rules/test/browser_rules_add-rule_01.js
@@ -29,32 +29,32 @@ const TEST_DATA = [
{ node: ".class3.class4", expected: ".class3.class4" },
{ node: "p", expected: "p" },
{ node: "h1", expected: ".asd\\@\\@\\@\\@a\\!\\!\\!\\!\\:\\:\\:\\@asd" },
{ node: "h2", expected: "#asd\\@\\@\\@a\\!\\!2a" }
];
add_task(function*() {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
- let {inspector, view} = yield openRuleView();
+ let {inspector, view, testActor} = yield openRuleView();
for (let data of TEST_DATA) {
- yield runTestData(inspector, view, data, "context-menu");
- yield runTestData(inspector, view, data, "button");
+ yield runTestData(testActor, inspector, view, data, "context-menu");
+ yield runTestData(testActor, inspector, view, data, "button");
}
});
-function* runTestData(inspector, view, data, method) {
+function* runTestData(testActor, inspector, view, data, method) {
let {node, expected} = data;
yield selectNode(node, inspector);
yield addNewRule(inspector, view, method);
yield testNewRule(view, expected, 1);
info("Resetting page content");
- content.document.body.innerHTML = TEST_URI;
+ yield testActor.eval("content.document.body.innerHTML = `" + TEST_URI + "`;");
}
function* addNewRule(inspector, view, method) {
if (method == "context-menu") {
info("Waiting for context menu to be shown");
let onPopup = once(view._contextmenu._menupopup, "popupshown");
let win = view.styleWindow;
--- a/devtools/client/inspector/rules/test/browser_rules_content_01.js
+++ b/devtools/client/inspector/rules/test/browser_rules_content_01.js
@@ -1,54 +1,51 @@
/* 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/ */
"use strict";
// Test that the rule-view content is correct
-add_task(function*() {
- yield addTab("data:text/html;charset=utf-8,browser_ruleview_content.js");
- let {toolbox, inspector, view} = yield openRuleView();
+const TEST_URI = `
+ <style type="text/css">
+ @media screen and (min-width: 10px) {
+ #testid {
+ background-color: blue;
+ }
+ }
+ .testclass, .unmatched {
+ background-color: green;
+ }
+ </style>
+ <div id='testid' class='testclass'>Styled Node</div>
+ <div id='testid2'>Styled Node</div>
+`;
- info("Creating the test document");
- let style = "" +
- "@media screen and (min-width: 10px) {" +
- " #testid {" +
- " background-color: blue;" +
- " }" +
- "}" +
- ".testclass, .unmatched {" +
- " background-color: green;" +
- "}";
- let styleNode = addStyle(content.document, style);
- content.document.body.innerHTML = "<div id='testid' class='testclass'>Styled Node</div>" +
- "<div id='testid2'>Styled Node</div>";
+add_task(function*() {
+ yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
+ let {inspector, view} = yield openRuleView();
- yield testContentAfterNodeSelection(inspector, view);
-});
-
-function* testContentAfterNodeSelection(inspector, ruleView) {
yield selectNode("#testid", inspector);
- is(ruleView.element.querySelectorAll("#noResults").length, 0,
+ is(view.element.querySelectorAll("#noResults").length, 0,
"After a highlight, no longer has a no-results element.");
- yield clearCurrentNodeSelection(inspector)
- is(ruleView.element.querySelectorAll("#noResults").length, 1,
+ yield clearCurrentNodeSelection(inspector);
+ is(view.element.querySelectorAll("#noResults").length, 1,
"After highlighting null, has a no-results element again.");
yield selectNode("#testid", inspector);
- let linkText = getRuleViewLinkTextByIndex(ruleView, 1);
- is(linkText, "inline:1 @screen and (min-width: 10px)",
+ let linkText = getRuleViewLinkTextByIndex(view, 1);
+ is(linkText, "inline:3 @screen and (min-width: 10px)",
"link text at index 1 contains media query text.");
- linkText = getRuleViewLinkTextByIndex(ruleView, 2);
- is(linkText, "inline:1",
+ linkText = getRuleViewLinkTextByIndex(view, 2);
+ is(linkText, "inline:7",
"link text at index 2 contains no media query text.");
- let classEditor = getRuleViewRuleEditor(ruleView, 2);
- is(classEditor.selectorText.querySelector(".ruleview-selector-matched").textContent,
+ let selector = getRuleViewRuleEditor(view, 2).selectorText;
+ is(selector.querySelector(".ruleview-selector-matched").textContent,
".testclass", ".textclass should be matched.");
- is(classEditor.selectorText.querySelector(".ruleview-selector-unmatched").textContent,
+ is(selector.querySelector(".ruleview-selector-unmatched").textContent,
".unmatched", ".unmatched should not be matched.");
-}
+});
--- a/devtools/client/inspector/rules/test/browser_rules_edit-property-increments.js
+++ b/devtools/client/inspector/rules/test/browser_rules_edit-property-increments.js
@@ -2,44 +2,42 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that increasing/decreasing values in rule view using
// arrow keys works correctly.
+const TEST_URI = `
+ <style>
+ #test {
+ margin-top:0px;
+ padding-top: 0px;
+ color:#000000;
+ background-color: #000000;
+ }
+ </style>
+ <div id="test"></div>
+`;
+
add_task(function*() {
- yield addTab("data:text/html;charset=utf-8,sample document for bug 722691");
- createDocument();
+ yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();
yield selectNode("#test", inspector);
yield testMarginIncrements(view);
yield testVariousUnitIncrements(view);
yield testHexIncrements(view);
yield testRgbIncrements(view);
yield testShorthandIncrements(view);
yield testOddCases(view);
});
-function createDocument() {
- content.document.body.innerHTML = "" +
- "<style>" +
- " #test {" +
- " margin-top:0px;" +
- " padding-top: 0px;" +
- " color:#000000;" +
- " background-color: #000000;" +
- " }" +
- "</style>" +
- "<div id=\"test\"></div>";
-}
-
function* testMarginIncrements(view) {
info("Testing keyboard increments on the margin property");
let idRuleEditor = getRuleViewRuleEditor(view, 1);
let marginPropEditor = idRuleEditor.rule.textProps[0].editor;
yield runIncrementTest(marginPropEditor, view, {
1: {alt: true, start: "0px", end: "0.1px", selectAll: true},
--- a/devtools/client/inspector/rules/test/browser_rules_style-editor-link.js
+++ b/devtools/client/inspector/rules/test/browser_rules_style-editor-link.js
@@ -51,23 +51,23 @@ const DOCUMENT_URL = "data:text/html;cha
'<p id="closing">more text</p>',
'<p>even more text</p>',
'</div>',
'</body>',
'</html>'].join("\n"));
add_task(function*() {
yield addTab(DOCUMENT_URL);
- let {toolbox, inspector, view} = yield openRuleView();
+ let {toolbox, inspector, view, testActor} = yield openRuleView();
yield selectNode("div", inspector);
yield testInlineStyle(view);
- yield testFirstInlineStyleSheet(view, toolbox);
- yield testSecondInlineStyleSheet(view, toolbox);
- yield testExternalStyleSheet(view, toolbox);
+ yield testFirstInlineStyleSheet(view, toolbox, testActor);
+ yield testSecondInlineStyleSheet(view, toolbox, testActor);
+ yield testExternalStyleSheet(view, toolbox, testActor);
});
function* testInlineStyle(view) {
info("Testing inline style");
let onTab = waitForTab();
info("Clicking on the first link in the rule-view");
clickLinkByIndex(view, 0);
@@ -75,77 +75,78 @@ function* testInlineStyle(view) {
let tab = yield onTab;
let tabURI = tab.linkedBrowser.documentURI.spec;
ok(tabURI.startsWith("view-source:"), "View source tab is open");
info("Closing tab");
gBrowser.removeTab(tab);
}
-function* testFirstInlineStyleSheet(view, toolbox) {
+function* testFirstInlineStyleSheet(view, toolbox, testActor) {
info("Testing inline stylesheet");
info("Listening for toolbox switch to the styleeditor");
let onSwitch = waitForStyleEditor(toolbox);
info("Clicking an inline stylesheet");
clickLinkByIndex(view, 4);
let editor = yield onSwitch;
ok(true, "Switched to the style-editor panel in the toolbox");
- validateStyleEditorSheet(editor, 0);
+ yield validateStyleEditorSheet(editor, 0, testActor);
}
-function* testSecondInlineStyleSheet(view, toolbox) {
+function* testSecondInlineStyleSheet(view, toolbox, testActor) {
info("Testing second inline stylesheet");
info("Waiting for the stylesheet editor to be selected");
let panel = toolbox.getCurrentPanel();
let onSelected = panel.UI.once("editor-selected");
info("Switching back to the inspector panel in the toolbox");
yield toolbox.selectTool("inspector");
info("Clicking on second inline stylesheet link");
testRuleViewLinkLabel(view);
clickLinkByIndex(view, 3);
let editor = yield onSelected;
is(toolbox.currentToolId, "styleeditor",
"The style editor is selected again");
- validateStyleEditorSheet(editor, 1);
+ yield validateStyleEditorSheet(editor, 1, testActor);
}
-function* testExternalStyleSheet(view, toolbox) {
+function* testExternalStyleSheet(view, toolbox, testActor) {
info("Testing external stylesheet");
info("Waiting for the stylesheet editor to be selected");
let panel = toolbox.getCurrentPanel();
let onSelected = panel.UI.once("editor-selected");
info("Switching back to the inspector panel in the toolbox");
yield toolbox.selectTool("inspector");
info("Clicking on an external stylesheet link");
testRuleViewLinkLabel(view);
clickLinkByIndex(view, 1);
let editor = yield onSelected;
is(toolbox.currentToolId, "styleeditor",
"The style editor is selected again");
- validateStyleEditorSheet(editor, 2);
+ yield validateStyleEditorSheet(editor, 2, testActor);
}
-function validateStyleEditorSheet(editor, expectedSheetIndex) {
+function* validateStyleEditorSheet(editor, expectedSheetIndex, testActor) {
info("validating style editor stylesheet");
is(editor.styleSheet.styleSheetIndex, expectedSheetIndex,
"loaded stylesheet index matches document stylesheet");
- let sheet = content.document.styleSheets[expectedSheetIndex];
+ let sheet = yield testActor.eval(
+ `content.document.styleSheets[${expectedSheetIndex}]`);
is(editor.styleSheet.href, sheet.href,
"loaded stylesheet href matches document stylesheet");
}
function testRuleViewLinkLabel(view) {
let link = getRuleViewLinkByIndex(view, 2);
let labelElem = link.querySelector(".ruleview-rule-source-label");
let value = labelElem.getAttribute("value");