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

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: Fix indentation. 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
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 var timeoutIDHolder = 0;
36 var timeoutIDs = this.timeoutIDs_;
37 // Define a wrapper function that will:
38 // 1. To indicate that this expected callback did fire, remove this
39 // timeoutID from the list of IDs we are maintaining.
40 // 2. Execute the callback that has been passed-in.
41 var callbackWrapper = function(callback) {
acolwell GONE FROM CHROMIUM 2013/08/05 21:06:06 nit: callback parameter isn't necessary here. Just
anandc 2013/08/06 18:03:30 Done.
42 delete timeoutIDs[timeoutIDHolder];
43 callback();
44 }
45
46 // Execute the wrapper after the specified delay.
47 timeoutIDHolder = setTimeout(
48 function() { callbackWrapper(callback); },
acolwell GONE FROM CHROMIUM 2013/08/05 21:06:06 nit: put the whole setTimeout call all on a single
anandc 2013/08/06 18:03:30 Done.
49 delay);
50
51 // Add to list of timeoutIDs, which we'll use eventually to check that
52 // all expected delayed callbacks did get executed.
53 timeoutIDs[timeoutIDHolder] = timeoutIDHolder;
54 };
55
32 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback ) 56 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback )
33 { 57 {
34 this.waitCallbacks_.push(callback); 58 this.waitCallbacks_.push(callback);
35 setTimeout(this.handleWaitCallback_.bind(this), 0); 59 setTimeout(this.handleWaitCallback_.bind(this), 0);
36 }; 60 };
37 61
38 EventExpectationsManager.prototype.expectingEvents = function() 62 EventExpectationsManager.prototype.expectingEvents = function()
39 { 63 {
40 for (var i = 0; i < this.eventTargetList_.length; ++i) { 64 for (var i = 0; i < this.eventTargetList_.length; ++i) {
41 if (this.eventTargetList_[i].expectations.length > 0) { 65 if (this.eventTargetList_[i].expectations.length > 0) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 { 193 {
170 object.addEventListener(eventName, test.step_func(function(event) { test.done(); })); 194 object.addEventListener(eventName, test.step_func(function(event) { test.done(); }));
171 }; 195 };
172 196
173 test.eventExpectations_ = new EventExpectationsManager(test); 197 test.eventExpectations_ = new EventExpectationsManager(test);
174 test.expectEvent = function(object, eventName, description) 198 test.expectEvent = function(object, eventName, description)
175 { 199 {
176 test.eventExpectations_.expectEvent(object, eventName, description); 200 test.eventExpectations_.expectEvent(object, eventName, description);
177 }; 201 };
178 202
203 test.expectDelayedCallback = function(callback, delay)
204 {
205 test.eventExpectations_.expectDelayedCallback(callback, delay);
206 }
207
179 test.waitForExpectedEvents = function(callback) 208 test.waitForExpectedEvents = function(callback)
180 { 209 {
181 test.eventExpectations_.waitForExpectedEvents(callback); 210 test.eventExpectations_.waitForExpectedEvents(callback);
182 }; 211 };
183 212
184 var oldTestDone = test.done.bind(test); 213 var oldTestDone = test.done.bind(test);
185 test.done = function() 214 test.done = function()
186 { 215 {
187 if (test.status == test.PASS) 216 // loop through and clear timeoutIDs
217 for (var i in test.eventExpectations_.timeoutIDs_) {
218 clearTimeout(test.eventExpectations_.timeoutIDs_[i]);
219 }
220 if (test.status == test.PASS) {
188 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); 221 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations.");
222 assert_equals(Object.keys(test.eventExpectations_.timeoutIDs_).l ength, 0);
223 }
189 oldTestDone(); 224 oldTestDone();
190 }; 225 };
191 }; 226 };
192 227
193 window['MediaSourceUtil'] = MediaSourceUtil; 228 window['MediaSourceUtil'] = MediaSourceUtil;
194 window['media_test'] = function(testFunction, description, options) 229 window['media_test'] = function(testFunction, description, options)
195 { 230 {
196 options = options || {}; 231 options = options || {};
197 return async_test(function(test) 232 return async_test(function(test)
198 { 233 {
(...skipping 21 matching lines...) Expand all
220 }; 255 };
221 256
222 openMediaSource_(test, mediaTag, function(mediaSource) 257 openMediaSource_(test, mediaTag, function(mediaSource)
223 { 258 {
224 testFunction(test, mediaTag, mediaSource); 259 testFunction(test, mediaTag, mediaSource);
225 }); 260 });
226 }, description, options); 261 }, description, options);
227 262
228 }; 263 };
229 })(window); 264 })(window);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698