summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/transitions/cancel-transition.html
blob: 7db540d85cf99a0df4938e7d3650f946172f0834 (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
<!DOCTYPE html>

<html>
<head>
    <style>
        #container {
            width: 700px;
            background-color: #fcc;
        }

        #container div {
            position: relative;
            background-color: #933;
            width: 200px;
            height: 50px;
            left: 50px;
            margin-top: 10px;
        }
        #container.run #left {
            left: 450px;
            -webkit-transition-property: left;
            -webkit-transition-duration: 1s;
            -webkit-transition-timing-function: linear;
        }
        #container.run #translate {
            -webkit-transform: translate(400px, 0px);
            -webkit-transition-property: -webkit-transform;
            -webkit-transition-duration: 1s;
            -webkit-transition-timing-function: linear;
        }
    </style>
    <script>
        if (window.testRunner) {
            testRunner.dumpAsText();
            testRunner.waitUntilDone();
        }

        function isEqual(actual, desired, tolerance)
        {
            var diff = Math.abs(actual - desired);
            return diff < tolerance;
        }

        function cancelTransition()
        {
            document.getElementById("container").className = "";
            document.body.offsetHeight;
        }

        function restartTransition()
        {
            document.getElementById("container").className = "run";
            document.body.offsetHeight;
            // The transition should restart at the beginning here. After 250 it should be halfway done.
            setTimeout(check, 500);
        }

        function check()
        {
            var left = parseFloat(window.getComputedStyle(document.getElementById('left')).left);
            result = "left: ";
            if (!isEqual(left, 250, 50))
                result += "<span style='color:red'>FAIL (was: " + left + ", expected: 250)</span>";
            else
                result += "<span style='color:green'>PASS</span>";

            result += ", webkitTransform: ";

            var transform = window.getComputedStyle(document.getElementById('translate')).webkitTransform;
            transform = transform.split("(");
            transform = transform[1].split(",");
            if (!isEqual(transform[4], 200, 50))
                result += "<span style='color:red'>FAIL (was: " + transform[4] + ", expected: 200)</span>";
            else
                result += "<span style='color:green'>PASS</span>";

            document.getElementById('result').innerHTML = result;
            if (window.testRunner)
                testRunner.notifyDone();
        }

        function start()
        {
            document.getElementById("container").className = "run";
            document.body.offsetHeight;
            setTimeout("cancelTransition()", 200);
            setTimeout("restartTransition()", 400);
        }
    </script>
</head>
<body onload="start()">
<p>
    Test removes the transition properties while the transition is running, then adds them back in.
    If working properly the transitions should start from the beginning. But there was a bug that
    would cause the transition to continue to run (although with no visible effect). So when you
    restarted, it would pick up where it left off.
</p>
<div id="container">
    <div id="left">left</div>
    <div id="translate">translate</div>
</div>
<div id="result"></div>
</body>
</html>