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..2dfaf4bc3352a77f6c7b3f42b2ba5084b6693d60 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,6 +30,26 @@ |
object.addEventListener(eventName, eventHandler); |
}; |
+ EventExpectationsManager.prototype.expectDelayedCallback = function(callback, delay) |
+ { |
+ var timeoutIDHolder = 0; |
+ // 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 = function(callback, timeoutIDs) { |
wolenetz
2013/08/02 21:24:07
nit: Remove timeoutIDs parameter. It should still
anandc
2013/08/02 22:37:48
Done.
|
+ delete timeoutIDs[timeoutIDHolder]; |
+ callback(); |
+ } |
+ |
+ // Execute the wrapper after the specified delay. |
+ var timeoutIDs = this.timeoutIDs_; |
+ timeoutIDHolder = setTimeout(function() {callbackWrapper(callback, timeoutIDs);}, delay); |
wolenetz
2013/08/02 21:24:07
nit: Remove timeoutIDs parameter. It should still
|
+ // Add to list of timeoutIDs, which we'll use eventually to check that |
+ // all expected delayed callbacks did get executed. |
+ this.timeoutIDs_[timeoutIDHolder] = timeoutIDHolder; |
wolenetz
2013/08/02 21:24:07
low-pri nit: We have a local reference to this.tim
anandc
2013/08/02 22:37:48
Done.
anandc
2013/08/02 22:37:48
Done.
|
+ }; |
+ |
EventExpectationsManager.prototype.waitForExpectedEvents = function(callback) |
{ |
this.waitCallbacks_.push(callback); |
@@ -176,6 +197,11 @@ |
test.eventExpectations_.expectEvent(object, eventName, description); |
}; |
+ test.expectDelayedCallback = function(callback, delay) |
+ { |
+ test.eventExpectations_.expectDelayedCallback(callback, delay); |
+ } |
+ |
test.waitForExpectedEvents = function(callback) |
{ |
test.eventExpectations_.waitForExpectedEvents(callback); |
@@ -184,8 +210,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(); |
}; |
}; |