cssimportrule.html (5678B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>CSSOM CSSRule CSSImportRule interface</title> 5 <link rel="author" title="Letitia Lew" href="mailto:lew.letitia@gmail.com"> 6 <link rel="help" href="http://www.w3.org/TR/cssom-1/#css-rules"> 7 <link rel="help" href="http://www.w3.org/TR/cssom-1/#the-cssrule-interface"> 8 <link rel="help" href="http://www.w3.org/TR/cssom-1/#the-cssimportrule-interface"> 9 <meta name="flags" content="dom"> 10 <meta name="assert" content="All properties for this CSSImportRule instance of CSSRule are initialized correctly"> 11 <script src="/resources/testharness.js"></script> 12 <script src="/resources/testharnessreport.js"></script> 13 14 <style id="styleElement" type="text/css"> 15 @import url("support/a-green.css"); 16 @import url("support/a-green.css") screen; 17 @import url("support/a-green.css") all; 18 @import url("support/a-green") supports((display: flex) or (display: block)); 19 @import url('quote"quote'); 20 @page { background-color: red; } 21 </style> 22 </head> 23 <body> 24 <div id="log"></div> 25 26 <script type="text/javascript"> 27 var styleSheet, ruleList, rule, ruleWithMedia, ruleWithMediaAll, ruleWithSupports, ruleWithQuote; 28 setup(function() { 29 styleSheet = document.getElementById("styleElement").sheet; 30 ruleList = styleSheet.cssRules; 31 rule = ruleList[0]; 32 ruleWithMedia = ruleList[1]; 33 ruleWithMediaAll = ruleList[2]; 34 ruleWithSupports = ruleList[3]; 35 ruleWithQuote = ruleList[4]; 36 }); 37 38 test(function() { 39 assert_true(rule instanceof CSSRule); 40 assert_true(rule instanceof CSSImportRule); 41 assert_true(ruleWithMedia instanceof CSSRule); 42 assert_true(ruleWithMedia instanceof CSSImportRule); 43 assert_true(ruleWithSupports instanceof CSSRule); 44 assert_true(ruleWithSupports instanceof CSSImportRule); 45 }, "CSSRule and CSSImportRule types"); 46 47 test(function() { 48 assert_equals(rule.STYLE_RULE, 1); 49 assert_equals(rule.IMPORT_RULE, 3); 50 assert_equals(rule.MEDIA_RULE, 4); 51 assert_equals(rule.FONT_FACE_RULE, 5); 52 assert_equals(rule.PAGE_RULE, 6); 53 assert_equals(rule.NAMESPACE_RULE, 10); 54 assert_idl_attribute(rule, "type"); 55 assert_equals(typeof rule.type, "number"); 56 }, "Type of CSSRule#type and constant values"); 57 58 test(function() { 59 assert_true(rule instanceof CSSRule); 60 assert_idl_attribute(rule, "cssText"); 61 assert_idl_attribute(rule, "parentRule"); 62 assert_idl_attribute(rule, "parentStyleSheet"); 63 64 assert_readonly(rule, "type"); 65 assert_readonly(rule, "parentRule"); 66 assert_readonly(rule, "parentStyleSheet"); 67 }, "Existence and writability of CSSRule attributes"); 68 69 test(function() { 70 assert_equals(rule.type, rule.IMPORT_RULE); 71 assert_equals(typeof rule.cssText, "string"); 72 assert_equals(rule.cssText, '@import url("support/a-green.css");'); 73 assert_equals(ruleWithMedia.cssText, '@import url("support/a-green.css") screen;'); 74 assert_equals(ruleWithMediaAll.cssText, '@import url("support/a-green.css") all;'); 75 assert_equals(ruleWithSupports.cssText, '@import url("support/a-green") supports((display: flex) or (display: block));'); 76 assert_equals(ruleWithQuote.cssText, '@import url("quote\\\"quote");'); 77 assert_equals(rule.parentRule, null); 78 assert_true(rule.parentStyleSheet instanceof CSSStyleSheet); 79 }, "Values of CSSRule attributes"); 80 81 test(function() { 82 assert_idl_attribute(rule, "href"); 83 assert_idl_attribute(rule, "media"); 84 assert_idl_attribute(rule, "styleSheet"); 85 86 assert_readonly(rule, "href"); 87 assert_readonly(rule, "styleSheet"); 88 }, "Existence and writability of CSSImportRule attributes"); 89 90 test(function() { 91 assert_equals(typeof rule.href, "string"); 92 assert_true(rule.media instanceof MediaList); 93 assert_true(rule.styleSheet instanceof CSSStyleSheet); 94 assert_true(ruleWithMedia.media.length > 0); 95 assert_equals(ruleWithMedia.media.mediaText, "screen"); 96 }, "Values of CSSImportRule attributes"); 97 98 test(function() { 99 ruleWithMedia.media = "print"; 100 assert_equals(ruleWithMedia.media.mediaText, "print"); 101 }, "CSSImportRule : MediaList mediaText attribute should be updated due to [PutForwards]"); 102 103 test(function() { 104 var ruleWithPage = ruleList[5]; 105 ruleWithPage.style = "margin-top: 10px;" 106 assert_equals(ruleWithPage.style.cssText, "margin-top: 10px;"); 107 }, "CSSStyleDeclaration cssText attribute should be updated due to [PutForwards]"); 108 109 test(function() { 110 styleSheet.media = "screen"; 111 assert_equals(styleSheet.media.mediaText, "screen"); 112 }, "StyleSheet : MediaList mediaText attribute should be updated due to [PutForwards]"); 113 114 test(function() { 115 assert_idl_attribute(ruleWithSupports, "supportsText"); 116 assert_readonly(ruleWithSupports, "supportsText"); 117 }, "Existence and writability of CSSImportRule supportsText attribute"); 118 119 test(function() { 120 assert_equals(ruleWithSupports.supportsText, "(display: flex) or (display: block)"); 121 }, "Value of CSSImportRule supportsText attribute"); 122 </script> 123 </body> 124 </html>