summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_extra_inherit_initial.html
blob: 8a94a05150eee8ff8564275fc5a2751094e51edb (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=940229
-->
<head>
  <title>Test handling extra inherit/initial/unset in CSS declarations (Bug 940229)</title>
  <script type="text/javascript" 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>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=940229">Mozilla Bug 940229</a>
<p id="display"></p>
<div id="content" style="display: none">

<div id="testnode"></div>
  
</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">

/*
 * Inspired by mistake in quotes noticed while reviewing bug 189519.
 */

let gPropsNeedComma = {
  "font": true,
  "font-family": true,
  "voice-family": true,
};

let gElement = document.getElementById("testnode");
let gDeclaration = gElement.style;

let kValuesToTestThoroughly = 3;

function test_property(property)
{
  let info = gCSSProperties[property];

  let delim = (property in gPropsNeedComma) ? ", " : " ";

  function test_value_pair(relation, val1, val2, extraval) {
    let decl = property + ": " + val1 + delim + val2;
    gElement.setAttribute("style", decl);
    if ("subproperties" in info) {
      // Shorthand property; inspect each subproperty value.
      for (let subprop of info.subproperties) {
        is(gDeclaration.getPropertyValue(subprop), "",
           ["expected", extraval, "ignored", relation, "value in",
            "'" + decl + "'", "when looking at subproperty",
            "'" + subprop + "'"].join(" "));
      }
    } else {
      // Longhand property.
      is(gDeclaration.getPropertyValue(property), "",
         ["expected", extraval, "ignored", relation, "value in",
          "'" + decl + "'"].join(" "));
    }
  }

  function test_value(value, valueIdx) {
    let specialKeywords = [ "inherit", "initial", "unset" ];

    if (valueIdx < kValuesToTestThoroughly) {
      // For the first few values, we test each special-keyword both before
      // and after the value.
      for (let keyword of specialKeywords) {
        test_value_pair("before", keyword, value, keyword);
        test_value_pair("after", value, keyword, keyword);
      }
    } else {
      // For later values, only test one keyword before & after it.
      let keywordIdx =
        (valueIdx - kValuesToTestThoroughly) % specialKeywords.length;
      keyword = specialKeywords[keywordIdx];
      test_value_pair("before", keyword, value, keyword);
      test_value_pair("after", value, keyword, keyword);
    }
  }

  for (let idx in info.initial_values) {
    test_value(info.initial_values[idx], idx);
  }
  for (let idx in info.other_values) {
    test_value(info.initial_values[idx], idx);
  }
}

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

function start_test() {
  for (let prop in gCSSProperties) {
    test_property(prop);
  }
  SimpleTest.finish();
}

// Turn off CSS error reporting for this test, since it's a bit expensive,
// and we're expecting to generate tons and tons of parse errors here.
SpecialPowers.pushPrefEnv({ "set": [["layout.css.report_errors", false]] },
                          start_test);

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