OLD | NEW |
---|---|
(Empty) | |
1 <!doctype html> | |
2 <script src="../resources/testharness.js"></script> | |
3 <script src="../resources/testharnessreport.js"></script> | |
4 <style> | |
5 @keyframes anim { | |
6 0% { left: 0px; } | |
7 20% { left: 500px; } | |
8 100% { left: 100px; } | |
9 } | |
10 | |
11 @keyframes anim-compositor { | |
12 0% { opacity: 1.0; } | |
13 100% { opacity: 1.0; } | |
14 } | |
15 | |
16 #target1 { | |
17 animation: anim 10s -3s linear paused; | |
18 background-color: rgb(0, 0, 0); | |
19 left: 0px; | |
20 } | |
21 | |
22 #target2 { | |
23 animation: anim 10s -6s linear paused; | |
24 background-color: rgb(0, 0, 0); | |
25 left: 100px; | |
26 } | |
27 | |
28 #target3 { | |
29 animation: anim-compositor 2s -1s linear paused; | |
30 } | |
31 </style> | |
32 <div id="target1"></div> | |
33 <div id="target2"></div> | |
34 <div id="target3"></div> | |
35 <script> | |
36 test(function() { | |
Timothy Loh
2015/01/30 02:43:44
Split this up into separate tests
shend
2015/02/01 23:49:13
Done.
| |
37 assert_equals(parseInt(getComputedStyle(target1).left), 450, 'left offset'); | |
38 assert_equals(parseInt(getComputedStyle(target2).left), 300, 'left offset'); | |
39 | |
40 var sheet = document.styleSheets[0]; | |
41 var rules = sheet.rules; | |
42 var keyframes = rules[0]; | |
43 keyframes.appendRule('50% { left: 500px; }'); | |
44 keyframes.deleteRule('20%'); | |
45 | |
46 assert_equals(parseInt(getComputedStyle(target1).left), 300, 'left offset'); | |
47 assert_equals(parseInt(getComputedStyle(target2).left), 420, 'left offset'); | |
48 | |
49 var newKeyframeRuleIndex = sheet.rules.length; | |
50 sheet.insertRule('@keyframes anim { 0% { left: 0px; } 100% { left: 300px; } }', newKeyframeRuleIndex); // Should override 'anim' | |
51 | |
52 assert_equals(parseInt(getComputedStyle(target1).left), 90, 'left offset'); | |
53 assert_equals(parseInt(getComputedStyle(target2).left), 180, 'left offset'); | |
54 | |
55 sheet.deleteRule(newKeyframeRuleIndex); // Should revert to original 'anim' | |
56 | |
57 assert_equals(parseInt(getComputedStyle(target1).left), 300, 'left offset'); | |
58 assert_equals(parseInt(getComputedStyle(target2).left), 420, 'left offset'); | |
59 | |
60 newStyle = document.createElement('style'); | |
61 newStyle.appendChild(document.createTextNode('@keyframes anim { 0% { left: 1 00px; } 100% { left: 400px; } }')); | |
62 document.head.appendChild(newStyle); | |
63 | |
64 assert_equals(parseInt(getComputedStyle(target1).left), 190, 'left offset'); | |
65 assert_equals(parseInt(getComputedStyle(target2).left), 280, 'left offset'); | |
66 | |
67 newStyle.innerHTML = '@keyframes anim { 0% { left: 200px; } 100% { left: 400 px; } }'; | |
68 | |
69 assert_equals(parseInt(getComputedStyle(target1).left), 260, 'left offset'); | |
70 assert_equals(parseInt(getComputedStyle(target2).left), 320, 'left offset'); | |
71 | |
72 document.head.removeChild(newStyle); // Should revert to original 'anim' wit h 50% { left: 500px; } replacing 20%. | |
73 | |
74 assert_equals(parseInt(getComputedStyle(target1).left), 300, 'left offset'); | |
75 assert_equals(parseInt(getComputedStyle(target2).left), 420, 'left offset'); | |
76 | |
77 assert_equals(keyframes.cssRules.length, 3); | |
78 var keyframe = keyframes[2]; | |
79 assert_equals(keyframe.keyText, '50%'); | |
80 keyframe.style.setProperty('background-color', 'rgb(200, 100, 50)'); | |
81 assert_equals(getComputedStyle(target1).backgroundColor, 'rgb(120, 60, 30)') ; | |
82 assert_equals(getComputedStyle(target2).backgroundColor, 'rgb(160, 80, 40)') ; | |
83 | |
84 keyframe.style.removeProperty('background-color'); | |
85 assert_equals(getComputedStyle(target1).backgroundColor, 'rgb(0, 0, 0)'); | |
86 assert_equals(getComputedStyle(target2).backgroundColor, 'rgb(0, 0, 0)'); | |
87 | |
88 keyframe.style.left = '200px'; | |
89 assert_equals(parseInt(getComputedStyle(target1).left), 120, 'left offset'); | |
90 assert_equals(parseInt(getComputedStyle(target2).left), 180, 'left offset'); | |
91 | |
92 keyframe.style.left = '500px'; | |
93 keyframe.keyText = '20%'; | |
94 assert_equals(parseInt(getComputedStyle(target1).left), 450, 'left offset'); | |
95 assert_equals(parseInt(getComputedStyle(target2).left), 300, 'left offset'); | |
96 | |
97 keyframes.name = 'foobar'; | |
98 assert_equals(parseInt(getComputedStyle(target1).left), 0, 'left offset'); | |
99 assert_equals(parseInt(getComputedStyle(target2).left), 100, 'left offset'); | |
100 | |
101 keyframes.name = 'anim'; | |
102 assert_equals(parseInt(getComputedStyle(target1).left), 450, 'left offset'); | |
103 assert_equals(parseInt(getComputedStyle(target2).left), 300, 'left offset'); | |
104 | |
105 var compositorKeyframes = rules[1]; | |
106 assert_approx_equals(parseFloat(getComputedStyle(target3).opacity), 1.0, 0.0 01, 'opacity'); | |
107 compositorKeyframes.appendRule('50% { opacity: 0.0; }'); | |
108 assert_approx_equals(parseFloat(getComputedStyle(target3).opacity), 0.0, 0.0 01, 'opacity'); | |
109 | |
110 }, "Check that changes to animation via CSSOM update it accordingly"); | |
111 </script> | |
OLD | NEW |