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

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: Wait for timeupdate and check for time-change, rather than waiting for a hard-coded change. 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 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 = this.test_.step_func(function() {
42 delete timeoutIDs[timeoutIDHolder];
43 callback();
44 });
45
46 // Default to a wait time of 300ms.
47 delay = (typeof delay === "undefined") ? 300 : delay;
48 // Execute the wrapper after the specified or default delay.
49 timeoutIDHolder = setTimeout(function() { callbackWrapper(); }, 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
62 EventExpectationsManager.prototype.waitForTimeUpdate = function(mediaElement , callback)
63 {
64 var initialTime = mediaElement.currentTime;
65
66 function onTimeUpdate() {
67 mediaElement.removeEventListener('timeupdate', onTimeUpdate);
wolenetz 2013/08/06 21:33:35 Simplify by only removing if the currentTime misma
anandc 2013/08/06 21:55:30 Done.
68 if (mediaElement.currentTime == initialTime)
69 mediaElement.addEventListener('timeupdate', onTimeUpdate);
70 else
71 callback();
72 }
73
74 mediaElement.addEventListener('timeupdate', onTimeUpdate);
75 };
76
38 EventExpectationsManager.prototype.expectingEvents = function() 77 EventExpectationsManager.prototype.expectingEvents = function()
39 { 78 {
40 for (var i = 0; i < this.eventTargetList_.length; ++i) { 79 for (var i = 0; i < this.eventTargetList_.length; ++i) {
41 if (this.eventTargetList_[i].expectations.length > 0) { 80 if (this.eventTargetList_[i].expectations.length > 0) {
42 return true; 81 return true;
43 } 82 }
44 } 83 }
45 return false; 84 return false;
46 } 85 }
47 86
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 { 208 {
170 object.addEventListener(eventName, test.step_func(function(event) { test.done(); })); 209 object.addEventListener(eventName, test.step_func(function(event) { test.done(); }));
171 }; 210 };
172 211
173 test.eventExpectations_ = new EventExpectationsManager(test); 212 test.eventExpectations_ = new EventExpectationsManager(test);
174 test.expectEvent = function(object, eventName, description) 213 test.expectEvent = function(object, eventName, description)
175 { 214 {
176 test.eventExpectations_.expectEvent(object, eventName, description); 215 test.eventExpectations_.expectEvent(object, eventName, description);
177 }; 216 };
178 217
218 test.expectDelayedCallback = function(callback, delay)
219 {
220 test.eventExpectations_.expectDelayedCallback(callback, delay);
221 }
222
223 test.waitForTimeUpdate = function(mediaElement, callback)
224 {
225 test.eventExpectations_.waitForTimeUpdate(mediaElement, callback);
226 }
227
179 test.waitForExpectedEvents = function(callback) 228 test.waitForExpectedEvents = function(callback)
180 { 229 {
181 test.eventExpectations_.waitForExpectedEvents(callback); 230 test.eventExpectations_.waitForExpectedEvents(callback);
182 }; 231 };
183 232
184 var oldTestDone = test.done.bind(test); 233 var oldTestDone = test.done.bind(test);
185 test.done = function() 234 test.done = function()
186 { 235 {
187 if (test.status == test.PASS) 236 // loop through and clear timeoutIDs
237 for (var i in test.eventExpectations_.timeoutIDs_) {
238 clearTimeout(test.eventExpectations_.timeoutIDs_[i]);
239 }
240 if (test.status == test.PASS) {
188 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations."); 241 assert_false(test.eventExpectations_.expectingEvents(), "No pend ing event expectations.");
242 assert_equals(Object.keys(test.eventExpectations_.timeoutIDs_).l ength, 0);
243 }
189 oldTestDone(); 244 oldTestDone();
190 }; 245 };
191 }; 246 };
192 247
193 window['MediaSourceUtil'] = MediaSourceUtil; 248 window['MediaSourceUtil'] = MediaSourceUtil;
194 window['media_test'] = function(testFunction, description, options) 249 window['media_test'] = function(testFunction, description, options)
195 { 250 {
196 options = options || {}; 251 options = options || {};
197 return async_test(function(test) 252 return async_test(function(test)
198 { 253 {
(...skipping 21 matching lines...) Expand all
220 }; 275 };
221 276
222 openMediaSource_(test, mediaTag, function(mediaSource) 277 openMediaSource_(test, mediaTag, function(mediaSource)
223 { 278 {
224 testFunction(test, mediaTag, mediaSource); 279 testFunction(test, mediaTag, mediaSource);
225 }); 280 });
226 }, description, options); 281 }, description, options);
227 282
228 }; 283 };
229 })(window); 284 })(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