mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 04:38:02 +00:00
Backed out changeset 1d2f59732f03 (bug 1195349) for test_cssColor.js failures.
This commit is contained in:
parent
9b55c67e43
commit
fdc764760b
@ -57,8 +57,7 @@ function CssColor(colorValue) {
|
||||
module.exports.colorUtils = {
|
||||
CssColor: CssColor,
|
||||
rgbToHsl: rgbToHsl,
|
||||
setAlpha: setAlpha,
|
||||
classifyColor: classifyColor
|
||||
setAlpha: setAlpha
|
||||
};
|
||||
|
||||
/**
|
||||
@ -75,10 +74,7 @@ CssColor.COLORUNIT = {
|
||||
CssColor.prototype = {
|
||||
_colorUnit: null,
|
||||
|
||||
// The value as-authored.
|
||||
authored: null,
|
||||
// A lower-cased copy of |authored|.
|
||||
lowerCased: null,
|
||||
|
||||
get colorUnit() {
|
||||
if (this._colorUnit === null) {
|
||||
@ -116,7 +112,7 @@ CssColor.prototype = {
|
||||
},
|
||||
|
||||
get specialValue() {
|
||||
return SPECIALVALUES.has(this.lowerCased) ? this.authored : null;
|
||||
return SPECIALVALUES.has(this.authored) ? this.authored : null;
|
||||
},
|
||||
|
||||
get name() {
|
||||
@ -175,8 +171,8 @@ CssColor.prototype = {
|
||||
return invalidOrSpecialValue;
|
||||
}
|
||||
if (!this.hasAlpha) {
|
||||
if (this.lowerCased.startsWith("rgb(")) {
|
||||
// The color is valid and begins with rgb(.
|
||||
if (this.authored.startsWith("rgb(")) {
|
||||
// The color is valid and begins with rgb(. Return the authored value.
|
||||
return this.authored;
|
||||
}
|
||||
let tuple = this._getRGBATuple();
|
||||
@ -190,8 +186,8 @@ CssColor.prototype = {
|
||||
if (invalidOrSpecialValue !== false) {
|
||||
return invalidOrSpecialValue;
|
||||
}
|
||||
if (this.lowerCased.startsWith("rgba(")) {
|
||||
// The color is valid and begins with rgba(.
|
||||
if (this.authored.startsWith("rgba(")) {
|
||||
// The color is valid and begins with rgba(. Return the authored value.
|
||||
return this.authored;
|
||||
}
|
||||
let components = this._getRGBATuple();
|
||||
@ -206,8 +202,8 @@ CssColor.prototype = {
|
||||
if (invalidOrSpecialValue !== false) {
|
||||
return invalidOrSpecialValue;
|
||||
}
|
||||
if (this.lowerCased.startsWith("hsl(")) {
|
||||
// The color is valid and begins with hsl(.
|
||||
if (this.authored.startsWith("hsl(")) {
|
||||
// The color is valid and begins with hsl(. Return the authored value.
|
||||
return this.authored;
|
||||
}
|
||||
if (this.hasAlpha) {
|
||||
@ -221,8 +217,8 @@ CssColor.prototype = {
|
||||
if (invalidOrSpecialValue !== false) {
|
||||
return invalidOrSpecialValue;
|
||||
}
|
||||
if (this.lowerCased.startsWith("hsla(")) {
|
||||
// The color is valid and begins with hsla(.
|
||||
if (this.authored.startsWith("hsla(")) {
|
||||
// The color is valid and begins with hsla(. Return the authored value.
|
||||
return this.authored;
|
||||
}
|
||||
if (this.hasAlpha) {
|
||||
@ -260,11 +256,7 @@ CssColor.prototype = {
|
||||
* Any valid color string
|
||||
*/
|
||||
newColor: function(color) {
|
||||
// Store a lower-cased version of the color to help with format
|
||||
// testing. The original text is kept as well so it can be
|
||||
// returned when needed.
|
||||
this.lowerCased = color.toLowerCase();
|
||||
this.authored = color;
|
||||
this.authored = color.toLowerCase();
|
||||
return this;
|
||||
},
|
||||
|
||||
@ -327,7 +319,7 @@ CssColor.prototype = {
|
||||
},
|
||||
|
||||
_hsl: function(maybeAlpha) {
|
||||
if (this.lowerCased.startsWith("hsl(") && maybeAlpha === undefined) {
|
||||
if (this.authored.startsWith("hsl(") && maybeAlpha === undefined) {
|
||||
// We can use it as-is.
|
||||
return this.authored;
|
||||
}
|
||||
@ -423,27 +415,6 @@ function setAlpha(colorValue, alpha) {
|
||||
return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a color, classify its type as one of the possible color
|
||||
* units, as known by |CssColor.colorUnit|.
|
||||
*
|
||||
* @param {String} value
|
||||
* The color, in any form accepted by CSS.
|
||||
* @return {String}
|
||||
* The color classification, one of "rgb", "hsl", "hex", or "name".
|
||||
*/
|
||||
function classifyColor(value) {
|
||||
value = value.toLowerCase();
|
||||
if (value.startsWith("rgb(") || value.startsWith("rgba(")) {
|
||||
return CssColor.COLORUNIT.rgb;
|
||||
} else if (value.startsWith("hsl(") || value.startsWith("hsla(")) {
|
||||
return CssColor.COLORUNIT.hsl;
|
||||
} else if (/^#[0-9a-f]+$/.exec(value)) {
|
||||
return CssColor.COLORUNIT.hex;
|
||||
}
|
||||
return CssColor.COLORUNIT.name;
|
||||
}
|
||||
|
||||
loader.lazyGetter(this, "DOMUtils", function () {
|
||||
return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
|
||||
});
|
||||
|
@ -1,31 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Test classifyColor.
|
||||
|
||||
"use strict";
|
||||
|
||||
const loader = new DevToolsLoader();
|
||||
const require = loader.require;
|
||||
const {colorUtils} = require("devtools/css-color");
|
||||
|
||||
const CLASSIFY_TESTS = [
|
||||
{ input: "rgb(255,0,192)", output: "rgb" },
|
||||
{ input: "RGB(255,0,192)", output: "rgb" },
|
||||
{ input: "rgba(255,0,192, 0.25)", output: "rgb" },
|
||||
{ input: "hsl(5, 5, 5)", output: "hsl" },
|
||||
{ input: "hsla(5, 5, 5, 0.25)", output: "hsl" },
|
||||
{ input: "hSlA(5, 5, 5, 0.25)", output: "hsl" },
|
||||
{ input: "#f0c", output: "hex" },
|
||||
{ input: "#fe01cb", output: "hex" },
|
||||
{ input: "#FE01CB", output: "hex" },
|
||||
{ input: "blue", output: "name" },
|
||||
{ input: "orange", output: "name" }
|
||||
];
|
||||
|
||||
function run_test() {
|
||||
for (let test of CLASSIFY_TESTS) {
|
||||
let result = colorUtils.classifyColor(test.input);
|
||||
equal(result, test.output, "test classifyColor(" + test.input + ")");
|
||||
}
|
||||
}
|
@ -16,7 +16,6 @@ support-files =
|
||||
[test_defineLazyPrototypeGetter.js]
|
||||
[test_async-utils.js]
|
||||
[test_consoleID.js]
|
||||
[test_cssColor.js]
|
||||
[test_prettifyCSS.js]
|
||||
[test_require_lazy.js]
|
||||
[test_require.js]
|
||||
|
Loading…
x
Reference in New Issue
Block a user