OLD | NEW |
| (Empty) |
1 description("This test checks the SVGColor API"); | |
2 | |
3 // Setup a real SVG document, as we want to access CSS style information. | |
4 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg"); | |
5 svgElement.setAttribute("width", "150"); | |
6 svgElement.setAttribute("height", "50"); | |
7 | |
8 var stopElement = document.createElementNS("http://www.w3.org/2000/svg", "stop")
; | |
9 stopElement.setAttribute("style", "stop-color: red; color: green"); | |
10 svgElement.appendChild(stopElement); | |
11 document.getElementById("description").appendChild(svgElement); | |
12 | |
13 function checkStopColor(type, red, green, blue) { | |
14 shouldBe("stopColor.colorType", type); | |
15 shouldBeEqualToString("(rgbColor = stopColor.rgbColor).toString()", "[object
RGBColor]"); | |
16 shouldBe("rgbColor.red.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" + re
d); | |
17 shouldBe("rgbColor.green.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" +
green); | |
18 shouldBe("rgbColor.blue.getFloatValue(CSSPrimitiveValue.CSS_NUMBER)", "" + b
lue); | |
19 } | |
20 | |
21 debug(""); | |
22 debug("Check initial color values"); | |
23 shouldBeEqualToString("(stopColor = stopElement.style.getPropertyCSSValue('stop-
color')).toString()", "[object SVGColor]"); | |
24 checkStopColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 255, 0, 0); | |
25 shouldBeEqualToString("stopElement.style.stopColor", "#ff0000"); | |
26 shouldBeEqualToString("document.defaultView.getComputedStyle(stopElement).stopCo
lor", "rgb(255, 0, 0)"); | |
27 | |
28 debug(""); | |
29 debug("Try invalid arguments for setColor()"); | |
30 shouldThrow("stopColor.setColor(null, null, null)"); | |
31 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_RGBCOLOR, svgElement, '')
;"); | |
32 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_RGBCOLOR, '', '')"); | |
33 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_CURRENTCOLOR + 1, '', '')
;"); | |
34 shouldThrow("stopColor.setColor()"); | |
35 shouldThrow("stopColor.setColor(stopColor)"); | |
36 | |
37 debug(""); | |
38 debug("Try assigning to the readonly colorType property, which silently fails"); | |
39 shouldBeUndefined("stopColor.colorType = SVGColor.SVG_COLORTYPE_UNKKNOWN;"); | |
40 shouldBe("stopColor.colorType", "SVGColor.SVG_COLORTYPE_RGBCOLOR"); | |
41 shouldBeEqualToString("stopElement.style.stopColor", "#ff0000"); | |
42 shouldBeEqualToString("document.defaultView.getComputedStyle(stopElement).stopCo
lor", "rgb(255, 0, 0)"); | |
43 | |
44 debug(""); | |
45 debug("Test using setColor() and SVG_COLORTYPE_UNKNOWN"); | |
46 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_UNKKNOWN, '', '')"); | |
47 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_UNKKNOWN, 'rgb(0,128,128)
', '')"); | |
48 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_UNKKNOWN, '', 'icc-color(
myRGB, 0, 1, 2)')"); | |
49 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_UNKKNOWN, 'rgb(0,0,0)', '
icc-color(myRGB, 0, 1, 2)')"); | |
50 | |
51 debug(""); | |
52 debug("Test using setColor() and SVG_COLORTYPE_RGBCOLOR_ICCCOLOR"); | |
53 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_RGBCOLOR_ICCCOLOR, 'rgb(7
7,0,77)', 'icc-color(myRGB, 0, 1, 2)')"); | |
54 shouldBe("stopColor.colorType", "SVGColor.SVG_COLORTYPE_RGBCOLOR"); | |
55 // FIXME: No support for ICC colors. | |
56 checkStopColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 255, 0, 0); | |
57 shouldBeEqualToString("stopElement.style.stopColor", "#ff0000"); | |
58 shouldBeEqualToString("document.defaultView.getComputedStyle(stopElement).stopCo
lor", "rgb(255, 0, 0)"); | |
59 | |
60 debug(""); | |
61 debug("Test using setColor() and SVG_COLORTYPE_CURRENTCOLOR"); | |
62 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_CURRENTCOLOR, 'rgb(77,0,7
7)', 'icc-color(myRGB, 0, 1, 2)')"); | |
63 shouldBe("stopColor.colorType", "SVGColor.SVG_COLORTYPE_RGBCOLOR"); | |
64 checkStopColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 255, 0, 0); | |
65 shouldBeEqualToString("stopElement.style.stopColor", "#ff0000"); | |
66 shouldBeEqualToString("document.defaultView.getComputedStyle(stopElement).stopCo
lor", "rgb(255, 0, 0)"); | |
67 | |
68 debug(""); | |
69 debug("Test using setColor() and SVG_COLORTYPE_RGBCOLOR"); | |
70 shouldThrow("stopColor.setColor(SVGColor.SVG_COLORTYPE_RGBCOLOR, 'rgb(0,77,0)',
'icc-color(myRGB, 0, 1, 2)')"); | |
71 shouldBe("stopColor.colorType", "SVGColor.SVG_COLORTYPE_RGBCOLOR"); | |
72 checkStopColor("SVGColor.SVG_COLORTYPE_RGBCOLOR", 255, 0, 0); | |
73 shouldBeEqualToString("document.defaultView.getComputedStyle(stopElement).stopCo
lor", "rgb(255, 0, 0)"); | |
74 | |
75 successfullyParsed = true; | |
OLD | NEW |