Bug 1246677 - 5 - Get rid of 'content' in ruleview test files; r=jdescottes
authorPatrick Brosset <pbrosset@mozilla.com>
Mon, 22 Feb 2016 10:33:04 +0100
changeset 322060 e19e266c58ba287548506335b780e1cfb1f8b537
parent 322059 fc9485acba1a8631057c93130a2f23db688d2441
child 322061 c2cb7715e1b6c18d874ddb547c8a81af6ce88c66
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1246677
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1246677 - 5 - Get rid of 'content' in ruleview test files; r=jdescottes MozReview-Commit-ID: Af07cexjJOv
devtools/client/inspector/rules/test/browser_rules_add-rule_01.js
devtools/client/inspector/rules/test/browser_rules_add-rule_05.js
devtools/client/inspector/rules/test/browser_rules_content_01.js
devtools/client/inspector/rules/test/browser_rules_edit-property-increments.js
devtools/client/inspector/rules/test/browser_rules_style-editor-link.js
--- 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,26 +29,27 @@ 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) {
     let {node, expected} = data;
     yield selectNode(node, inspector);
     yield addNewRule(inspector, view);
     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* testNewRule(view, expected, index) {
   let idRuleEditor = getRuleViewRuleEditor(view, index);
   let editor = idRuleEditor.selectorText.ownerDocument.activeElement;
   is(editor.value, expected,
       "Selector editor value is as expected: " + expected);
--- a/devtools/client/inspector/rules/test/browser_rules_add-rule_05.js
+++ b/devtools/client/inspector/rules/test/browser_rules_add-rule_05.js
@@ -29,26 +29,27 @@ 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) {
     let {node, expected} = data;
     yield selectNode(node, inspector);
     yield addNewRuleFromContextMenu(inspector, view);
     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* addNewRuleFromContextMenu(inspector, view) {
   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,48 +2,46 @@
 /* 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;
+      background: none;
+      transition: initial;
+      z-index: 0;
+    }
+  </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);
   yield testZeroValueIncrements(view);
 });
 
-function createDocument() {
-  content.document.body.innerHTML = "" +
-    "<style>" +
-    "  #test {" +
-    "    margin-top:0px;" +
-    "    padding-top: 0px;" +
-    "    color:#000000;" +
-    "    background-color: #000000;" +
-    "    background: none;" +
-    "    transition: initial;" +
-    "    z-index: 0;" +
-    "  }" +
-    "</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,79 +75,83 @@ 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];
-  is(editor.styleSheet.href, sheet.href,
-    "loaded stylesheet href matches document stylesheet");
+  let href = editor.styleSheet.href || editor.styleSheet.nodeHref;
+
+  let expectedHref = yield testActor.eval(
+    `content.document.styleSheets[${expectedSheetIndex}].href ||
+     content.document.location.href`);
+
+  is(href, expectedHref, "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");
   let tooltipText = labelElem.getAttribute("tooltiptext");