Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/media/autoplay-non-whitelisted-scope.html |
| diff --git a/third_party/WebKit/LayoutTests/media/autoplay-non-whitelisted-scope.html b/third_party/WebKit/LayoutTests/media/autoplay-non-whitelisted-scope.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b427d8b5e065276c85dbdde8cf9b85a999d1a01e |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/media/autoplay-non-whitelisted-scope.html |
| @@ -0,0 +1,81 @@ |
| +<!DOCTYPE html> |
| +<title>Test for autoplay of whitelisted frames</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="media-file.js"></script> |
| +<script src="media-controls.js"></script> |
| +<body> |
| +<script> |
| + |
| +test(function() { |
| + assert_true(!!window.internals |
| + && !!window.internals.settings, |
| + "This test only works when run as a layout test!"); |
| +}, "Prerequisites to running the rest of the tests"); |
| + |
| +window.internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| +window.internals.settings.setMediaPlaybackGestureWhitelistScope( |
| + document.URL.substring(0, document.URL.lastIndexOf('/') + 1) + "foo/"); |
| + |
| +testRunner.setAutoplayAllowed(true); |
| + |
| +function createMediaElement(type) { |
| + var e = document.createElement(type); |
| + e.src = findMediaFile(type, 'content/test'); |
| + return e; |
| +} |
| + |
| +function createVideoElement() { |
| + return createMediaElement('video'); |
| +} |
| + |
| +function createAudioElement() { |
| + return createMediaElement('audio'); |
| +} |
| + |
| +async_test(function(t) { |
| + var e = createVideoElement(); |
| + e.autoplay = true; |
| + document.body.appendChild(e); |
| + |
| + var expectedEvents = [ 'canplay']; |
|
mlamouri (slow - plz ping)
2017/02/10 14:28:45
style: ['canplay'] or [ 'canplay' ] :)
Zhiqiang Zhang (Slow)
2017/02/10 14:47:11
Done.
|
| + var eventWatcher = new EventWatcher(t, e, expectedEvents); |
| + eventWatcher.wait_for(expectedEvents).then( |
| + t.step_func_done(function() { |
| + assert_true(e.paused); |
| + })); |
| +}, "Test that a video with an autoplay attribute doesn't autoplay when not whitelisted."); |
| + |
| +promise_test(function(t) { |
| + return promise_rejects( |
| + t, |
| + new DOMException( |
| + 'play() can only be initiated by a user gesture.', |
| + 'NotAllowedError'), |
| + createVideoElement().play()); |
| +}, "Test that play() on a video fails without gesture when not whitelisted."); |
| + |
| +async_test(function(t) { |
| + var e = createAudioElement(); |
| + e.autoplay = true; |
| + document.body.appendChild(e); |
| + |
| + var expectedEvents = [ 'canplay']; |
| + var eventWatcher = new EventWatcher(t, e, expectedEvents); |
| + eventWatcher.wait_for(expectedEvents).then( |
| + t.step_func_done(function() { |
| + assert_true(e.paused); |
| + })); |
| +}, "Test that an audio with an autoplay attribute doesn't autoplay when not whitelisted."); |
| + |
| +promise_test(function(t) { |
| + return promise_rejects( |
| + t, |
| + new DOMException( |
| + 'play() can only be initiated by a user gesture.', |
| + 'NotAllowedError'), |
| + createAudioElement().play()); |
| +}, "Test that play() on an audio fails without gesture when not whitelisted."); |
| + |
| +</script> |
| +</body> |