1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/test/test_smilSyncbaseTarget.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,180 @@ 1.4 +<?xml version="1.0" encoding="UTF-8" ?> 1.5 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.6 +<head> 1.7 + <title>Test for syncbase targetting</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.10 +</head> 1.11 +<body> 1.12 +<p id="display"></p> 1.13 +<div id="content" style="display: none"> 1.14 +<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" 1.15 + onload="this.pauseAnimations()"> 1.16 + <circle cx="-20" cy="20" r="15" fill="blue" id="circle"> 1.17 + <set attributeName="cx" to="0" begin="2s" dur="1s" id="a"/> 1.18 + <set attributeName="cx" to="0" begin="2s" dur="1s" xml:id="b"/> 1.19 + <set attributeName="cx" to="0" begin="2s" dur="1s" id="あ"/> 1.20 + <set attributeName="cx" to="0" begin="2s" dur="1s" id="a.b"/> 1.21 + <set attributeName="cx" to="0" begin="2s" dur="1s" id="a-b"/> 1.22 + <set attributeName="cx" to="0" begin="2s" dur="1s" id="a:b"/> 1.23 + <set attributeName="cx" to="0" begin="2s" dur="1s" id="-a"/> 1.24 + <set attributeName="cx" to="0" begin="2s" dur="1s" id="0"/> 1.25 + </circle> 1.26 +</svg> 1.27 +</div> 1.28 +<pre id="test"> 1.29 +<script class="testbody" type="text/javascript"> 1.30 +<![CDATA[ 1.31 +/** Test for syncbase targetting behavior **/ 1.32 + 1.33 +SimpleTest.waitForExplicitFinish(); 1.34 + 1.35 +function main() { 1.36 + var svg = getElement("svg"); 1.37 + ok(svg.animationsPaused(), "should be paused by <svg> load handler"); 1.38 + is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); 1.39 + 1.40 + testSpecs(); 1.41 + testChangeId(); 1.42 + testRemoveTimebase(); 1.43 + 1.44 + SimpleTest.finish(); 1.45 +} 1.46 + 1.47 +function testSpecs() { 1.48 + var anim = createAnim(); 1.49 + 1.50 + // Sanity check--initial state 1.51 + ok(noStart(anim), "Unexpected initial value for indefinite start time."); 1.52 + 1.53 + var specs = [ [ 'a.begin', 2 ], 1.54 + [ 'b.begin', 'todo' ], // xml:id support, bug 275196 1.55 + [ 'あ.begin', 2 ], // unicode id 1.56 + [ ' a.begin ', 2 ], // whitespace 1.57 + [ 'a\\.b.begin', 2 ], // escaping 1.58 + [ 'a\\-b.begin', 2 ], // escaping 1.59 + [ 'a:b.begin', 2 ], 1.60 + // Invalid 1.61 + [ '-a.begin', 'notok' ], // invalid XML ID 1.62 + [ '\\-a.begin', 'notok' ], // invalid XML ID 1.63 + [ '0.begin', 'notok' ], // invalid XML ID 1.64 + [ '\xB7.begin', 'notok' ], // invalid XML ID 1.65 + [ '\x7B.begin', 'notok' ], // invalid XML ID 1.66 + [ '.begin', 'notok' ], 1.67 + [ ' .end ', 'notok' ], 1.68 + [ 'a.begin-5a', 'notok' ], 1.69 + // Offsets 1.70 + [ ' a.begin + 1min', 2 + 60 ], 1.71 + [ ' a.begin-0.5s', 1.5 ], 1.72 + ]; 1.73 + for (var i = 0; i < specs.length; i++) { 1.74 + var spec = specs[i][0]; 1.75 + var expected = specs[i][1]; 1.76 + anim.setAttribute('begin', spec); 1.77 + try { 1.78 + if (typeof(expected) == 'number') { 1.79 + is(anim.getStartTime(), expected, 1.80 + "Unexpected start time with spec: " + spec); 1.81 + } else if (expected == 'todo') { 1.82 + todo_is(anim.getStartTime(), 2,"Unexpected success with spec: " + spec); 1.83 + } else { 1.84 + anim.getStartTime(); 1.85 + ok(false, "Unexpected success with spec: " + spec); 1.86 + } 1.87 + } catch(e) { 1.88 + if (e.name == "InvalidStateError" && 1.89 + e.code == DOMException.INVALID_STATE_ERR) { 1.90 + if (typeof(expected) == 'number') 1.91 + ok(false, "Failed with spec: " + spec); 1.92 + else if (expected == 'todo') 1.93 + todo(false, "Yet to implement: " + spec); 1.94 + else 1.95 + ok(true); 1.96 + } else { 1.97 + ok(false, "Unexpected exception: " + e + "(with spec: " + spec + ")"); 1.98 + } 1.99 + } 1.100 + } 1.101 + 1.102 + anim.parentNode.removeChild(anim); 1.103 +} 1.104 + 1.105 +function testChangeId() { 1.106 + var anim = createAnim(); 1.107 + 1.108 + anim.setAttribute('begin', 'a.begin'); 1.109 + is(anim.getStartTime(), 2, "Unexpected start time."); 1.110 + 1.111 + var a = getElement('a'); 1.112 + a.setAttribute('id', 'a1'); 1.113 + ok(noStart(anim), "Unexpected return value after changing target ID."); 1.114 + 1.115 + a.setAttribute('id', 'a'); 1.116 + is(anim.getStartTime(), 2, 1.117 + "Unexpected start time after resetting target ID."); 1.118 + 1.119 + anim.parentNode.removeChild(anim); 1.120 +} 1.121 + 1.122 +function testRemoveTimebase() { 1.123 + var anim = createAnim(); 1.124 + anim.setAttribute('begin', 'a.begin'); 1.125 + ok(!noStart(anim), "Unexpected start time before removing timebase."); 1.126 + 1.127 + var circle = getElement('circle'); 1.128 + var a = getElement('a'); 1.129 + // Sanity check 1.130 + is(a, circle.firstElementChild, "Unexpected document structure"); 1.131 + 1.132 + // Remove timebase 1.133 + a.parentNode.removeChild(a); 1.134 + ok(noStart(anim), "Unexpected start time after removing timebase."); 1.135 + 1.136 + // Reinsert timebase 1.137 + circle.insertBefore(a, circle.firstElementChild); 1.138 + ok(!noStart(anim), "Unexpected start time after re-inserting timebase."); 1.139 + 1.140 + // Remove dependent element 1.141 + anim.parentNode.removeChild(anim); 1.142 + ok(noStart(anim), "Unexpected start time after removing dependent."); 1.143 + 1.144 + // Create a new dependent 1.145 + var anim2 = createAnim(); 1.146 + anim2.setAttribute('begin', 'a.begin'); 1.147 + is(anim2.getStartTime(), 2, 1.148 + "Unexpected start time after adding new dependent."); 1.149 +} 1.150 + 1.151 +function createAnim() { 1.152 + const svgns="http://www.w3.org/2000/svg"; 1.153 + var anim = document.createElementNS(svgns,'animate'); 1.154 + anim.setAttribute('attributeName','cx'); 1.155 + anim.setAttribute('from','0'); 1.156 + anim.setAttribute('to','100'); 1.157 + anim.setAttribute('begin','indefinite'); 1.158 + anim.setAttribute('dur','1s'); 1.159 + return getElement('circle').appendChild(anim); 1.160 +} 1.161 + 1.162 +function noStart(elem) { 1.163 + var exceptionCaught = false; 1.164 + 1.165 + try { 1.166 + elem.getStartTime(); 1.167 + } catch(e) { 1.168 + exceptionCaught = true; 1.169 + is (e.name, "InvalidStateError", 1.170 + "Unexpected exception from getStartTime."); 1.171 + is (e.code, DOMException.INVALID_STATE_ERR, 1.172 + "Unexpected exception code from getStartTime."); 1.173 + } 1.174 + 1.175 + return exceptionCaught; 1.176 +} 1.177 + 1.178 +window.addEventListener("load", main, false); 1.179 +]]> 1.180 +</script> 1.181 +</pre> 1.182 +</body> 1.183 +</html>