Chromium Code Reviews| Index: LayoutTests/http/tests/media/media-source/mediasource-util.js |
| diff --git a/LayoutTests/http/tests/media/media-source/mediasource-util.js b/LayoutTests/http/tests/media/media-source/mediasource-util.js |
| index 456f012f4d99dc613dbdf3ac07f224d518097e76..13803f495075c5ee48d49fb9ac802f2d4d7ba94a 100644 |
| --- a/LayoutTests/http/tests/media/media-source/mediasource-util.js |
| +++ b/LayoutTests/http/tests/media/media-source/mediasource-util.js |
| @@ -4,6 +4,7 @@ |
| this.test_ = test; |
| this.eventTargetList_ = []; |
| this.waitCallbacks_ = []; |
| + this.timeoutIDs_ = {}; |
| }; |
| EventExpectationsManager.prototype.expectEvent = function(object, eventName, description) |
| @@ -35,6 +36,25 @@ |
| setTimeout(this.handleWaitCallback_.bind(this), 0); |
| }; |
| + EventExpectationsManager.prototype.waitForTimeUpdate = function(mediaElement, callback) |
| + { |
| + var initialTime = mediaElement.currentTime; |
| + |
| + 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.
|
| + if (mediaElement.currentTime == initialTime) { |
| + // timeupdate fired but current media time did not change. |
| + // Continue waiting for another timeupdate event. |
| + 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
|
| + } |
| + else { |
| + mediaElement.removeEventListener('timeupdate', onTimeUpdate); |
| + callback(); |
| + } |
| + } |
| + |
| + mediaElement.addEventListener('timeupdate', onTimeUpdate); |
| + }; |
| + |
| EventExpectationsManager.prototype.expectingEvents = function() |
| { |
| for (var i = 0; i < this.eventTargetList_.length; ++i) { |
| @@ -176,6 +196,16 @@ |
| test.eventExpectations_.expectEvent(object, eventName, description); |
| }; |
| + 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.
|
| + { |
| + test.eventExpectations_.expectDelayedCallback(callback, delay); |
| + } |
| + |
| + test.waitForTimeUpdate = function(mediaElement, callback) |
| + { |
| + test.eventExpectations_.waitForTimeUpdate(mediaElement, callback); |
| + } |
| + |
| test.waitForExpectedEvents = function(callback) |
| { |
| test.eventExpectations_.waitForExpectedEvents(callback); |
| @@ -184,8 +214,14 @@ |
| var oldTestDone = test.done.bind(test); |
| test.done = function() |
| { |
| - if (test.status == test.PASS) |
| + // loop through and clear timeoutIDs |
| + for (var i in test.eventExpectations_.timeoutIDs_) { |
| + clearTimeout(test.eventExpectations_.timeoutIDs_[i]); |
| + } |
| + if (test.status == test.PASS) { |
| assert_false(test.eventExpectations_.expectingEvents(), "No pending event expectations."); |
| + assert_equals(Object.keys(test.eventExpectations_.timeoutIDs_).length, 0); |
| + } |
| oldTestDone(); |
| }; |
| }; |