OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <head> | 2 <head> |
3 <title>Test of -webkit-animation-play-state</title> | 3 <title>Test of -webkit-animation-play-state</title> |
4 <style> | 4 <style> |
5 #box1 { | 5 .target { |
6 height: 100px; | 6 height: 100px; |
7 width: 100px; | 7 width: 100px; |
8 -webkit-animation-duration: 40ms; | |
9 -webkit-animation-timing-function: linear; | |
10 } | |
11 #translate { | |
8 background-color: blue; | 12 background-color: blue; |
9 margin: 0; | |
10 -webkit-animation-duration: 2s; | |
11 -webkit-animation-timing-function: linear; | |
12 -webkit-animation-name: "move1"; | 13 -webkit-animation-name: "move1"; |
13 -webkit-animation-play-state: running; | |
14 } | 14 } |
15 @-webkit-keyframes "move1" { | 15 @-webkit-keyframes "move1" { |
16 from { -webkit-transform: translateX(0); } | 16 from { -webkit-transform: translateX(100px); } |
17 to { -webkit-transform: translateX(100px); } | 17 to { -webkit-transform: translateX(200px); } |
18 } | 18 } |
19 #box2 { | 19 #left { |
20 position:absolute; | 20 position: relative; |
21 top: 260px; | |
22 height: 100px; | |
23 width: 100px; | |
24 background-color: red; | 21 background-color: red; |
25 -webkit-animation-duration: 2s; | |
26 -webkit-animation-timing-function: linear; | |
27 -webkit-animation-name: "move2"; | 22 -webkit-animation-name: "move2"; |
28 } | 23 } |
29 @-webkit-keyframes "move2" { | 24 @-webkit-keyframes "move2" { |
30 from { left: 0; } | 25 from { left: 100px; } |
31 to { left: 100px; } | 26 to { left: 200px; } |
27 } | |
28 .paused { | |
29 -webkit-animation-play-state: paused; | |
32 } | 30 } |
33 </style> | 31 </style> |
34 <script src="resources/animation-test-helpers.js" type="text/javascript"></scr ipt> | 32 <script src="resources/animation-test-helpers.js" type="text/javascript"></scr ipt> |
35 <script type="text/javascript"> | 33 <script type="text/javascript"> |
36 | 34 if (window.testRunner) { |
37 const expectedValues = [ | 35 testRunner.dumpAsText(); |
38 // [time, element-id, property, expected-value, tolerance] | 36 testRunner.waitUntilDone(); |
39 [0.5, "box1", "webkitTransform", [1,0,0,1,25,0], 24], | |
40 [1.1, "box1", "webkitTransform", [1,0,0,1,50,0], 5], | |
41 [1.5, "box1", "webkitTransform", [1,0,0,1,50,0], 5], | |
42 [2.5, "box1", "webkitTransform", [1,0,0,1,75,0], 24], | |
43 [0.5, "box2", "left", 25, 24], | |
44 [1.1, "box2", "left", 50, 5], | |
45 [1.5, "box2", "left", 50, 5], | |
46 [2.5, "box2", "left", 75, 24], | |
47 ]; | |
48 | |
49 function stop() | |
50 { | |
51 document.getElementById("box1").style.webkitAnimationPlayState = "paused "; | |
52 document.getElementById("box2").style.webkitAnimationPlayState = "paused "; | |
53 } | 37 } |
54 | 38 |
55 function start() | 39 function log(message) { |
56 { | 40 var div = document.createElement('div'); |
57 document.getElementById("box1").style.webkitAnimationPlayState = "runnin g"; | 41 div.textContent = message; |
58 document.getElementById("box2").style.webkitAnimationPlayState = "runnin g"; | 42 document.body.appendChild(div); |
59 } | 43 } |
60 | 44 |
61 setTimeout(stop, 1000); | 45 function logPassFail(expected, actual, id, description) { |
62 setTimeout(start, 2000); | 46 var didPass = expected === actual; |
63 runAnimationTest(expectedValues, null, null, true); | 47 log((didPass ? 'PASS' : 'FAIL') + ': Element \'' + id + '\' had ' + (didPa ss ? 'correct' : 'incorrect') + ' style ' + description); |
48 } | |
49 | |
50 function togglePaused() { | |
51 var targets = document.getElementsByClassName('target'); | |
52 for (var i = 0; i < targets.length; ++i) { | |
53 targets[i].classList.toggle('paused'); | |
54 } | |
55 } | |
56 | |
57 var start = function() { | |
58 document.removeEventListener('webkitAnimationStart', start, false); | |
59 setTimeout(pause, 20); | |
60 } | |
61 | |
62 var transform; | |
63 var left; | |
64 function pause() { | |
65 togglePaused(); | |
66 transform = getComputedStyle(document.getElementById('translate')).webkitT ransform; | |
67 left = getComputedStyle(document.getElementById('left')).left; | |
68 setTimeout(resume, 20); | |
69 } | |
70 | |
71 function resume() { | |
72 logPassFail(transform, getComputedStyle(document.getElementById('translate ')).webkitTransform, 'translate', 'when paused'); | |
73 logPassFail(left, getComputedStyle(document.getElementById('left')).left, 'left', 'when paused'); | |
74 togglePaused(); | |
75 setTimeout(end, 60); | |
dstockwell
2013/10/24 00:35:02
60 is still quite short, should we just wait for t
Steve Block
2013/10/24 00:41:45
Using the end event actually makes it more flaky,
| |
76 } | |
77 | |
78 function end() { | |
79 logPassFail('none', getComputedStyle(document.getElementById('translate')) .webkitTransform, 'translate', 'at end'); | |
80 logPassFail('auto', getComputedStyle(document.getElementById('left')).left , 'left', 'at end'); | |
81 if (window.testRunner) { | |
82 testRunner.notifyDone(); | |
83 } | |
84 } | |
85 | |
86 document.addEventListener('webkitAnimationStart', start, false); | |
64 </script> | 87 </script> |
65 </head> | 88 </head> |
66 <body> | 89 <body> |
67 <p> | 90 <p> |
68 This tests the operation of -webkit-animation-play-state. After 2 second the box should stop and after one | 91 This tests the operation of -webkit-animation-play-state. We test style |
69 more second it should start again. We test it both while in motion and when stop ped. | 92 while the animations are paused and once unpaused. |
70 <div id="box1"> | 93 </p> |
71 </div> | 94 <div class="target" id="translate">transform</div> |
72 <div id="box2"> | 95 <div class="target" id="left">left</div> |
73 </div> | |
74 <div id="result"> | |
75 </div> | |
76 </body> | 96 </body> |
77 </html> | 97 </html> |
OLD | NEW |