Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Test for autoplay of muted video</title> | 2 <title>Test for autoplay of muted video</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 src="media-controls.js"></script> | 6 <script src="media-controls.js"></script> |
| 7 <script> | 7 <script> |
| 8 test(function() { | 8 test(function() { |
| 9 assert_true(!!window.internals | 9 assert_true(!!window.internals |
| 10 && !!window.internals.settings | 10 && !!window.internals.settings |
| 11 && !!window.internals.runtimeFlags | 11 && !!window.internals.runtimeFlags |
| 12 && !!window.eventSender, | 12 && !!window.eventSender, |
| 13 "This test only works when run as a layout test!"); | 13 "This test only works when run as a layout test!"); |
| 14 }, "Prerequisites to running the rest of the tests"); | 14 }, "Prerequisites to running the rest of the tests"); |
| 15 | 15 |
| 16 window.internals.settings.setMediaPlaybackRequiresUserGesture(true); | 16 window.internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| 17 window.internals.runtimeFlags.autoplayMutedVideosEnabled = true; | 17 window.internals.runtimeFlags.autoplayMutedVideosEnabled = true; |
| 18 testRunner.setAutoplayAllowed(true); | 18 testRunner.setAutoplayAllowed(true); |
| 19 | 19 |
| 20 function createMutedVideoElement() { | 20 function createMutedMediaElement(type) { |
| 21 var e = document.createElement('video'); | 21 var e = document.createElement(type); |
| 22 e.src = findMediaFile('video', 'content/test'); | 22 e.src = findMediaFile(type, 'content/test'); |
| 23 e.muted = true; | 23 e.muted = true; |
| 24 return e; | 24 return e; |
| 25 } | 25 } |
| 26 | 26 |
| 27 function createMutedVideoElement() { | |
| 28 return createMutedMediaElement('video'); | |
| 29 } | |
| 30 | |
| 31 function createMutedAudioElement() { | |
| 32 return createMutedMediaElement('audio'); | |
| 33 } | |
| 34 | |
| 27 async_test(function(t) { | 35 async_test(function(t) { |
| 28 var e = createMutedVideoElement(); | 36 var e = createMutedVideoElement(); |
| 29 e.autoplay = true; | 37 e.autoplay = true; |
| 30 | 38 |
| 31 var expectedEvents = [ 'canplay', 'play', 'playing']; | 39 var expectedEvents = [ 'canplay', 'play', 'playing']; |
| 32 var eventWatcher = new EventWatcher(t, e, expectedEvents); | 40 var eventWatcher = new EventWatcher(t, e, expectedEvents); |
| 33 eventWatcher.wait_for(expectedEvents).then( | 41 eventWatcher.wait_for(expectedEvents).then( |
| 34 t.step_func_done(function() { | 42 t.step_func_done(function() { |
| 35 assert_false(e.paused); | 43 assert_false(e.paused); |
| 36 })); | 44 })); |
| 37 }, "Test that a muted video with an autoplay attribute autoplays."); | 45 }, "Test that a muted video with an autoplay attribute autoplays."); |
| 38 | 46 |
| 39 promise_test(function() { | 47 promise_test(function() { |
| 40 return createMutedVideoElement().play(); | 48 return createMutedVideoElement().play(); |
| 41 }, "Test that play() on a muted video succeeds without gesture."); | 49 }, "Test that play() on a muted video succeeds without gesture."); |
| 42 | 50 |
| 51 promise_test(function (t) { | |
| 52 return promise_rejects( | |
| 53 t, | |
| 54 new DOMException( | |
| 55 'play() can only be initiated by a user gesture.', | |
| 56 'NotAllowedError'), | |
| 57 createMutedAudioElement().play()); | |
| 58 }, "Test that play() on a muted audio without gesture will reject."); | |
| 59 | |
| 60 async_test(function (t) { | |
| 61 var e = createMutedAudioElement(); | |
| 62 e.autoplay = true; | |
| 63 e.onplay = t.unreached_func(); | |
| 64 e.oncanplaythrough = t.step_func(function() { | |
| 65 setTimeout(t.step_func_done(function() { | |
| 66 assert_true(e.paused); | |
| 67 }), 100); | |
|
mlamouri (slow - plz ping)
2016/06/15 20:29:12
You should avoid setTimeout() with other values th
whywhat
2016/06/16 12:39:46
Done.
| |
| 68 }); | |
| 69 }, "Test that autoplay on a muted audio without gesture has no effect."); | |
| 70 | |
| 43 promise_test(function(t) { | 71 promise_test(function(t) { |
| 44 var e = createMutedVideoElement(); | 72 var e = createMutedVideoElement(); |
| 45 return e.play().then(t.step_func_done(function() { | 73 return e.play().then(t.step_func_done(function() { |
| 46 e.muted = false; | 74 e.muted = false; |
| 47 assert_true(e.paused, "The video should be paused."); | 75 assert_true(e.paused, "The video should be paused."); |
| 48 })); | 76 })); |
| 49 }, "Test that unmuting an autoplayed video without gesture pauses."); | 77 }, "Test that unmuting an autoplayed video without gesture pauses."); |
| 50 | 78 |
| 51 async_test(function(t) { | 79 async_test(function(t) { |
| 52 var e = createMutedVideoElement(); | 80 var e = createMutedVideoElement(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 65 promise_test(function(t) { | 93 promise_test(function(t) { |
| 66 testRunner.setAutoplayAllowed(false); | 94 testRunner.setAutoplayAllowed(false); |
| 67 return promise_rejects( | 95 return promise_rejects( |
| 68 t, | 96 t, |
| 69 new DOMException( | 97 new DOMException( |
| 70 'play() can only be initiated by a user gesture.', | 98 'play() can only be initiated by a user gesture.', |
| 71 'NotAllowedError'), | 99 'NotAllowedError'), |
| 72 createMutedVideoElement().play()); | 100 createMutedVideoElement().play()); |
| 73 }, "Test that muted videos don't autoplay when the setting is disabled"); | 101 }, "Test that muted videos don't autoplay when the setting is disabled"); |
| 74 </script> | 102 </script> |
| OLD | NEW |