dom/smil/test/test_smilSync.xhtml

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <head>
michael@0 3 <title>Test for SMIL sync behaviour </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" width="120px" height="120px">
michael@0 11 <circle cx="20" cy="20" r="15" fill="blue">
michael@0 12 <animate attributeName="cx" attributeType="XML" from="20" to="100"
michael@0 13 begin="indefinite" dur="4s" restart="always" id="anim1"/>
michael@0 14 </circle>
michael@0 15 <circle cx="20" cy="20" r="15" fill="blue">
michael@0 16 <animate attributeName="cx" attributeType="XML" from="0" to="50"
michael@0 17 begin="0" dur="1s" additive="sum" fill="freeze" id="anim2"/>
michael@0 18 </circle>
michael@0 19 <circle cx="20" cy="20" r="15" fill="blue">
michael@0 20 <animate attributeName="cx" attributeType="XML" from="0" to="50"
michael@0 21 begin="0" dur="10s" additive="sum" fill="freeze" id="anim3"/>
michael@0 22 </circle>
michael@0 23 <circle cx="20" cy="20" r="15" fill="blue">
michael@0 24 <animate attributeName="cx" attributeType="XML" from="0" to="50"
michael@0 25 begin="0" dur="10s" additive="sum" fill="freeze" id="anim4"/>
michael@0 26 </circle>
michael@0 27 <circle cx="20" cy="20" r="15" fill="blue">
michael@0 28 <animate attributeName="cx" attributeType="XML" from="0" to="50"
michael@0 29 begin="0" dur="40s" additive="sum" fill="freeze" id="anim5"/>
michael@0 30 </circle>
michael@0 31 <circle cx="20" cy="20" r="15" fill="blue">
michael@0 32 <animate attributeName="cx" attributeType="XML" from="20" to="100"
michael@0 33 begin="100s" dur="4s" restart="always" id="anim6"/>
michael@0 34 </circle>
michael@0 35 </svg>
michael@0 36 </div>
michael@0 37 <pre id="test">
michael@0 38 <script class="testbody" type="text/javascript">
michael@0 39 <![CDATA[
michael@0 40 /** Test for SMIL sync behavior **/
michael@0 41
michael@0 42 /* Global Variables */
michael@0 43 var svg = document.getElementById("svg");
michael@0 44
michael@0 45 SimpleTest.waitForExplicitFinish();
michael@0 46
michael@0 47 function main() {
michael@0 48 testBeginAt(document.getElementById("anim1"));
michael@0 49 testChangeBaseVal(document.getElementById("anim2"));
michael@0 50 testChangeWhilePaused(document.getElementById("anim3"));
michael@0 51 testChangeAnimAttribute(document.getElementById("anim4"));
michael@0 52 testChangeTimingAttribute(document.getElementById("anim5"));
michael@0 53 testSetCurrentTime(document.getElementById("anim6"));
michael@0 54 SimpleTest.finish();
michael@0 55 }
michael@0 56
michael@0 57 function testBeginAt(anim) {
michael@0 58 // This (hugely important) test checks that a call to beginElement updates to
michael@0 59 // the new interval
michael@0 60
michael@0 61 // Check some pre-conditions
michael@0 62 is(anim.getAttribute("restart"), "always");
michael@0 63 ok(anim.getSimpleDuration() >= 4);
michael@0 64
michael@0 65 // First start the animation
michael@0 66 svg.setCurrentTime(2);
michael@0 67 anim.beginElement();
michael@0 68
michael@0 69 // Then restart it--twice
michael@0 70 svg.setCurrentTime(4);
michael@0 71 anim.beginElement();
michael@0 72 anim.beginElementAt(-1);
michael@0 73
michael@0 74 // The first restart should win if the state machine has been successfully
michael@0 75 // updated. If we get '3' back instead we haven't updated properly.
michael@0 76 is(anim.getStartTime(), 4);
michael@0 77 }
michael@0 78
michael@0 79 function testChangeBaseVal(anim) {
michael@0 80 // Check that a change to the base value is updated even after animation is
michael@0 81 // frozen
michael@0 82
michael@0 83 // preconditions -- element should have ended
michael@0 84 try {
michael@0 85 anim.getStartTime();
michael@0 86 ok(false, "Element has not ended yet.");
michael@0 87 } catch (e) { }
michael@0 88
michael@0 89 // check frozen value is applied
michael@0 90 var target = anim.targetElement;
michael@0 91 is(target.cx.animVal.value, 70);
michael@0 92 is(target.cx.baseVal.value, 20);
michael@0 93
michael@0 94 // change base val and re-check
michael@0 95 target.cx.baseVal.value = 30;
michael@0 96 is(target.cx.animVal.value, 80);
michael@0 97 is(target.cx.baseVal.value, 30);
michael@0 98 }
michael@0 99
michael@0 100 function testChangeWhilePaused(anim) {
michael@0 101 // Check that a change to the base value is updated even when the animation is
michael@0 102 // paused
michael@0 103
michael@0 104 svg.pauseAnimations();
michael@0 105 svg.setCurrentTime(anim.getSimpleDuration() / 2);
michael@0 106
michael@0 107 // check paused value is applied
michael@0 108 var target = anim.targetElement;
michael@0 109 is(target.cx.animVal.value, 45);
michael@0 110 is(target.cx.baseVal.value, 20);
michael@0 111
michael@0 112 // change base val and re-check
michael@0 113 target.cx.baseVal.value = 30;
michael@0 114 is(target.cx.animVal.value, 55);
michael@0 115 is(target.cx.baseVal.value, 30);
michael@0 116 }
michael@0 117
michael@0 118 function testChangeAnimAttribute(anim) {
michael@0 119 // Check that a change to an animation attribute causes an update even when
michael@0 120 // the animation is frozen and paused
michael@0 121
michael@0 122 // Make sure animation is paused and frozen
michael@0 123 svg.pauseAnimations();
michael@0 124 svg.setCurrentTime(anim.getStartTime() + anim.getSimpleDuration() + 1);
michael@0 125
michael@0 126 // Check frozen value is applied
michael@0 127 var target = anim.targetElement;
michael@0 128 is(target.cx.animVal.value, 70);
michael@0 129 is(target.cx.baseVal.value, 20);
michael@0 130
michael@0 131 // Make the animation no longer additive
michael@0 132 anim.removeAttribute("additive");
michael@0 133 is(target.cx.animVal.value, 50);
michael@0 134 is(target.cx.baseVal.value, 20);
michael@0 135 }
michael@0 136
michael@0 137 function testChangeTimingAttribute(anim) {
michael@0 138 // Check that a change to a timing attribute causes an update even when
michael@0 139 // the animation is paused
michael@0 140
michael@0 141 svg.pauseAnimations();
michael@0 142 svg.setCurrentTime(anim.getSimpleDuration() / 2);
michael@0 143
michael@0 144 // Check part-way value is applied
michael@0 145 var target = anim.targetElement;
michael@0 146 is(target.cx.animVal.value, 45);
michael@0 147 is(target.cx.baseVal.value, 20);
michael@0 148
michael@0 149 // Make the animation no longer additive
michael@0 150 anim.setAttribute("dur", String(anim.getSimpleDuration() / 2) + "s");
michael@0 151 is(target.cx.animVal.value, 70);
michael@0 152 is(target.cx.baseVal.value, 20);
michael@0 153
michael@0 154 // Remove fill
michael@0 155 anim.removeAttribute("fill");
michael@0 156 is(target.cx.animVal.value, 20);
michael@0 157 is(target.cx.baseVal.value, 20);
michael@0 158 }
michael@0 159
michael@0 160 function testSetCurrentTime(anim) {
michael@0 161 // This test checks that a call to setCurrentTime flushes restarts
michael@0 162 //
michael@0 163 // Actually, this same scenario arises in test_smilRestart.xhtml but we
michael@0 164 // isolate this particular situation here for easier diagnosis if this ever
michael@0 165 // fails.
michael@0 166 //
michael@0 167 // At first we have:
michael@0 168 // currentTime begin="100s"
michael@0 169 // v v
michael@0 170 // Doc time: 0---\/\/\/-------99----------100-------
michael@0 171 //
michael@0 172 svg.setCurrentTime(99);
michael@0 173 is(anim.getStartTime(), 100);
michael@0 174
michael@0 175 // Then we restart giving us:
michael@0 176 //
michael@0 177 // beginElement begin="100s"
michael@0 178 // v v
michael@0 179 // Doc time: 0---\/\/\/-------99----------100-------
michael@0 180 //
michael@0 181 // So our current interval is
michael@0 182 //
michael@0 183 // begin="100s"
michael@0 184 // v
michael@0 185 // +---------------|
michael@0 186 // Doc time: 0---\/\/\/-------99-100-101-102-103-----
michael@0 187 //
michael@0 188 anim.beginElement();
michael@0 189 is(anim.getStartTime(), svg.getCurrentTime());
michael@0 190
michael@0 191 // Then we skip to half-way, i.e.
michael@0 192 //
michael@0 193 // currentTime
michael@0 194 // v
michael@0 195 // begin="100s"
michael@0 196 // v
michael@0 197 // +---------------|
michael@0 198 // Doc time: 0---\/\/\/-------99-100-101-102-103-----
michael@0 199 //
michael@0 200 // At this point we should flush our restarts and early end the first interval
michael@0 201 // and start the second interval, giving us
michael@0 202 //
michael@0 203 // So our timegraph looks like:
michael@0 204 //
michael@0 205 // currentTime
michael@0 206 // v
michael@0 207 // +---------------|
michael@0 208 // +---|
michael@0 209 // Doc time: 0---\/\/\/-------99-100-101-102-103-104-
michael@0 210 //
michael@0 211 var newTime = anim.getStartTime() + 0.5 * anim.getSimpleDuration();
michael@0 212 svg.setCurrentTime(newTime);
michael@0 213
michael@0 214 // Finally we call beginElement again giving us
michael@0 215 //
michael@0 216 // currentTime
michael@0 217 // v
michael@0 218 // +---------------|
michael@0 219 // +---|
michael@0 220 // +---|
michael@0 221 // Doc time: 0---\/\/\/-------99-100-101-102-103-104-105-
michael@0 222 //
michael@0 223 // If, however, setCurrentTime failed to flush restarts out starting point
michael@0 224 // we do come to update the timegraph would be:
michael@0 225 //
michael@0 226 // beginElementAt
michael@0 227 // v
michael@0 228 // begin="100s"
michael@0 229 // v
michael@0 230 // +---------------|
michael@0 231 // Doc time: 0---\/\/\/-------99-100-101-102-103-----
michael@0 232 //
michael@0 233 // And as soon as we encountered the begin="100s" spec we'd do a restart
michael@0 234 // according to the SMIL algorithms and a restart involves a reset which
michael@0 235 // clears the instance times created by DOM calls and so we'd end up with
michael@0 236 // just:
michael@0 237 //
michael@0 238 // currentTime
michael@0 239 // v
michael@0 240 // +---------------|
michael@0 241 // +---|
michael@0 242 // Doc time: 0---\/\/\/-------99-100-101-102-103-104-
michael@0 243 //
michael@0 244 // Which is probably not what the author intended.
michael@0 245 //
michael@0 246 anim.beginElement();
michael@0 247 is(anim.getStartTime(), svg.getCurrentTime());
michael@0 248 }
michael@0 249
michael@0 250 window.addEventListener("load", main, false);
michael@0 251 ]]>
michael@0 252 </script>
michael@0 253 </pre>
michael@0 254 </body>
michael@0 255 </html>

mercurial