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

Side by Side 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: Check for completion of all expected delayed callbacks. Created 7 years, 4 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function(window) { 1 (function(window) {
2 EventExpectationsManager = function(test) 2 EventExpectationsManager = function(test)
3 { 3 {
4 this.test_ = test; 4 this.test_ = test;
5 this.eventTargetList_ = []; 5 this.eventTargetList_ = [];
6 this.waitCallbacks_ = []; 6 this.waitCallbacks_ = [];
7 this.timeoutIDs_ = [];
7 }; 8 };
8 9
9 EventExpectationsManager.prototype.expectEvent = function(object, eventName, description) 10 EventExpectationsManager.prototype.expectEvent = function(object, eventName, description)
10 { 11 {
11 var eventInfo = { 'target': object, 'type': eventName, 'description': de scription}; 12 var eventInfo = { 'target': object, 'type': eventName, 'description': de scription};
12 var expectations = this.getExpectations_(object); 13 var expectations = this.getExpectations_(object);
13 expectations.push(eventInfo); 14 expectations.push(eventInfo);
14 15
15 var t = this; 16 var t = this;
16 var waitHandler = this.test_.step_func(function() { t.handleWaitCallback _(); }); 17 var waitHandler = this.test_.step_func(function() { t.handleWaitCallback _(); });
17 var eventHandler = this.test_.step_func(function(event) 18 var eventHandler = this.test_.step_func(function(event)
18 { 19 {
19 object.removeEventListener(eventName, eventHandler); 20 object.removeEventListener(eventName, eventHandler);
20 var expected = expectations[0]; 21 var expected = expectations[0];
21 assert_equals(event.target, expected.target, "Event target match."); 22 assert_equals(event.target, expected.target, "Event target match.");
22 assert_equals(event.type, expected.type, "Event types match."); 23 assert_equals(event.type, expected.type, "Event types match.");
23 assert_equals(eventInfo.description, expected.description, "Descript ions match for '" + event.type + "'."); 24 assert_equals(eventInfo.description, expected.description, "Descript ions match for '" + event.type + "'.");
24 25
25 expectations.shift(1); 26 expectations.shift(1);
26 if (t.waitCallbacks_.length > 0) 27 if (t.waitCallbacks_.length > 0)
27 setTimeout(waitHandler, 0); 28 setTimeout(waitHandler, 0);
28 }); 29 });
29 object.addEventListener(eventName, eventHandler); 30 object.addEventListener(eventName, eventHandler);
30 }; 31 };
31 32
33 EventExpectationsManager.prototype.expectDelayedCallback = function(callback , delay)
34 {
35 // Define a wrapper function that will:
36 // 1. Execute the callback that has been passed-in.
37 // 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
38 // ("first" chronologically)
39 var callbackWrapper = function(callback, timeoutIDs) {
40 callback();
41 timeoutIDs.shift();
42 }
43
44 // Execute the wrapper after the specified delay.
45 var timeoutIDs = this.timeoutIDs_;
46 var timeoutID = setTimeout(function() {callbackWrapper(callback, timeout IDs);}, delay);
47 // Add to list of timeoutIDs, which we'll use eventually to check that
48 // all expected delayed callbacks did get executed.
49 timeoutIDs.push(timeoutID);
50 };
51
32 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback ) 52 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback )
33 { 53 {
34 this.waitCallbacks_.push(callback); 54 this.waitCallbacks_.push(callback);
35 setTimeout(this.handleWaitCallback_.bind(this), 0); 55 setTimeout(this.handleWaitCallback_.bind(this), 0);
36 }; 56 };
37 57
38 EventExpectationsManager.prototype.expectingEvents = function() 58 EventExpectationsManager.prototype.expectingEvents = function()
39 { 59 {
40 for (var i = 0; i < this.eventTargetList_.length; ++i) { 60 for (var i = 0; i < this.eventTargetList_.length; ++i) {
41 if (this.eventTargetList_[i].expectations.length > 0) { 61 if (this.eventTargetList_[i].expectations.length > 0) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 { 189 {
170 object.addEventListener(eventName, test.step_func(function(event) { test.done(); })); 190 object.addEventListener(eventName, test.step_func(function(event) { test.done(); }));
171 }; 191 };
172 192
173 test.eventExpectations_ = new EventExpectationsManager(test); 193 test.eventExpectations_ = new EventExpectationsManager(test);
174 test.expectEvent = function(object, eventName, description) 194 test.expectEvent = function(object, eventName, description)
175 { 195 {
176 test.eventExpectations_.expectEvent(object, eventName, description); 196 test.eventExpectations_.expectEvent(object, eventName, description);
177 }; 197 };
178 198
199 test.expectDelayedCallback = function(callback, delay)
200 {
201 test.eventExpectations_.expectDelayedCallback(callback, delay);
202 }
203
179 test.waitForExpectedEvents = function(callback) 204 test.waitForExpectedEvents = function(callback)
180 { 205 {
181 test.eventExpectations_.waitForExpectedEvents(callback); 206 test.eventExpectations_.waitForExpectedEvents(callback);
182 }; 207 };
183 208
184 var oldTestDone = test.done.bind(test); 209 var oldTestDone = test.done.bind(test);
185 test.done = function() 210 test.done = function()
186 { 211 {
187 if (test.status == test.PASS) 212 // loop through and clear timeoutIDs
213 var timeoutIDs = test.eventExpectations_.timeoutIDs_;
214 for (var i = 0; i < timeoutIDs.length; ++i) {
215 clearTimeout(timeoutIDs[i]);
216 }
217
218 if (test.status == test.PASS) {
188 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); 219 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations.");
220 assert_equals(timeoutIDs.length, 0);
221 }
189 oldTestDone(); 222 oldTestDone();
190 }; 223 };
191 }; 224 };
192 225
193 window['MediaSourceUtil'] = MediaSourceUtil; 226 window['MediaSourceUtil'] = MediaSourceUtil;
194 window['media_test'] = function(testFunction, description, options) 227 window['media_test'] = function(testFunction, description, options)
195 { 228 {
196 options = options || {}; 229 options = options || {};
197 return async_test(function(test) 230 return async_test(function(test)
198 { 231 {
(...skipping 21 matching lines...) Expand all
220 }; 253 };
221 254
222 openMediaSource_(test, mediaTag, function(mediaSource) 255 openMediaSource_(test, mediaTag, function(mediaSource)
223 { 256 {
224 testFunction(test, mediaTag, mediaSource); 257 testFunction(test, mediaTag, mediaSource);
225 }); 258 });
226 }, description, options); 259 }, description, options);
227 260
228 }; 261 };
229 })(window); 262 })(window);
OLDNEW
« 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