Chromium Code Reviews| 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 _(); }); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 28 }); | 29 }); |
| 29 object.addEventListener(eventName, eventHandler); | 30 object.addEventListener(eventName, eventHandler); |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback ) | 33 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback ) |
| 33 { | 34 { |
| 34 this.waitCallbacks_.push(callback); | 35 this.waitCallbacks_.push(callback); |
| 35 setTimeout(this.handleWaitCallback_.bind(this), 0); | 36 setTimeout(this.handleWaitCallback_.bind(this), 0); |
| 36 }; | 37 }; |
| 37 | 38 |
| 39 EventExpectationsManager.prototype.waitForTimeUpdate = function(mediaElement , callback) | |
| 40 { | |
| 41 var initialTime = mediaElement.currentTime; | |
| 42 | |
| 43 function onTimeUpdate() { | |
|
wolenetz
2013/08/06 22:01:10
nit: step_func here, so caller's callback doesn't
anandc
2013/08/06 22:17:42
Ah yes, thank you. Done.
| |
| 44 if (mediaElement.currentTime == initialTime) { | |
| 45 // timeupdate fired but current media time did not change. | |
| 46 // Continue waiting for another timeupdate event. | |
| 47 mediaElement.addEventListener('timeupdate', onTimeUpdate); | |
|
wolenetz
2013/08/06 22:01:10
nit: No need to re-add. While duplicates are suppr
anandc
2013/08/06 22:17:42
Hmm. Did not know that duplicates are suppressed.
wolenetz
2013/08/06 22:35:55
Yes, per http://www.w3.org/TR/2000/REC-DOM-Level-2
| |
| 48 } | |
| 49 else { | |
| 50 mediaElement.removeEventListener('timeupdate', onTimeUpdate); | |
| 51 callback(); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 mediaElement.addEventListener('timeupdate', onTimeUpdate); | |
| 56 }; | |
| 57 | |
| 38 EventExpectationsManager.prototype.expectingEvents = function() | 58 EventExpectationsManager.prototype.expectingEvents = function() |
| 39 { | 59 { |
| 40 for (var i = 0; i < this.eventTargetList_.length; ++i) { | 60 for (var i = 0; i < this.eventTargetList_.length; ++i) { |
| 41 if (this.eventTargetList_[i].expectations.length > 0) { | 61 if (this.eventTargetList_[i].expectations.length > 0) { |
| 42 return true; | 62 return true; |
| 43 } | 63 } |
| 44 } | 64 } |
| 45 return false; | 65 return false; |
| 46 } | 66 } |
| 47 | 67 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 { | 189 { |
| 170 object.addEventListener(eventName, test.step_func(function(event) { test.done(); })); | 190 object.addEventListener(eventName, test.step_func(function(event) { test.done(); })); |
| 171 }; | 191 }; |
| 172 | 192 |
| 173 test.eventExpectations_ = new EventExpectationsManager(test); | 193 test.eventExpectations_ = new EventExpectationsManager(test); |
| 174 test.expectEvent = function(object, eventName, description) | 194 test.expectEvent = function(object, eventName, description) |
| 175 { | 195 { |
| 176 test.eventExpectations_.expectEvent(object, eventName, description); | 196 test.eventExpectations_.expectEvent(object, eventName, description); |
| 177 }; | 197 }; |
| 178 | 198 |
| 199 test.expectDelayedCallback = function(callback, delay) | |
|
wolenetz
2013/08/06 22:01:10
This needs removal, too.
anandc
2013/08/06 22:17:42
Thanks. Done.
| |
| 200 { | |
| 201 test.eventExpectations_.expectDelayedCallback(callback, delay); | |
| 202 } | |
| 203 | |
| 204 test.waitForTimeUpdate = function(mediaElement, callback) | |
| 205 { | |
| 206 test.eventExpectations_.waitForTimeUpdate(mediaElement, callback); | |
| 207 } | |
| 208 | |
| 179 test.waitForExpectedEvents = function(callback) | 209 test.waitForExpectedEvents = function(callback) |
| 180 { | 210 { |
| 181 test.eventExpectations_.waitForExpectedEvents(callback); | 211 test.eventExpectations_.waitForExpectedEvents(callback); |
| 182 }; | 212 }; |
| 183 | 213 |
| 184 var oldTestDone = test.done.bind(test); | 214 var oldTestDone = test.done.bind(test); |
| 185 test.done = function() | 215 test.done = function() |
| 186 { | 216 { |
| 187 if (test.status == test.PASS) | 217 // loop through and clear timeoutIDs |
| 218 for (var i in test.eventExpectations_.timeoutIDs_) { | |
| 219 clearTimeout(test.eventExpectations_.timeoutIDs_[i]); | |
| 220 } | |
| 221 if (test.status == test.PASS) { | |
| 188 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); | 222 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); |
| 223 assert_equals(Object.keys(test.eventExpectations_.timeoutIDs_).l ength, 0); | |
| 224 } | |
| 189 oldTestDone(); | 225 oldTestDone(); |
| 190 }; | 226 }; |
| 191 }; | 227 }; |
| 192 | 228 |
| 193 window['MediaSourceUtil'] = MediaSourceUtil; | 229 window['MediaSourceUtil'] = MediaSourceUtil; |
| 194 window['media_test'] = function(testFunction, description, options) | 230 window['media_test'] = function(testFunction, description, options) |
| 195 { | 231 { |
| 196 options = options || {}; | 232 options = options || {}; |
| 197 return async_test(function(test) | 233 return async_test(function(test) |
| 198 { | 234 { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 220 }; | 256 }; |
| 221 | 257 |
| 222 openMediaSource_(test, mediaTag, function(mediaSource) | 258 openMediaSource_(test, mediaTag, function(mediaSource) |
| 223 { | 259 { |
| 224 testFunction(test, mediaTag, mediaSource); | 260 testFunction(test, mediaTag, mediaSource); |
| 225 }); | 261 }); |
| 226 }, description, options); | 262 }, description, options); |
| 227 | 263 |
| 228 }; | 264 }; |
| 229 })(window); | 265 })(window); |
| OLD | NEW |