test_moz_document_rules.html (4164B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test for @-moz-document rules</title> 5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 7 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 8 </head> 9 <body onload="run()"> 10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=398962">Mozilla Bug 398962</a> 11 <iframe id="iframe" src="http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.html"></iframe> 12 <pre id="test"> 13 <script type="application/javascript"> 14 15 var [gStyleSheetService, gIOService] = (function() { 16 return [ 17 Cc["@mozilla.org/content/style-sheet-service;1"] 18 .getService(Ci.nsIStyleSheetService), 19 Cc["@mozilla.org/network/io-service;1"] 20 .getService(Ci.nsIIOService) 21 ]; 22 })(); 23 function set_user_sheet(sheeturi) 24 { 25 var uri = gIOService.newURI(sheeturi); 26 gStyleSheetService.loadAndRegisterSheet(uri, gStyleSheetService.USER_SHEET); 27 } 28 function remove_user_sheet(sheeturi) 29 { 30 var uri = gIOService.newURI(sheeturi); 31 gStyleSheetService.unregisterSheet(uri, gStyleSheetService.USER_SHEET); 32 } 33 34 function run() 35 { 36 var iframe = document.getElementById("iframe"); 37 var subdoc = iframe.contentDocument; 38 var subwin = iframe.contentWindow; 39 var cs = subwin.getComputedStyle(subdoc.getElementById("display")); 40 var zIndexCounter = 0; 41 42 function test_document_rule(urltests, shouldapply) 43 { 44 var zIndex = ++zIndexCounter; 45 var encodedRule = encodeURI("@-moz-document " + urltests + " { ") + 46 "%23" + // encoded hash character for "#display" 47 encodeURI("display { z-index: " + zIndex + " } }"); 48 var sheeturi = "data:text/css," + encodedRule; 49 set_user_sheet(sheeturi); 50 if (shouldapply) { 51 is(cs.zIndex, String(zIndex), 52 "@-moz-document " + urltests + 53 " should apply to this document"); 54 } else { 55 is(cs.zIndex, "auto", 56 "@-moz-document " + urltests + 57 " should NOT apply to this document"); 58 } 59 remove_user_sheet(sheeturi); 60 } 61 62 test_document_rule("domain(mochi.test)", true); 63 test_document_rule("domain(\"mochi.test\")", true); 64 test_document_rule("domain('mochi.test')", true); 65 test_document_rule("domain('test')", true); 66 test_document_rule("domain(.test)", false); 67 test_document_rule("domain('.test')", false); 68 test_document_rule("domain('ochi.test')", false); 69 test_document_rule("domain(ochi.test)", false); 70 test_document_rule("url-prefix(http://moch)", true); 71 test_document_rule("url-prefix(http://och)", false); 72 test_document_rule("url-prefix(http://mochi.test)", true); 73 test_document_rule("url-prefix(http://mochi.test:88)", true); 74 test_document_rule("url-prefix(http://mochi.test:8888)", true); 75 test_document_rule("url-prefix(http://mochi.test:8888/)", true); 76 test_document_rule("url-prefix('http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.html')", true); 77 test_document_rule("url-prefix('http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.htmlx')", false); 78 test_document_rule("url(http://mochi.test:8888/)", false); 79 test_document_rule("url('http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.html')", true); 80 test_document_rule("url('http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.htmlx')", false); 81 test_document_rule("regexp(.*ochi.*)", false); // syntax error 82 test_document_rule("regexp('.*ochi.*')", true); 83 test_document_rule("regexp('ochi.*')", false); 84 test_document_rule("regexp('.*ochi')", false); 85 test_document_rule("regexp('http:.*ochi.*')", true); 86 test_document_rule("regexp('http:.*ochi')", false); 87 test_document_rule("regexp('http:.*oCHi.*')", false); // case sensitive 88 89 SimpleTest.finish(); 90 } 91 92 SimpleTest.waitForExplicitFinish(); 93 94 </script> 95 </pre> 96 </body> 97 </html>