svgenum-animation-4.html (6245B)
1 <!doctype html> 2 <html> 3 <meta charset="utf-8"> 4 <title>Test CompositeOperationType enumeration animations</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 var defsElement = createSVGElement("defs"); 18 rootSVGElement.appendChild(defsElement); 19 20 var off1 = createSVGElement("feOffset"); 21 off1.setAttribute("dx", "35"); 22 off1.setAttribute("dy", "25"); 23 off1.setAttribute("result", "off1"); 24 25 var flood1 = createSVGElement("feFlood"); 26 flood1.setAttribute("flood-color", "#408067"); 27 flood1.setAttribute("flood-opacity", ".8"); 28 flood1.setAttribute("result", "F1"); 29 30 var overComposite1 = createSVGElement("feComposite"); 31 overComposite1.setAttribute("in", "F1"); 32 overComposite1.setAttribute("in2", "off1"); 33 overComposite1.setAttribute("operator", "over"); 34 overComposite1.setAttribute("k1", ".5"); 35 overComposite1.setAttribute("k2", ".1"); 36 overComposite1.setAttribute("k3", ".5"); 37 overComposite1.setAttribute("k4", ".3"); 38 39 overComposite1.setAttribute("result", "C1"); 40 41 var off2 = createSVGElement("feOffset"); 42 off2.setAttribute("in", "SourceGraphic"); 43 off2.setAttribute("dx", "60"); 44 off2.setAttribute("dy", "50"); 45 off2.setAttribute("result", "off2"); 46 47 var flood2 = createSVGElement("feFlood"); 48 flood2.setAttribute("flood-color", "#408067"); 49 flood2.setAttribute("flood-opacity", ".6"); 50 flood2.setAttribute("result", "F2"); 51 52 var overComposite2 = createSVGElement("feComposite"); 53 overComposite2.setAttribute("in", "F2"); 54 overComposite2.setAttribute("in2", "off2"); 55 overComposite2.setAttribute("operator", "in"); 56 overComposite2.setAttribute("result", "C2"); 57 58 var off3 = createSVGElement("feOffset"); 59 off3.setAttribute("in", "SourceGraphic"); 60 off3.setAttribute("dx", "85"); 61 off3.setAttribute("dy", "75"); 62 off3.setAttribute("result", "off3"); 63 64 var flood3 = createSVGElement("feFlood"); 65 flood3.setAttribute("flood-color", "#408067"); 66 flood3.setAttribute("flood-opacity", ".4"); 67 flood3.setAttribute("result", "F3"); 68 69 var overComposite3 = createSVGElement("feComposite"); 70 overComposite3.setAttribute("in2", "off3"); 71 overComposite3.setAttribute("operator", "in"); 72 overComposite3.setAttribute("result", "C3"); 73 74 var merge = createSVGElement("feMerge"); 75 76 var mergeNode1 = createSVGElement("feMergeNode"); 77 mergeNode1.setAttribute("in", "C1"); 78 79 var mergeNode2 = createSVGElement("feMergeNode"); 80 mergeNode2.setAttribute("in", "C2"); 81 82 var mergeNode3 = createSVGElement("feMergeNode"); 83 mergeNode3.setAttribute("in", "C3"); 84 85 var mergeNode4 = createSVGElement("feMergeNode"); 86 mergeNode4.setAttribute("in", "SourceGraphic"); 87 88 merge.appendChild(mergeNode3); 89 merge.appendChild(mergeNode2); 90 merge.appendChild(mergeNode1); 91 merge.appendChild(mergeNode4); 92 93 var overFilter = createSVGElement("filter"); 94 overFilter.setAttribute("id", "overFilter"); 95 overFilter.setAttribute("filterUnits", "objectBoundingBox"); 96 overFilter.setAttribute("x", "0"); 97 overFilter.setAttribute("y", "0"); 98 overFilter.setAttribute("width", "3.5"); 99 overFilter.setAttribute("height", "4"); 100 overFilter.appendChild(off1); 101 overFilter.appendChild(flood1); 102 overFilter.appendChild(overComposite1); 103 overFilter.appendChild(off2); 104 overFilter.appendChild(flood2); 105 overFilter.appendChild(overComposite2); 106 overFilter.appendChild(off3); 107 overFilter.appendChild(flood3); 108 overFilter.appendChild(overComposite3); 109 overFilter.appendChild(merge); 110 111 defsElement.appendChild(overFilter); 112 113 // Setup test document 114 var rect = createSVGElement("rect"); 115 rect.setAttribute("id", "rect"); 116 rect.setAttribute("width", "100"); 117 rect.setAttribute("height", "100"); 118 rect.setAttribute("fill", "#408067"); 119 rect.setAttribute("filter", "url(#overFilter)"); 120 rect.setAttribute("onclick", "executeTest()"); 121 rootSVGElement.appendChild(rect); 122 123 var animate = createSVGElement("animate"); 124 animate.setAttribute("id", "animation"); 125 animate.setAttribute("attributeName", "operator"); 126 animate.setAttribute("begin", "0s"); 127 animate.setAttribute("dur", "5s"); 128 animate.setAttribute("values", "in;out;atop;xor;arithmetic"); 129 overComposite1.appendChild(animate); 130 131 // Setup animation test 132 function sample1() { 133 assert_equals(overComposite1.operator.animVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER); 134 assert_equals(overComposite1.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER); 135 } 136 137 function sample2() { 138 assert_equals(overComposite1.operator.animVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_IN); 139 assert_equals(overComposite1.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER); 140 } 141 142 function sample3() { 143 assert_equals(overComposite1.operator.animVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OUT); 144 assert_equals(overComposite1.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER); 145 } 146 147 function sample4() { 148 assert_equals(overComposite1.operator.animVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ATOP); 149 assert_equals(overComposite1.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER); 150 } 151 152 function sample5() { 153 assert_equals(overComposite1.operator.animVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_XOR); 154 assert_equals(overComposite1.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER); 155 } 156 157 function sample6() { 158 assert_equals(overComposite1.operator.animVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_ARITHMETIC); 159 assert_equals(overComposite1.operator.baseVal, SVGFECompositeElement.SVG_FECOMPOSITE_OPERATOR_OVER); 160 } 161 162 smil_async_test((t) => { 163 const expectedValues = [ 164 // [animationId, time, sampleCallback] 165 ["animation", 0.0, sample1], 166 ["animation", 0.001, sample2], 167 ["animation", 0.999, sample2], 168 ["animation", 1.001, sample3], 169 ["animation", 1.999, sample3], 170 ["animation", 2.001, sample4], 171 ["animation", 2.999, sample4], 172 ["animation", 3.001, sample5], 173 ["animation", 3.999, sample5], 174 ["animation", 4.001, sample6], 175 ["animation", 4.999, sample6], 176 ["animation", 5.001, sample1] 177 ]; 178 179 runAnimationTest(t, expectedValues); 180 }); 181 182 </script>