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

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 notes describing functionality of waitForTimeUpdate. 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_ = {};
wolenetz 2013/08/06 23:06:48 This still needs removal :)
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)
196 // This function waits for a timeupdate event to be fired accompanied by
197 // a change in currentTime of the mediaElement. Only when both have
198 // occurred does it eventually invoke callback.
199 {
200 test.eventExpectations_.waitForTimeUpdate(mediaElement, callback);
201 }
202
179 test.waitForExpectedEvents = function(callback) 203 test.waitForExpectedEvents = function(callback)
180 { 204 {
181 test.eventExpectations_.waitForExpectedEvents(callback); 205 test.eventExpectations_.waitForExpectedEvents(callback);
182 }; 206 };
183 207
184 var oldTestDone = test.done.bind(test); 208 var oldTestDone = test.done.bind(test);
185 test.done = function() 209 test.done = function()
186 { 210 {
187 if (test.status == test.PASS) 211 // loop through and clear timeoutIDs
wolenetz 2013/08/06 23:06:48 And clearing timeoutIDs needs removal too.
212 for (var i in test.eventExpectations_.timeoutIDs_) {
213 clearTimeout(test.eventExpectations_.timeoutIDs_[i]);
214 }
215 if (test.status == test.PASS) {
188 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); 216 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations.");
217 assert_equals(Object.keys(test.eventExpectations_.timeoutIDs_).l ength, 0);
wolenetz 2013/08/06 23:06:48 And this line also needs removal.
218 }
189 oldTestDone(); 219 oldTestDone();
190 }; 220 };
191 }; 221 };
192 222
193 window['MediaSourceUtil'] = MediaSourceUtil; 223 window['MediaSourceUtil'] = MediaSourceUtil;
194 window['media_test'] = function(testFunction, description, options) 224 window['media_test'] = function(testFunction, description, options)
195 { 225 {
196 options = options || {}; 226 options = options || {};
197 return async_test(function(test) 227 return async_test(function(test)
198 { 228 {
(...skipping 21 matching lines...) Expand all
220 }; 250 };
221 251
222 openMediaSource_(test, mediaTag, function(mediaSource) 252 openMediaSource_(test, mediaTag, function(mediaSource)
223 { 253 {
224 testFunction(test, mediaTag, mediaSource); 254 testFunction(test, mediaTag, mediaSource);
225 }); 255 });
226 }, description, options); 256 }, description, options);
227 257
228 }; 258 };
229 })(window); 259 })(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