| Index: third_party/WebKit/LayoutTests/media/autoplay-muted-conditions.html
|
| diff --git a/third_party/WebKit/LayoutTests/media/autoplay-muted-conditions.html b/third_party/WebKit/LayoutTests/media/autoplay-muted-conditions.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4c148587dd5f6a3d64476db32f0209aa8570096f
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/media/autoplay-muted-conditions.html
|
| @@ -0,0 +1,142 @@
|
| +<!DOCTYPE html>
|
| +<title>Test autoplay muted behaviour in various system conditions.</title>
|
| +<script src="../resources/testharness.js"></script>
|
| +<script src="../resources/testharnessreport.js"></script>
|
| +<script src="media-file.js"></script>
|
| +<body></body>
|
| +<script>
|
| +var tests = [
|
| + {
|
| + name: 'regular conditions',
|
| + conditions: {
|
| + dataSaver: false,
|
| + cellular: false,
|
| + lowEndDevice: false,
|
| + },
|
| + expectations: {
|
| + autoplay: true
|
| + }
|
| + },
|
| + {
|
| + name: 'cellular connections',
|
| + conditions: {
|
| + dataSaver: false,
|
| + cellular: true,
|
| + lowEndDevice: false,
|
| + },
|
| + expectations: {
|
| + autoplay: true
|
| + }
|
| + },
|
| + {
|
| + name: 'cellular connections with Data Saver',
|
| + conditions: {
|
| + dataSaver: true,
|
| + cellular: true,
|
| + lowEndDevice: false,
|
| + },
|
| + expectations: {
|
| + autoplay: false
|
| + }
|
| + },
|
| + {
|
| + name: 'Data Saver',
|
| + conditions: {
|
| + dataSaver: true,
|
| + cellular: false,
|
| + lowEndDevice: false,
|
| + },
|
| + expectations: {
|
| + autoplay: false
|
| + }
|
| + },
|
| + {
|
| + name: 'low end device',
|
| + conditions: {
|
| + dataSaver: false,
|
| + cellular: false,
|
| + lowEndDevice: true,
|
| + },
|
| + expectations: {
|
| + autoplay: false
|
| + }
|
| + },
|
| +];
|
| +
|
| +var asyncTests = tests.map(test => async_test('Testing autoplay behaviour for ' + test.name));
|
| +
|
| +var currentTest = 0;
|
| +function runNextTest() {
|
| + asyncTests[currentTest].done();
|
| +
|
| + ++currentTest;
|
| + if (currentTest == tests.length)
|
| + return;
|
| +
|
| + asyncTests[currentTest].step_func(runTest(asyncTests[currentTest], tests[currentTest]));
|
| +}
|
| +
|
| +function runTest(t, test) {
|
| + // Sanity checks for 'conditions'.
|
| + assert_true('dataSaver' in test.conditions);
|
| + assert_true('cellular' in test.conditions);
|
| + assert_true('lowEndDevice' in test.conditions);
|
| +
|
| + internals.settings.setDataSaverEnabled(test.conditions.dataSaver);
|
| + if (test.conditions.cellular)
|
| + internals.setNetworkConnectionInfoOverride(true, 'cellular3g', 2.0);
|
| + else
|
| + internals.clearNetworkConnectionInfoOverride();
|
| + internals.settings.setForcePreloadNoneForMediaElements(test.conditions.lowEndDevice);
|
| +
|
| + // Generic required settings.
|
| + internals.settings.setMediaPlaybackRequiresUserGesture(true);
|
| + internals.runtimeFlags.autoplayMutedVideosEnabled = true;
|
| +
|
| + t.add_cleanup(() => {
|
| + internals.settings.setDataSaverEnabled(false);
|
| + internals.clearNetworkConnectionInfoOverride();
|
| + internals.settings.setForcePreloadNoneForMediaElements(false);
|
| + internals.settings.setMediaPlaybackRequiresUserGesture(false);
|
| + internals.runtimeFlags.autoplayMutedVideosEnabled = false;
|
| + });
|
| +
|
| + var count = 0;
|
| + [ 'attribute', 'method' ].forEach(type => {
|
| + var media = document.createElement('video');
|
| + document.body.appendChild(media);
|
| +
|
| + var expectedEvents = [];
|
| + if (test.expectations.autoplay)
|
| + expectedEvents = [ 'play', 'playing' ];
|
| + else
|
| + expectedEvents = [ 'suspend' ];
|
| +
|
| + var eventWatcher = new EventWatcher(t, media, expectedEvents);
|
| + eventWatcher.wait_for(expectedEvents).then(_ => {
|
| + if (test.expectations.autoplay) {
|
| + assert_equals(media.readyState, media.HAVE_ENOUGH_DATA);
|
| + assert_false(media.paused);
|
| + } else {
|
| + assert_true(media.paused);
|
| + }
|
| +
|
| + document.body.removeChild(media);
|
| + ++count;
|
| + if (count == 2)
|
| + runNextTest();
|
| + });
|
| +
|
| + media.muted = true;
|
| + media.src = findMediaFile('video', 'content/test');
|
| +
|
| + if (type == 'attribute')
|
| + media.autoplay = true;
|
| + else if (type == 'method')
|
| + media.play().catch(e => {});
|
| + });
|
| +}
|
| +
|
| +asyncTests[currentTest].step_func(runTest(asyncTests[currentTest], tests[currentTest]));
|
| +
|
| +</script>
|
|
|