Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / css-mediarule-functions.html
blob381ec5a133e9d04060c7ac3f4f317396aa1c01ae
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.testRunner)
19 testRunner.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: IndexSizeError: 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: IndexSizeError: 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: SyntaxError: DOM Exception 12!");
67 // Test that insertRule raises an exception for illegally placed rules.
68 try {
69 // NamespaceRule illegal inside a MediaRule.
70 var index = mediaRule.insertRule("@namespace mynamespace url(http://www.w3.org/1999/xhtml);", 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: HierarchyRequestError: DOM Exception 3!");
78 try {
79 // ImportRule illegal inside a MediaRule.
80 var index = mediaRule.insertRule("@import url(sheet.css);", mediaRule.cssRules.length);
81 log("FAIL: an exception should have been thrown!");
82 } catch (e) {
83 if (e.code == 3)
84 log("PASS: Exception raised successfully. Type: " + e);
85 else
86 log("FAIL: wrong exception type thrown. " + e.code + " was thrown, should of been Error: HierarchyRequestError: DOM Exception 3!");
88 try {
89 // CharsetRule illegal inside a MediaRule.
90 var index = mediaRule.insertRule("@charset \"ISO-8859-1\";", mediaRule.cssRules.length);
91 log("FAIL: an exception should have been thrown!");
92 } catch (e) {
93 // FIXME: this should throw a HIERARCHY_REQUEST_ERR, not a SYNTAX_ERR.
94 if (e.code == 12)
95 log("PASS: Exception raised successfully. Type: " + e);
96 else
97 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been Error: SyntaxError: DOM Exception 12!");
99 try {
100 // Nested MediaRule illegal inside a MediaRule.
101 var index = mediaRule.insertRule("@media screen { p { color: red; } };", mediaRule.cssRules.length);
102 log("FAIL: an exception should have been thrown!");
103 } catch (e) {
104 // FIXME: this should throw a HIERARCHY_REQUEST_ERR, not a SYNTAX_ERR.
105 if (e.code == 12)
106 log("PASS: Exception raised successfully. Type: " + e);
107 else
108 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been Error: SyntaxError: DOM Exception 12!");
112 // CSSMediaRule.deleteRule(index) tests
114 // Test that deleteRule works.
115 try {
116 mediaRule.deleteRule(mediaRule.cssRules.length - 1);
117 log("PASS: No exception raised! Rule at position 'length - 1' deleted successfully.");
118 } catch (e) {
119 log("FAIL: no exception should have been thrown! Type of thrown exception was: " + e);
122 // Test that deleteRule raises an exception for specified indexes not corresponding to a
123 // rule in the media rule list.
124 try {
125 mediaRule.deleteRule(mediaRule.cssRules.length);
126 log("FAIL: an exception should have been thrown!");
127 } catch (e) {
128 if (e.code == 1)
129 log("PASS: Exception raised successfully. Type: " + e);
130 else
131 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been 'Error: IndexSizeError: DOM Exception 1'.");
133 try {
134 mediaRule.deleteRule(-1);
135 log("FAIL: an exception should have been thrown!");
136 } catch (e) {
137 if (e.code == 1)
138 log("PASS: Exception raised successfully. Type: " + e);
139 else
140 log("FAIL: wrong exception type thrown. " + e + " was thrown, should of been 'Error: IndexSizeError: DOM Exception 1'.");
143 </script>
144 </head>
145 <body onload="test();">
146 <p>This tests the insertRule(rule, index) and deleteRule(index) methods of the CSSMediaRule interface. It has passed if
147 all of the output below begins with the text "PASS".
148 <ol id="console">
149 </ol>
150 </body>
151 </html>