test_parseStyleSheetImport.html (3125B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1202095 5 --> 6 <head> 7 <title>Test for Bug 1202095</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 <style> 11 @import url('bug1202095.css'); 12 @import url('bug1202095-2.css'); 13 </style> 14 </head> 15 <body> 16 <script type="application/javascript"> 17 const InspectorUtils = SpecialPowers.InspectorUtils; 18 19 function do_test() { 20 var sheet = document.styleSheets[1]; 21 var importRule = sheet.cssRules[0]; 22 is(importRule.type, CSSRule.IMPORT_RULE, 23 "initial sheet has @import rule"); 24 25 var importedSheet = importRule.styleSheet; 26 importedSheet.deleteRule(0); 27 is(importedSheet.cssRules.length, 0, "imported sheet now has no rules"); 28 29 // "suffixed" refers to the "-2". 30 var suffixedSheet = sheet.cssRules[1].styleSheet; 31 InspectorUtils.parseStyleSheet(suffixedSheet, ""); 32 is(suffixedSheet.cssRules.length, 0, "second imported sheet now has no rules"); 33 34 // Re-parse the style sheet, preserving the imports. 35 InspectorUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');" + 36 "@import url('bug1202095-2.css');"); 37 is(sheet.cssRules[0].type, CSSRule.IMPORT_RULE, 38 "re-parsed sheet has @import rule"); 39 is(sheet.cssRules[0].styleSheet, importedSheet, 40 "imported sheet has not changed"); 41 is(sheet.cssRules[1].styleSheet, suffixedSheet, 42 "second imported sheet has not changed"); 43 44 // Re-parse the style sheet, preserving both imports, but changing 45 // the order. 46 InspectorUtils.parseStyleSheet(sheet, "@import url('bug1202095-2.css');" + 47 "@import url('bug1202095.css');"); 48 is(sheet.cssRules[0].styleSheet, suffixedSheet, 49 "reordering preserved suffixed style sheet"); 50 is(sheet.cssRules[1].styleSheet, importedSheet, 51 "reordering preserved unsuffixed style sheet"); 52 53 // Re-parse the style sheet, removing the imports. 54 InspectorUtils.parseStyleSheet(sheet, ""); 55 is(sheet.cssRules.length, 0, "style sheet now has no rules"); 56 57 // Re-parse the style sheet, adding one import back. This should 58 // not allow reuse. 59 InspectorUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');"); 60 is(sheet.cssRules[0].type, CSSRule.IMPORT_RULE, 61 "re-re-re-parsed sheet has @import rule"); 62 isnot(sheet.cssRules[0].styleSheet, importedSheet, 63 "imported sheet has changed now"); 64 65 // Re-parse the style sheet, importing the same URL twice. 66 // The style sheet should be reused once, but not two times. 67 importedSheet = sheet.cssRules[0].styleSheet; 68 InspectorUtils.parseStyleSheet(sheet, "@import url('bug1202095.css');" + 69 "@import url('bug1202095.css');"); 70 is(sheet.cssRules[0].styleSheet, importedSheet, 71 "first imported sheet is reused"); 72 isnot(sheet.cssRules[1].styleSheet, importedSheet, 73 "second imported sheet is reused"); 74 75 SimpleTest.finish(); 76 } 77 78 SimpleTest.waitForExplicitFinish(); 79 addLoadEvent(do_test); 80 </script> 81 </body> 82 </html>