OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <style> | 3 <style> |
4 .failed { | 4 .failed { |
5 color: red; | 5 color: red; |
6 font-weight: bold; | 6 font-weight: bold; |
7 } | 7 } |
8 | 8 |
9 .passed { | 9 .passed { |
10 color: green; | 10 color: green; |
11 font-weight: bold; | 11 font-weight: bold; |
12 } | 12 } |
13 </style> | 13 </style> |
14 <script> | 14 <script> |
15 if (window.testRunner) | 15 if (window.testRunner) |
16 window.testRunner.dumpAsText(); | 16 window.testRunner.dumpAsText(); |
17 var count = 0; | 17 var count = 0; |
18 | 18 |
19 function shouldThrowException(node) | 19 function shouldThrowException(node) |
20 { | 20 { |
21 document.body.appendChild(document.createElement("br")); | 21 document.body.appendChild(document.createElement("br")); |
22 var header = document.createElement("div"); | 22 var header = document.createElement("div"); |
23 header.textContent = ++count + ". Verifying XMLSerializer.serializeToString(
) should THROW exception with node value = " + node; | 23 header.textContent = ++count + ". Verifying XMLSerializer.serializeToString(
) should THROW exception with " + (arguments.length ? "argument " + node : "no a
rgument"); |
24 document.body.appendChild(header); | 24 document.body.appendChild(header); |
25 | 25 |
26 var xs = new XMLSerializer(); | 26 var xs = new XMLSerializer(); |
27 try { | 27 try { |
28 var str = xs.serializeToString(node); | 28 var str = xs.serializeToString.apply(xs, arguments); |
29 | 29 |
30 var result = document.createElement("div"); | 30 var result = document.createElement("div"); |
31 result.className = "failed" | 31 result.className = "failed" |
32 result.textContent = "FAIL"; | 32 result.textContent = "FAIL"; |
33 document.body.appendChild(result); | 33 document.body.appendChild(result); |
34 } catch (exception) { | 34 } catch (exception) { |
35 var err = "Exception thrown = [" + exception.name + ": " + exception.mes
sage + "]"; | 35 var err = "Exception thrown = [" + exception.name + ": " + exception.mes
sage + "]"; |
36 var content = document.createElement("div"); | 36 var content = document.createElement("div"); |
37 content.textContent = err; | 37 content.textContent = err; |
38 document.body.appendChild(content); | 38 document.body.appendChild(content); |
39 | 39 |
40 var result = document.createElement("div"); | 40 var result = document.createElement("div"); |
41 result.className = "passed" | 41 result.className = "passed" |
42 result.textContent = "PASS"; | 42 result.textContent = "PASS"; |
43 document.body.appendChild(result); | 43 document.body.appendChild(result); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 function shouldNOTThrowException(node) | 47 function shouldNOTThrowException(node) |
48 { | 48 { |
49 document.body.appendChild(document.createElement("br")); | 49 document.body.appendChild(document.createElement("br")); |
50 var header = document.createElement("div"); | 50 var header = document.createElement("div"); |
51 header.textContent = ++count + ". Verifying XMLSerializer.serializeToString(
) should NOT-THROW exception with node value = " + node; | 51 header.textContent = ++count + ". Verifying XMLSerializer.serializeToString(
) should NOT-THROW exception with argument " + node; |
52 document.body.appendChild(header); | 52 document.body.appendChild(header); |
53 | 53 |
54 var xs = new XMLSerializer(); | 54 var xs = new XMLSerializer(); |
55 try { | 55 try { |
56 var str = xs.serializeToString(node); | 56 var str = xs.serializeToString(node); |
57 | 57 |
58 var result = document.createElement("div"); | 58 var result = document.createElement("div"); |
59 result.className = "passed" | 59 result.className = "passed" |
60 result.textContent = "PASS"; | 60 result.textContent = "PASS"; |
61 document.body.appendChild(result); | 61 document.body.appendChild(result); |
62 } catch (exception) { | 62 } catch (exception) { |
63 var err = "Exception thrown = [" + exception.name + ": " + exception.mes
sage + "]"; | 63 var err = "Exception thrown = [" + exception.name + ": " + exception.mes
sage + "]"; |
64 var content = document.createElement("div"); | 64 var content = document.createElement("div"); |
65 content.textContent = err; | 65 content.textContent = err; |
66 document.body.appendChild(content); | 66 document.body.appendChild(content); |
67 | 67 |
68 var result = document.createElement("div"); | 68 var result = document.createElement("div"); |
69 result.className = "failed" | 69 result.className = "failed" |
70 result.textContent = "FAIL"; | 70 result.textContent = "FAIL"; |
71 document.body.appendChild(result); | 71 document.body.appendChild(result); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 function runTest() | 75 function runTest() |
76 { | 76 { |
| 77 shouldThrowException(); |
77 shouldThrowException(null); | 78 shouldThrowException(null); |
78 shouldThrowException(undefined); | 79 shouldThrowException(undefined); |
79 shouldThrowException("<html><title>Hello World</title></html>"); | 80 shouldThrowException("<html><title>Hello World</title></html>"); |
80 shouldThrowException(document.children); | 81 shouldThrowException(document.children); |
81 | 82 |
82 shouldNOTThrowException(document); | 83 shouldNOTThrowException(document); |
83 shouldNOTThrowException(document.documentElement); | 84 shouldNOTThrowException(document.documentElement); |
84 shouldNOTThrowException(document.firstChild); | 85 shouldNOTThrowException(document.firstChild); |
85 shouldNOTThrowException(document.createElement("div")); | 86 shouldNOTThrowException(document.createElement("div")); |
86 shouldNOTThrowException(document.getElementById("heading")); | 87 shouldNOTThrowException(document.getElementById("heading")); |
87 shouldNOTThrowException(document.createElement("custom")); | 88 shouldNOTThrowException(document.createElement("custom")); |
88 | 89 |
89 var domParser = new DOMParser(); | 90 var domParser = new DOMParser(); |
90 | 91 |
91 var htmlDoc = domParser.parseFromString("<html/>", "text/html"); | 92 var htmlDoc = domParser.parseFromString("<html/>", "text/html"); |
92 shouldNOTThrowException(htmlDoc); | 93 shouldNOTThrowException(htmlDoc); |
93 shouldNOTThrowException(htmlDoc.firstChild); | 94 shouldNOTThrowException(htmlDoc.firstChild); |
94 | 95 |
95 var xmlDoc = domParser.parseFromString("<root/>", "text/xml"); | 96 var xmlDoc = domParser.parseFromString("<root/>", "text/xml"); |
96 shouldNOTThrowException(xmlDoc); | 97 shouldNOTThrowException(xmlDoc); |
97 shouldNOTThrowException(xmlDoc.lastChild); | 98 shouldNOTThrowException(xmlDoc.lastChild); |
98 } | 99 } |
99 </script> | 100 </script> |
100 </head> | 101 </head> |
101 <body onload="runTest();"> | 102 <body onload="runTest();"> |
102 This tests XMLSerializer.serializeToString() throwing exception when node value
is invalid and passing otherwise. | 103 This tests XMLSerializer.serializeToString() throwing exception when node value
is invalid and passing otherwise. |
103 <h1 id="heading"/> | 104 <h1 id="heading"/> |
104 </body> | 105 </body> |
105 </html> | 106 </html> |
OLD | NEW |