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..46444b9f2d800e9145ac83cb3cec6199afe3aea9 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) |
@@ -29,12 +30,50 @@ |
object.addEventListener(eventName, eventHandler); |
}; |
+ EventExpectationsManager.prototype.expectDelayedCallback = function(callback, delay) |
+ { |
+ var timeoutIDHolder = 0; |
+ var timeoutIDs = this.timeoutIDs_; |
+ // Define a wrapper function that will: |
+ // 1. To indicate that this expected callback did fire, remove this |
+ // timeoutID from the list of IDs we are maintaining. |
+ // 2. Execute the callback that has been passed-in. |
+ var callbackWrapper = this.test_.step_func(function() { |
+ delete timeoutIDs[timeoutIDHolder]; |
+ callback(); |
+ }); |
+ |
+ // Default to a wait time of 300ms. |
+ delay = (typeof delay === "undefined") ? 300 : delay; |
+ // Execute the wrapper after the specified or default delay. |
+ timeoutIDHolder = setTimeout(function() { callbackWrapper(); }, delay); |
+ |
+ // Add to list of timeoutIDs, which we'll use eventually to check that |
+ // all expected delayed callbacks did get executed. |
+ timeoutIDs[timeoutIDHolder] = timeoutIDHolder; |
+ }; |
+ |
EventExpectationsManager.prototype.waitForExpectedEvents = function(callback) |
{ |
this.waitCallbacks_.push(callback); |
setTimeout(this.handleWaitCallback_.bind(this), 0); |
}; |
+ EventExpectationsManager.prototype.waitForTimeUpdate = function(mediaElement, callback) |
+ { |
+ var initialTime = mediaElement.currentTime; |
+ |
+ function onTimeUpdate() { |
+ mediaElement.removeEventListener('timeupdate', onTimeUpdate); |
wolenetz
2013/08/06 21:33:35
Simplify by only removing if the currentTime misma
anandc
2013/08/06 21:55:30
Done.
|
+ if (mediaElement.currentTime == initialTime) |
+ mediaElement.addEventListener('timeupdate', onTimeUpdate); |
+ else |
+ callback(); |
+ } |
+ |
+ mediaElement.addEventListener('timeupdate', onTimeUpdate); |
+ }; |
+ |
EventExpectationsManager.prototype.expectingEvents = function() |
{ |
for (var i = 0; i < this.eventTargetList_.length; ++i) { |
@@ -176,6 +215,16 @@ |
test.eventExpectations_.expectEvent(object, eventName, description); |
}; |
+ test.expectDelayedCallback = function(callback, delay) |
+ { |
+ 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 +233,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(); |
}; |
}; |