Thu, 22 Jan 2015 13:21:57 +0100
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 hyperlinking</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 | onload="this.pauseAnimations()"> |
michael@0 | 12 | <circle cx="-100" cy="20" r="15" fill="blue" id="circle"/> |
michael@0 | 13 | </svg> |
michael@0 | 14 | </div> |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | <script class="testbody" type="text/javascript"> |
michael@0 | 17 | <![CDATA[ |
michael@0 | 18 | /** Test for SMIL keySplines **/ |
michael@0 | 19 | |
michael@0 | 20 | /* Global Variables */ |
michael@0 | 21 | const SVGNS="http://www.w3.org/2000/svg"; |
michael@0 | 22 | var gSvg = document.getElementById("svg"); |
michael@0 | 23 | var gAnim; |
michael@0 | 24 | |
michael@0 | 25 | var gTestStages = |
michael@0 | 26 | [ testActive, |
michael@0 | 27 | testSeekToFirst, |
michael@0 | 28 | testKickStart, |
michael@0 | 29 | testKickStartWithUnresolved, |
michael@0 | 30 | testFiltering |
michael@0 | 31 | ]; |
michael@0 | 32 | |
michael@0 | 33 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 34 | |
michael@0 | 35 | function continueTest() |
michael@0 | 36 | { |
michael@0 | 37 | if (gTestStages.length == 0) { |
michael@0 | 38 | SimpleTest.finish(); |
michael@0 | 39 | return; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | window.location.hash = ""; |
michael@0 | 43 | if (gAnim) { |
michael@0 | 44 | gAnim.parentNode.removeChild(gAnim); |
michael@0 | 45 | } |
michael@0 | 46 | gAnim = createAnim(); |
michael@0 | 47 | gSvg.setCurrentTime(0); |
michael@0 | 48 | gTestStages.shift()(); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function createAnim() { |
michael@0 | 52 | var anim = document.createElementNS(SVGNS,'animate'); |
michael@0 | 53 | anim.setAttribute('attributeName','cx'); |
michael@0 | 54 | anim.setAttribute('from','0'); |
michael@0 | 55 | anim.setAttribute('to','100'); |
michael@0 | 56 | anim.setAttribute('dur','1s'); |
michael@0 | 57 | anim.setAttribute('begin','indefinite'); |
michael@0 | 58 | anim.setAttribute('id','anim'); |
michael@0 | 59 | return document.getElementById('circle').appendChild(anim); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | // Traversing a hyperlink, condition 1: |
michael@0 | 63 | // |
michael@0 | 64 | // "If the target element is active, seek the document time back to the |
michael@0 | 65 | // (current) begin time of the element. If there are multiple begin times, use |
michael@0 | 66 | // the begin time that corresponds to the current "begin instance"." |
michael@0 | 67 | // |
michael@0 | 68 | function testActive() { |
michael@0 | 69 | gAnim.setAttribute('begin','2s; 4s'); |
michael@0 | 70 | gSvg.setCurrentTime(2.5); |
michael@0 | 71 | fireLink(rewindActiveInterval1); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function rewindActiveInterval1() { |
michael@0 | 75 | is(gSvg.getCurrentTime(), 2, |
michael@0 | 76 | "Unexpected time after activating link to animation in the middle of " + |
michael@0 | 77 | "first active interval"); |
michael@0 | 78 | |
michael@0 | 79 | // Seek to second interval |
michael@0 | 80 | gSvg.setCurrentTime(4.5); |
michael@0 | 81 | fireLink(rewindActiveInterval2); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function rewindActiveInterval2() { |
michael@0 | 85 | is(gSvg.getCurrentTime(), 4, |
michael@0 | 86 | "Unexpected time after activating link to animation in the middle of " + |
michael@0 | 87 | "second active interval"); |
michael@0 | 88 | |
michael@0 | 89 | // Try a negative time |
michael@0 | 90 | gAnim.setAttribute("begin", "-0.5"); |
michael@0 | 91 | gSvg.setCurrentTime(0.2); |
michael@0 | 92 | fireLink(rewindActiveIntervalAtZero); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | function rewindActiveIntervalAtZero() { |
michael@0 | 96 | is(gSvg.getCurrentTime(), 0, |
michael@0 | 97 | "Unexpected time after activating link to animation in the middle of " + |
michael@0 | 98 | "an active interval that overlaps zero"); |
michael@0 | 99 | |
michael@0 | 100 | continueTest(); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | // Traversing a hyperlink, condition 2: |
michael@0 | 104 | // |
michael@0 | 105 | // "Else if the target element begin time is resolved (i.e., there is any |
michael@0 | 106 | // resolved time in the list of begin times, or if the begin time was forced by |
michael@0 | 107 | // an earlier hyperlink or a beginElement() method call), seek the document time |
michael@0 | 108 | // (forward or back, as needed) to the earliest resolved begin time of the |
michael@0 | 109 | // target element. Note that the begin time may be resolved as a result of an |
michael@0 | 110 | // earlier hyperlink, DOM or event activation. Once the begin time is resolved, |
michael@0 | 111 | // hyperlink traversal always seeks." |
michael@0 | 112 | // |
michael@0 | 113 | function testSeekToFirst() { |
michael@0 | 114 | // Seek forwards |
michael@0 | 115 | gAnim.setAttribute('begin','2s'); |
michael@0 | 116 | gSvg.setCurrentTime(0); |
michael@0 | 117 | fireLink(forwardToInterval1); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function forwardToInterval1() { |
michael@0 | 121 | is(gSvg.getCurrentTime(), 2, |
michael@0 | 122 | "Unexpected time after activating link to animation scheduled to start " + |
michael@0 | 123 | "the future"); |
michael@0 | 124 | |
michael@0 | 125 | // Seek backwards |
michael@0 | 126 | gSvg.setCurrentTime(3.5); |
michael@0 | 127 | fireLink(backwardToInterval1); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | function backwardToInterval1() { |
michael@0 | 131 | is(gSvg.getCurrentTime(), 2, |
michael@0 | 132 | "Unexpected time after activating link to animation that ran in the past"); |
michael@0 | 133 | |
michael@0 | 134 | // What if the first begin instance is negative? |
michael@0 | 135 | gAnim.setAttribute('begin','-0.5s'); |
michael@0 | 136 | gSvg.setCurrentTime(1); |
michael@0 | 137 | fireLink(backwardToZero); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | function backwardToZero() { |
michael@0 | 141 | is(gSvg.getCurrentTime(), 0, |
michael@0 | 142 | "Unexpected time after activating link to animation that ran in the " + |
michael@0 | 143 | "past with a negative time"); |
michael@0 | 144 | |
michael@0 | 145 | continueTest(); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | // Traversing a hyperlink, condition 3: |
michael@0 | 149 | // |
michael@0 | 150 | // "Else (animation begin time is unresolved) just resolve the target animation |
michael@0 | 151 | // begin time at current document time. Disregard the sync-base or event base of |
michael@0 | 152 | // the animation, and do not "back-propagate" any timing logic to resolve the |
michael@0 | 153 | // child, but rather treat it as though it were defined with begin="indefinite" |
michael@0 | 154 | // and just resolve begin time to the current document time." |
michael@0 | 155 | // |
michael@0 | 156 | function testKickStart() { |
michael@0 | 157 | gSvg.setCurrentTime(1); |
michael@0 | 158 | fireLink(startedAt1s); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | function startedAt1s() { |
michael@0 | 162 | is(gSvg.getCurrentTime(), 1, |
michael@0 | 163 | "Unexpected time after kick-starting animation with indefinite start " + |
michael@0 | 164 | "by hyperlink"); |
michael@0 | 165 | is(gAnim.getStartTime(), 1, |
michael@0 | 166 | "Unexpected start time for kick-started animation"); |
michael@0 | 167 | |
michael@0 | 168 | continueTest(); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | function testKickStartWithUnresolved() { |
michael@0 | 172 | gAnim.setAttribute("begin", "circle.click"); |
michael@0 | 173 | gSvg.setCurrentTime(3); |
michael@0 | 174 | fireLink(startedAt3s); |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | function startedAt3s() { |
michael@0 | 178 | is(gSvg.getCurrentTime(), 3, |
michael@0 | 179 | "Unexpected time after kick-starting animation with unresolved start " + |
michael@0 | 180 | "by hyperlink"); |
michael@0 | 181 | is(gAnim.getStartTime(), 3, |
michael@0 | 182 | "Unexpected start time for kick-started animation with unresolved begin " + |
michael@0 | 183 | "condition"); |
michael@0 | 184 | |
michael@0 | 185 | continueTest(); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | function testFiltering() { |
michael@0 | 189 | gAnim.setAttribute('begin','-3s; 1s; 2s; 3s; 4s; 5s; 6s; 7s; 8s; 9s; 10s'); |
michael@0 | 190 | gSvg.setCurrentTime(12); |
michael@0 | 191 | fireLink(rewindToFirst); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | function rewindToFirst() { |
michael@0 | 195 | is(gSvg.getCurrentTime(), 1, |
michael@0 | 196 | "Unexpected time after triggering animation with a hyperlink after " + |
michael@0 | 197 | "numerous intervals have passed"); |
michael@0 | 198 | |
michael@0 | 199 | continueTest(); |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | function fireLink(callback) { |
michael@0 | 203 | // First we need to reset the hash because otherwise the redundant hashchange |
michael@0 | 204 | // events will be suppressed |
michael@0 | 205 | if (window.location.hash === '') { |
michael@0 | 206 | fireLinkPart2(callback); |
michael@0 | 207 | } else { |
michael@0 | 208 | window.location.hash = ''; |
michael@0 | 209 | window.addEventListener("hashchange", |
michael@0 | 210 | function clearHash() { |
michael@0 | 211 | window.removeEventListener("hashchange", clearHash, false); |
michael@0 | 212 | window.setTimeout(fireLinkPart2, 0, callback); |
michael@0 | 213 | }, |
michael@0 | 214 | false); |
michael@0 | 215 | } |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | function fireLinkPart2(callback) { |
michael@0 | 219 | window.addEventListener("hashchange", |
michael@0 | 220 | function triggerCallback() { |
michael@0 | 221 | window.removeEventListener("hashchange", triggerCallback, false); |
michael@0 | 222 | window.setTimeout(callback, 0); |
michael@0 | 223 | }, |
michael@0 | 224 | false); |
michael@0 | 225 | window.location.hash = '#anim'; |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | window.addEventListener("load", continueTest, false); |
michael@0 | 229 | ]]> |
michael@0 | 230 | </script> |
michael@0 | 231 | </pre> |
michael@0 | 232 | </body> |
michael@0 | 233 | </html> |