1 var _recordedEvents = new Array();
2 // Number of events we're supposed to receive.
3 var _expectedEventCount = 0;
4 // Function invoked when we've received _expectedEventCount events.
6 // Have we processed the events? This is used to make sure we process the
8 var _processedEvents = false;
10 /* Call this function to record manually transition end events:
13 event [required]: the event passed with "webkitTransitionEnd" or "transitionend"
16 function recordTransitionEndEvent(event)
18 if (event.type != "webkitTransitionEnd" && event.type != "transitionend" )
19 throw("Invalid transition end event!");
21 _recordedEvents.push([
24 Math.round(event.elapsedTime * 1000) / 1000 // round to ms to avoid floating point imprecision
26 if (_recordedEvents.length == _expectedEventCount)
30 /* This is the helper function to run transition end event tests:
32 Test page requirements:
33 - The body must contain an empty div with id "result"
34 - The body must contain a div with with id "container"
35 - Call this function directly from the <script> inside the test page
38 expected [required]: an array of arrays defining the expected parameter values for the recorded transition end events (see below)
39 callback [optional]: a function to be executed just before the test starts (none by default)
41 Each sub-array must contain these items in this order:
42 - the name of the CSS property that was transitioning
43 - the id of the element on which the CSS property was transitioning
44 - the elapsed time in seconds at which the CSS property finished transitioning
45 - a boolean indicating if an event listener should be automatically added to the element to record the transition end event or if the script calls recordTransitionEndEvent() directly
48 function runTransitionTest(expected, callback)
50 _expectedEventCount = expected.length;
52 if (window.testRunner) {
53 testRunner.dumpAsText();
54 testRunner.waitUntilDone();
57 function processEndEvents(expected)
60 return; // Only need to process events once
62 _processedEvents = true;
64 function compareEventInfo(e1, e2)
66 // Sort by property name then event target id
68 // Index 0 is the property name
69 if (e1[0]<e2[0]) return -1;
70 if (e1[0]>e2[0]) return +1;
72 // Index 1 is the target id
73 if (e1[1]<e2[1]) return -1;
74 if (e1[1]>e2[1]) return +1;
79 function examineResults(results, expected)
81 // Sort recorded and expected events arrays so they have the same ordering
82 expected.sort(compareEventInfo);
83 results.sort(compareEventInfo);
86 for (var i=0; i < results.length && i < expected.length; ++i) {
87 var pass = expected[i][0] == results[i][0] && expected[i][1] == results[i][1] && expected[i][2] == results[i][2];
90 result += "PASS --- ";
92 result += "FAIL --- ";
94 result += "[Expected] Property: " + expected[i][0] + " ";
95 result += "Target: " + expected[i][1] + " ";
96 result += "Elapsed Time: " + expected[i][2];
100 result += "[Received] Property: " + results[i][0] + " ";
101 result += "Target: " + results[i][1] + " ";
102 result += "Elapsed Time: " + results[i][2];
109 if (expected.length > results.length) {
110 result += "<p>FAIL - Missing events<br>";
111 for (i=results.length; i < expected.length; ++i) {
112 result += "[Missing] Property: " + expected[i][0] + " ";
113 result += "Target: " + expected[i][1] + " ";
114 result += "Elapsed Time: " + expected[i][2] + "<br>";
117 } else if (expected.length < results.length) {
118 result += "<p>FAIL - Unexpected events<br>";
119 for (i=expected.length; i < results.length; ++i) {
120 result += "[Unexpected] Property: " + results[i][0] + " ";
121 result += "Target: " + results[i][1] + " ";
122 result += "Elapsed Time: " + results[i][2] + "<br>";
130 document.body.removeChild(document.getElementById('container'));
131 document.getElementById('result').innerHTML = examineResults(_recordedEvents, expected);
133 if (window.testRunner)
134 testRunner.notifyDone();
137 function startTest(expected, callback, maxTime)
145 for (var i=0; i < expected.length; ++i) {
146 if (expected[i][3]) {
147 var box = document.getElementById(expected[i][1]);
148 box.addEventListener("webkitTransitionEnd", recordTransitionEndEvent, false);
151 var time = expected[i][2];
156 _endFunction = function() { processEndEvents(expected); };
157 // Add one second of fudge. We don't just use the run-webkit-tests timeout
158 // because processEndEvents gives more information on what failed.
159 window.setTimeout(_endFunction, maxTime * 1000 + 1000);
162 window.addEventListener('load', function() { startTest(expected, callback) }, false);