LayoutTests:
[WebKit-https.git] / LayoutTests / fast / dom / svg-element-attribute-js-null.xhtml
1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <head>
3     <style type="text/css">
4         .pass { color: green; }
5         .fail { color: red; }
6     </style>
7     <script type="text/javascript" charset="utf-8">
8         function printOut(msg)
9         {
10             var console = document.getElementById("console");
11             var span = document.createElementNS('http://www.w3.org/1999/xhtml', 'span');
12             span.appendChild(document.createTextNode(msg));
13             span.appendChild(document.createElementNS('http://www.w3.org/1999/xhtml', 'br'));
14             console.appendChild(span);
15         }
16
17         function resultStringifier(result)
18         {
19             if (result === "")
20                 return "the empty string";
21             else if (result === undefined)
22                 return "undefined";
23             else if (result === null)
24                 return "null";
25             return "the string '" + result + "'";
26         }
27
28         function nullTestElementAttribute(elementType, element, attr, expected)
29         {
30             element[attr] = null;
31
32             var result;
33             if (element[attr] === expected)
34                 result = "TEST SUCCEEDED: The value was " + resultStringifier(expected) + ".";
35             else
36                 result = "TEST FAILED: The value should have been " + resultStringifier(expected) + " but was " + resultStringifier(element[attr]) + ".";
37
38             result += " [tested " + elementType + "." + attr + "]";
39             printOut(result);
40         }
41         
42         function runTests()
43         {
44             if (window.layoutTestController)
45                 layoutTestController.dumpAsText();
46
47             var svgNS = 'http://www.w3.org/2000/svg';
48             var svg = document.createElementNS(svgNS, 'svg');
49
50             var listing = [
51                 {
52                     type: 'SVGElement',
53                     elementToUse: svg,
54                     attributes: [
55                         {name: 'id', expectedNull: ''},
56                         {name: 'xmlbase', expectedNull: ''}
57                     ]
58                 },
59                 {
60                     type: 'SVGAngle',
61                     elementToUse: svg.createSVGAngle(),
62                     attributes: [
63                         {name: 'valueAsString', expectedNull: '0deg'}
64                     ]
65                 },
66                 {
67                     type: 'SVGLength',
68                     elementToUse: svg.createSVGLength(),
69                     attributes: [
70                         {name: 'valueAsString', expectedNull: '0'}
71                     ]
72                 },
73                 {
74                     type: 'SVGScriptElement',
75                     elementToUse: document.createElementNS(svgNS, 'script'),
76                     attributes: [
77                         {name: 'type', expectedNull: ''}
78                     ]
79                 }
80             ];
81
82             for (element in listing) {
83                 var type = listing[element].type;
84                 var elementToUse = listing[element].elementToUse;
85                 var attrs = listing[element].attributes;
86                 for (attr in attrs) {
87                     nullTestElementAttribute(type, elementToUse, attrs[attr].name, attrs[attr].expectedNull);
88                 }
89                 printOut('');
90             }
91         }
92         
93     </script>
94 </head>
95
96 <body onload="runTests();">
97     <p>This test setting various attributes of a SVG elements to JavaScript null.</p>
98     <div id="console"></div>
99 </body>
100 </html>