1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/test/test_smilHyperlinking.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,233 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<head> 1.6 + <title>Test for hyperlinking</title> 1.7 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.8 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.9 +</head> 1.10 +<body> 1.11 +<p id="display"></p> 1.12 +<div id="content" style="display:none"> 1.13 +<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" 1.14 + onload="this.pauseAnimations()"> 1.15 + <circle cx="-100" cy="20" r="15" fill="blue" id="circle"/> 1.16 +</svg> 1.17 +</div> 1.18 +<pre id="test"> 1.19 +<script class="testbody" type="text/javascript"> 1.20 +<![CDATA[ 1.21 +/** Test for SMIL keySplines **/ 1.22 + 1.23 +/* Global Variables */ 1.24 +const SVGNS="http://www.w3.org/2000/svg"; 1.25 +var gSvg = document.getElementById("svg"); 1.26 +var gAnim; 1.27 + 1.28 +var gTestStages = 1.29 + [ testActive, 1.30 + testSeekToFirst, 1.31 + testKickStart, 1.32 + testKickStartWithUnresolved, 1.33 + testFiltering 1.34 + ]; 1.35 + 1.36 +SimpleTest.waitForExplicitFinish(); 1.37 + 1.38 +function continueTest() 1.39 +{ 1.40 + if (gTestStages.length == 0) { 1.41 + SimpleTest.finish(); 1.42 + return; 1.43 + } 1.44 + 1.45 + window.location.hash = ""; 1.46 + if (gAnim) { 1.47 + gAnim.parentNode.removeChild(gAnim); 1.48 + } 1.49 + gAnim = createAnim(); 1.50 + gSvg.setCurrentTime(0); 1.51 + gTestStages.shift()(); 1.52 +} 1.53 + 1.54 +function createAnim() { 1.55 + var anim = document.createElementNS(SVGNS,'animate'); 1.56 + anim.setAttribute('attributeName','cx'); 1.57 + anim.setAttribute('from','0'); 1.58 + anim.setAttribute('to','100'); 1.59 + anim.setAttribute('dur','1s'); 1.60 + anim.setAttribute('begin','indefinite'); 1.61 + anim.setAttribute('id','anim'); 1.62 + return document.getElementById('circle').appendChild(anim); 1.63 +} 1.64 + 1.65 +// Traversing a hyperlink, condition 1: 1.66 +// 1.67 +// "If the target element is active, seek the document time back to the 1.68 +// (current) begin time of the element. If there are multiple begin times, use 1.69 +// the begin time that corresponds to the current "begin instance"." 1.70 +// 1.71 +function testActive() { 1.72 + gAnim.setAttribute('begin','2s; 4s'); 1.73 + gSvg.setCurrentTime(2.5); 1.74 + fireLink(rewindActiveInterval1); 1.75 +} 1.76 + 1.77 +function rewindActiveInterval1() { 1.78 + is(gSvg.getCurrentTime(), 2, 1.79 + "Unexpected time after activating link to animation in the middle of " + 1.80 + "first active interval"); 1.81 + 1.82 + // Seek to second interval 1.83 + gSvg.setCurrentTime(4.5); 1.84 + fireLink(rewindActiveInterval2); 1.85 +} 1.86 + 1.87 +function rewindActiveInterval2() { 1.88 + is(gSvg.getCurrentTime(), 4, 1.89 + "Unexpected time after activating link to animation in the middle of " + 1.90 + "second active interval"); 1.91 + 1.92 + // Try a negative time 1.93 + gAnim.setAttribute("begin", "-0.5"); 1.94 + gSvg.setCurrentTime(0.2); 1.95 + fireLink(rewindActiveIntervalAtZero); 1.96 +} 1.97 + 1.98 +function rewindActiveIntervalAtZero() { 1.99 + is(gSvg.getCurrentTime(), 0, 1.100 + "Unexpected time after activating link to animation in the middle of " + 1.101 + "an active interval that overlaps zero"); 1.102 + 1.103 + continueTest(); 1.104 +} 1.105 + 1.106 +// Traversing a hyperlink, condition 2: 1.107 +// 1.108 +// "Else if the target element begin time is resolved (i.e., there is any 1.109 +// resolved time in the list of begin times, or if the begin time was forced by 1.110 +// an earlier hyperlink or a beginElement() method call), seek the document time 1.111 +// (forward or back, as needed) to the earliest resolved begin time of the 1.112 +// target element. Note that the begin time may be resolved as a result of an 1.113 +// earlier hyperlink, DOM or event activation. Once the begin time is resolved, 1.114 +// hyperlink traversal always seeks." 1.115 +// 1.116 +function testSeekToFirst() { 1.117 + // Seek forwards 1.118 + gAnim.setAttribute('begin','2s'); 1.119 + gSvg.setCurrentTime(0); 1.120 + fireLink(forwardToInterval1); 1.121 +} 1.122 + 1.123 +function forwardToInterval1() { 1.124 + is(gSvg.getCurrentTime(), 2, 1.125 + "Unexpected time after activating link to animation scheduled to start " + 1.126 + "the future"); 1.127 + 1.128 + // Seek backwards 1.129 + gSvg.setCurrentTime(3.5); 1.130 + fireLink(backwardToInterval1); 1.131 +} 1.132 + 1.133 +function backwardToInterval1() { 1.134 + is(gSvg.getCurrentTime(), 2, 1.135 + "Unexpected time after activating link to animation that ran in the past"); 1.136 + 1.137 + // What if the first begin instance is negative? 1.138 + gAnim.setAttribute('begin','-0.5s'); 1.139 + gSvg.setCurrentTime(1); 1.140 + fireLink(backwardToZero); 1.141 +} 1.142 + 1.143 +function backwardToZero() { 1.144 + is(gSvg.getCurrentTime(), 0, 1.145 + "Unexpected time after activating link to animation that ran in the " + 1.146 + "past with a negative time"); 1.147 + 1.148 + continueTest(); 1.149 +} 1.150 + 1.151 +// Traversing a hyperlink, condition 3: 1.152 +// 1.153 +// "Else (animation begin time is unresolved) just resolve the target animation 1.154 +// begin time at current document time. Disregard the sync-base or event base of 1.155 +// the animation, and do not "back-propagate" any timing logic to resolve the 1.156 +// child, but rather treat it as though it were defined with begin="indefinite" 1.157 +// and just resolve begin time to the current document time." 1.158 +// 1.159 +function testKickStart() { 1.160 + gSvg.setCurrentTime(1); 1.161 + fireLink(startedAt1s); 1.162 +} 1.163 + 1.164 +function startedAt1s() { 1.165 + is(gSvg.getCurrentTime(), 1, 1.166 + "Unexpected time after kick-starting animation with indefinite start " + 1.167 + "by hyperlink"); 1.168 + is(gAnim.getStartTime(), 1, 1.169 + "Unexpected start time for kick-started animation"); 1.170 + 1.171 + continueTest(); 1.172 +} 1.173 + 1.174 +function testKickStartWithUnresolved() { 1.175 + gAnim.setAttribute("begin", "circle.click"); 1.176 + gSvg.setCurrentTime(3); 1.177 + fireLink(startedAt3s); 1.178 +} 1.179 + 1.180 +function startedAt3s() { 1.181 + is(gSvg.getCurrentTime(), 3, 1.182 + "Unexpected time after kick-starting animation with unresolved start " + 1.183 + "by hyperlink"); 1.184 + is(gAnim.getStartTime(), 3, 1.185 + "Unexpected start time for kick-started animation with unresolved begin " + 1.186 + "condition"); 1.187 + 1.188 + continueTest(); 1.189 +} 1.190 + 1.191 +function testFiltering() { 1.192 + gAnim.setAttribute('begin','-3s; 1s; 2s; 3s; 4s; 5s; 6s; 7s; 8s; 9s; 10s'); 1.193 + gSvg.setCurrentTime(12); 1.194 + fireLink(rewindToFirst); 1.195 +} 1.196 + 1.197 +function rewindToFirst() { 1.198 + is(gSvg.getCurrentTime(), 1, 1.199 + "Unexpected time after triggering animation with a hyperlink after " + 1.200 + "numerous intervals have passed"); 1.201 + 1.202 + continueTest(); 1.203 +} 1.204 + 1.205 +function fireLink(callback) { 1.206 + // First we need to reset the hash because otherwise the redundant hashchange 1.207 + // events will be suppressed 1.208 + if (window.location.hash === '') { 1.209 + fireLinkPart2(callback); 1.210 + } else { 1.211 + window.location.hash = ''; 1.212 + window.addEventListener("hashchange", 1.213 + function clearHash() { 1.214 + window.removeEventListener("hashchange", clearHash, false); 1.215 + window.setTimeout(fireLinkPart2, 0, callback); 1.216 + }, 1.217 + false); 1.218 + } 1.219 +} 1.220 + 1.221 +function fireLinkPart2(callback) { 1.222 + window.addEventListener("hashchange", 1.223 + function triggerCallback() { 1.224 + window.removeEventListener("hashchange", triggerCallback, false); 1.225 + window.setTimeout(callback, 0); 1.226 + }, 1.227 + false); 1.228 + window.location.hash = '#anim'; 1.229 +} 1.230 + 1.231 +window.addEventListener("load", continueTest, false); 1.232 +]]> 1.233 +</script> 1.234 +</pre> 1.235 +</body> 1.236 +</html>