4 Test for interaction between prefixed and non-prefixed @keyframes rules with
7 <script src='/resources/testharness.js'
></script>
8 <script src='/resources/testharnessreport.js'
></script>
12 * Appends a style element to the document head.
14 * @param t The testharness.js Test object. If provided, this will be used
15 * to register a cleanup callback to remove the style element
16 * when the test finishes.
18 * @param rules A dictionary object with selector names and rules to set on
21 function addStyle(t
, rules
) {
22 var extraStyle
= document
.createElement('style');
23 document
.head
.appendChild(extraStyle
);
25 var sheet
= extraStyle
.sheet
;
26 for (var selector
in rules
) {
27 sheet
.insertRule(selector
+ '{' + rules
[selector
] + '}',
28 sheet
.cssRules
.length
);
32 if (t
&& typeof t
.add_cleanup
=== 'function') {
33 t
.add_cleanup(function() {
40 * Appends a div to the document body.
42 * @param t The testharness.js Test object. If provided, this will be used
43 * to register a cleanup callback to remove the div when the test
46 * @param attrs A dictionary object with attribute names and values to set on
49 function addDiv(t
, attrs
) {
50 var div
= document
.createElement('div');
52 for (var attrName
in attrs
) {
53 div
.setAttribute(attrName
, attrs
[attrName
]);
56 document
.body
.appendChild(div
);
57 if (t
&& typeof t
.add_cleanup
=== 'function') {
58 t
.add_cleanup(function() {
67 { '@-webkit-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });
69 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
71 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
72 }, '-webkit- prefix keyframes');
76 { '@-moz-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });
78 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
80 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
81 }, '-moz- prefix keyframes');
85 { '@-WEBKIT-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });
87 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
89 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
90 }, '-WEBKIT- prefix keyframes');
94 { '@-MOZ-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });
96 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
98 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
99 }, '-MOZ- prefix keyframes');
103 { '@-webkit-KEYFRAMES anim': 'from,to { color: rgb(0, 255, 0); }' });
105 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
107 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
108 }, '-webkit- prefix KEYFRAMES');
112 { '@keyframes anim': 'from,to { color: rgb(0, 255, 0); }',
113 '@-webkit-keyframes anim': 'from,to { color: rgb(255, 0, 0); }' });
115 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
117 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
118 }, '-webkit-keyframes should not override earlier non-prefix keyframes');
122 { '@keyframes anim': 'from,to { color: rgb(0, 255, 0); }',
123 '@-moz-keyframes anim': 'from,to { color: rgb(255, 0, 0); }' });
125 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
127 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
128 }, '-moz-keyframes should not override earlier non-prefix keyframes');
132 { '@-moz-keyframes anim': 'from,to { color: rgb(255, 0, 0); }',
133 '@keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });
135 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
137 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
138 }, 'non-prefix keyframes should override earlier -moz-keyframes');
142 { '@-webkit-keyframes anim': 'from,to { color: rgb(255, 0, 0); }',
143 '@keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });
145 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
147 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
148 }, 'non-prefix keyframes should override earlier -webkit-keyframes');
152 { '@-webkit-keyframes anim': 'from,to { color: rgb(255, 0, 0); }',
153 '@-moz-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });
155 var div
= addDiv(t
, { style
: 'animation: anim 100s' });
157 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
160 { '@-moz-keyframes anim2': 'from,to { color: rgb(255, 0, 0); }',
161 '@-webkit-keyframes anim2': 'from,to { color: rgb(0, 255, 0); }' });
163 var div
= addDiv(t
, { style
: 'animation: anim2 100s' });
165 assert_equals(getComputedStyle(div
).color
, 'rgb(0, 255, 0)');
166 }, 'last prefixed keyframes should override earlier prefixed keyframes');