blob: 39991f3ecee174ef198a28499020c106b432a067 [file] [log] [blame]
<svg xmlns="http://www.w3.org/2000/svg">
<style type="text/css"><![CDATA[
#foo {
fill: red;
}
]]></style>
<rect width="50" height="50" id="foo"/>
<script>
function expectsException(col, value) {
try {
col.setRGBColor(value);
} catch(ex) {
return ex.code == 1;
}
return false;
}
function expectsValid(col, value, expectedvalue) {
try {
col.setRGBColor(value);
if (col.cssText == expectedvalue) {
return true;
}
} catch(ex) {
}
col.setRGBColor("red");
return false;
}
/* test that incorrect color strings throw an exception */
var col = document.styleSheets[0].cssRules[0].style.getPropertyCSSValue("fill");
if (!expectsException(col, "rgb(100%,100%,0%")) return;
if (!expectsException(col, "rgba(100%,100%,0%")) return;
if (!expectsException(col, "rgb(100%,100%,r)")) return;
if (!expectsException(col, "rgb (100%,100%,r)")) return;
if (!expectsException(col, "hsl(100%,100%,100%)")) return;
if (!expectsException(col, "yello")) return;
if (!expectsException(col, "!#fff")) return;
if (!expectsException(col, "#sdf")) return;
if (!expectsException(col, "#")) return;
if (!expectsException(col, "#f")) return;
if (!expectsException(col, "#ff")) return;
if (!expectsException(col, "#ffff")) return;
if (!expectsException(col, "#fffff")) return;
if (!expectsException(col, "#fffffff")) return;
if (!expectsException(col, "green,")) return;
if (!expectsValid(col, "rgb(0, 10, 20%)", "#000A33")) return;
if (!expectsValid(col, "rgb(0, 10, 20)", "#000A14")) return;
if (!expectsValid(col, "#FFF", "#FFFFFF")) return;
if (!expectsValid(col, "#FFFFFF", "#FFFFFF")) return;
if (!expectsValid(col, " green", "#008000")) return;
if (!expectsValid(col, "green ", "#008000")) return;
if (!expectsValid(col, "green", "#008000")) return;
</script>
</svg>