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

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

Issue 2850553002: Autoplay: use an autoplay policy setting in Blink. (Closed)
Patch Set: rebase Created 3 years, 7 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 <!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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 })); 308 }));
309 309
310 setTimeout(t.step_func(function() { 310 setTimeout(t.step_func(function() {
311 audio.pause(); 311 audio.pause();
312 audio.src = findMediaFile('audio', 'content/test'); 312 audio.src = findMediaFile('audio', 'content/test');
313 }), 0); 313 }), 0);
314 }, 314 },
315 ]; 315 ];
316 316
317 tests.forEach(function(test) { 317 tests.forEach(function(test) {
318 internals.settings.setMediaPlaybackRequiresUserGesture(false); 318 internals.settings.setAutoplayPolicy('no-user-gesture-required');
319 async_test(function(t) { 319 async_test(function(t) {
320 var audio = document.createElement("audio"); 320 var audio = document.createElement("audio");
321 test(t, audio); 321 test(t, audio);
322 }, test.name); 322 }, test.name);
323 }); 323 });
324 324
325 var testsWithUserGesture = [ 325 var testsWithUserGesture = [
326 // Test that play() on an element when media playback requires a gesture 326 // Test that play() on an element when media playback requires a gesture
327 // returns a resolved promise if there is a user gesture. 327 // returns a resolved promise if there is a user gesture.
328 function playRequiresUserGestureAndHasIt(t, audio) { 328 function playRequiresUserGestureAndHasIt(t, audio) {
329 audio.src = findMediaFile("audio", "content/test"); 329 audio.src = findMediaFile("audio", "content/test");
330 playWithUserGesture(t, audio); 330 playWithUserGesture(t, audio);
331 }, 331 },
332 332
333 // Test that play() on an element when media playback requires a gesture 333 // Test that play() on an element when media playback requires a gesture
334 // returns a rejected promise if there is no user gesture. 334 // returns a rejected promise if there is no user gesture.
335 function playRequiresUserGestureAndDoesNotHaveIt(t, audio) { 335 function playRequiresUserGestureAndDoesNotHaveIt(t, audio) {
336 audio.src = findMediaFile("audio", "content/test"); 336 audio.src = findMediaFile("audio", "content/test");
337 playExpectingRejectedPromise(t, audio, "NotAllowedError"); 337 playExpectingRejectedPromise(t, audio, "NotAllowedError");
338 } 338 }
339 ]; 339 ];
340 340
341 testsWithUserGesture.forEach(function(test) { 341 testsWithUserGesture.forEach(function(test) {
342 internals.settings.setMediaPlaybackRequiresUserGesture(true); 342 internals.settings.setAutoplayPolicy('user-gesture-required');
343 async_test(function(t) { 343 async_test(function(t) {
344 var audio = document.createElement("audio"); 344 var audio = document.createElement("audio");
345 test(t, audio); 345 test(t, audio);
346 }, test.name); 346 }, test.name);
347 }); 347 });
348 348
349 function playExpectingResolvedPromise(t, audio) { 349 function playExpectingResolvedPromise(t, audio) {
350 audio.play().then(t.step_func_done(function() { 350 audio.play().then(t.step_func_done(function() {
351 assert_equals(arguments.length, 1); 351 assert_equals(arguments.length, 1);
352 assert_equals(arguments[0], undefined); 352 assert_equals(arguments[0], undefined);
(...skipping 10 matching lines...) Expand all
363 function playWithUserGesture(t, audio) { 363 function playWithUserGesture(t, audio) {
364 document.onclick = function() { 364 document.onclick = function() {
365 playExpectingResolvedPromise(t, audio); 365 playExpectingResolvedPromise(t, audio);
366 document.onclick = null; 366 document.onclick = null;
367 }; 367 };
368 368
369 eventSender.mouseDown(); 369 eventSender.mouseDown();
370 eventSender.mouseUp(); 370 eventSender.mouseUp();
371 } 371 }
372 </script> 372 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698