From 04ec46a1ec0d7a6a4bd48a9b2db478e1cbeea50d Mon Sep 17 00:00:00 2001 From: Matt Kelly Date: Mon, 9 Apr 2012 17:05:26 -0700 Subject: [PATCH] Adding csscolor test. --- tests/csscolor/config.yml | 5 +++++ tests/csscolor/test.js | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/csscolor/config.yml create mode 100644 tests/csscolor/test.js diff --git a/tests/csscolor/config.yml b/tests/csscolor/config.yml new file mode 100644 index 0000000..4033011 --- /dev/null +++ b/tests/csscolor/config.yml @@ -0,0 +1,5 @@ +--- + r: 0 + spec: "http://www.w3.org/TR/css3-color/" + sources: ["https://github.com/Modernizr/Modernizr"] + title: "CSS3 Color" diff --git a/tests/csscolor/test.js b/tests/csscolor/test.js new file mode 100644 index 0000000..217842c --- /dev/null +++ b/tests/csscolor/test.js @@ -0,0 +1,47 @@ +test("CSS opacity", function() { + + // Browsers that actually have CSS Opacity implemented have done so + // according to spec, which means their return values are within the + // range of [0.0,1.0] - including the leading zero. + + var + elem = document.createElement("div"), + baseRule = "opacity:.55", + rules = H.prefixes.expandCss( baseRule ); + + elem.style.cssText = rules; + + // The non-literal . in this regex is intentional: + // German Chrome returns this value as 0,55 + // github.com/Modernizr/Modernizr/issues/#issue/59/comment/516632 + assert( /^0.55$/.test( elem.style.opacity ), "CSS opacity supported" ); + +}); + +test("CSS color properties, RGBA support", function() { + + var elem = document.createElement("div"); + + // Set an rgba() color and check the returned value + + elem.style.cssText = "background-color:rgba(150,255,150,.5)"; + + assert( H.test.string( elem.style.backgroundColor, "rgba" ), "RGBA color supported" ); + +}); + +test("CSS color properties, HSLA support", function() { + + var bgcolor, + elem = document.createElement("div"); + + // Same as rgba(), in fact, browsers re-map hsla() to rgba() internally, + // except IE9 who retains it as hsla + + elem.style.cssText = "background-color:hsla(120,40%,100%,.5)"; + + bgcolor = elem.style.backgroundColor; + + assert( H.test.string( bgcolor, "rgba" ) || H.test.string( bgcolor, "hsla" ), "HSLA color supported" ); + +});