Bug 1302787 - Add a test for old-style and css-color-4 color function syntax in devtool. r=tromey
☠☠ backed out by d4c9d1de3534 ☠ ☠
authorJerryShih <hshih@mozilla.com>
Sun, 16 Oct 2016 03:15:37 +0800
changeset 318192 554359eddb9358b8e1821808eedb3801d3d2e29d
parent 318191 281ed6b1d3b4f34c1545bc963a1bf9ed976d5ab5
child 318193 e45980db4f43317938659fd957a60ab3ea6c533c
push id33211
push usercbook@mozilla.com
push dateMon, 17 Oct 2016 09:38:38 +0000
treeherderautoland@e4ef6fa03aa8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey
bugs1302787
milestone52.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 1302787 - Add a test for old-style and css-color-4 color function syntax in devtool. r=tromey
devtools/client/shared/test/unit/test_cssColor-03.js
devtools/client/shared/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/devtools/client/shared/test/unit/test_cssColor-03.js
@@ -0,0 +1,61 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test css-color-4 color function syntax and old-style syntax.
+
+"use strict";
+
+var Cu = Components.utils;
+var Ci = Components.interfaces;
+var Cc = Components.classes;
+
+var {require, loader} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+const {colorUtils} = require("devtools/shared/css/color");
+
+loader.lazyGetter(this, "DOMUtils", function () {
+  return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
+});
+
+const OLD_STYLE_TESTS = [
+  "rgb(255,0,192)",
+  "RGB(255,0,192)",
+  "RGB(100%,0%,83%)",
+  "rgba(255,0,192,0.25)",
+  "hsl(120, 100%, 40%)",
+  "hsla(120, 100%, 40%, 0.25)",
+  "hSlA(240, 100%, 50%, 0.25)",
+];
+
+const CSS_COLOR_4_TESTS = [
+  "rgb(255.0,0.0,192.0)",
+  "RGB(255 0 192)",
+  "RGB(100% 0% 83% / 0.5)",
+  "RGB(100%,0%,83%,0.5)",
+  "RGB(100%,0%,83%,50%)",
+  "rgba(255,0,192)",
+  "hsl(50deg,15%,25%)",
+  "hsl(240 25% 33%)",
+  "hsl(50deg 25% 33% / 0.25)",
+  "hsl(60 120% 60% / 0.25)",
+  "hSlA(5turn 40% 4%)",
+];
+
+function run_test() {
+  for (let test of OLD_STYLE_TESTS) {
+    let ours = colorUtils.colorToRGBA(test, true);
+    let platform = DOMUtils.colorToRGBA(test);
+    deepEqual(ours, platform, "color " + test + " matches DOMUtils");
+    ok(ours !== null, "'" + test + "' is a color");
+  }
+
+  for (let test of CSS_COLOR_4_TESTS) {
+    let oursOld = colorUtils.colorToRGBA(test, true);
+    let oursNew = colorUtils.colorToRGBA(test, false);
+    let platform = DOMUtils.colorToRGBA(test);
+    notEqual(oursOld, platform, "old style parser for color " + test +
+             " should not match DOMUtils");
+    ok(oursOld === null, "'" + test + "' is not a color with old parser");
+    deepEqual(oursNew, platform, "css-color-4 parser for color " + test + " matches DOMUtils");
+    ok(oursNew !== null, "'" + test + "' is a color with css-color-4 parser");
+  }
+}
--- a/devtools/client/shared/test/unit/xpcshell.ini
+++ b/devtools/client/shared/test/unit/xpcshell.ini
@@ -10,16 +10,17 @@ support-files =
 
 [test_advanceValidate.js]
 [test_attribute-parsing-01.js]
 [test_attribute-parsing-02.js]
 [test_bezierCanvas.js]
 [test_cssAngle.js]
 [test_cssColor-01.js]
 [test_cssColor-02.js]
+[test_cssColor-03.js]
 [test_cssColorDatabase.js]
 [test_cubicBezier.js]
 [test_escapeCSSComment.js]
 [test_parseDeclarations.js]
 [test_parsePseudoClassesAndAttributes.js]
 [test_parseSingleValue.js]
 [test_rewriteDeclarations.js]
 [test_source-utils.js]