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

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: Add only 1 listener to timeupdate. Use step_func. 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_ = {};
wolenetz 2013/08/06 22:35:55 Oh noes! This also needs removal :)
anandc 2013/08/06 23:27:22 Many thanks for catching these. Done.
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 _(); });
(...skipping 11 matching lines...) Expand all
28 }); 29 });
29 object.addEventListener(eventName, eventHandler); 30 object.addEventListener(eventName, eventHandler);
30 }; 31 };
31 32
32 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback ) 33 EventExpectationsManager.prototype.waitForExpectedEvents = function(callback )
33 { 34 {
34 this.waitCallbacks_.push(callback); 35 this.waitCallbacks_.push(callback);
35 setTimeout(this.handleWaitCallback_.bind(this), 0); 36 setTimeout(this.handleWaitCallback_.bind(this), 0);
36 }; 37 };
37 38
39 EventExpectationsManager.prototype.waitForTimeUpdate = function(mediaElement , callback)
40 {
41 var initialTime = mediaElement.currentTime;
42
43 var onTimeUpdate = this.test_.step_func(function()
44 {
45 if (mediaElement.currentTime != initialTime) {
46 mediaElement.removeEventListener('timeupdate', onTimeUpdate);
47 callback();
48 }
49 });
50
51 mediaElement.addEventListener('timeupdate', onTimeUpdate);
52 };
53
38 EventExpectationsManager.prototype.expectingEvents = function() 54 EventExpectationsManager.prototype.expectingEvents = function()
39 { 55 {
40 for (var i = 0; i < this.eventTargetList_.length; ++i) { 56 for (var i = 0; i < this.eventTargetList_.length; ++i) {
41 if (this.eventTargetList_[i].expectations.length > 0) { 57 if (this.eventTargetList_[i].expectations.length > 0) {
42 return true; 58 return true;
43 } 59 }
44 } 60 }
45 return false; 61 return false;
46 } 62 }
47 63
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 { 185 {
170 object.addEventListener(eventName, test.step_func(function(event) { test.done(); })); 186 object.addEventListener(eventName, test.step_func(function(event) { test.done(); }));
171 }; 187 };
172 188
173 test.eventExpectations_ = new EventExpectationsManager(test); 189 test.eventExpectations_ = new EventExpectationsManager(test);
174 test.expectEvent = function(object, eventName, description) 190 test.expectEvent = function(object, eventName, description)
175 { 191 {
176 test.eventExpectations_.expectEvent(object, eventName, description); 192 test.eventExpectations_.expectEvent(object, eventName, description);
177 }; 193 };
178 194
195 test.waitForTimeUpdate = function(mediaElement, callback)
wolenetz 2013/08/06 22:35:55 nit: Please add brief documentation here that not
anandc 2013/08/06 22:49:37 Good point. Done.
acolwell GONE FROM CHROMIUM 2013/08/06 23:05:09 nit: An alternative is to just change the method n
anandc 2013/08/06 23:27:22 Renaming is better. Done.
196 {
197 test.eventExpectations_.waitForTimeUpdate(mediaElement, callback);
acolwell GONE FROM CHROMIUM 2013/08/06 23:05:09 nit: Why is added as part of the EventExpectations
anandc 2013/08/06 23:27:22 Of course. :-) Thank you. Done.
198 }
199
179 test.waitForExpectedEvents = function(callback) 200 test.waitForExpectedEvents = function(callback)
180 { 201 {
181 test.eventExpectations_.waitForExpectedEvents(callback); 202 test.eventExpectations_.waitForExpectedEvents(callback);
182 }; 203 };
183 204
184 var oldTestDone = test.done.bind(test); 205 var oldTestDone = test.done.bind(test);
185 test.done = function() 206 test.done = function()
186 { 207 {
187 if (test.status == test.PASS) 208 // loop through and clear timeoutIDs
209 for (var i in test.eventExpectations_.timeoutIDs_) {
acolwell GONE FROM CHROMIUM 2013/08/06 23:05:09 nit: I think this can be removed since timeoutIDs
anandc 2013/08/06 23:27:22 Yes, removed.
210 clearTimeout(test.eventExpectations_.timeoutIDs_[i]);
211 }
212 if (test.status == test.PASS) {
188 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); 213 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations.");
214 assert_equals(Object.keys(test.eventExpectations_.timeoutIDs_).l ength, 0);
acolwell GONE FROM CHROMIUM 2013/08/06 23:05:09 nit: ditto
anandc 2013/08/06 23:27:22 Done.
215 }
189 oldTestDone(); 216 oldTestDone();
190 }; 217 };
191 }; 218 };
192 219
193 window['MediaSourceUtil'] = MediaSourceUtil; 220 window['MediaSourceUtil'] = MediaSourceUtil;
194 window['media_test'] = function(testFunction, description, options) 221 window['media_test'] = function(testFunction, description, options)
195 { 222 {
196 options = options || {}; 223 options = options || {};
197 return async_test(function(test) 224 return async_test(function(test)
198 { 225 {
(...skipping 21 matching lines...) Expand all
220 }; 247 };
221 248
222 openMediaSource_(test, mediaTag, function(mediaSource) 249 openMediaSource_(test, mediaTag, function(mediaSource)
223 { 250 {
224 testFunction(test, mediaTag, mediaSource); 251 testFunction(test, mediaTag, mediaSource);
225 }); 252 });
226 }, description, options); 253 }, description, options);
227 254
228 }; 255 };
229 })(window); 256 })(window);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698