summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_counter_style.html
blob: 58f5763451e157809fbca18eb19fe31411e6c95d (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
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Test for css3-counter-style (Bug 966166)</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style type="text/css">
    #ol_test, #ol_ref {
      display: inline-block;
      list-style-position: inside;
    }
    #ol_test { list-style-type: test; }
    #ol_ref { list-style-type: ref; }
    #div_test, #div_ref {
      display: inline-block;
      counter-reset: a -1;
    }
    #div_test::before { content: counter(a, test); }
    #div_ref::before { content: counter(a, ref); }
  </style>
  <style type="text/css" id="counter">
  </style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=966166">Mozilla Bug 966166</a>
<div id="display"></div>
<ol id="ol_test" start="-1"><li></li></ol><br>
<ol id="ol_ref" start="-1"><li></li></ol><br>
<div id="div_test"></div><br>
<div id="div_ref"></div><br>
<pre id="test">
<script type="application/javascript">
var gOlTest = document.getElementById("ol_test"),
    gOlRef = document.getElementById("ol_ref"),
    gDivTest = document.getElementById("div_test"),
    gDivRef = document.getElementById("div_ref"),
    gCounterSheet = document.getElementById("counter").sheet;

var testRule, refRule;

var basicStyle = "system: extends decimal; range: infinite infinite; ";
var info = [
  ["system",
   "system: fixed -1; symbols: xxx;",
   "system: fixed; symbols: xxx;"],
  ["system",
   "system: extends decimal;",
   "system: extends cjk-ideographic;"],
  ["negative", "", "negative: '((' '))';"],
  ["negative", "", "negative: '---';"],
  ["prefix", "", "prefix: '###';"],
  ["suffix", "", "suffix: '###';"],
  ["range",
   "fallback: cjk-ideographic;",
   "fallback: cjk-ideographic; range: 10 infinite;"],
  ["pad", "", "pad: 10 '0';"],
  ["fallback",
   "range: 0 infinite;",
   "range: 0 infinite; fallback: cjk-ideographic;"],
  ["symbols",
   "system: symbolic; symbols: '1';",
   "system: symbolic; symbols: '111';"],
  ["additiveSymbols",
   "system: additive; additive-symbols: 1 '1';",
   "system: additive; additive-symbols: 1 '111';"],
];

// force a reflow before test to eliminate bug 994418
gOlTest.getBoundingClientRect().width;

for (var i in info) {
  var item = info[i];
  var desc = item[0],
      testStyle = item[1],
      refStyle = item[2];
  var isFix = (desc == "prefix" || desc == "suffix");

  while (gCounterSheet.cssRules.length > 0) {
    gCounterSheet.deleteRule(0);
  }
  gCounterSheet.insertRule("@counter-style test { " +
    basicStyle + testStyle + "}", 0);
  gCounterSheet.insertRule("@counter-style ref { " +
    basicStyle + refStyle + "}", 1);
  testRule = gCounterSheet.cssRules[0];
  refRule = gCounterSheet.cssRules[1];

  var olTestWidth = gOlTest.getBoundingClientRect().width;
  var olRefWidth = gOlRef.getBoundingClientRect().width;
  ok(olTestWidth > 0, "test ol has width");
  ok(olRefWidth > 0, "ref ol has width");
  ok(olTestWidth != olRefWidth,
     "OLs have different width " +
     "for rule '" + testStyle + "' and '" + refStyle + "'");

  var divTestWidth = gDivTest.getBoundingClientRect().width;
  var divRefWidth = gDivRef.getBoundingClientRect().width;
  if (!isFix) {
    ok(divTestWidth > 0, "test div has width");
    ok(divRefWidth > 0, "ref div has width");
    ok(divTestWidth != divRefWidth,
       "DIVs have different width" +
       "for rule '" + testStyle + "' and '" + refStyle + "'");
  }

  ok(testRule[desc] != refRule[desc],
     "rules have different values for desciptor '" + desc + "'");
  testRule[desc] = refRule[desc];

  var olNewWidth = gOlTest.getBoundingClientRect().width;
  var divNewWidth = gDivTest.getBoundingClientRect().width;
  is(olNewWidth, olRefWidth);
  if (!isFix) {
    is(divNewWidth, divRefWidth);
  }
}
</script>
</pre>
</body>
</html>