summaryrefslogtreecommitdiffstats
path: root/layout/style/test/chrome/test_moz_document_rules.html
blob: 87fba40558e63fa5ee9da77945d31dfcb0af8ddc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for @-moz-document rules</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body onload="run()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=398962">Mozilla Bug 398962</a>
<iframe id="iframe" src="http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.html"></iframe>
<pre id="test">
<script type="application/javascript; version=1.8">

var [gStyleSheetService, gIOService] = (function() {
    return [
            Components.classes["@mozilla.org/content/style-sheet-service;1"]
                .getService(Components.interfaces.nsIStyleSheetService),
            Components.classes["@mozilla.org/network/io-service;1"]
                .getService(Components.interfaces.nsIIOService)
           ];
})();
function set_user_sheet(sheeturi)
{
    var uri = gIOService.newURI(sheeturi, null, null);
    gStyleSheetService.loadAndRegisterSheet(uri, gStyleSheetService.USER_SHEET);
}
function remove_user_sheet(sheeturi)
{
    var uri = gIOService.newURI(sheeturi, null, null);
    gStyleSheetService.unregisterSheet(uri, gStyleSheetService.USER_SHEET);
}

function run()
{
    var iframe = document.getElementById("iframe");
    var subdoc = iframe.contentDocument;
    var subwin = iframe.contentWindow;
    var cs = subwin.getComputedStyle(subdoc.getElementById("display"), "");
    var zIndexCounter = 0;

    function test_document_rule(urltests, shouldapply)
    {
        var zIndex = ++zIndexCounter;
        var encodedRule = encodeURI("@-moz-document " + urltests + " { ") +
                          "%23" + // encoded hash character for "#display"
                          encodeURI("display { z-index: " + zIndex + " } }");
        var sheeturi = "data:text/css," + encodedRule;
        set_user_sheet(sheeturi);
        if (shouldapply) {
            is(cs.zIndex, String(zIndex),
               "@-moz-document " + urltests +
               " should apply to this document");
        } else {
            is(cs.zIndex, "auto",
               "@-moz-document " + urltests +
               " should NOT apply to this document");
        }
        remove_user_sheet(sheeturi);
    }

    test_document_rule("domain(mochi.test)", true);
    test_document_rule("domain(\"mochi.test\")", true);
    test_document_rule("domain('mochi.test')", true);
    test_document_rule("domain('test')", true);
    test_document_rule("domain(.test)", false);
    test_document_rule("domain('.test')", false);
    test_document_rule("domain('ochi.test')", false);
    test_document_rule("domain(ochi.test)", false);
    test_document_rule("url-prefix(http://moch)", true);
    test_document_rule("url-prefix(http://och)", false);
    test_document_rule("url-prefix(http://mochi.test)", true);
    test_document_rule("url-prefix(http://mochi.test:88)", true);
    test_document_rule("url-prefix(http://mochi.test:8888)", true);
    test_document_rule("url-prefix(http://mochi.test:8888/)", true);
    test_document_rule("url-prefix('http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.html')", true);
    test_document_rule("url-prefix('http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.htmlx')", false);
    test_document_rule("url(http://mochi.test:8888/)", false);
    test_document_rule("url('http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.html')", true);
    test_document_rule("url('http://mochi.test:8888/tests/layout/style/test/chrome/moz_document_helper.htmlx')", false);
    test_document_rule("regexp(.*ochi.*)", false); // syntax error
    test_document_rule("regexp('.*ochi.*')", true);
    test_document_rule("regexp('ochi.*')", false);
    test_document_rule("regexp('.*ochi')", false);
    test_document_rule("regexp('http:.*ochi.*')", true);
    test_document_rule("regexp('http:.*ochi')", false);
    test_document_rule("regexp('http:.*oCHi.*')", false); // case sensitive

    SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();

</script>
</pre>
</body>
</html>