dom/smil/test/test_smilRepeatDuration.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/test/test_smilRepeatDuration.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,139 @@
     1.4 +<!doctype html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=948245
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for repeat duration calculation (Bug 948245)</title>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank"
    1.17 +href="https://bugzilla.mozilla.org/show_bug.cgi?id=948245">Mozilla Bug 948245</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content" style="display: none">
    1.20 +<svg id="svg" onload="this.pauseAnimations()">
    1.21 +  <rect>
    1.22 +    <animate id="a"/>
    1.23 +    <animate id="b" begin="a.end"/>
    1.24 +  </rect>
    1.25 +</svg>
    1.26 +</div>
    1.27 +<pre id="test">
    1.28 +<script class="testbody" type="text/javascript">
    1.29 +  // Tests the calculation of the repeat duration which is one of the steps
    1.30 +  // towards determining the active duration.
    1.31 +  //
    1.32 +  // The repeat duration is determined by the following three attributes:
    1.33 +  //
    1.34 +  // dur:         may be definite (e.g. '2s') or 'indefinite' (the default)
    1.35 +  // repeatCount: may be definite (e.g. '2.5'), 'indefinite', or not set
    1.36 +  // repeatDur:   may be definite (e.g. '5s'), 'indefinite', or not set
    1.37 +  //
    1.38 +  // That leaves 18 combinations to test.
    1.39 +  var testCases =
    1.40 +    [
    1.41 +      // 1. repeatDur: definite, repeatCount: definite, dur: definite
    1.42 +      // (Two test cases here to ensure we get the minimum)
    1.43 +      { repeatDur: 15, repeatCount: 2, dur: 10, result: 15 },
    1.44 +      { repeatDur: 25, repeatCount: 2, dur: 10, result: 20 },
    1.45 +      // 2. repeatDur: indefinite, repeatCount: definite, dur: definite
    1.46 +      { repeatDur: 'indefinite', repeatCount: 2, dur: 10, result: 20 },
    1.47 +      // 3. repeatDur: not set, repeatCount: definite, dur: definite
    1.48 +      { repeatCount: 2, dur: 10, result: 20 },
    1.49 +      // 4. repeatDur: definite, repeatCount: indefinite, dur: definite
    1.50 +      { repeatDur: 15, repeatCount: 'indefinite', dur: 10, result: 15 },
    1.51 +      // 5. repeatDur: indefinite, repeatCount: indefinite, dur: definite
    1.52 +      { repeatDur: 'indefinite', repeatCount: 'indefinite', dur: 10,
    1.53 +        result: 'indefinite' },
    1.54 +      // 6. repeatDur: not set, repeatCount: indefinite, dur: definite
    1.55 +      { repeatCount: 'indefinite', dur: 10, result: 'indefinite' },
    1.56 +      // 7. repeatDur: definite, repeatCount: not set, dur: definite
    1.57 +      { repeatDur: 15, dur: 10, result: 15 },
    1.58 +      // 8. repeatDur: indefinite, repeatCount: not set, dur: definite
    1.59 +      { repeatDur: 'indefinite', dur: 10, result: 'indefinite' },
    1.60 +      // 9. repeatDur: not set, repeatCount: not set, dur: definite
    1.61 +      { dur: 10, result: 10 },
    1.62 +      // 10. repeatDur: definite, repeatCount: definite, dur: indefinite
    1.63 +      { repeatDur: 15, repeatCount: 2, dur: 'indefinite', result: 15 },
    1.64 +      // 11. repeatDur: indefinite, repeatCount: definite, dur: indefinite
    1.65 +      { repeatDur: 'indefinite', repeatCount: 2, dur: 'indefinite',
    1.66 +        result: 'indefinite' },
    1.67 +      // 12. repeatDur: not set, repeatCount: definite, dur: indefinite
    1.68 +      { repeatCount: 2, dur: 'indefinite', result: 'indefinite' },
    1.69 +      // 13. repeatDur: definite, repeatCount: indefinite, dur: indefinite
    1.70 +      { repeatDur: 15, repeatCount: 'indefinite', dur: 'indefinite',
    1.71 +        result: 15 },
    1.72 +      // 14. repeatDur: indefinite, repeatCount: indefinite, dur: indefinite
    1.73 +      { repeatDur: 'indefinite', repeatCount: 'indefinite', dur: 'indefinite',
    1.74 +        result: 'indefinite' },
    1.75 +      // 15. repeatDur: not set, repeatCount: indefinite, dur: indefinite
    1.76 +      { repeatCount: 'indefinite', dur: 'indefinite', result: 'indefinite' },
    1.77 +      // 16. repeatDur: definite, repeatCount: not set, dur: indefinite
    1.78 +      { repeatDur: 15, dur: 'indefinite', result: 15 },
    1.79 +      // 17. repeatDur: indefinite, repeatCount: not set, dur: indefinite
    1.80 +      { repeatDur: 'indefinite', dur: 'indefinite', result: 'indefinite' },
    1.81 +      // 18. repeatDur: not set, repeatCount: not set, dur: indefinite
    1.82 +      { dur: 'indefinite', result: 'indefinite' }
    1.83 +    ];
    1.84 +
    1.85 +  // We can test the repeat duration by setting these attributes on animation
    1.86 +  // 'a' and checking the start time of 'b' which is defined to start when 'a'
    1.87 +  // finishes.
    1.88 +  //
    1.89 +  // Since 'a' has no end/min/max attributes the end of its active interval
    1.90 +  // should coincide with the end of its repeat duration.
    1.91 +  //
    1.92 +  // Sometimes the repeat duration is defined to be 'indefinite'. In this case
    1.93 +  // calling getStartTime on b will throw an exception so we need to catch that
    1.94 +  // exception and translate it to 'indefinite' as follows:
    1.95 +  function getRepeatDuration() {
    1.96 +    try {
    1.97 +      return $('b').getStartTime();
    1.98 +    } catch(e) {
    1.99 +      if (e.name == "InvalidStateError" &&
   1.100 +          e.code == DOMException.INVALID_STATE_ERR) {
   1.101 +        return 'indefinite';
   1.102 +      } else {
   1.103 +        ok(false, "Unexpected exception: " + e);
   1.104 +        return null;
   1.105 +      }
   1.106 +    }
   1.107 +  }
   1.108 +
   1.109 +  // Animation doesn't start until onload
   1.110 +  SimpleTest.waitForExplicitFinish();
   1.111 +  window.addEventListener("load", runTests, false);
   1.112 +
   1.113 +  // Run through each of the test cases
   1.114 +  function runTests() {
   1.115 +    ok($('svg').animationsPaused(), "should be paused by <svg> load handler");
   1.116 +
   1.117 +    testCases.forEach(function(test) {
   1.118 +      var a = $('a');
   1.119 +
   1.120 +      // Set the attributes
   1.121 +      var msgPieces = [];
   1.122 +      [ 'repeatDur', 'repeatCount', 'dur' ].forEach(function(attr) {
   1.123 +        if (typeof test[attr] != "undefined") {
   1.124 +          a.setAttribute(attr, test[attr].toString());
   1.125 +          msgPieces.push(attr + ': ' + test[attr].toString());
   1.126 +        } else {
   1.127 +          a.removeAttribute(attr);
   1.128 +          msgPieces.push(attr + ': <not set>');
   1.129 +        }
   1.130 +      });
   1.131 +      var msg = msgPieces.join(', ');
   1.132 +
   1.133 +      // Check the result
   1.134 +      ise(getRepeatDuration(), test.result, msg);
   1.135 +    });
   1.136 +
   1.137 +    SimpleTest.finish();
   1.138 +  }
   1.139 +</script>
   1.140 +</pre>
   1.141 +</body>
   1.142 +</html>

mercurial