summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_animations_event_handler_attribute.html
blob: 036a77779f8556fada0ffafa97ec5ab8dd2e901f (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!doctype html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=911987
-->
<head>
  <meta charset=utf-8>
  <title>Test for CSS Animation and Transition event handler
         attributes. (Bug 911987)</title>
  <script type="application/javascript"
    src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript" src="animation_utils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style>
  @keyframes anim  { to { margin-left: 100px } }
  </style>
</head>
<body>
<a target="_blank"
  href="https://bugzilla.mozilla.org/show_bug.cgi?id=911987">Mozilla Bug
  911987</a>
<div id="display"></div>
<pre id="test">
<script type="application/javascript">
'use strict';

// Create the div element with event handlers.
// We need two elements: one with the content attribute speficied and one
// with the IDL attribute specified since we can't set these independently.
function createAndRegisterTargets(eventAttributes) {
  var displayElement = document.getElementById('display');
  var contentAttributeElement = document.createElement("div");
  var idlAttributeElement     = document.createElement("div");
  displayElement.appendChild(contentAttributeElement);
  displayElement.appendChild(idlAttributeElement);

  // Add handlers
  eventAttributes.forEach(event => {
    contentAttributeElement.setAttribute(event, 'handleEvent(event);');
    contentAttributeElement.handlerType = 'content attribute';
    idlAttributeElement[event] = handleEvent;
    idlAttributeElement.handlerType = 'IDL attribute';
  });

  return [contentAttributeElement, idlAttributeElement];
}

function handleEvent(event) {
  if (event.target.receivedEventType) {
    ok(false, `Received ${event.type} event, but this element have previous `
              `received event '${event.target.receivedEventType}'.`);
    return;
  }
  event.target.receivedEventType = event.type;
}

function checkReceivedEvents(eventType, elements) {
  elements.forEach(element => {
    is(element.receivedEventType, eventType,
       `Expected to receive '${eventType}', got
        '${element.receivedEventType}', for event handler registered
        using ${element.handlerType}`);
    element.receivedEventType = undefined;
  });
}

// Take over the refresh driver right from the start.
advance_clock(0);

// 1. Test CSS Animation event handlers.

var targets = createAndRegisterTargets([ 'onanimationstart',
                                         'onanimationiteration',
                                         'onanimationend' ]);
targets.forEach(div => {
  div.setAttribute('style', 'animation: anim 100ms 2');
  getComputedStyle(div).animationName;  // flush
});

advance_clock(0);
checkReceivedEvents("animationstart", targets);

advance_clock(100);
checkReceivedEvents("animationiteration", targets);

advance_clock(200);
checkReceivedEvents("animationend", targets);

targets.forEach(div => { div.remove(); });

// 2a. Test CSS Transition event handlers (without transitioncancel)

var targets = createAndRegisterTargets([ 'ontransitionrun',
                                         'ontransitionstart',
                                         'ontransitionend',
                                         'ontransitioncancel' ]);
targets.forEach(div => {
  div.style.transition = 'margin-left 100ms 200ms';
  getComputedStyle(div).marginLeft; // flush
  div.style.marginLeft = "200px";
  getComputedStyle(div).marginLeft; // flush
});

advance_clock(0);
checkReceivedEvents("transitionrun", targets);

advance_clock(200);
checkReceivedEvents("transitionstart", targets);

advance_clock(100);
checkReceivedEvents("transitionend", targets);

targets.forEach(div => { div.remove(); });

// 2b. Test CSS Transition cancel event handler.

var targets = createAndRegisterTargets([ 'ontransitioncancel' ]);
targets.forEach(div => {
  div.style.transition = 'margin-left 100ms 200ms';
  getComputedStyle(div).marginLeft; // flush
  div.style.marginLeft = "200px";
  getComputedStyle(div).marginLeft; // flush
});

advance_clock(200);

targets.forEach(div => {
  div.style.display = "none"
});
getComputedStyle(targets[0]).display; // flush

advance_clock(0);
checkReceivedEvents("transitioncancel", targets);

advance_clock(100);
targets.forEach( div => { is(div.receivedEventType, undefined); });

targets.forEach(div => { div.remove(); });

// 3. Test prefixed CSS Animation event handlers.

var targets = createAndRegisterTargets([ 'onwebkitanimationstart',
                                         'onwebkitanimationiteration',
                                         'onwebkitanimationend' ]);
targets.forEach(div => {
  div.setAttribute('style', 'animation: anim 100ms 2');
  getComputedStyle(div).animationName;  // flush
});

advance_clock(0);
checkReceivedEvents("webkitAnimationStart", targets);

advance_clock(100);
checkReceivedEvents("webkitAnimationIteration", targets);

advance_clock(200);
checkReceivedEvents("webkitAnimationEnd", targets);

targets.forEach(div => { div.remove(); });

// 4. Test prefixed CSS Transition event handlers.

advance_clock(0);
var targets = createAndRegisterTargets([ 'onwebkittransitionend' ]);
targets.forEach(div => {
  div.style.transition = 'margin-left 100ms';
  getComputedStyle(div).marginLeft; // flush
  div.style.marginLeft = "200px";
  getComputedStyle(div).marginLeft; // flush
});

advance_clock(100);
checkReceivedEvents("webkitTransitionEnd", targets);

targets.forEach(div => { div.remove(); });

SpecialPowers.DOMWindowUtils.restoreNormalRefresh();

</script>
</body>
</html>