summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_css_supports.html
blob: a6b1e8d303f4964dcc1d8f4a241db8e5ad037d87 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=779917
-->
<head>
  <title>Test for Bug 779917</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=779917">Mozilla Bug 779917</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 779917 **/

function runTest()
{
  var passingConditions = [
    "color: green",
    "(color: green)",
    "((color: green))",
    "(color: green !important)",
    "(color: rainbow) or (color: green)",
    "(color: green) or (color: rainbow)",
    "(color: green) and (color: blue)",
    "(color: rainbow) or (color: iridescent) or (color: green)",
    "(color: red) and (color: green) and (color: blue)",
    "(color:green)",
    "not (color: rainbow)",
    "not (not (color: green))",
    "(unknown:) or (color: green)",
    "(unknown) or (color: green)",
    "(font: 16px serif)",
    "(color:) or (color: green)",
    "not (@page)",
    "not ({ something @with [ balanced ] brackets })",
    "an-extension(of some kind) or (color: green)",
    "not ()",
    "( Font:  20px serif ! Important) ",
    "(color: /* comment */ green)",
    "(/* comment */ color: green)",
    "(color: green /* comment */)",
    "(color: green) /* comment */",
    "/* comment */ (color: green)",
    "(color /* comment */: green)",
    "(color: green) /* unclosed comment",
    "(color: green",
    "(((((((color: green",
    "(font-family: 'Helvetica"
  ];

  var failingConditions = [
    "(color: rainbow)",
    "(color: rainbow) and (color: green)",
    "(color: blue) and (color: rainbow)",
    "(color: green) and (color: green) or (color: green)",
    "(color: green) or (color: green) and (color: green)",
    "not not (color: green)",
    "not (color: rainbow) and not (color: iridescent)",
    "not (color: rainbow) or (color: green)",
    "(not (color: rainbow) or (color: green))",
    "(unknown: green)",
    "not ({ something @with (unbalanced brackets })",
    "(color: green) or an-extension(that is [unbalanced)",
    "not(unknown: unknown)",
    "(color: green) or(color: blue)",
    "(color: green;)",
    "(font-family: 'Helvetica\n",
    "(font-family: 'Helvetica\n')",
    "()",
    ""
  ];

  var passingDeclarations = [
    ["color", "green"],
    ["color", " green "],
    ["Color", "Green"],
    ["color", "green /* comment */"],
    ["color", "/* comment */ green"],
    ["color", "green /* unclosed comment"],
    ["font", "16px serif"],
    ["font", "16px /* comment */ serif"],
    ["font", "16px\nserif"],
    ["color", "\\0067reen"]
  ];

  var failingDeclarations = [
    ["color ", "green"],
    ["color", "rainbow"],
    ["color", "green green"],
    ["color", "green !important"],
    ["\\0063olor", "green"],
    ["/* comment */color", "green"],
    ["color/* comment */", "green"],
    ["font-family", "'Helvetica\n"],
    ["font-family", "'Helvetica\n'"],
    ["color", "green;"],
    ["color", ""],
    ["unknown", "unknown"],
    ["", "green"],
    ["", ""]
  ];

  passingConditions.forEach(function(aCondition) {
    is(CSS.supports(aCondition), true, "CSS.supports returns true for passing condition \"" + aCondition + "\"");
  });

  failingConditions.forEach(function(aCondition) {
    is(CSS.supports(aCondition), false, "CSS.supports returns false for failing condition \"" + aCondition + "\"");
  });

  passingDeclarations.forEach(function(aDeclaration) {
    is(CSS.supports(aDeclaration[0], aDeclaration[1]), true, "CSS.supports returns true for supported declaration \"" + aDeclaration.join(":") + "\"");
  });

  failingDeclarations.forEach(function(aDeclaration) {
    is(CSS.supports(aDeclaration[0], aDeclaration[1]), false, "CSS.supports returns false for unsupported declaration \"" + aDeclaration.join(":") + "\"");
  });

  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
runTest();
</script>
</pre>
</body>
</html>