blob: 86016ef5a3db6636bf97edc58992f30f909c13a2 [file] [log] [blame]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CSSOM - CSSStyleSheet interface</title>
<link rel="help" href="https://drafts.csswg.org/cssom/#the-cssstylesheet-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style id="my-stylesheet">
body { width: 50%; }
#foo { height: 100px; }
</style>
<script>
test(function () {
var styleSheet = document.styleSheets[0];
styleSheet.cssRules[0].randomProperty = 1;
styleSheet.cssRules[1].randomProperty = 2;
assert_equals(styleSheet, document.getElementById("my-stylesheet").sheet, "CSSStyleSheet and LinkStyle's sheet attribute");
assert_equals(styleSheet.cssRules.length, 2, "CSSStyleSheet cssRules attribute");
assert_equals(styleSheet.cssRules[0].cssText, "body { width: 50%; }", "CSSStyleSheet cssRules attribute");
assert_equals(styleSheet.cssRules[1].cssText, "#foo { height: 100px; }", "CSSStyleSheet cssRules attribute");
assert_equals(styleSheet.cssRules[2], undefined, "CSSStyleSheet cssRules attribute");
styleSheet.insertRule("#bar { margin: 10px; }", 1);
assert_equals(styleSheet.cssRules.length, 3, "CSSStyleSheet cssRules attribute after insertRule function");
assert_equals(styleSheet.cssRules[0].cssText, "body { width: 50%; }", "CSSStyleSheet cssRules attribute");
assert_equals(styleSheet.cssRules[1].cssText, "#bar { margin: 10px; }", "CSSStyleSheet cssRules attribute after insertRule function");
assert_equals(styleSheet.cssRules[2].cssText, "#foo { height: 100px; }", "CSSStyleSheet cssRules attribute after insertRule function");
assert_equals(styleSheet.cssRules[0].randomProperty, 1, "[SameObject] cssRules attribute after insertRule function");
assert_equals(styleSheet.cssRules[2].randomProperty, 2, "[SameObject] cssRules attribute after insertRule function");
styleSheet.deleteRule(1);
assert_equals(styleSheet.cssRules.length, 2, "CSSStyleSheet cssRules attribute after deleteRule function");
assert_equals(styleSheet.cssRules[0].cssText, "body { width: 50%; }", "CSSStyleSheet cssRules attribute after deleteRule function");
assert_equals(styleSheet.cssRules[1].cssText, "#foo { height: 100px; }", "CSSStyleSheet cssRules attribute after deleteRule function");
assert_equals(styleSheet.cssRules[2], undefined, "CSSStyleSheet cssRules attribute after deleteRule function");
assert_equals(styleSheet.cssRules[0].randomProperty, 1, "[SameObject] cssRules attribute after deleteRule function");
assert_equals(styleSheet.cssRules[1].randomProperty, 2, "[SameObject] cssRules attribute after deleteRule function");
});
</script>
</head>
</html>