tor-browser

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

animate-marker-orient-to-angle.html (3158B)


      1 <!doctype html>
      2 <html>
      3 <meta charset="utf-8">
      4 <title>Animate SVGMarkerElement orientAttr to an angle</title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/resources/SVGAnimationTestCase-testharness.js"></script>
      8 
      9 <svg>
     10 </svg>
     11 
     12 <script>
     13 var rootSVGElement = document.querySelector("svg");
     14 var epsilon = 1.0;
     15 
     16 // Setup test document
     17 
     18 var marker = createSVGElement("marker");
     19 marker.setAttribute("id", "marker");
     20 marker.setAttribute("viewBox", "0 0 10 10");
     21 marker.setAttribute("markerWidth", "2");
     22 marker.setAttribute("markerHeight", "2");
     23 marker.setAttribute("refX", "5");
     24 marker.setAttribute("refY", "5");
     25 marker.setAttribute("markerUnits", "strokeWidth");
     26 
     27 var markerPath = createSVGElement("path");
     28 markerPath.setAttribute("fill", "blue");
     29 markerPath.setAttribute("d", "M 5 0 L 10 10 L 0 10 Z");
     30 marker.appendChild(markerPath);
     31 
     32 var defsElement = createSVGElement("defs");
     33 defsElement.appendChild(marker);
     34 rootSVGElement.appendChild(defsElement);
     35 
     36 var path = createSVGElement("path");
     37 path.setAttribute("id", "path");
     38 path.setAttribute("onclick", "executeTest()");
     39 path.setAttribute("fill", "none");
     40 path.setAttribute("stroke", "green");
     41 path.setAttribute("stroke-width", "10");
     42 path.setAttribute("marker-start", "url(#marker)");
     43 path.setAttribute("marker-end", "url(#marker)");
     44 path.setAttribute("d", "M 130 135 L 180 135 L 180 185");
     45 path.setAttribute("transform", "translate(-130, -120)");
     46 rootSVGElement.appendChild(path);
     47 
     48 var animate1 = createSVGElement("animate");
     49 animate1.setAttribute("id", "animation");
     50 animate1.setAttribute("attributeName", "orient");
     51 animate1.setAttribute("begin", "0s");
     52 animate1.setAttribute("dur", "4s");
     53 animate1.setAttribute("to", "180deg");
     54 animate1.setAttribute("fill", "freeze");
     55 marker.appendChild(animate1);
     56 
     57 // Setup animation test
     58 function sample1() {
     59    assert_approx_equals(marker.orientAngle.animVal.value, 0, epsilon);
     60    assert_equals(marker.orientAngle.baseVal.value, 0);
     61 
     62    assert_equals(marker.orientType.animVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE);
     63    assert_equals(marker.orientType.baseVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE);
     64 }
     65 
     66 function sample2() {
     67    assert_approx_equals(marker.orientAngle.animVal.value, 90, epsilon);
     68    assert_equals(marker.orientAngle.baseVal.value, 0);
     69 
     70    assert_equals(marker.orientType.animVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE);
     71    assert_equals(marker.orientType.baseVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE);
     72 }
     73 
     74 function sample3() {
     75    assert_approx_equals(marker.orientAngle.animVal.value, 180, epsilon);
     76    assert_equals(marker.orientAngle.baseVal.value, 0);
     77 
     78    assert_equals(marker.orientType.animVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE);
     79    assert_equals(marker.orientType.baseVal, SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE);
     80 }
     81 
     82 smil_async_test((t) => {
     83    const expectedValues = [
     84        // [animationId, time, sampleCallback]
     85        ["animation", 0.0,   sample1],
     86        ["animation", 2.0,   sample2],
     87        ["animation", 3.999, sample3],
     88        ["animation", 4.001, sample3]
     89    ];
     90 
     91    runAnimationTest(t, expectedValues);
     92 });
     93 
     94 </script>