2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / LayoutTests / fast / dom / css-mediarule-functions.html
blobfa4d54ff464a0f9d822e1b9e6543e375450c0bbc
1 <!DOCTYPE html>
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>CSSMediaRule functions test</title>
7 <style id="style1">
8 @media all { .test { color: green; } }
9 </style>
10 <script>
11 function log(message) {
12 var item = document.createElement("li");
13 item.appendChild(document.createTextNode(message));
14 document.getElementById("console").appendChild(item);
17 function test() {
18 if (window.layoutTestController)
19 layoutTestController.dumpAsText();
21 var styleSheet = document.getElementById('style1').sheet;
22 var mediaRule = styleSheet.cssRules[0];
24 // CSSMediaRule.insertRule(rule, index) tests
26 // Test that insertRule works.
27 try {
28 var index = mediaRule.insertRule(".test2 { color: blue; }", mediaRule.cssRules.length);
29 log("PASS: No exception raised! New rule inserted successfully.");
30 } catch (e) {
31 log("FAIL: no exception should have been thrown! Type of thrown exception was: " + e);
34 // Test that insertRule raises an exception for indexes greater than the length of the list.
35 try {
36 var index = mediaRule.insertRule("p {color: red; }", mediaRule.cssRules.length + 1);
37 log("FAIL: an exception should have been thrown!");
38 } catch (e) {
39 if (e.code == 1)
40 log("PASS: Exception raised successfully. Type: " + e);
41 else
42 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been 'Error: INDEX_SIZE_ERR: DOM Exception 1'.");
45 // Test that insertRule raises an exception for indexes less than 0.
46 try {
47 var index = mediaRule.insertRule("p {color: red; }", -1);
48 log("FAIL: an exception should have been thrown!");
49 } catch (e) {
50 if (e.code == 1)
51 log("PASS: Exception raised successfully. Type: " + e);
52 else
53 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been 'Error: INDEX_SIZE_ERR: DOM Exception 1'.");
56 // Test that insertRule raises an exception for malformed rules.
57 try {
58 var index = mediaRule.insertRule("badbeef }{", mediaRule.cssRules.length);
59 log("FAIL: an exception should have been thrown!");
60 } catch (e) {
61 if (e.code == 12)
62 log("PASS: Exception raised successfully. Type: " + e);
63 else
64 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been Error: SYNTAX_ERR: DOM Exception 12!");
67 // Test that insertRule raises an exception for illegally placed rules.
68 try {
69 // ImportRule illegal inside a MediaRule.
70 var index = mediaRule.insertRule("@import url(sheet.css);", mediaRule.cssRules.length);
71 log("FAIL: an exception should have been thrown!");
72 } catch (e) {
73 if (e.code == 3)
74 log("PASS: Exception raised successfully. Type: " + e);
75 else
76 log("FAIL: wrong exception type thrown. " + e.code + " was thrown, should of been Error: HIERARCHY_REQUEST_ERR: DOM Exception 3!");
78 try {
79 // CharsetRule illegal inside a MediaRule.
80 var index = mediaRule.insertRule("@charset \"ISO-8859-1\";", mediaRule.cssRules.length);
81 log("FAIL: an exception should have been thrown!");
82 } catch (e) {
83 // FIXME: this should throw a HIERARCHY_REQUEST_ERR, not a SYNTAX_ERR.
84 if (e.code == 12)
85 log("PASS: Exception raised successfully. Type: " + e);
86 else
87 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been Error: SYNTAX_ERR: DOM Exception 12!");
89 try {
90 // Nested MediaRule illegal inside a MediaRule.
91 var index = mediaRule.insertRule("@media screen { p { color: red; } };", mediaRule.cssRules.length);
92 log("FAIL: an exception should have been thrown!");
93 } catch (e) {
94 // FIXME: this should throw a HIERARCHY_REQUEST_ERR, not a SYNTAX_ERR.
95 if (e.code == 12)
96 log("PASS: Exception raised successfully. Type: " + e);
97 else
98 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been Error: SYNTAX_ERR: DOM Exception 12!");
102 // CSSMediaRule.deleteRule(index) tests
104 // Test that deleteRule works.
105 try {
106 mediaRule.deleteRule(mediaRule.cssRules.length - 1);
107 log("PASS: No exception raised! Rule at position 'length - 1' deleted successfully.");
108 } catch (e) {
109 log("FAIL: no exception should have been thrown! Type of thrown exception was: " + e);
112 // Test that deleteRule raises an exception for specified indexes not corresponding to a
113 // rule in the media rule list.
114 try {
115 mediaRule.deleteRule(mediaRule.cssRules.length);
116 log("FAIL: an exception should have been thrown!");
117 } catch (e) {
118 if (e.code == 1)
119 log("PASS: Exception raised successfully. Type: " + e);
120 else
121 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been 'Error: INDEX_SIZE_ERR: DOM Exception 1'.");
123 try {
124 mediaRule.deleteRule(-1);
125 log("FAIL: an exception should have been thrown!");
126 } catch (e) {
127 if (e.code == 1)
128 log("PASS: Exception raised successfully. Type: " + e);
129 else
130 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been 'Error: INDEX_SIZE_ERR: DOM Exception 1'.");
133 </script>
134 </head>
135 <body onload="test();">
136 <p>This tests the insertRule(rule, index) and deleteRule(index) methods of the CSSMediaRule interface. It has passed if
137 all of the output below begins with the text "PASS".
138 <ol id="console">
139 </ol>
140 </body>
141 </html>