| <!DOCTYPE html> |
| <title>Test for autoplay of urls not in webapp scope</title> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="media-controls.js"></script> |
| <body> |
| <script> |
| |
| test(function() { |
| assert_true(!!window.internals |
| && !!internals.settings, |
| "This test only works when run as a layout test!"); |
| }, "Prerequisites to running the rest of the tests"); |
| |
| internals.settings.setAutoplayPolicy('user-gesture-required'); |
| internals.settings.setWebAppScope( |
| document.URL.substring(0, document.URL.lastIndexOf('/') + 1) + "foo/"); |
| |
| function createMediaElement(type) { |
| var e = document.createElement(type); |
| e.src = type == 'audio' ? 'content/test.oga' : 'content/test.ogv'; |
| 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' ]; |
| 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 in webapp scope."); |
| |
| promise_test(function(t) { |
| return promise_rejects_dom( |
| t, |
| 'NotAllowedError', |
| createVideoElement().play()); |
| }, "Test that play() on a video fails without gesture when not in webapp scope."); |
| |
| 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 in webapp scope."); |
| |
| promise_test(function(t) { |
| return promise_rejects_dom( |
| t, |
| 'NotAllowedError', |
| createAudioElement().play()); |
| }, "Test that play() on an audio fails without gesture when not in webapp scope."); |
| |
| </script> |
| </body> |