tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_smilContainerBinding.xhtml (2955B)


      1 <?xml version="1.0" encoding="UTF-8" ?>
      2 <html xmlns="http://www.w3.org/1999/xhtml">
      3 <head>
      4  <title>Test for adding and removing animations from a time container</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <p id="display"></p>
     10 <div id="content" style="display: none">
     11 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
     12     onload="this.pauseAnimations()">
     13  <circle cx="-20" cy="20" r="15" fill="blue" id="circle">
     14    <set attributeName="cy" to="120" begin="0s; 2s" dur="1s" id="b"/>
     15  </circle>
     16 </svg>
     17 </div>
     18 <pre id="test">
     19 <script class="testbody" type="text/javascript">
     20 <![CDATA[
     21 /** Test for adding and removing animations from a time container */
     22 
     23 SimpleTest.waitForExplicitFinish();
     24 
     25 function main() {
     26  var svg = getElement("svg");
     27  ok(svg.animationsPaused(), "should be paused by <svg> load handler");
     28  is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
     29 
     30  // Create animation and check initial state
     31  var anim = createAnim();
     32  anim.setAttribute('begin','b.begin+2s; 6s');
     33  ok(noStart(anim), "Animation has start time before attaching to document.");
     34 
     35  // Attach animation to container
     36  var circle = getElement("circle");
     37  circle.appendChild(anim);
     38 
     39  // Check state after attaching
     40  is(anim.getStartTime(), 2);
     41 
     42  // Unbind from tree -- the syncbase instance time(s) should become unresolved
     43  // but the offset time should remain
     44  anim.remove();
     45  is(anim.getStartTime(), 6);
     46 
     47  // Rebind and check everything is re-resolved
     48  circle.appendChild(anim);
     49  is(anim.getStartTime(), 2);
     50 
     51  // Advance document time to t=1s
     52  // Now the current interval for b is 2s-3s but the current interval for anim
     53  // is still 2s-2.5s based on b's previous interval
     54  svg.setCurrentTime(1);
     55  is(anim.getStartTime(), 2);
     56 
     57  // Unbind
     58  anim.remove();
     59  is(anim.getStartTime(), 6);
     60 
     61  // Rebind
     62  // At this point only the current interval will be re-added to anim (this is
     63  // for consistency since old intervals may or may not have been filtered).
     64  // Therefore the start time should be 4s instead of 2s.
     65  circle.appendChild(anim);
     66  is(anim.getStartTime(), 4);
     67 
     68  SimpleTest.finish();
     69 }
     70 
     71 function createAnim() {
     72  const svgns="http://www.w3.org/2000/svg";
     73  var anim = document.createElementNS(svgns,'set');
     74  anim.setAttribute('attributeName','cx');
     75  anim.setAttribute('to','100');
     76  anim.setAttribute('dur','0.5s');
     77  return anim;
     78 }
     79 
     80 function noStart(elem) {
     81  var exceptionCaught = false;
     82 
     83  try {
     84    elem.getStartTime();
     85  } catch(e) {
     86    exceptionCaught = true;
     87    is (e.name, "InvalidStateError",
     88        "Unexpected exception from getStartTime.");
     89    is (e.code, DOMException.INVALID_STATE_ERR,
     90        "Unexpected exception code from getStartTime.");
     91  }
     92 
     93  return exceptionCaught;
     94 }
     95 
     96 window.addEventListener("load", main);
     97 ]]>
     98 </script>
     99 </pre>
    100 </body>
    101 </html>