layout/style/test/chrome/test_moz_document_rules.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <title>Test for @-moz-document rules</title>
     5   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     6   <script type="application/javascript" 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; version=1.8">
    15 var [gStyleSheetService, gIOService] = (function() {
    16     return [
    17             Components.classes["@mozilla.org/content/style-sheet-service;1"]
    18                 .getService(Components.interfaces.nsIStyleSheetService),
    19             Components.classes["@mozilla.org/network/io-service;1"]
    20                 .getService(Components.interfaces.nsIIOService)
    21            ];
    22 })();
    23 function set_user_sheet(sheeturi)
    24 {
    25     var uri = gIOService.newURI(sheeturi, null, null);
    26     gStyleSheetService.loadAndRegisterSheet(uri, gStyleSheetService.USER_SHEET);
    27 }
    28 function remove_user_sheet(sheeturi)
    29 {
    30     var uri = gIOService.newURI(sheeturi, null, null);
    31     gStyleSheetService.unregisterSheet(uri, gStyleSheetService.USER_SHEET);
    32 }
    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;
    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, 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     }
    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
    89     SimpleTest.finish();
    90 }
    92 SimpleTest.waitForExplicitFinish();
    94 </script>
    95 </pre>
    96 </body>
    97 </html>

mercurial