summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/media/mq-parsing.html
blob: 4dda62ad94b452f01ae6062cef3fe545d93957f7 (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
<html>
<head>
    <style type="text/css">
        @media screen {
            #console { color: black; }
        }
    </style>
    <script>
        function resultStringifier(result)
        {
            if (result === "")
                return "<b>\"\"</b>";
            else if (result === undefined)
                return "<b>undefined</b>";
            else if (result === null)
                return "<b>null</b>";
            return "\"" + result + "\"";
        }

        function printOut(expect, res) {
            var console = document.getElementById("console");
            var span = document.createElement('span');

            var a =  resultStringifier(expect);
            var b = resultStringifier(res);
            if (a === b)
                span.innerHTML += "PASS: Got " + b + " as expected.<br>";
            else
                span.innerHTML += "FAIL: Got " + b + " but was expecting " + a + "<br>";
            console.appendChild(span);
        }

        function runTests() {
            if (window.testRunner)
                testRunner.dumpAsText();

            var rules = document.styleSheets[0].cssRules;
            var mediaList = rules.item(0).media;

            printOut("screen", mediaList.mediaText);

            mediaList.mediaText = null;
            printOut("", mediaList.mediaText);

            mediaList.mediaText = "screen"
            mediaList.mediaText = ",,all,,";
            printOut("not all, not all, all, not all, not all", mediaList.mediaText);

            mediaList.mediaText = ",,all,, ";
            printOut("not all, not all, all, not all, not all", mediaList.mediaText);

            output = "all";
            try {
                mediaList.mediaText = ",screen,,&invalid,,";
            } catch(e) {
                output = null;
            }
            printOut("not all, screen, not all, not all, not all, not all", mediaList.mediaText);

            output = "all";
            try {
                mediaList.mediaText = ",screen,,(invalid,),,";
            } catch(e) {
                output = null;
            }
            printOut("not all, screen, not all, not all, not all, not all", mediaList.mediaText);

            output = "all";
            try {
                mediaList.mediaText = ",(all,),,";
            } catch(e) {
                output = null;
            }
            printOut("not all, not all, not all, not all", mediaList.mediaText);
        }
    </script>
</head>
<body onload="runTests()">
    <div id="console"></div>
</body>
</html>