Chromium Code Reviews| 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..9d84d6e5a9d46ccb488479a149e207c71f726f29 |
| --- /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 = []; |
|
foolip
2016/11/03 10:14:40
asyncTests = tests.map(test => async_test('Testing
mlamouri (slow - plz ping)
2016/11/03 20:02:32
Done.
|
| +tests.forEach(test => { |
| + asyncTests.push(async_test('Testing autoplay behaviour for ' + test.name)); |
| +}); |
| + |
| +internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| +internals.runtimeFlags.autoplayMutedVideosEnabled = true; |
| + |
| +var currentTest = 0; |
| +function runNextTest() { |
| + asyncTests[currentTest].done(); |
| + |
| + ++currentTest; |
| + if (currentTest == tests.length) { |
| + internals.settings.setDataSaverEnabled(false); |
|
foolip
2016/11/03 10:14:40
If it matters that these are reset when the test i
mlamouri (slow - plz ping)
2016/11/03 20:02:32
Done.
|
| + internals.clearNetworkConnectionInfoOverride(); |
| + internals.settings.setForcePreloadNoneForMediaElements(false); |
| + internals.settings.setMediaPlaybackRequiresUserGesture(false); |
| + internals.runtimeFlags.autoplayMutedVideosEnabled = false; |
| + 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); |
| + |
| + var count = 0; |
| + [ 'attribute', 'method' ].forEach(type => { |
| + var media = document.createElement('video'); |
| + document.body.appendChild(media); |
|
foolip
2016/11/03 10:14:40
Does appending make a difference?
mlamouri (slow - plz ping)
2016/11/03 20:02:32
No. But why not appending?
foolip
2016/11/03 20:25:57
It's fine if you like it better, but in general I
|
| + |
| + 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> |