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

Side by Side Diff: third_party/WebKit/LayoutTests/media/preload-conditions.html

Issue 2466273006: Allow metadata preload on cellular connections and disallow autoplay muted for low end devices. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>Test media preloading behaviour with different conditions.</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script>
5 <script src="media-file.js"></script>
6 <script>
7 var tests = [
8 {
9 name: 'regular conditions',
10 conditions: {
11 dataSaver: false,
12 cellular: false,
13 lowEndDevice: false,
14 },
15 expectations: {
16 default: 'auto',
17 allowed: [ 'none', 'metadata', 'auto' ]
18 }
19 },
20 {
21 name: 'cellular connections',
22 conditions: {
23 dataSaver: false,
24 cellular: true,
25 lowEndDevice: false,
26 },
27 expectations: {
28 default: 'metadata',
29 allowed: [ 'none', 'metadata' ]
30 }
31 },
32 {
33 name: 'cellular connections with Data Saver',
34 conditions: {
35 dataSaver: true,
36 cellular: true,
37 lowEndDevice: false,
38 },
39 expectations: {
40 default: 'none',
41 allowed: [ 'none' ]
42 }
43 },
44 {
45 name: 'Data Saver',
46 conditions: {
47 dataSaver: true,
48 cellular: false,
49 lowEndDevice: false,
50 },
51 expectations: {
52 default: 'none',
53 allowed: [ 'none' ]
54 }
55 },
56 {
57 name: 'low end device',
58 conditions: {
59 dataSaver: false,
60 cellular: false,
61 lowEndDevice: true,
62 },
63 expectations: {
64 default: 'none',
65 allowed: [ 'none' ]
66 }
67 },
68 ];
69
70 function checkPreloadAttribute(media, value, expected) {
71 // Use IDL attribute.
72 media.removeAttribute("preload");
73 media.preload = value;
74 assert_equals(media.getAttribute("preload"), value);
75 assert_equals(media.preload, expected);
76
77 // Use. content attribute.
78 media.removeAttribute("preload");
79 media.setAttribute("preload", value);
80 assert_equals(media.preload, expected);
81 assert_equals(media.getAttribute("preload"), value);
82 }
83
84 var asyncTests = [];
85 tests.forEach(test => {
86 asyncTests.push(async_test('Testing preload behaviour for ' + test.name));
87 });
88
89 var currentTest = 0;
90 function runNextTest() {
91 asyncTests[currentTest].done();
92
93 ++currentTest;
94 if (currentTest == tests.length) {
95 internals.settings.setDataSaverEnabled(false);
96 internals.clearNetworkConnectionInfoOverride();
97 internals.settings.setForcePreloadNoneForMediaElements(false);
98 return;
99 }
100
101 asyncTests[currentTest].step_func(runTest(asyncTests[currentTest], tests[curre ntTest]));
102 }
103
104 function runTest(t, test) {
105 // Sanity checks for 'conditions'.
106 assert_true('dataSaver' in test.conditions);
107 assert_true('cellular' in test.conditions);
108 assert_true('lowEndDevice' in test.conditions);
109
110 internals.settings.setDataSaverEnabled(test.conditions.dataSaver);
111 if (test.conditions.cellular)
112 internals.setNetworkConnectionInfoOverride(true, 'cellular3g', 2.0);
113 else
114 internals.clearNetworkConnectionInfoOverride();
115 internals.settings.setForcePreloadNoneForMediaElements(test.conditions.lowEndD evice);
116
117 var media = document.createElement('video');
118
119 // Test IDL without any value.
120 assert_equals(media.preload, test.expectations.default);
121 assert_equals(media.getAttribute('preload'), null);
foolip 2016/11/03 10:14:40 assert_false(media.hasAttribute('preload'))
mlamouri (slow - plz ping) 2016/11/03 20:02:32 Done.
122
123 // Test allowed values.
124 [ 'none', 'metadata', 'auto' ].forEach(t.step_func(preload => {
foolip 2016/11/03 10:14:41 It's harmless, but here you don't need step_func,
mlamouri (slow - plz ping) 2016/11/03 20:02:32 Removed superfluous t.step_func.
125 var expected = test.expectations.allowed.indexOf(preload) != -1
foolip 2016/11/03 10:14:40 Can use .includes(preload)
mlamouri (slow - plz ping) 2016/11/03 20:02:32 Youhou, didn't know this :)
126 ? preload : test.expectations.default;
127 checkPreloadAttribute(media, preload, expected);
128 }));
129
130 // Test not allowed values.
131 [ 'default', 'something', 'foo' ].forEach(t.step_func(preload => {
132 checkPreloadAttribute(media, preload, test.expectations.default);
133 }));
134
135 // Test loading events.
136 var expectedLoading = 4;
foolip 2016/11/03 10:14:40 If it weren't for the global state in internals st
mlamouri (slow - plz ping) 2016/11/03 20:02:32 We could have two tests but I don't think it would
foolip 2016/11/03 20:25:57 Yeah, that wouldn't remove the extra book keeping.
137 [ '', 'none', 'metadata', 'auto' ].forEach(t.step_func(preload => {
foolip 2016/11/03 10:14:40 Why the empty string here? Maybe fold it into the
mlamouri (slow - plz ping) 2016/11/03 20:02:32 The empty string is to make sure that when we expo
foolip 2016/11/03 20:25:57 OK, maybe add '' to the 'not allowed' values above
mlamouri (slow - plz ping) 2016/11/09 19:42:05 Done.
138 var media = document.createElement('video');
139 media.preload = preload;
140 media.src = findMediaFile('video', 'content/test');
141
142 switch (media.preload) {
143 case 'none':
144 media.onloadedmetadata = t.unreached_func();
145 media.onprogress = t.unreached_func();
146
147 media.onsuspend = t.step_func(_ => {
148 assert_equals(media.readyState, HTMLMediaElement.HAVE_NOTHING);
149 --expectedLoading;
150 if (expectedLoading == 0)
151 runNextTest();
152 });
153 break;
154 case 'metadata':
155 if (media.readyState >= HTMLMediaElement.HAVE_METADATA) {
foolip 2016/11/03 10:14:40 This should be impossible at this point. assert_eq
mlamouri (slow - plz ping) 2016/11/03 20:02:32 Done.
156 --expectedLoading;
157 break;
158 }
159
160 media.onloadedmetadata = t.step_func(_ => {
161 assert_equals(media.readyState, HTMLMediaElement.HAVE_METADATA);
162 --expectedLoading;
163 if (expectedLoading == 0)
164 runNextTest();
165 });
166 break;
167 case 'auto':
168 if (media.readyState == HTMLMediaElement.HAVE_ENOUGH_DATA) {
169 --expectedLoading;
170 break;
171 }
172
173 media.oncanplaythrough = t.step_func(_ => {
174 assert_equals(media.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA);
175 --expectedLoading;
176 if (expectedLoading == 0)
177 runNextTest();
178 });
179 break;
180 }
181 }))
182 }
183
184 asyncTests[currentTest].step_func(runTest(asyncTests[currentTest], tests[current Test]));
185
186 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698