igor.o@sisa.samsung.com | db6a62c | 2012-02-09 02:07:11 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 2 | "http://www.w3.org/TR/html4/loose.dtd"> |
| 3 | |
| 4 | <html lang="en"> |
| 5 | <head> |
| 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 7 | <title>Test simple animation with fill modes</title> |
| 8 | <style type="text/css" media="screen"> |
| 9 | .box { |
| 10 | position: relative; |
| 11 | left: 100px; |
| 12 | top: 10px; |
| 13 | height: 100px; |
| 14 | width: 100px; |
| 15 | -webkit-animation-delay: 0.1s; |
| 16 | -webkit-animation-duration: 2s; |
| 17 | -webkit-animation-timing-function: linear; |
| 18 | -webkit-animation-name: anim; |
| 19 | -webkit-animation-direction: reverse |
| 20 | } |
| 21 | @-webkit-keyframes anim { |
| 22 | from { left: 200px; } |
| 23 | to { left: 300px; } |
| 24 | } |
| 25 | #a { |
| 26 | background-color: blue; |
| 27 | -webkit-animation-fill-mode: none; |
| 28 | } |
| 29 | #b { |
| 30 | background-color: red; |
| 31 | -webkit-animation-fill-mode: backwards; |
| 32 | } |
| 33 | #c { |
| 34 | background-color: green; |
| 35 | -webkit-animation-fill-mode: forwards; |
| 36 | } |
| 37 | #d { |
| 38 | background-color: yellow; |
| 39 | -webkit-animation-fill-mode: both; |
| 40 | } |
| 41 | #e { |
simon.fraser@apple.com | 187e4e4 | 2015-07-21 21:19:20 +0000 | [diff] [blame] | 42 | background-color: gray; |
igor.o@sisa.samsung.com | db6a62c | 2012-02-09 02:07:11 +0000 | [diff] [blame] | 43 | -webkit-animation-fill-mode: both; |
| 44 | -webkit-animation-iteration-count: 2; |
| 45 | -webkit-animation-direction: alternate; |
| 46 | } |
| 47 | </style> |
| 48 | <script type="text/javascript" charset="utf-8"> |
| 49 | const numAnims = 5; |
| 50 | var animsFinished = 0; |
| 51 | const allowance = 5; |
| 52 | const expectedValues = [ |
| 53 | {id: "a", start: 100, end: 100}, |
| 54 | {id: "b", start: 300, end: 100}, |
simon.fraser@apple.com | 187e4e4 | 2015-07-21 21:19:20 +0000 | [diff] [blame] | 55 | {id: "c", start: 100, end: 200}, |
| 56 | {id: "d", start: 300, end: 200}, |
igor.o@sisa.samsung.com | db6a62c | 2012-02-09 02:07:11 +0000 | [diff] [blame] | 57 | {id: "e", start: 200, end: 200} |
| 58 | ]; |
| 59 | var result = ""; |
| 60 | |
rniwa@webkit.org | ad35b68 | 2012-06-11 17:22:07 +0000 | [diff] [blame] | 61 | if (window.testRunner) { |
| 62 | testRunner.dumpAsText(); |
| 63 | testRunner.waitUntilDone(); |
igor.o@sisa.samsung.com | db6a62c | 2012-02-09 02:07:11 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | function animationEnded(event) { |
| 67 | if (++animsFinished == numAnims) { |
| 68 | setTimeout(endTest, 0); // this set timeout should be ok in the test environment |
| 69 | // since we're just giving style a chance to resolve |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | function endTest() { |
| 74 | |
| 75 | for (var i=0; i < expectedValues.length; i++) { |
| 76 | var el = document.getElementById(expectedValues[i].id); |
| 77 | var expectedValue = expectedValues[i].end; |
| 78 | var realValue = window.getComputedStyle(el).getPropertyCSSValue("left").getFloatValue(CSSPrimitiveValue.CSS_NUMBER); |
| 79 | if (Math.abs(expectedValue - realValue) < allowance) { |
| 80 | result += "PASS"; |
| 81 | } else { |
| 82 | result += "FAIL"; |
| 83 | } |
| 84 | result += " - end of animation - id: " + expectedValues[i].id + " expected: " + expectedValue + " actual: " + realValue + "<br>"; |
| 85 | } |
| 86 | document.getElementById('result').innerHTML = result; |
| 87 | |
rniwa@webkit.org | ad35b68 | 2012-06-11 17:22:07 +0000 | [diff] [blame] | 88 | if (window.testRunner) |
| 89 | testRunner.notifyDone(); |
igor.o@sisa.samsung.com | db6a62c | 2012-02-09 02:07:11 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | window.onload = function () { |
| 93 | for (var i=0; i < expectedValues.length; i++) { |
| 94 | var el = document.getElementById(expectedValues[i].id); |
| 95 | var expectedValue = expectedValues[i].start; |
| 96 | var realValue = window.getComputedStyle(el).getPropertyCSSValue("left").getFloatValue(CSSPrimitiveValue.CSS_NUMBER); |
| 97 | if (Math.abs(expectedValue - realValue) < allowance) { |
| 98 | result += "PASS"; |
| 99 | } else { |
| 100 | result += "FAIL"; |
| 101 | } |
| 102 | result += " - start of animation - id: " + expectedValues[i].id + " expected: " + expectedValue + " actual: " + realValue + "<br>"; |
| 103 | } |
| 104 | document.addEventListener("webkitAnimationEnd", animationEnded, false); |
| 105 | }; |
| 106 | |
| 107 | </script> |
| 108 | </head> |
| 109 | <body> |
| 110 | This test performs an animation of the left property with four different |
| 111 | fill modes. It animates over 0.1 second with a 0.1 second delay. |
| 112 | It takes snapshots at document load and the end of the animation. |
| 113 | <div id="a" class="box"> |
| 114 | None |
| 115 | </div> |
| 116 | <div id="b" class="box"> |
| 117 | Backwards |
| 118 | </div> |
| 119 | <div id="c" class="box"> |
| 120 | Forwards |
| 121 | </div> |
| 122 | <div id="d" class="box"> |
| 123 | Both |
| 124 | </div> |
| 125 | <div id="e" class="box"> |
| 126 | Both iterating |
| 127 | </div> |
| 128 | <div id="result"> |
| 129 | </div> |
| 130 | </body> |
| 131 | </html> |