Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: third_party/WebKit/LayoutTests/media/autoplay-muted-conditions.html

Issue 2466273006: Allow metadata preload on cellular connections and disallow autoplay muted for low end devices. (Closed)
Patch Set: add not allowed value Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/preload-conditions.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/media/preload-conditions.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698