OLD | NEW |
---|---|
1 (function(window) { | 1 (function(window) { |
2 EventExpectationsManager = function(test) | 2 EventExpectationsManager = function(test) |
3 { | 3 { |
4 this.test_ = test; | 4 this.test_ = test; |
5 this.eventTargetList_ = []; | 5 this.eventTargetList_ = []; |
6 this.waitCallbacks_ = []; | 6 this.waitCallbacks_ = []; |
7 this.timeoutIDs_ = []; | |
7 }; | 8 }; |
8 | 9 |
9 EventExpectationsManager.prototype.expectEvent = function(object, eventName, description) | 10 EventExpectationsManager.prototype.expectEvent = function(object, eventName, description) |
10 { | 11 { |
11 var eventInfo = { 'target': object, 'type': eventName, 'description': de scription}; | 12 var eventInfo = { 'target': object, 'type': eventName, 'description': de scription}; |
12 var expectations = this.getExpectations_(object); | 13 var expectations = this.getExpectations_(object); |
13 expectations.push(eventInfo); | 14 expectations.push(eventInfo); |
14 | 15 |
15 var t = this; | 16 var t = this; |
16 var waitHandler = this.test_.step_func(function() { t.handleWaitCallback _(); }); | 17 var waitHandler = this.test_.step_func(function() { t.handleWaitCallback _(); }); |
17 var eventHandler = this.test_.step_func(function(event) | 18 var eventHandler = this.test_.step_func(function(event) |
18 { | 19 { |
19 object.removeEventListener(eventName, eventHandler); | 20 object.removeEventListener(eventName, eventHandler); |
20 var expected = expectations[0]; | 21 var expected = expectations[0]; |
21 assert_equals(event.target, expected.target, "Event target match."); | 22 assert_equals(event.target, expected.target, "Event target match."); |
22 assert_equals(event.type, expected.type, "Event types match."); | 23 assert_equals(event.type, expected.type, "Event types match."); |
23 assert_equals(eventInfo.description, expected.description, "Descript ions match for '" + event.type + "'."); | 24 assert_equals(eventInfo.description, expected.description, "Descript ions match for '" + event.type + "'."); |
24 | 25 |
25 expectations.shift(1); | 26 expectations.shift(1); |
26 if (t.waitCallbacks_.length > 0) | 27 if (t.waitCallbacks_.length > 0) |
27 setTimeout(waitHandler, 0); | 28 setTimeout(waitHandler, 0); |
28 }); | 29 }); |
29 object.addEventListener(eventName, eventHandler); | 30 object.addEventListener(eventName, eventHandler); |
30 }; | 31 }; |
31 | 32 |
33 EventExpectationsManager.prototype.callOnTimeout = function(callback, timeou t) | |
34 { | |
35 var timeoutID = setTimeout(callback, timeout); | |
wolenetz
2013/07/31 19:42:37
For purposes of automatically failing the test if
anandc
2013/07/31 22:17:32
Done.
| |
36 this.timeoutIDs_.push(timeoutID); | |
37 }; | |
38 | |
32 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback ) | 39 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback ) |
33 { | 40 { |
34 this.waitCallbacks_.push(callback); | 41 this.waitCallbacks_.push(callback); |
35 setTimeout(this.handleWaitCallback_.bind(this), 0); | 42 setTimeout(this.handleWaitCallback_.bind(this), 0); |
36 }; | 43 }; |
37 | 44 |
38 EventExpectationsManager.prototype.expectingEvents = function() | 45 EventExpectationsManager.prototype.expectingEvents = function() |
39 { | 46 { |
40 for (var i = 0; i < this.eventTargetList_.length; ++i) { | 47 for (var i = 0; i < this.eventTargetList_.length; ++i) { |
41 if (this.eventTargetList_[i].expectations.length > 0) { | 48 if (this.eventTargetList_[i].expectations.length > 0) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 { | 176 { |
170 object.addEventListener(eventName, test.step_func(function(event) { test.done(); })); | 177 object.addEventListener(eventName, test.step_func(function(event) { test.done(); })); |
171 }; | 178 }; |
172 | 179 |
173 test.eventExpectations_ = new EventExpectationsManager(test); | 180 test.eventExpectations_ = new EventExpectationsManager(test); |
174 test.expectEvent = function(object, eventName, description) | 181 test.expectEvent = function(object, eventName, description) |
175 { | 182 { |
176 test.eventExpectations_.expectEvent(object, eventName, description); | 183 test.eventExpectations_.expectEvent(object, eventName, description); |
177 }; | 184 }; |
178 | 185 |
186 test.callOnTimeout = function(callback, timeout) | |
wolenetz
2013/07/31 19:42:37
nit: Would 'expectTimeout' be better?
anandc
2013/07/31 22:17:32
Now named expectDelayedCallback.
| |
187 { | |
188 test.eventExpectations_.callOnTimeout(callback, timeout); | |
189 } | |
190 | |
179 test.waitForExpectedEvents = function(callback) | 191 test.waitForExpectedEvents = function(callback) |
180 { | 192 { |
181 test.eventExpectations_.waitForExpectedEvents(callback); | 193 test.eventExpectations_.waitForExpectedEvents(callback); |
182 }; | 194 }; |
183 | 195 |
184 var oldTestDone = test.done.bind(test); | 196 var oldTestDone = test.done.bind(test); |
185 test.done = function() | 197 test.done = function() |
186 { | 198 { |
199 // loop through and clear timeoutIDs | |
200 var timeoutIDs = test.eventExpectations_.timeoutIDs_; | |
201 while (timeoutIDs.length > 0) { | |
202 clearTimeout(timeoutIDs.shift()); | |
203 } | |
204 | |
187 if (test.status == test.PASS) | 205 if (test.status == test.PASS) |
188 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); | 206 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); |
wolenetz
2013/07/31 19:42:37
Need to also assert that there are no pending time
anandc
2013/07/31 22:17:32
Done.
| |
189 oldTestDone(); | 207 oldTestDone(); |
190 }; | 208 }; |
191 }; | 209 }; |
192 | 210 |
193 window['MediaSourceUtil'] = MediaSourceUtil; | 211 window['MediaSourceUtil'] = MediaSourceUtil; |
194 window['media_test'] = function(testFunction, description, options) | 212 window['media_test'] = function(testFunction, description, options) |
195 { | 213 { |
196 options = options || {}; | 214 options = options || {}; |
197 return async_test(function(test) | 215 return async_test(function(test) |
198 { | 216 { |
(...skipping 21 matching lines...) Expand all Loading... | |
220 }; | 238 }; |
221 | 239 |
222 openMediaSource_(test, mediaTag, function(mediaSource) | 240 openMediaSource_(test, mediaTag, function(mediaSource) |
223 { | 241 { |
224 testFunction(test, mediaTag, mediaSource); | 242 testFunction(test, mediaTag, mediaSource); |
225 }); | 243 }); |
226 }, description, options); | 244 }, description, options); |
227 | 245 |
228 }; | 246 }; |
229 })(window); | 247 })(window); |
OLD | NEW |