Bug 1253822 - Rewrite browser_rules_authored_color.js to avoid timeouts;r=gl
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 14 Nov 2016 11:11:43 +0100
changeset 323010 ce21333d6f8f9f681c9fa36845424b8b841eff32
parent 323009 92e6d3b367bf544e31cdac4131c652eeaf6367e2
child 323011 c010db9d4302df3bb5002b9da43aeaea30e907ad
push id34364
push userjdescottes@mozilla.com
push dateThu, 17 Nov 2016 15:58:28 +0000
treeherderautoland@ce21333d6f8f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1253822
milestone53.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 1253822 - Rewrite browser_rules_authored_color.js to avoid timeouts;r=gl Update the test to avoid closing / reopening the toolbox each time a new color is tested. An element is created upfront for each color to test, and the test simply selects a different node when switching to a different color. MozReview-Commit-ID: Atz70fwoMN2
devtools/client/inspector/rules/test/browser_rules_authored_color.js
--- a/devtools/client/inspector/rules/test/browser_rules_authored_color.js
+++ b/devtools/client/inspector/rules/test/browser_rules_authored_color.js
@@ -1,65 +1,67 @@
 /* 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 for as-authored styles.
+// Test for as-authored color styles.
 
-function* createTestContent(style) {
-  let html = `<style type="text/css">
-      ${style}
-      </style>
-      <div id="testid" class="testclass">Styled Node</div>`;
-  let tab = yield addTab("data:text/html;charset=utf-8," +
-                         encodeURIComponent(html));
-
-  let {inspector, view} = yield openRuleView();
-  yield selectNode("#testid", inspector);
-  return {view, tab};
-}
+/**
+ * Array of test color objects:
+ *   {String} name: name of the used & expected color format.
+ *   {String} id: id of the element that will be created to test this color.
+ *   {String} color: initial value of the color property applied to the test element.
+ *   {String} result: expected value of the color property after edition.
+ */
+const colors = [
+  {name: "hex", id: "test1", color: "#f0c", result: "#0f0"},
+  {name: "rgb", id: "test2", color: "rgb(0,128,250)", result: "rgb(0, 255, 0)"},
+  // Test case preservation.
+  {name: "hex", id: "test3", color: "#F0C", result: "#0F0"},
+];
 
 add_task(function* () {
-  let colors = [
-    {name: "hex", text: "#f0c", result: "#0f0"},
-    {name: "rgb", text: "rgb(0,128,250)", result: "rgb(0, 255, 0)"},
-    // Test case preservation.
-    {name: "hex", text: "#F0C", result: "#0F0"},
-  ];
-
   Services.prefs.setCharPref("devtools.defaultColorUnit", "authored");
 
+  let html = "";
+  for (let {color, id} of colors) {
+    html += `<div id="${id}" style="color: ${color}">Styled Node</div>`;
+  }
+
+  let tab = yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(html));
+
+  let {inspector, view} = yield openRuleView();
+
   for (let color of colors) {
-    let {view, tab} = yield createTestContent("#testid {" +
-                                              "  color: " + color.text + ";" +
-                                              "} ");
+    let cPicker = view.tooltips.colorPicker;
+    let selector = "#" + color.id;
+    yield selectNode(selector, inspector);
 
-    let cPicker = view.tooltips.colorPicker;
-    let swatch = getRuleViewProperty(view, "#testid", "color").valueSpan
+    let swatch = getRuleViewProperty(view, "element", "color").valueSpan
         .querySelector(".ruleview-colorswatch");
     let onColorPickerReady = cPicker.once("ready");
     swatch.click();
     yield onColorPickerReady;
 
     yield simulateColorPickerChange(view, cPicker, [0, 255, 0, 1], {
-      selector: "#testid",
+      selector,
       name: "color",
       value: "rgb(0, 255, 0)"
     });
 
     let spectrum = cPicker.spectrum;
     let onHidden = cPicker.tooltip.once("hidden");
     // Validating the color change ends up updating the rule view twice
     let onRuleViewChanged = waitForNEvents(view, "ruleview-changed", 2);
     focusAndSendKey(spectrum.element.ownerDocument.defaultView, "RETURN");
     yield onHidden;
     yield onRuleViewChanged;
 
-    is(getRuleViewPropertyValue(view, "#testid", "color"), color.result,
+    is(getRuleViewPropertyValue(view, "element", "color"), color.result,
        "changing the color preserved the unit for " + color.name);
+  }
 
-    let target = TargetFactory.forTab(tab);
-    yield gDevTools.closeToolbox(target);
-    gBrowser.removeCurrentTab();
-  }
+  let target = TargetFactory.forTab(tab);
+  yield gDevTools.closeToolbox(target);
+  gBrowser.removeCurrentTab();
 });