tor-browser

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

svgtransform-animation-discrete.html (2538B)


      1 <!doctype html>
      2 <html>
      3 <title>Test calcMode=discrete animation on SVGAnimateTransform.</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/SVGAnimationTestCase-testharness.js"></script>
      7 
      8 <svg>
      9 </svg>
     10 
     11 <script>
     12 var rootSVGElement = document.querySelector("svg");
     13 var epsilon = 1.0;
     14 
     15 // Setup test document
     16 var rect = createSVGElement("rect");
     17 rect.setAttribute("id", "rect");
     18 rect.setAttribute("width", "100");
     19 rect.setAttribute("height", "100");
     20 rect.setAttribute("x", "0");
     21 rect.setAttribute("y", "0");
     22 rect.setAttribute("fill", "green");
     23 rect.setAttribute("onclick", "executeTest()");
     24 
     25 var animate = createSVGElement("animateTransform");
     26 animate.setAttribute("id", "animation");
     27 animate.setAttribute("attributeName", "transform");
     28 animate.setAttribute("type", "translate");
     29 animate.setAttribute("from", "100,100");
     30 animate.setAttribute("to", "0,0");
     31 animate.setAttribute("type", "translate");
     32 animate.setAttribute("calcMode", "discrete");
     33 animate.setAttribute("begin", "0s");
     34 animate.setAttribute("dur", "4s");
     35 rect.appendChild(animate);
     36 rootSVGElement.appendChild(rect);
     37 
     38 // Setup animation test
     39 function sample1() {
     40    // Check initial/end conditions
     41    assert_equals(rect.transform.animVal.numberOfItems, 1);
     42    assert_equals(rect.transform.animVal.getItem(0).type, SVGTransform.SVG_TRANSFORM_TRANSLATE);
     43    assert_approx_equals(rect.transform.animVal.getItem(0).matrix.e, 100, epsilon);
     44    assert_approx_equals(rect.transform.animVal.getItem(0).matrix.f, 100, epsilon);
     45    assert_equals(rect.transform.baseVal.numberOfItems, 0);
     46 }
     47 
     48 function sample2() {
     49    assert_equals(rect.transform.animVal.numberOfItems, 1);
     50    assert_equals(rect.transform.animVal.getItem(0).type, SVGTransform.SVG_TRANSFORM_TRANSLATE);
     51    assert_approx_equals(rect.transform.animVal.getItem(0).matrix.e, 0, epsilon);
     52    assert_approx_equals(rect.transform.animVal.getItem(0).matrix.f, 0, epsilon);
     53    assert_equals(rect.transform.baseVal.numberOfItems, 0);
     54 }
     55 
     56 function sample3() {
     57    assert_equals(rect.transform.animVal.numberOfItems, 0);
     58    assert_equals(rect.transform.baseVal.numberOfItems, 0);
     59 }
     60 
     61 smil_async_test((t) => {
     62    const expectedValues = [
     63        // [animationId, time, sampleCallback]
     64        ["animation", 0.001, sample1],
     65        ["animation", 1.999, sample1],
     66        ["animation", 2.001, sample2],
     67        ["animation", 3.999, sample2],
     68        ["animation", 4.001, sample3]
     69    ];
     70 
     71    runAnimationTest(t, expectedValues);
     72 });
     73 
     74 </script>