summaryrefslogtreecommitdiffstats
path: root/dom/smil/test/test_smilRepeatDuration.html
blob: 3690a956645566d477d5aebbebf158763cab6070 (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
<!doctype html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=948245
-->
<head>
  <meta charset="utf-8">
  <title>Test for repeat duration calculation (Bug 948245)</title>
  <script type="text/javascript" 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=948245">Mozilla Bug 948245</a>
<p id="display"></p>
<div id="content" style="display: none">
<svg id="svg" onload="this.pauseAnimations()">
  <rect>
    <animate id="a"/>
    <animate id="b" begin="a.end"/>
  </rect>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
  // Tests the calculation of the repeat duration which is one of the steps
  // towards determining the active duration.
  //
  // The repeat duration is determined by the following three attributes:
  //
  // dur:         may be definite (e.g. '2s') or 'indefinite' (the default)
  // repeatCount: may be definite (e.g. '2.5'), 'indefinite', or not set
  // repeatDur:   may be definite (e.g. '5s'), 'indefinite', or not set
  //
  // That leaves 18 combinations to test.
  var testCases =
    [
      // 1. repeatDur: definite, repeatCount: definite, dur: definite
      // (Two test cases here to ensure we get the minimum)
      { repeatDur: 15, repeatCount: 2, dur: 10, result: 15 },
      { repeatDur: 25, repeatCount: 2, dur: 10, result: 20 },
      // 2. repeatDur: indefinite, repeatCount: definite, dur: definite
      { repeatDur: 'indefinite', repeatCount: 2, dur: 10, result: 20 },
      // 3. repeatDur: not set, repeatCount: definite, dur: definite
      { repeatCount: 2, dur: 10, result: 20 },
      // 4. repeatDur: definite, repeatCount: indefinite, dur: definite
      { repeatDur: 15, repeatCount: 'indefinite', dur: 10, result: 15 },
      // 5. repeatDur: indefinite, repeatCount: indefinite, dur: definite
      { repeatDur: 'indefinite', repeatCount: 'indefinite', dur: 10,
        result: 'indefinite' },
      // 6. repeatDur: not set, repeatCount: indefinite, dur: definite
      { repeatCount: 'indefinite', dur: 10, result: 'indefinite' },
      // 7. repeatDur: definite, repeatCount: not set, dur: definite
      { repeatDur: 15, dur: 10, result: 15 },
      // 8. repeatDur: indefinite, repeatCount: not set, dur: definite
      { repeatDur: 'indefinite', dur: 10, result: 'indefinite' },
      // 9. repeatDur: not set, repeatCount: not set, dur: definite
      { dur: 10, result: 10 },
      // 10. repeatDur: definite, repeatCount: definite, dur: indefinite
      { repeatDur: 15, repeatCount: 2, dur: 'indefinite', result: 15 },
      // 11. repeatDur: indefinite, repeatCount: definite, dur: indefinite
      { repeatDur: 'indefinite', repeatCount: 2, dur: 'indefinite',
        result: 'indefinite' },
      // 12. repeatDur: not set, repeatCount: definite, dur: indefinite
      { repeatCount: 2, dur: 'indefinite', result: 'indefinite' },
      // 13. repeatDur: definite, repeatCount: indefinite, dur: indefinite
      { repeatDur: 15, repeatCount: 'indefinite', dur: 'indefinite',
        result: 15 },
      // 14. repeatDur: indefinite, repeatCount: indefinite, dur: indefinite
      { repeatDur: 'indefinite', repeatCount: 'indefinite', dur: 'indefinite',
        result: 'indefinite' },
      // 15. repeatDur: not set, repeatCount: indefinite, dur: indefinite
      { repeatCount: 'indefinite', dur: 'indefinite', result: 'indefinite' },
      // 16. repeatDur: definite, repeatCount: not set, dur: indefinite
      { repeatDur: 15, dur: 'indefinite', result: 15 },
      // 17. repeatDur: indefinite, repeatCount: not set, dur: indefinite
      { repeatDur: 'indefinite', dur: 'indefinite', result: 'indefinite' },
      // 18. repeatDur: not set, repeatCount: not set, dur: indefinite
      { dur: 'indefinite', result: 'indefinite' }
    ];

  // We can test the repeat duration by setting these attributes on animation
  // 'a' and checking the start time of 'b' which is defined to start when 'a'
  // finishes.
  //
  // Since 'a' has no end/min/max attributes the end of its active interval
  // should coincide with the end of its repeat duration.
  //
  // Sometimes the repeat duration is defined to be 'indefinite'. In this case
  // calling getStartTime on b will throw an exception so we need to catch that
  // exception and translate it to 'indefinite' as follows:
  function getRepeatDuration() {
    try {
      return $('b').getStartTime();
    } catch(e) {
      if (e.name == "InvalidStateError" &&
          e.code == DOMException.INVALID_STATE_ERR) {
        return 'indefinite';
      } else {
        ok(false, "Unexpected exception: " + e);
        return null;
      }
    }
  }

  // Animation doesn't start until onload
  SimpleTest.waitForExplicitFinish();
  window.addEventListener("load", runTests, false);

  // Run through each of the test cases
  function runTests() {
    ok($('svg').animationsPaused(), "should be paused by <svg> load handler");

    testCases.forEach(function(test) {
      var a = $('a');

      // Set the attributes
      var msgPieces = [];
      [ 'repeatDur', 'repeatCount', 'dur' ].forEach(function(attr) {
        if (typeof test[attr] != "undefined") {
          a.setAttribute(attr, test[attr].toString());
          msgPieces.push(attr + ': ' + test[attr].toString());
        } else {
          a.removeAttribute(attr);
          msgPieces.push(attr + ': <not set>');
        }
      });
      var msg = msgPieces.join(', ');

      // Check the result
      is(getRepeatDuration(), test.result, msg);
    });

    SimpleTest.finish();
  }
</script>
</pre>
</body>
</html>