dom/smil/test/test_smilRepeatDuration.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!doctype html>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=948245
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for repeat duration calculation (Bug 948245)</title>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank"
michael@0 14 href="https://bugzilla.mozilla.org/show_bug.cgi?id=948245">Mozilla Bug 948245</a>
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content" style="display: none">
michael@0 17 <svg id="svg" onload="this.pauseAnimations()">
michael@0 18 <rect>
michael@0 19 <animate id="a"/>
michael@0 20 <animate id="b" begin="a.end"/>
michael@0 21 </rect>
michael@0 22 </svg>
michael@0 23 </div>
michael@0 24 <pre id="test">
michael@0 25 <script class="testbody" type="text/javascript">
michael@0 26 // Tests the calculation of the repeat duration which is one of the steps
michael@0 27 // towards determining the active duration.
michael@0 28 //
michael@0 29 // The repeat duration is determined by the following three attributes:
michael@0 30 //
michael@0 31 // dur: may be definite (e.g. '2s') or 'indefinite' (the default)
michael@0 32 // repeatCount: may be definite (e.g. '2.5'), 'indefinite', or not set
michael@0 33 // repeatDur: may be definite (e.g. '5s'), 'indefinite', or not set
michael@0 34 //
michael@0 35 // That leaves 18 combinations to test.
michael@0 36 var testCases =
michael@0 37 [
michael@0 38 // 1. repeatDur: definite, repeatCount: definite, dur: definite
michael@0 39 // (Two test cases here to ensure we get the minimum)
michael@0 40 { repeatDur: 15, repeatCount: 2, dur: 10, result: 15 },
michael@0 41 { repeatDur: 25, repeatCount: 2, dur: 10, result: 20 },
michael@0 42 // 2. repeatDur: indefinite, repeatCount: definite, dur: definite
michael@0 43 { repeatDur: 'indefinite', repeatCount: 2, dur: 10, result: 20 },
michael@0 44 // 3. repeatDur: not set, repeatCount: definite, dur: definite
michael@0 45 { repeatCount: 2, dur: 10, result: 20 },
michael@0 46 // 4. repeatDur: definite, repeatCount: indefinite, dur: definite
michael@0 47 { repeatDur: 15, repeatCount: 'indefinite', dur: 10, result: 15 },
michael@0 48 // 5. repeatDur: indefinite, repeatCount: indefinite, dur: definite
michael@0 49 { repeatDur: 'indefinite', repeatCount: 'indefinite', dur: 10,
michael@0 50 result: 'indefinite' },
michael@0 51 // 6. repeatDur: not set, repeatCount: indefinite, dur: definite
michael@0 52 { repeatCount: 'indefinite', dur: 10, result: 'indefinite' },
michael@0 53 // 7. repeatDur: definite, repeatCount: not set, dur: definite
michael@0 54 { repeatDur: 15, dur: 10, result: 15 },
michael@0 55 // 8. repeatDur: indefinite, repeatCount: not set, dur: definite
michael@0 56 { repeatDur: 'indefinite', dur: 10, result: 'indefinite' },
michael@0 57 // 9. repeatDur: not set, repeatCount: not set, dur: definite
michael@0 58 { dur: 10, result: 10 },
michael@0 59 // 10. repeatDur: definite, repeatCount: definite, dur: indefinite
michael@0 60 { repeatDur: 15, repeatCount: 2, dur: 'indefinite', result: 15 },
michael@0 61 // 11. repeatDur: indefinite, repeatCount: definite, dur: indefinite
michael@0 62 { repeatDur: 'indefinite', repeatCount: 2, dur: 'indefinite',
michael@0 63 result: 'indefinite' },
michael@0 64 // 12. repeatDur: not set, repeatCount: definite, dur: indefinite
michael@0 65 { repeatCount: 2, dur: 'indefinite', result: 'indefinite' },
michael@0 66 // 13. repeatDur: definite, repeatCount: indefinite, dur: indefinite
michael@0 67 { repeatDur: 15, repeatCount: 'indefinite', dur: 'indefinite',
michael@0 68 result: 15 },
michael@0 69 // 14. repeatDur: indefinite, repeatCount: indefinite, dur: indefinite
michael@0 70 { repeatDur: 'indefinite', repeatCount: 'indefinite', dur: 'indefinite',
michael@0 71 result: 'indefinite' },
michael@0 72 // 15. repeatDur: not set, repeatCount: indefinite, dur: indefinite
michael@0 73 { repeatCount: 'indefinite', dur: 'indefinite', result: 'indefinite' },
michael@0 74 // 16. repeatDur: definite, repeatCount: not set, dur: indefinite
michael@0 75 { repeatDur: 15, dur: 'indefinite', result: 15 },
michael@0 76 // 17. repeatDur: indefinite, repeatCount: not set, dur: indefinite
michael@0 77 { repeatDur: 'indefinite', dur: 'indefinite', result: 'indefinite' },
michael@0 78 // 18. repeatDur: not set, repeatCount: not set, dur: indefinite
michael@0 79 { dur: 'indefinite', result: 'indefinite' }
michael@0 80 ];
michael@0 81
michael@0 82 // We can test the repeat duration by setting these attributes on animation
michael@0 83 // 'a' and checking the start time of 'b' which is defined to start when 'a'
michael@0 84 // finishes.
michael@0 85 //
michael@0 86 // Since 'a' has no end/min/max attributes the end of its active interval
michael@0 87 // should coincide with the end of its repeat duration.
michael@0 88 //
michael@0 89 // Sometimes the repeat duration is defined to be 'indefinite'. In this case
michael@0 90 // calling getStartTime on b will throw an exception so we need to catch that
michael@0 91 // exception and translate it to 'indefinite' as follows:
michael@0 92 function getRepeatDuration() {
michael@0 93 try {
michael@0 94 return $('b').getStartTime();
michael@0 95 } catch(e) {
michael@0 96 if (e.name == "InvalidStateError" &&
michael@0 97 e.code == DOMException.INVALID_STATE_ERR) {
michael@0 98 return 'indefinite';
michael@0 99 } else {
michael@0 100 ok(false, "Unexpected exception: " + e);
michael@0 101 return null;
michael@0 102 }
michael@0 103 }
michael@0 104 }
michael@0 105
michael@0 106 // Animation doesn't start until onload
michael@0 107 SimpleTest.waitForExplicitFinish();
michael@0 108 window.addEventListener("load", runTests, false);
michael@0 109
michael@0 110 // Run through each of the test cases
michael@0 111 function runTests() {
michael@0 112 ok($('svg').animationsPaused(), "should be paused by <svg> load handler");
michael@0 113
michael@0 114 testCases.forEach(function(test) {
michael@0 115 var a = $('a');
michael@0 116
michael@0 117 // Set the attributes
michael@0 118 var msgPieces = [];
michael@0 119 [ 'repeatDur', 'repeatCount', 'dur' ].forEach(function(attr) {
michael@0 120 if (typeof test[attr] != "undefined") {
michael@0 121 a.setAttribute(attr, test[attr].toString());
michael@0 122 msgPieces.push(attr + ': ' + test[attr].toString());
michael@0 123 } else {
michael@0 124 a.removeAttribute(attr);
michael@0 125 msgPieces.push(attr + ': <not set>');
michael@0 126 }
michael@0 127 });
michael@0 128 var msg = msgPieces.join(', ');
michael@0 129
michael@0 130 // Check the result
michael@0 131 ise(getRepeatDuration(), test.result, msg);
michael@0 132 });
michael@0 133
michael@0 134 SimpleTest.finish();
michael@0 135 }
michael@0 136 </script>
michael@0 137 </pre>
michael@0 138 </body>
michael@0 139 </html>

mercurial