Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: LayoutTests/http/tests/media/media-source/mediasource-util.js

Issue 20114005: Layout Test for basic MSE seek scenario. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Properly track and remove timeoutIDs for each delayed callback. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/http/tests/media/media-source/mediasource-play-then-seek-back-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2c93e2f805bab404afe3ecbe0ff790b4a3cbb1d1 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)
+ {
+ // 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, index) {
+ timeoutIDs.splice(index, 1);
wolenetz 2013/08/01 18:32:24 I don't think this will always work as intended. E
anandc 2013/08/01 22:10:10 This was really useful. Thanks. Done.
+ callback();
+ }
+
+ // Execute the wrapper after the specified delay.
+ var timeoutIDs = this.timeoutIDs_;
wolenetz 2013/08/01 18:32:24 nit: why not just use this.timeoutIDs_ everywhere,
anandc 2013/08/01 22:10:10 Done in most places. There is a problem with the
+ var index = timeoutIDs.length;
+ var timeoutID = setTimeout(function() {callbackWrapper(callback, timeoutIDs, index);}, delay);
+ // Add to list of timeoutIDs, which we'll use eventually to check that
+ // all expected delayed callbacks did get executed.
+ timeoutIDs[index] = timeoutID;
+ };
+
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,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();
};
};
« no previous file with comments | « LayoutTests/http/tests/media/media-source/mediasource-play-then-seek-back-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698