summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_keyframes_vendor_prefix.html
blob: 4463bd259a8f8f067a332b074f39b6bd868090f2 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<meta charset=utf-8>
<title>
Test for interaction between prefixed and non-prefixed @keyframes rules with
the same name
</title>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<div id='log'></div>
<script>
/**
 * Appends a style element to the document head.
 *
 * @param t  The testharness.js Test object. If provided, this will be used
 *           to register a cleanup callback to remove the style element
 *           when the test finishes.
 *
 * @param rules  A dictionary object with selector names and rules to set on
 *               the style sheet.
 */
function addStyle(t, rules) {
  var extraStyle = document.createElement('style');
  document.head.appendChild(extraStyle);
  if (rules) {
    var sheet = extraStyle.sheet;
    for (var selector in rules) {
      sheet.insertRule(selector + '{' + rules[selector] + '}',
                       sheet.cssRules.length);
    }
  }

  if (t && typeof t.add_cleanup === 'function') {
    t.add_cleanup(function() {
      extraStyle.remove();
    });
  }
}

/**
 * Appends a div to the document body.
 *
 * @param t  The testharness.js Test object. If provided, this will be used
 *           to register a cleanup callback to remove the div when the test
 *           finishes.
 *
 * @param attrs  A dictionary object with attribute names and values to set on
 *               the div.
 */
function addDiv(t, attrs) {
  var div = document.createElement('div');
  if (attrs) {
    for (var attrName in attrs) {
      div.setAttribute(attrName, attrs[attrName]);
    }
  }
  document.body.appendChild(div);
  if (t && typeof t.add_cleanup === 'function') {
    t.add_cleanup(function() {
      div.remove();
    });
  }
  return div;
}

test(function(t) {
  addStyle(t,
    { '@-webkit-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, '-webkit- prefix keyframes');

test(function(t) {
  addStyle(t,
    { '@-moz-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, '-moz- prefix keyframes');

test(function(t) {
  addStyle(t,
    { '@-WEBKIT-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, '-WEBKIT- prefix keyframes');

test(function(t) {
  addStyle(t,
    { '@-MOZ-keyframes anim': 'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, '-MOZ- prefix keyframes');

test(function(t) {
  addStyle(t,
    { '@-webkit-KEYFRAMES anim': 'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, '-webkit- prefix KEYFRAMES');

test(function(t) {
  addStyle(t,
    { '@keyframes anim':         'from,to { color: rgb(0, 255, 0); }',
      '@-webkit-keyframes anim': 'from,to { color: rgb(255, 0, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, '-webkit-keyframes should not override earlier non-prefix keyframes');

test(function(t) {
  addStyle(t,
    { '@keyframes anim':      'from,to { color: rgb(0, 255, 0); }',
      '@-moz-keyframes anim': 'from,to { color: rgb(255, 0, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, '-moz-keyframes should not override earlier non-prefix keyframes');

test(function(t) {
  addStyle(t,
    { '@-moz-keyframes anim': 'from,to { color: rgb(255, 0, 0); }',
      '@keyframes anim':      'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, 'non-prefix keyframes should override earlier -moz-keyframes');

test(function(t) {
  addStyle(t,
    { '@-webkit-keyframes anim': 'from,to { color: rgb(255, 0, 0); }',
      '@keyframes anim':         'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, 'non-prefix keyframes should override earlier -webkit-keyframes');

test(function(t) {
  addStyle(t,
    { '@-webkit-keyframes anim': 'from,to { color: rgb(255, 0, 0); }',
      '@-moz-keyframes anim':    'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');

  addStyle(t,
    { '@-moz-keyframes anim2':    'from,to { color: rgb(255, 0, 0); }',
      '@-webkit-keyframes anim2': 'from,to { color: rgb(0, 255, 0); }' });

  var div = addDiv(t, { style: 'animation: anim2 100s' });

  assert_equals(getComputedStyle(div).color, 'rgb(0, 255, 0)');
}, 'last prefixed keyframes should override earlier prefixed keyframes');
</script>