Bug 917389 - Re-enable browser_css_color.js on Linux 32 bit tests. r=harth

This commit is contained in:
Michael Ratcliffe 2013-09-18 11:34:44 +01:00
parent bb9ed1b84b
commit eb81693e5d
2 changed files with 44 additions and 30 deletions

View File

@ -6,6 +6,28 @@
const COLOR_UNIT_PREF = "devtools.defaultColorUnit";
const {Cc, Ci, Cu} = require("chrome");
const REGEX_JUST_QUOTES = /^""$/;
const REGEX_RGB_3_TUPLE = /^rgb\(([\d.]+),\s*([\d.]+),\s*([\d.]+)\)$/i;
const REGEX_RGBA_4_TUPLE = /^rgba\(([\d.]+),\s*([\d.]+),\s*([\d.]+),\s*([\d.]+|1|0)\)$/i;
const REGEX_HSL_3_TUPLE = /^\bhsl\(([\d.]+),\s*([\d.]+%),\s*([\d.]+%)\)$/i;
/**
* This regex matches:
* - #F00
* - #FF0000
* - hsl()
* - hsla()
* - rgb()
* - rgba()
* - red
*
* It also matches css keywords e.g. "background-color" otherwise
* "background" would be replaced with #6363CE ("background" is a platform
* color).
*/
const REGEX_ALL_COLORS = /#[0-9a-fA-F]{3}\b|#[0-9a-fA-F]{6}\b|hsl\(.*?\)|hsla\(.*?\)|rgba?\(.*?\)|\b[a-zA-Z-]+\b/g;
let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
/**
@ -152,6 +174,10 @@ CssColor.prototype = {
return "transparent";
}
if (!this.hasAlpha) {
if (this.authored.startsWith("rgb(")) {
// The color is valid and begins with rgb(. Return the authored value.
return this.authored;
}
let tuple = this._getRGBATuple();
return "rgb(" + tuple.r + ", " + tuple.g + ", " + tuple.b + ")";
}
@ -165,6 +191,10 @@ CssColor.prototype = {
if (this.transparent) {
return "transparent";
}
if (this.authored.startsWith("rgba(")) {
// The color is valid and begins with rgba(. Return the authored value.
return this.authored;
}
let components = this._getRGBATuple();
return "rgba(" + components.r + ", " +
components.g + ", " +
@ -179,6 +209,10 @@ CssColor.prototype = {
if (this.transparent) {
return "transparent";
}
if (this.authored.startsWith("hsl(")) {
// The color is valid and begins with hsl(. Return the authored value.
return this.authored;
}
if (this.hasAlpha) {
return this.hsla;
}
@ -192,11 +226,9 @@ CssColor.prototype = {
if (this.transparent) {
return "transparent";
}
// Because an hsla rbg roundtrip would lose accuracy we use the authored
// values if this is an hsla color.
if (this.authored.startsWith("hsla(")) {
let [, h, s, l, a] = /^\bhsla\(([\d.]+),\s*([\d.]+%),\s*([\d.]+%),\s*([\d.]+|0|1)\)$/gi.exec(this.authored);
return "hsla(" + h + ", " + s + ", " + l + ", " + a + ")";
// The color is valid and begins with hsla(. Return the authored value.
return this.authored;
}
if (this.hasAlpha) {
let a = this._getRGBATuple().a;
@ -261,13 +293,13 @@ CssColor.prototype = {
return "transparent";
}
let rgba = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(\d+\.\d+|1|0)\)$/gi.exec(computed);
let rgba = computed.match(REGEX_RGBA_4_TUPLE);
if (rgba) {
let [, r, g, b, a] = rgba;
return {r: r, g: g, b: b, a: a};
} else {
let rgb = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/gi.exec(computed);
let rgb = computed.match(REGEX_RGB_3_TUPLE);
let [, r, g, b] = rgb;
return {r: r, g: g, b: b, a: 1};
@ -277,10 +309,10 @@ CssColor.prototype = {
_hslNoAlpha: function() {
let {r, g, b} = this._getRGBATuple();
// Because an hsl rbg roundtrip would lose accuracy we use the authored
// values if this is an hsla color.
if (this.authored.startsWith("hsl(")) {
let [, h, s, l] = /^\bhsl\(([\d.]+),\s*([\d.]+%),\s*([\d.]+%)\)$/gi.exec(this.authored);
// We perform string manipulations on our output so let's ensure that it
// is formatted as we expect.
let [, h, s, l] = this.authored.match(REGEX_HSL_3_TUPLE);
return "hsl(" + h + ", " + s + ", " + l + ")";
}
@ -365,23 +397,11 @@ CssColor.prototype = {
* Converted CSS String e.g. "color:#F00; background-color:#0F0;"
*/
function processCSSString(value) {
if (value && /^""$/.test(value)) {
if (value && REGEX_JUST_QUOTES.test(value)) {
return value;
}
// This regex matches:
// - #F00
// - #FF0000
// - hsl()
// - hsla()
// - rgb()
// - rgba()
// - red
//
// It also matches css keywords e.g. "background-color" otherwise
// "background" would be replaced with #6363CE ("background" is a platform
// color).
let colorPattern = /#[0-9a-fA-F]{3}\b|#[0-9a-fA-F]{6}\b|hsl\(.*?\)|hsla\(.*?\)|rgba?\(.*?\)|\b[a-zA-Z-]+\b/g;
let colorPattern = REGEX_ALL_COLORS;
value = value.replace(colorPattern, function(match) {
let color = new CssColor(match);

View File

@ -9,12 +9,6 @@ let {Loader} = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {}
let {colorUtils} = devtools.require("devtools/shared/css-color");
function test() {
// FIXME: Enable this test on Linux once bug 916544 is fixed
if (Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS === "Linux") {
Services = colorUtils.CssColor = Loader = null;
return;
}
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
@ -302,7 +296,7 @@ function getTestData() {
{authored: "hsla(0, 0%, 0%, 0)", name: "transparent", hex: "transparent", hsl: "transparent", rgb: "transparent"},
{authored: "rgba(50, 60, 70, 0.5)", name: "rgba(50, 60, 70, 0.5)", hex: "rgba(50, 60, 70, 0.5)", hsl: "hsla(210, 17%, 24%, 0.5)", rgb: "rgba(50, 60, 70, 0.5)"},
{authored: "rgba(0, 0, 0, 0.3)", name: "rgba(0, 0, 0, 0.3)", hex: "rgba(0, 0, 0, 0.3)", hsl: "hsla(0, 0%, 0%, 0.3)", rgb: "rgba(0, 0, 0, 0.3)"},
{authored: "rgba(255, 255, 255, 0.7)", name: "rgba(255, 255, 255, 0.7)", hex: "rgba(255, 255, 255, 0.7)", hsl: "hsla(0, 0%, 100%, 0.7)", rgb: "rgba(255, 255, 255, 0.7)"},
{authored: "rgba(255, 255, 255, 0.6)", name: "rgba(255, 255, 255, 0.6)", hex: "rgba(255, 255, 255, 0.6)", hsl: "hsla(0, 0%, 100%, 0.6)", rgb: "rgba(255, 255, 255, 0.6)"},
{authored: "rgba(127, 89, 45, 1)", name: "#7F592D", hex: "#7F592D", hsl: "hsl(32.195, 48%, 34%)", rgb: "rgb(127, 89, 45)"},
{authored: "hsla(19.304, 56%, 40%, 1)", name: "#9F512C", hex: "#9F512C", hsl: "hsl(19.304, 57%, 40%)", rgb: "rgb(159, 81, 44)"},
{authored: "invalidColor", name: "", hex: "", hsl: "", rgb: ""}