| 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 = tests.map(test => async_test('Testing autoplay behaviour for '
+ test.name)); |
| 67 |
| 68 var currentTest = 0; |
| 69 function runNextTest() { |
| 70 asyncTests[currentTest].done(); |
| 71 |
| 72 ++currentTest; |
| 73 if (currentTest == tests.length) |
| 74 return; |
| 75 |
| 76 asyncTests[currentTest].step_func(runTest(asyncTests[currentTest], tests[curre
ntTest])); |
| 77 } |
| 78 |
| 79 function runTest(t, test) { |
| 80 // Sanity checks for 'conditions'. |
| 81 assert_true('dataSaver' in test.conditions); |
| 82 assert_true('cellular' in test.conditions); |
| 83 assert_true('lowEndDevice' in test.conditions); |
| 84 |
| 85 internals.settings.setDataSaverEnabled(test.conditions.dataSaver); |
| 86 if (test.conditions.cellular) |
| 87 internals.setNetworkConnectionInfoOverride(true, 'cellular3g', 2.0); |
| 88 else |
| 89 internals.clearNetworkConnectionInfoOverride(); |
| 90 internals.settings.setForcePreloadNoneForMediaElements(test.conditions.lowEndD
evice); |
| 91 |
| 92 // Generic required settings. |
| 93 internals.settings.setMediaPlaybackRequiresUserGesture(true); |
| 94 internals.runtimeFlags.autoplayMutedVideosEnabled = true; |
| 95 |
| 96 t.add_cleanup(() => { |
| 97 internals.settings.setDataSaverEnabled(false); |
| 98 internals.clearNetworkConnectionInfoOverride(); |
| 99 internals.settings.setForcePreloadNoneForMediaElements(false); |
| 100 internals.settings.setMediaPlaybackRequiresUserGesture(false); |
| 101 internals.runtimeFlags.autoplayMutedVideosEnabled = false; |
| 102 }); |
| 103 |
| 104 var count = 0; |
| 105 [ 'attribute', 'method' ].forEach(type => { |
| 106 var media = document.createElement('video'); |
| 107 document.body.appendChild(media); |
| 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 |