summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_property_syntax_errors.html
blob: 1e3f3820362e2973c74ba4a78052983d5fabbd80 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
  <title>Test that we reject syntax errors listed in property_database.js</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="property_database.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="run()">
<p id="display"></p>
<iframe id="quirks" src="data:text/html,<div id='testnode'></div>"></iframe>
<div id="content" style="display: none">

<div id="testnode"></div>
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();
SimpleTest.requestLongerTimeout(4);

function check_not_accepted(decl, property, info, badval)
{
  decl.setProperty(property, badval, "");

  is(decl.getPropertyValue(property), "",
     "invalid value '" + badval + "' not accepted for '" + property +
     "' property");

  if ("subproperties" in info) {
    for (var sidx in info.subproperties) {
      var subprop = info.subproperties[sidx];
      is(decl.getPropertyValue(subprop), "",
         "invalid value '" + badval + "' not accepted for '" + property +
         "' property when testing subproperty '" + subprop + "'");
    }
  }

  decl.removeProperty(property);
}

function check_value_balanced(decl, property, badval)
{
  var goodProp =
    (property == "background-color") ? "color" : "background-color";
  decl.cssText = goodProp + ": red; " + property + ": " + badval + "; " +
                 goodProp + ": green";
  is(decl.getPropertyValue(goodProp), "green",
     "invalid value '" + property + ": " + badval +
     "' is balanced and does not lead to parsing errors afterwards");
  decl.cssText = "";
}

function check_value_unbalanced(decl, property, badval)
{
  var goodProp =
    (property == "background-color") ? "color" : "background-color";
  decl.cssText = goodProp + ": green; " + property + ": " + badval + "; " +
                 goodProp + ": red";
  is(decl.getPropertyValue(goodProp), "green",
     "invalid value '" + property + ": " + badval +
     "' is unbalanced and absorbs what follows it");
  decl.cssText = "";
}

function check_empty_value_rejected(decl, emptyval, property)
{
  var goodProp =
    (property == "background-color") ? "color" : "background-color";
  decl.cssText = goodProp + ": red; " + property + ":" + emptyval + "; " +
                 goodProp + ": green";
  is(decl.length, 1,
     "empty value '" + property + ":" + emptyval +
     "' is not accepted");
  is(decl.getPropertyValue(goodProp), "green",
     "empty value '" + property + ":" + emptyval +
     "' is balanced and does not lead to parsing errors afterwards");
  decl.cssText = "";
}

function run()
{
  var gDeclaration = document.getElementById("testnode").style;
  var quirksFrame = document.getElementById("quirks");
  var wrappedFrame = SpecialPowers.wrap(quirksFrame);
  var gQuirksDeclaration = wrappedFrame.contentDocument
                             .getElementById("testnode").style;

  for (var property in gCSSProperties) {
    var info = gCSSProperties[property];

    check_empty_value_rejected(gDeclaration, "", property);
    check_empty_value_rejected(gDeclaration, " ", property);

    for (var idx in info.invalid_values) {
      check_not_accepted(gDeclaration, property, info,
                         info.invalid_values[idx]);
      check_not_accepted(gQuirksDeclaration, property, info,
                         info.invalid_values[idx]);
      check_value_balanced(gDeclaration, property,
                           info.invalid_values[idx]);
    }

    if ("quirks_values" in info) {
      for (var quirkval in info.quirks_values) {
        var standardval = info.quirks_values[quirkval];
        check_not_accepted(gDeclaration, property, info, quirkval);
        check_value_balanced(gDeclaration, property, quirkval);

        gQuirksDeclaration.setProperty(property, quirkval, "");
        gDeclaration.setProperty(property, standardval, "");
        var quirkret = gQuirksDeclaration.getPropertyValue(property);
        var standardret = gDeclaration.getPropertyValue(property);
        isnot(quirkret, "", property + ": " + quirkval +
                            " should be accepted in quirks mode");
        is(quirkret, standardret, property + ": " + quirkval + " result");

        if ("subproperties" in info) {
          for (var sidx in info.subproperties) {
            var subprop = info.subproperties[sidx];
            var quirksub = gQuirksDeclaration.getPropertyValue(subprop);
            var standardsub = gDeclaration.getPropertyValue(subprop);
            isnot(quirksub, "", property + ": " + quirkval +
                                " should be accepted in quirks mode" +
                                " when testing subproperty " + subprop);
            is(quirksub, standardsub, property + ": " + quirkval + " result" +
                                      " when testing subproperty " + subprop);
          }
        }

        gQuirksDeclaration.removeProperty(property);
        gDeclaration.removeProperty(property);
      }
    }

    for (var idx in info.unbalanced_values) {
      check_not_accepted(gDeclaration, property, info,
                         info.invalid_values[idx]);
      check_not_accepted(gQuirksDeclaration, property, info,
                         info.invalid_values[idx]);
      check_value_unbalanced(gDeclaration, property,
                             info.unbalanced_values[idx]);
    }
  }

  SimpleTest.finish();
}

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