blob: 62ad133d5f60ab12ad85182091d45e2a88d3e63a [file] [log] [blame]
Nazım Can Altınovada50ea22016-12-28 08:45:341<!doctype html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <title>CSSOM - CSSStyleSheet interface</title>
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8 <style id="my-stylesheet">
9 body { width: 50%; }
10 #foo { height: 100px; }
11 </style>
12
13 <script>
14 test(function () {
15 var styleSheet = document.styleSheets[0];
16 styleSheet.cssRules[0].randomProperty = 1;
17 styleSheet.cssRules[1].randomProperty = 2;
18
19 assert_equals(styleSheet, document.getElementById("my-stylesheet").sheet, "CSSStyleSheet and LinkStyle's sheet attribute");
20 assert_equals(styleSheet.cssRules.length, 2, "CSSStyleSheet cssRules attribute");
21 assert_equals(styleSheet.cssRules[0].cssText, "body { width: 50%; }", "CSSStyleSheet cssRules attribute");
22 assert_equals(styleSheet.cssRules[1].cssText, "#foo { height: 100px; }", "CSSStyleSheet cssRules attribute");
23 assert_equals(styleSheet.cssRules[2], undefined, "CSSStyleSheet cssRules attribute");
24
25 styleSheet.insertRule("#bar { margin: 10px; }", 1);
26 assert_equals(styleSheet.cssRules.length, 3, "CSSStyleSheet cssRules attribute after insertRule function");
27 assert_equals(styleSheet.cssRules[0].cssText, "body { width: 50%; }", "CSSStyleSheet cssRules attribute");
28 assert_equals(styleSheet.cssRules[1].cssText, "#bar { margin: 10px; }", "CSSStyleSheet cssRules attribute after insertRule function");
29 assert_equals(styleSheet.cssRules[2].cssText, "#foo { height: 100px; }", "CSSStyleSheet cssRules attribute after insertRule function");
30 assert_equals(styleSheet.cssRules[0].randomProperty, 1, "[SameObject] cssRules attribute after insertRule function");
31 assert_equals(styleSheet.cssRules[2].randomProperty, 2, "[SameObject] cssRules attribute after insertRule function");
32
33 styleSheet.deleteRule(1);
34 assert_equals(styleSheet.cssRules.length, 2, "CSSStyleSheet cssRules attribute after deleteRule function");
35 assert_equals(styleSheet.cssRules[0].cssText, "body { width: 50%; }", "CSSStyleSheet cssRules attribute after deleteRule function");
36 assert_equals(styleSheet.cssRules[1].cssText, "#foo { height: 100px; }", "CSSStyleSheet cssRules attribute after deleteRule function");
37 assert_equals(styleSheet.cssRules[2], undefined, "CSSStyleSheet cssRules attribute after deleteRule function");
38 assert_equals(styleSheet.cssRules[0].randomProperty, 1, "[SameObject] cssRules attribute after deleteRule function");
39 assert_equals(styleSheet.cssRules[1].randomProperty, 2, "[SameObject] cssRules attribute after deleteRule function");
40 });
41 </script>
42</head>
43</html>