dom/smil/test/test_smilBackwardsSeeking.xhtml

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <head>
michael@0 3 <title>Test for backwards seeking behavior </title>
michael@0 4 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 6 </head>
michael@0 7 <body>
michael@0 8 <p id="display"></p>
michael@0 9 <div id="content" style="display: none">
michael@0 10 <svg id="svg" xmlns="http://www.w3.org/2000/svg" />
michael@0 11 </div>
michael@0 12 <pre id="test">
michael@0 13 <script class="testbody" type="text/javascript">
michael@0 14 <![CDATA[
michael@0 15 /** Test for backwards seeking behavior **/
michael@0 16
michael@0 17 var gSvg = document.getElementById("svg");
michael@0 18
michael@0 19 SimpleTest.waitForExplicitFinish();
michael@0 20
michael@0 21 function main()
michael@0 22 {
michael@0 23 // Pause our document, so that the setCurrentTime calls are the only
michael@0 24 // thing affecting document time
michael@0 25 gSvg.pauseAnimations();
michael@0 26
michael@0 27 // We define a series of scenarios, sample times, and expected return values
michael@0 28 // from getStartTime.
michael@0 29 //
michael@0 30 // Each scenario is basically a variation on the following arrangement:
michael@0 31 //
michael@0 32 // <svg>
michael@0 33 // <set ... dur="1s" begin="<A-BEGIN>"/>
michael@0 34 // <set ... dur="1s" begin="<B-BEGIN>"/>
michael@0 35 // </svg>
michael@0 36 //
michael@0 37 // Each test then consists of the following:
michael@0 38 // animA: attributes to be applied to a
michael@0 39 // animB: attributes to be applied to b
michael@0 40 // times: a series of triples which consist of:
michael@0 41 // <sample time, a's expected start time, b's expected start time>
michael@0 42 // * The sample time is the time passed to setCurrentTime and so is
michael@0 43 // in seconds.
michael@0 44 // * The expected start times are compared with the return value of
michael@0 45 // getStartTime. To check for an unresolved start time where
michael@0 46 // getStartTime would normally throw an exception use
michael@0 47 // 'unresolved'.
michael@0 48 // * We also allow the special notation to indicate a call to
michael@0 49 // beginElement
michael@0 50 // <'beginElementAt', id of animation element, offset>
michael@0 51 //
michael@0 52 // In the diagrams below '^' means the time before the seek and '*' is the
michael@0 53 // seek time.
michael@0 54 var testCases = Array();
michael@0 55
michael@0 56 // 0: Simple case
michael@0 57 //
michael@0 58 // A: +-------
michael@0 59 // B: +------- begin: a.begin
michael@0 60 // * ^
michael@0 61 testCases[0] = {
michael@0 62 'animA': {'begin':'1s', 'id':'a'},
michael@0 63 'animB': {'begin':'a.begin'},
michael@0 64 'times': [ [0, 1, 1],
michael@0 65 [1, 1, 1],
michael@0 66 [2, 'unresolved', 'unresolved'],
michael@0 67 [0, 1, 1],
michael@0 68 [1.5, 1, 1],
michael@0 69 [1, 1, 1],
michael@0 70 [2, 'unresolved', 'unresolved'] ]
michael@0 71 };
michael@0 72
michael@0 73 // 1: Restored times should be live
michael@0 74 //
michael@0 75 // When we restore times they should be live. So we have the following
michael@0 76 // scenario.
michael@0 77 //
michael@0 78 // A: +-------
michael@0 79 // B: +------- begin: a.begin
michael@0 80 // * ^
michael@0 81 //
michael@0 82 // Then we call beginElement at an earlier time which should give us the
michael@0 83 // following.
michael@0 84 //
michael@0 85 // A: +-------
michael@0 86 // B: +-------
michael@0 87 // * ^
michael@0 88 //
michael@0 89 // If the times are not live however we'll end up with this
michael@0 90 //
michael@0 91 // A: +-------
michael@0 92 // B: +-+-------
michael@0 93 // * ^
michael@0 94 testCases[1] = {
michael@0 95 'animA': {'begin':'1s', 'id':'a', 'restart':'whenNotActive'},
michael@0 96 'animB': {'begin':'a.begin', 'restart':'always'},
michael@0 97 'times': [ [0, 1, 1],
michael@0 98 [2, 'unresolved', 'unresolved'],
michael@0 99 [0.25, 1, 1],
michael@0 100 ['beginElementAt', 'a', 0.25], // = start time of 0.5
michael@0 101 [0.25, 0.5, 0.5],
michael@0 102 [1, 0.5, 0.5],
michael@0 103 [1.5, 'unresolved', 'unresolved'] ]
michael@0 104 };
michael@0 105
michael@0 106 // 2: Multiple intervals A
michael@0 107 //
michael@0 108 // A: +- +-
michael@0 109 // B: +- +- begin: a.begin+4s
michael@0 110 // * ^
michael@0 111 testCases[2] = {
michael@0 112 'animA': {'begin':'1s; 3s', 'id':'a'},
michael@0 113 'animB': {'begin':'a.begin+4s'},
michael@0 114 'times': [ [0, 1, 5],
michael@0 115 [3, 3, 5],
michael@0 116 [6.5, 'unresolved', 7],
michael@0 117 [4, 'unresolved', 5],
michael@0 118 [6, 'unresolved', 7],
michael@0 119 [2, 3, 5],
michael@0 120 ['beginElementAt', 'a', 0],
michael@0 121 [2, 2, 5],
michael@0 122 [5, 'unresolved', 5],
michael@0 123 [6, 'unresolved', 6],
michael@0 124 [7, 'unresolved', 7],
michael@0 125 [8, 'unresolved', 'unresolved'] ]
michael@0 126 };
michael@0 127
michael@0 128 for (var i = 0; i < testCases.length; i++) {
michael@0 129 gSvg.setCurrentTime(0);
michael@0 130 var test = testCases[i];
michael@0 131
michael@0 132 // Create animation elements
michael@0 133 var animA = createAnim(test.animA);
michael@0 134 var animB = createAnim(test.animB);
michael@0 135
michael@0 136 // Run samples
michael@0 137 for (var j = 0; j < test.times.length; j++) {
michael@0 138 var times = test.times[j];
michael@0 139 if (times[0] == 'beginElementAt') {
michael@0 140 var anim = getElement(times[1]);
michael@0 141 anim.beginElementAt(times[2]);
michael@0 142 } else {
michael@0 143 gSvg.setCurrentTime(times[0]);
michael@0 144 checkStartTime(animA, times[1], times[0], i, 'a');
michael@0 145 checkStartTime(animB, times[2], times[0], i, 'b');
michael@0 146 }
michael@0 147 }
michael@0 148
michael@0 149 // Tidy up
michael@0 150 animA.parentNode.removeChild(animA);
michael@0 151 animB.parentNode.removeChild(animB);
michael@0 152 }
michael@0 153
michael@0 154 SimpleTest.finish();
michael@0 155 }
michael@0 156
michael@0 157 function createAnim(attr)
michael@0 158 {
michael@0 159 const svgns = "http://www.w3.org/2000/svg";
michael@0 160 var anim = document.createElementNS(svgns, 'set');
michael@0 161 anim.setAttribute('attributeName','x');
michael@0 162 anim.setAttribute('to','10');
michael@0 163 anim.setAttribute('dur','1s');
michael@0 164 for (name in attr) {
michael@0 165 anim.setAttribute(name, attr[name]);
michael@0 166 }
michael@0 167 return gSvg.appendChild(anim);
michael@0 168 }
michael@0 169
michael@0 170 function checkStartTime(anim, expectedStartTime, sampleTime, caseNum, id)
michael@0 171 {
michael@0 172 var startTime = 'unresolved';
michael@0 173 try {
michael@0 174 startTime = anim.getStartTime();
michael@0 175 } catch (e) {
michael@0 176 if (e.name != "InvalidStateError" ||
michael@0 177 e.code != DOMException.INVALID_STATE_ERR)
michael@0 178 throw e;
michael@0 179 }
michael@0 180
michael@0 181 var msg = "Test case " + caseNum + ", t=" + sampleTime + " animation '" +
michael@0 182 id + "': Unexpected getStartTime:";
michael@0 183 is(startTime, expectedStartTime, msg);
michael@0 184 }
michael@0 185
michael@0 186 window.addEventListener("load", main, false);
michael@0 187 ]]>
michael@0 188 </script>
michael@0 189 </pre>
michael@0 190 </body>
michael@0 191 </html>

mercurial