dom/smil/test/test_smilSyncbaseTarget.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 <?xml version="1.0" encoding="UTF-8" ?>
michael@0 2 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 3 <head>
michael@0 4 <title>Test for syncbase targetting</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7 </head>
michael@0 8 <body>
michael@0 9 <p id="display"></p>
michael@0 10 <div id="content" style="display: none">
michael@0 11 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
michael@0 12 onload="this.pauseAnimations()">
michael@0 13 <circle cx="-20" cy="20" r="15" fill="blue" id="circle">
michael@0 14 <set attributeName="cx" to="0" begin="2s" dur="1s" id="a"/>
michael@0 15 <set attributeName="cx" to="0" begin="2s" dur="1s" xml:id="b"/>
michael@0 16 <set attributeName="cx" to="0" begin="2s" dur="1s" id="あ"/>
michael@0 17 <set attributeName="cx" to="0" begin="2s" dur="1s" id="a.b"/>
michael@0 18 <set attributeName="cx" to="0" begin="2s" dur="1s" id="a-b"/>
michael@0 19 <set attributeName="cx" to="0" begin="2s" dur="1s" id="a:b"/>
michael@0 20 <set attributeName="cx" to="0" begin="2s" dur="1s" id="-a"/>
michael@0 21 <set attributeName="cx" to="0" begin="2s" dur="1s" id="0"/>
michael@0 22 </circle>
michael@0 23 </svg>
michael@0 24 </div>
michael@0 25 <pre id="test">
michael@0 26 <script class="testbody" type="text/javascript">
michael@0 27 <![CDATA[
michael@0 28 /** Test for syncbase targetting behavior **/
michael@0 29
michael@0 30 SimpleTest.waitForExplicitFinish();
michael@0 31
michael@0 32 function main() {
michael@0 33 var svg = getElement("svg");
michael@0 34 ok(svg.animationsPaused(), "should be paused by <svg> load handler");
michael@0 35 is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
michael@0 36
michael@0 37 testSpecs();
michael@0 38 testChangeId();
michael@0 39 testRemoveTimebase();
michael@0 40
michael@0 41 SimpleTest.finish();
michael@0 42 }
michael@0 43
michael@0 44 function testSpecs() {
michael@0 45 var anim = createAnim();
michael@0 46
michael@0 47 // Sanity check--initial state
michael@0 48 ok(noStart(anim), "Unexpected initial value for indefinite start time.");
michael@0 49
michael@0 50 var specs = [ [ 'a.begin', 2 ],
michael@0 51 [ 'b.begin', 'todo' ], // xml:id support, bug 275196
michael@0 52 [ 'あ.begin', 2 ], // unicode id
michael@0 53 [ ' a.begin ', 2 ], // whitespace
michael@0 54 [ 'a\\.b.begin', 2 ], // escaping
michael@0 55 [ 'a\\-b.begin', 2 ], // escaping
michael@0 56 [ 'a:b.begin', 2 ],
michael@0 57 // Invalid
michael@0 58 [ '-a.begin', 'notok' ], // invalid XML ID
michael@0 59 [ '\\-a.begin', 'notok' ], // invalid XML ID
michael@0 60 [ '0.begin', 'notok' ], // invalid XML ID
michael@0 61 [ '\xB7.begin', 'notok' ], // invalid XML ID
michael@0 62 [ '\x7B.begin', 'notok' ], // invalid XML ID
michael@0 63 [ '.begin', 'notok' ],
michael@0 64 [ ' .end ', 'notok' ],
michael@0 65 [ 'a.begin-5a', 'notok' ],
michael@0 66 // Offsets
michael@0 67 [ ' a.begin + 1min', 2 + 60 ],
michael@0 68 [ ' a.begin-0.5s', 1.5 ],
michael@0 69 ];
michael@0 70 for (var i = 0; i < specs.length; i++) {
michael@0 71 var spec = specs[i][0];
michael@0 72 var expected = specs[i][1];
michael@0 73 anim.setAttribute('begin', spec);
michael@0 74 try {
michael@0 75 if (typeof(expected) == 'number') {
michael@0 76 is(anim.getStartTime(), expected,
michael@0 77 "Unexpected start time with spec: " + spec);
michael@0 78 } else if (expected == 'todo') {
michael@0 79 todo_is(anim.getStartTime(), 2,"Unexpected success with spec: " + spec);
michael@0 80 } else {
michael@0 81 anim.getStartTime();
michael@0 82 ok(false, "Unexpected success with spec: " + spec);
michael@0 83 }
michael@0 84 } catch(e) {
michael@0 85 if (e.name == "InvalidStateError" &&
michael@0 86 e.code == DOMException.INVALID_STATE_ERR) {
michael@0 87 if (typeof(expected) == 'number')
michael@0 88 ok(false, "Failed with spec: " + spec);
michael@0 89 else if (expected == 'todo')
michael@0 90 todo(false, "Yet to implement: " + spec);
michael@0 91 else
michael@0 92 ok(true);
michael@0 93 } else {
michael@0 94 ok(false, "Unexpected exception: " + e + "(with spec: " + spec + ")");
michael@0 95 }
michael@0 96 }
michael@0 97 }
michael@0 98
michael@0 99 anim.parentNode.removeChild(anim);
michael@0 100 }
michael@0 101
michael@0 102 function testChangeId() {
michael@0 103 var anim = createAnim();
michael@0 104
michael@0 105 anim.setAttribute('begin', 'a.begin');
michael@0 106 is(anim.getStartTime(), 2, "Unexpected start time.");
michael@0 107
michael@0 108 var a = getElement('a');
michael@0 109 a.setAttribute('id', 'a1');
michael@0 110 ok(noStart(anim), "Unexpected return value after changing target ID.");
michael@0 111
michael@0 112 a.setAttribute('id', 'a');
michael@0 113 is(anim.getStartTime(), 2,
michael@0 114 "Unexpected start time after resetting target ID.");
michael@0 115
michael@0 116 anim.parentNode.removeChild(anim);
michael@0 117 }
michael@0 118
michael@0 119 function testRemoveTimebase() {
michael@0 120 var anim = createAnim();
michael@0 121 anim.setAttribute('begin', 'a.begin');
michael@0 122 ok(!noStart(anim), "Unexpected start time before removing timebase.");
michael@0 123
michael@0 124 var circle = getElement('circle');
michael@0 125 var a = getElement('a');
michael@0 126 // Sanity check
michael@0 127 is(a, circle.firstElementChild, "Unexpected document structure");
michael@0 128
michael@0 129 // Remove timebase
michael@0 130 a.parentNode.removeChild(a);
michael@0 131 ok(noStart(anim), "Unexpected start time after removing timebase.");
michael@0 132
michael@0 133 // Reinsert timebase
michael@0 134 circle.insertBefore(a, circle.firstElementChild);
michael@0 135 ok(!noStart(anim), "Unexpected start time after re-inserting timebase.");
michael@0 136
michael@0 137 // Remove dependent element
michael@0 138 anim.parentNode.removeChild(anim);
michael@0 139 ok(noStart(anim), "Unexpected start time after removing dependent.");
michael@0 140
michael@0 141 // Create a new dependent
michael@0 142 var anim2 = createAnim();
michael@0 143 anim2.setAttribute('begin', 'a.begin');
michael@0 144 is(anim2.getStartTime(), 2,
michael@0 145 "Unexpected start time after adding new dependent.");
michael@0 146 }
michael@0 147
michael@0 148 function createAnim() {
michael@0 149 const svgns="http://www.w3.org/2000/svg";
michael@0 150 var anim = document.createElementNS(svgns,'animate');
michael@0 151 anim.setAttribute('attributeName','cx');
michael@0 152 anim.setAttribute('from','0');
michael@0 153 anim.setAttribute('to','100');
michael@0 154 anim.setAttribute('begin','indefinite');
michael@0 155 anim.setAttribute('dur','1s');
michael@0 156 return getElement('circle').appendChild(anim);
michael@0 157 }
michael@0 158
michael@0 159 function noStart(elem) {
michael@0 160 var exceptionCaught = false;
michael@0 161
michael@0 162 try {
michael@0 163 elem.getStartTime();
michael@0 164 } catch(e) {
michael@0 165 exceptionCaught = true;
michael@0 166 is (e.name, "InvalidStateError",
michael@0 167 "Unexpected exception from getStartTime.");
michael@0 168 is (e.code, DOMException.INVALID_STATE_ERR,
michael@0 169 "Unexpected exception code from getStartTime.");
michael@0 170 }
michael@0 171
michael@0 172 return exceptionCaught;
michael@0 173 }
michael@0 174
michael@0 175 window.addEventListener("load", main, false);
michael@0 176 ]]>
michael@0 177 </script>
michael@0 178 </pre>
michael@0 179 </body>
michael@0 180 </html>

mercurial