layout/style/test/test_property_syntax_errors.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/test/test_property_syntax_errors.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,152 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +-->
     1.8 +<head>
     1.9 +  <title>Test that we reject syntax errors listed in property_database.js</title>
    1.10 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.11 +  <script type="text/javascript" src="property_database.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body onload="run()">
    1.15 +<p id="display"></p>
    1.16 +<iframe id="quirks" src="data:text/html,<div id='testnode'></div>"></iframe>
    1.17 +<div id="content" style="display: none">
    1.18 +
    1.19 +<div id="testnode"></div>
    1.20 +  
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +
    1.25 +SimpleTest.waitForExplicitFinish();
    1.26 +
    1.27 +function check_not_accepted(decl, property, info, badval)
    1.28 +{
    1.29 +  decl.setProperty(property, badval, "");
    1.30 +
    1.31 +  is(decl.getPropertyValue(property), "",
    1.32 +     "invalid value '" + badval + "' not accepted for '" + property +
    1.33 +     "' property");
    1.34 +
    1.35 +  if ("subproperties" in info) {
    1.36 +    for (var sidx in info.subproperties) {
    1.37 +      var subprop = info.subproperties[sidx];
    1.38 +      is(decl.getPropertyValue(subprop), "",
    1.39 +         "invalid value '" + badval + "' not accepted for '" + property +
    1.40 +         "' property when testing subproperty '" + subprop + "'");
    1.41 +    }
    1.42 +  }
    1.43 +
    1.44 +  decl.removeProperty(property);
    1.45 +}
    1.46 +
    1.47 +function check_value_balanced(decl, property, badval)
    1.48 +{
    1.49 +  var goodProp =
    1.50 +    (property == "background-color") ? "color" : "background-color";
    1.51 +  decl.cssText = goodProp + ": red; " + property + ": " + badval + "; " +
    1.52 +                 goodProp + ": green";
    1.53 +  is(decl.getPropertyValue(goodProp), "green",
    1.54 +     "invalid value '" + property + ": " + badval +
    1.55 +     "' is balanced and does not lead to parsing errors afterwards");
    1.56 +  decl.cssText = "";
    1.57 +}
    1.58 +
    1.59 +function check_value_unbalanced(decl, property, badval)
    1.60 +{
    1.61 +  var goodProp =
    1.62 +    (property == "background-color") ? "color" : "background-color";
    1.63 +  decl.cssText = goodProp + ": green; " + property + ": " + badval + "; " +
    1.64 +                 goodProp + ": red";
    1.65 +  is(decl.getPropertyValue(goodProp), "green",
    1.66 +     "invalid value '" + property + ": " + badval +
    1.67 +     "' is unbalanced and absorbs what follows it");
    1.68 +  decl.cssText = "";
    1.69 +}
    1.70 +
    1.71 +function check_empty_value_rejected(decl, emptyval, property)
    1.72 +{
    1.73 +  var goodProp =
    1.74 +    (property == "background-color") ? "color" : "background-color";
    1.75 +  decl.cssText = goodProp + ": red; " + property + ":" + emptyval + "; " +
    1.76 +                 goodProp + ": green";
    1.77 +  is(decl.length, 1,
    1.78 +     "empty value '" + property + ":" + emptyval +
    1.79 +     "' is not accepted");
    1.80 +  is(decl.getPropertyValue(goodProp), "green",
    1.81 +     "empty value '" + property + ":" + emptyval +
    1.82 +     "' is balanced and does not lead to parsing errors afterwards");
    1.83 +  decl.cssText = "";
    1.84 +}
    1.85 +
    1.86 +function run()
    1.87 +{
    1.88 +  var gDeclaration = document.getElementById("testnode").style;
    1.89 +  var gQuirksDeclaration = document.getElementById("quirks").contentDocument
    1.90 +                             .getElementById("testnode").style;
    1.91 +
    1.92 +  for (var property in gCSSProperties) {
    1.93 +    var info = gCSSProperties[property];
    1.94 +
    1.95 +    check_empty_value_rejected(gDeclaration, "", property);
    1.96 +    check_empty_value_rejected(gDeclaration, " ", property);
    1.97 +
    1.98 +    for (var idx in info.invalid_values) {
    1.99 +      check_not_accepted(gDeclaration, property, info,
   1.100 +                         info.invalid_values[idx]);
   1.101 +      check_not_accepted(gQuirksDeclaration, property, info,
   1.102 +                         info.invalid_values[idx]);
   1.103 +      check_value_balanced(gDeclaration, property,
   1.104 +                           info.invalid_values[idx]);
   1.105 +    }
   1.106 +
   1.107 +    if ("quirks_values" in info) {
   1.108 +      for (var quirkval in info.quirks_values) {
   1.109 +        var standardval = info.quirks_values[quirkval];
   1.110 +        check_not_accepted(gDeclaration, property, info, quirkval);
   1.111 +        check_value_balanced(gDeclaration, property, quirkval);
   1.112 +
   1.113 +        gQuirksDeclaration.setProperty(property, quirkval, "");
   1.114 +        gDeclaration.setProperty(property, standardval, "");
   1.115 +        var quirkret = gQuirksDeclaration.getPropertyValue(property);
   1.116 +        var standardret = gDeclaration.getPropertyValue(property);
   1.117 +        isnot(quirkret, "", property + ": " + quirkval +
   1.118 +                            " should be accepted in quirks mode");
   1.119 +        is(quirkret, standardret, property + ": " + quirkval + " result");
   1.120 +
   1.121 +        if ("subproperties" in info) {
   1.122 +          for (var sidx in info.subproperties) {
   1.123 +            var subprop = info.subproperties[sidx];
   1.124 +            var quirksub = gQuirksDeclaration.getPropertyValue(subprop);
   1.125 +            var standardsub = gDeclaration.getPropertyValue(subprop);
   1.126 +            isnot(quirksub, "", property + ": " + quirkval +
   1.127 +                                " should be accepted in quirks mode" +
   1.128 +                                " when testing subproperty " + subprop);
   1.129 +            is(quirksub, standardsub, property + ": " + quirkval + " result" +
   1.130 +                                      " when testing subproperty " + subprop);
   1.131 +          }
   1.132 +        }
   1.133 +
   1.134 +        gQuirksDeclaration.removeProperty(property);
   1.135 +        gDeclaration.removeProperty(property);
   1.136 +      }
   1.137 +    }
   1.138 +
   1.139 +    for (var idx in info.unbalanced_values) {
   1.140 +      check_not_accepted(gDeclaration, property, info,
   1.141 +                         info.invalid_values[idx]);
   1.142 +      check_not_accepted(gQuirksDeclaration, property, info,
   1.143 +                         info.invalid_values[idx]);
   1.144 +      check_value_unbalanced(gDeclaration, property,
   1.145 +                             info.unbalanced_values[idx]);
   1.146 +    }
   1.147 +  }
   1.148 +
   1.149 +  SimpleTest.finish();
   1.150 +}
   1.151 +
   1.152 +</script>
   1.153 +</pre>
   1.154 +</body>
   1.155 +</html>

mercurial