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
.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.
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: INDEX_SIZE_ERR: 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: INDEX_SIZE_ERR: 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: SYNTAX_ERR: DOM Exception 12!");
67 // Test that insertRule raises an exception for illegally placed rules.
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!");
74 log("PASS: Exception raised successfully. Type: " + e
);
76 log("FAIL: wrong exception type thrown. " + e
.code
+ " was thrown, should of been Error: HIERARCHY_REQUEST_ERR: DOM Exception 3!");
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!");
83 // FIXME: this should throw a HIERARCHY_REQUEST_ERR, not a SYNTAX_ERR.
85 log("PASS: Exception raised successfully. Type: " + e
);
87 log("FAIL: wrong exception type thrown. " + e
+ " was thrown, should of been Error: SYNTAX_ERR: DOM Exception 12!");
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!");
94 // FIXME: this should throw a HIERARCHY_REQUEST_ERR, not a SYNTAX_ERR.
96 log("PASS: Exception raised successfully. Type: " + e
);
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.
106 mediaRule
.deleteRule(mediaRule
.cssRules
.length
- 1);
107 log("PASS: No exception raised! Rule at position 'length - 1' deleted successfully.");
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.
115 mediaRule
.deleteRule(mediaRule
.cssRules
.length
);
116 log("FAIL: an exception should have been thrown!");
119 log("PASS: Exception raised successfully. Type: " + e
);
121 log("FAIL: wrong exception type thrown. " + e
+ " was thrown, should of been 'Error: INDEX_SIZE_ERR: DOM Exception 1'.");
124 mediaRule
.deleteRule(-1);
125 log("FAIL: an exception should have been thrown!");
128 log("PASS: Exception raised successfully. Type: " + e
);
130 log("FAIL: wrong exception type thrown. " + e
+ " was thrown, should of been 'Error: INDEX_SIZE_ERR: DOM Exception 1'.");
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".