summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/svg/animations/accumulate-values-width-animation.html
blob: 7813494a6a2cb9ad33a16d65a6b6869f9c639ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!doctype html>
<html>
<meta charset="utf-8">
<title>This tests values animation and accumulate='sum'</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/SVGAnimationTestCase-testharness.js"></script>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

<!-- an1: Change width to 100 in 10s with a wobbling animation -->
<rect width="20" height="100" fill="green">
    <animate id="an1" attributeName="width" dur="2s" values="0; 30; 20" accumulate="sum" repeatCount="5" fill="freeze"/>
</rect>

</svg>

<script>
var rootSVGElement = document.querySelector("svg");
var epsilon = 1.0;

// Setup animation test
function sample1() {
    assert_approx_equals(rect.width.animVal.value, 0, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample2() {
    assert_approx_equals(rect.width.animVal.value, 30, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample3() {
    assert_approx_equals(rect.width.animVal.value, 20, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample4() {
    assert_approx_equals(rect.width.animVal.value, 50, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample5() {
    assert_approx_equals(rect.width.animVal.value, 40, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample6() {
    assert_approx_equals(rect.width.animVal.value, 70, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample7() {
    assert_approx_equals(rect.width.animVal.value, 60, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample8() {
    assert_approx_equals(rect.width.animVal.value, 90, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample9() {
    assert_approx_equals(rect.width.animVal.value, 80, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample10() {
    assert_approx_equals(rect.width.animVal.value, 110, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

function sample11() {
    assert_approx_equals(rect.width.animVal.value, 100, epsilon);
    assert_equals(rect.width.baseVal.value, 20);
}

smil_async_test((t) => {
    rect = rootSVGElement.ownerDocument.getElementsByTagName("rect")[0];

    const expectedValues = [
        // [animationId, time, sampleCallback]
        ["an1", 0.0,    sample1],
        ["an1", 1.0,    sample2],
        ["an1", 1.999,  sample3],
        ["an1", 2.001,  sample3],
        ["an1", 3.0,    sample4],
        ["an1", 3.999,  sample5],
        ["an1", 4.001,  sample5],
        ["an1", 5.0,    sample6],
        ["an1", 5.999,  sample7],
        ["an1", 6.001,  sample7],
        ["an1", 7.0,    sample8],
        ["an1", 7.999,  sample9],
        ["an1", 8.001,  sample9],
        ["an1", 9.0,    sample10],
        ["an1", 9.999,  sample11],
        ["an1", 10.001, sample11],
        ["an1", 11.0,   sample11],
        ["an1", 60.0,   sample11]
    ];

    runAnimationTest(t, expectedValues);
});

window.animationStartsImmediately = true;

</script>