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..0ed3c58ac3ac145c4629ecea10aa7a8d6ce5cdf3 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,25 @@ |
object.addEventListener(eventName, eventHandler); |
}; |
+ EventExpectationsManager.prototype.expectDelayedCallback = function(callback, delay) |
+ { |
+ // Define a wrapper function that will: |
+ // 1. Execute the callback that has been passed-in. |
+ // 2. Clean-up the list of timeoutIDs, removing the first in the list |
wolenetz
2013/08/01 00:16:15
I don't think we should require that the timeoutID
anandc
2013/08/01 18:12:03
Makes sense. Done.
There also was a bug where, if
|
+ // ("first" chronologically) |
+ var callbackWrapper = function(callback, timeoutIDs) { |
+ callback(); |
+ timeoutIDs.shift(); |
+ } |
+ |
+ // Execute the wrapper after the specified delay. |
+ var timeoutIDs = this.timeoutIDs_; |
+ var timeoutID = setTimeout(function() {callbackWrapper(callback, timeoutIDs);}, delay); |
+ // Add to list of timeoutIDs, which we'll use eventually to check that |
+ // all expected delayed callbacks did get executed. |
+ timeoutIDs.push(timeoutID); |
+ }; |
+ |
EventExpectationsManager.prototype.waitForExpectedEvents = function(callback) |
{ |
this.waitCallbacks_.push(callback); |
@@ -176,6 +196,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 +209,16 @@ |
var oldTestDone = test.done.bind(test); |
test.done = function() |
{ |
- if (test.status == test.PASS) |
+ // loop through and clear timeoutIDs |
+ var timeoutIDs = test.eventExpectations_.timeoutIDs_; |
+ for (var i = 0; i < timeoutIDs.length; ++i) { |
+ clearTimeout(timeoutIDs[i]); |
+ } |
+ |
+ if (test.status == test.PASS) { |
assert_false(test.eventExpectations_.expectingEvents(), "No pending event expectations."); |
+ assert_equals(timeoutIDs.length, 0); |
+ } |
oldTestDone(); |
}; |
}; |