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

Side by Side Diff: third_party/WebKit/LayoutTests/media/media-play-promise.html

Issue 2199363002: Change play promises behaviour in the load algorithm. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 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 | « no previous file | third_party/WebKit/Source/core/html/HTMLMediaElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Test the play() behaviour with regards to the returned promise for media elements.</title> 2 <title>Test the play() behaviour with regards to the returned promise for media elements.</title>
3 <script src="../resources/testharness.js"></script> 3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script> 4 <script src="../resources/testharnessreport.js"></script>
5 <script src="media-file.js"></script> 5 <script src="media-file.js"></script>
6 <script> 6 <script>
7 // This is testing the behavior of play() with regards to the returned 7 // This is testing the behavior of play() with regards to the returned
8 // promise. This test file is creating a small framework in order to be able 8 // promise. This test file is creating a small framework in order to be able
9 // to test different cases easily and independently of each other. 9 // to test different cases easily and independently of each other.
10 // All tests have to be part of the tests and testsWithUserGesture arrays. 10 // All tests have to be part of the tests and testsWithUserGesture arrays.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 audio.onplaying = t.step_func(function() { 213 audio.onplaying = t.step_func(function() {
214 assert_equals(audio.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA); 214 assert_equals(audio.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA);
215 assert_false(audio.paused); 215 assert_false(audio.paused);
216 audio.pause(); 216 audio.pause();
217 playExpectingResolvedPromise(t, audio); 217 playExpectingResolvedPromise(t, audio);
218 }); 218 });
219 219
220 audio.oncanplaythrough = t.step_func(function() { 220 audio.oncanplaythrough = t.step_func(function() {
221 audio.play(); 221 audio.play();
222 }); 222 });
223 } 223 },
224
225 // Test that running the load algorithm will not drop all the promises about
226 // to be resolved.
227 function loadAlgorithmDoesNotCancelTasks(t, audio) {
228 audio.src = findMediaFile('audio', 'content/test');
229 audio.addEventListener('canplaythrough', t.step_func(function() {
230 // The play() promise will be queued to be resolved.
231 playExpectingResolvedPromise(t, audio);
232 audio.src = findMediaFile('audio', 'content/test');
233 assert_true(audio.paused);
234 }));
235 },
236
237 // Test that when the load algorithm is run, if it does not pause the
238 // playback, it will leave the promise pending, allowing it to be resolved.
239 function loadAlgorithmKeepPromisesPendingWhenNotPausing(t, audio) {
240 playExpectingResolvedPromise(t, audio);
241 setTimeout(t.step_func(function() {
242 audio.src = findMediaFile('audio', 'content/test');
243 assert_false(audio.paused);
244 }), 0);
245 },
246
247 // Test that when the load algorithm is run, if it resolves multiple
248 // promises, they are resolved in the order in which they were added.
249 function loadAlgorithmResolveOrdering(t, audio) {
250 audio.src = findMediaFile('audio', 'content/test');
251 audio.addEventListener('canplaythrough', t.step_func(function() {
252 var firstPromiseResolved = false;
253 audio.play().then(t.step_func(_ => firstPromiseResolved = true),
254 t.unreached_func());
255
256 audio.play().then(t.step_func_done(function() {
257 assert_true(firstPromiseResolved);
258 }), t.unreached_func());
259
260 audio.src = findMediaFile('audio', 'content/test');
261 }));
262 },
263
264 // Test that when the load algorithm is run, if it does not pause the
265 // playback, it will leave the promise pending, allowing it to be resolved
266 // (version with preload='none').
267 // TODO(mlamouri): there is a bug in Blink where the media element ends up
268 // in a broken state, see https://crbug.com/633591
269 // function loadAlgorithmKeepPromisesPendingWhenNotPausingAndPreloadNone(t, audio) {
270 // audio.preload = 'none';
271 // playExpectingRejectedPromise(t, audio, 'AbortError');
272 // setTimeout(_ => audio.src = findMediaFile('audio', 'content/test'), 0 );
273 // },
274
275 // Test that when the load algorithm is run, if it does pause the playback,
276 // it will reject the pending promises.
277 function loadAlgorithmRejectPromisesWhenPausing(t, audio) {
278 playExpectingRejectedPromise(t, audio, 'AbortError');
279 audio.src = findMediaFile('audio', 'content/test');
280 assert_true(audio.paused);
281 },
282
283 // Test that when the load algorithm is run, if it does pause the playback,
284 // it will reject the pending promises (version with preload='none').
285 function loadAlgorithmRejectPromisesWhenPausingAndPreloadNone(t, audio) {
286 audio.preload = 'none';
287 playExpectingRejectedPromise(t, audio, 'AbortError');
288 audio.src = findMediaFile('audio', 'content/test');
289 assert_true(audio.paused);
290 },
291
292 // Test that when the load algorithm is run, if it rejects multiple
293 // promises, they are rejected in the order in which they were added.
294 function loadAlgorithmResolveOrdering(t, audio) {
295 var firstPromiseRejected = false;
296 audio.play().then(t.unreached_func(), t.step_func(function(e) {
297 assert_equals(e.name, 'AbortError');
298 assert_equals(e.message,
299 'The play() request was interrupted by a call to pause().');
300 firstPromiseRejected = true;
301 }));
302
303 audio.play().then(t.unreached_func(), t.step_func_done(function(e) {
304 assert_equals(e.name, 'AbortError');
305 assert_equals(e.message,
306 'The play() request was interrupted by a call to pause().');
307 assert_true(firstPromiseRejected);
308 }));
309
310 setTimeout(t.step_func(function() {
311 audio.pause();
312 audio.src = findMediaFile('audio', 'content/test');
313 }), 0);
314 },
224 ]; 315 ];
225 316
226 tests.forEach(function(test) { 317 tests.forEach(function(test) {
227 internals.settings.setMediaPlaybackRequiresUserGesture(false); 318 internals.settings.setMediaPlaybackRequiresUserGesture(false);
228 async_test(function(t) { 319 async_test(function(t) {
229 var audio = document.createElement("audio"); 320 var audio = document.createElement("audio");
230 test(t, audio); 321 test(t, audio);
231 }, test.name); 322 }, test.name);
232 }); 323 });
233 324
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 362
272 function playWithUserGesture(t, audio) { 363 function playWithUserGesture(t, audio) {
273 document.onclick = function() { 364 document.onclick = function() {
274 playExpectingResolvedPromise(t, audio); 365 playExpectingResolvedPromise(t, audio);
275 document.onclick = null; 366 document.onclick = null;
276 }; 367 };
277 368
278 eventSender.mouseDown(); 369 eventSender.mouseDown();
279 eventSender.mouseUp(); 370 eventSender.mouseUp();
280 } 371 }
281 </script> 372 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/HTMLMediaElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698