5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8">
6 <title>CSSMediaRule functions test
</title>
8 @media all { .test { color: green; } }
11 function log(message
) {
12 var item
= document
.createElement("li");
13 item
.appendChild(document
.createTextNode(message
));
14 document
.getElementById("console").appendChild(item
);
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.
28 var index
= mediaRule
.insertRule(".test2 { color: blue; }", mediaRule
.cssRules
.length
);
29 log("PASS: No exception raised! New rule inserted successfully.");
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.
36 var index
= mediaRule
.insertRule("p {color: red; }", mediaRule
.cssRules
.length
+ 1);
37 log("FAIL: an exception should have been thrown!");
40 log("PASS: Exception raised successfully. Type: " + e
);
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.
47 var index
= mediaRule
.insertRule("p {color: red; }", -1);
48 log("FAIL: an exception should have been thrown!");
51 log("PASS: Exception raised successfully. Type: " + e
);
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.
58 var index
= mediaRule
.insertRule("badbeef }{", mediaRule
.cssRules
.length
);
59 log("FAIL: an exception should have been thrown!");
62 log("PASS: Exception raised successfully. Type: " + e
);
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.
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!");
74 log("PASS: Exception raised successfully. Type: " + e
);
76 log("FAIL: wrong exception type thrown. " + e
.code
+ " was thrown, should of been Error: HierarchyRequestError: DOM Exception 3!");
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!");
84 log("PASS: Exception raised successfully. Type: " + e
);
86 log("FAIL: wrong exception type thrown. " + e
.code
+ " was thrown, should of been Error: HierarchyRequestError: DOM Exception 3!");
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!");
93 // FIXME: this should throw a HIERARCHY_REQUEST_ERR, not a SYNTAX_ERR.
95 log("PASS: Exception raised successfully. Type: " + e
);
97 log("FAIL: wrong exception type thrown. " + e
+ " was thrown, should of been Error: SyntaxError: DOM Exception 12!");
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!");
104 // FIXME: this should throw a HIERARCHY_REQUEST_ERR, not a SYNTAX_ERR.
106 log("PASS: Exception raised successfully. Type: " + e
);
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.
116 mediaRule
.deleteRule(mediaRule
.cssRules
.length
- 1);
117 log("PASS: No exception raised! Rule at position 'length - 1' deleted successfully.");
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.
125 mediaRule
.deleteRule(mediaRule
.cssRules
.length
);
126 log("FAIL: an exception should have been thrown!");
129 log("PASS: Exception raised successfully. Type: " + e
);
131 log("FAIL: wrong exception type thrown. " + e
+ " was thrown, should of been 'Error: IndexSizeError: DOM Exception 1'.");
134 mediaRule
.deleteRule(-1);
135 log("FAIL: an exception should have been thrown!");
138 log("PASS: Exception raised successfully. Type: " + e
);
140 log("FAIL: wrong exception type thrown. " + e
+ " was thrown, should of been 'Error: IndexSizeError: DOM Exception 1'.");
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".