Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <title>Test autoplay muted behaviour in various system conditions.</title> | |
| 3 <script src="../resources/testharness.js"></script> | |
| 4 <script src="../resources/testharnessreport.js"></script> | |
| 5 <script src="media-file.js"></script> | |
| 6 <body></body> | |
| 7 <script> | |
| 8 var tests = [ | |
| 9 { | |
| 10 name: 'regular conditions', | |
| 11 conditions: { | |
| 12 dataSaver: false, | |
| 13 cellular: false, | |
| 14 lowEndDevice: false, | |
| 15 }, | |
| 16 expectations: { | |
| 17 autoplay: true | |
| 18 } | |
| 19 }, | |
| 20 { | |
| 21 name: 'cellular connections', | |
| 22 conditions: { | |
| 23 dataSaver: false, | |
| 24 cellular: true, | |
| 25 lowEndDevice: false, | |
| 26 }, | |
| 27 expectations: { | |
| 28 autoplay: true | |
| 29 } | |
| 30 }, | |
| 31 { | |
| 32 name: 'cellular connections with Data Saver', | |
| 33 conditions: { | |
| 34 dataSaver: true, | |
| 35 cellular: true, | |
| 36 lowEndDevice: false, | |
| 37 }, | |
| 38 expectations: { | |
| 39 autoplay: false | |
| 40 } | |
| 41 }, | |
| 42 { | |
| 43 name: 'Data Saver', | |
| 44 conditions: { | |
| 45 dataSaver: true, | |
| 46 cellular: false, | |
| 47 lowEndDevice: false, | |
| 48 }, | |
| 49 expectations: { | |
| 50 autoplay: false | |
| 51 } | |
| 52 }, | |
| 53 { | |
| 54 name: 'low end device', | |
| 55 conditions: { | |
| 56 dataSaver: false, | |
| 57 cellular: false, | |
| 58 lowEndDevice: true, | |
| 59 }, | |
| 60 expectations: { | |
| 61 autoplay: false | |
| 62 } | |
| 63 }, | |
| 64 ]; | |
| 65 | |
| 66 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.
| |
| 67 tests.forEach(test => { | |
| 68 asyncTests.push(async_test('Testing autoplay behaviour for ' + test.name)); | |
| 69 }); | |
| 70 | |
| 71 internals.settings.setMediaPlaybackRequiresUserGesture(true); | |
| 72 internals.runtimeFlags.autoplayMutedVideosEnabled = true; | |
| 73 | |
| 74 var currentTest = 0; | |
| 75 function runNextTest() { | |
| 76 asyncTests[currentTest].done(); | |
| 77 | |
| 78 ++currentTest; | |
| 79 if (currentTest == tests.length) { | |
| 80 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.
| |
| 81 internals.clearNetworkConnectionInfoOverride(); | |
| 82 internals.settings.setForcePreloadNoneForMediaElements(false); | |
| 83 internals.settings.setMediaPlaybackRequiresUserGesture(false); | |
| 84 internals.runtimeFlags.autoplayMutedVideosEnabled = false; | |
| 85 return; | |
| 86 } | |
| 87 | |
| 88 asyncTests[currentTest].step_func(runTest(asyncTests[currentTest], tests[curre ntTest])); | |
| 89 } | |
| 90 | |
| 91 function runTest(t, test) { | |
| 92 // Sanity checks for 'conditions'. | |
| 93 assert_true('dataSaver' in test.conditions); | |
| 94 assert_true('cellular' in test.conditions); | |
| 95 assert_true('lowEndDevice' in test.conditions); | |
| 96 | |
| 97 internals.settings.setDataSaverEnabled(test.conditions.dataSaver); | |
| 98 if (test.conditions.cellular) | |
| 99 internals.setNetworkConnectionInfoOverride(true, 'cellular3g', 2.0); | |
| 100 else | |
| 101 internals.clearNetworkConnectionInfoOverride(); | |
| 102 internals.settings.setForcePreloadNoneForMediaElements(test.conditions.lowEndD evice); | |
| 103 | |
| 104 var count = 0; | |
| 105 [ 'attribute', 'method' ].forEach(type => { | |
| 106 var media = document.createElement('video'); | |
| 107 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
| |
| 108 | |
| 109 var expectedEvents = []; | |
| 110 if (test.expectations.autoplay) | |
| 111 expectedEvents = [ 'play', 'playing' ]; | |
| 112 else | |
| 113 expectedEvents = [ 'suspend' ]; | |
| 114 | |
| 115 var eventWatcher = new EventWatcher(t, media, expectedEvents); | |
| 116 eventWatcher.wait_for(expectedEvents).then(_ => { | |
| 117 if (test.expectations.autoplay) { | |
| 118 assert_equals(media.readyState, media.HAVE_ENOUGH_DATA); | |
| 119 assert_false(media.paused); | |
| 120 } else { | |
| 121 assert_true(media.paused); | |
| 122 } | |
| 123 | |
| 124 document.body.removeChild(media); | |
| 125 ++count; | |
| 126 if (count == 2) | |
| 127 runNextTest(); | |
| 128 }); | |
| 129 | |
| 130 media.muted = true; | |
| 131 media.src = findMediaFile('video', 'content/test'); | |
| 132 | |
| 133 if (type == 'attribute') | |
| 134 media.autoplay = true; | |
| 135 else if (type == 'method') | |
| 136 media.play().catch(e => {}); | |
| 137 }); | |
| 138 } | |
| 139 | |
| 140 asyncTests[currentTest].step_func(runTest(asyncTests[currentTest], tests[current Test])); | |
| 141 | |
| 142 </script> | |
| OLD | NEW |