Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/media/preload-conditions.html |
| diff --git a/third_party/WebKit/LayoutTests/media/preload-conditions.html b/third_party/WebKit/LayoutTests/media/preload-conditions.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aebd9c8b575ab36047b5b71551f8459b8c14389d |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/media/preload-conditions.html |
| @@ -0,0 +1,186 @@ |
| +<!DOCTYPE html> |
| +<title>Test media preloading behaviour with different conditions.</title> |
| +<script src="../resources/testharness.js"></script> |
| +<script src="../resources/testharnessreport.js"></script> |
| +<script src="media-file.js"></script> |
| +<script> |
| +var tests = [ |
| + { |
| + name: 'regular conditions', |
| + conditions: { |
| + dataSaver: false, |
| + cellular: false, |
| + lowEndDevice: false, |
| + }, |
| + expectations: { |
| + default: 'auto', |
| + allowed: [ 'none', 'metadata', 'auto' ] |
| + } |
| + }, |
| + { |
| + name: 'cellular connections', |
| + conditions: { |
| + dataSaver: false, |
| + cellular: true, |
| + lowEndDevice: false, |
| + }, |
| + expectations: { |
| + default: 'metadata', |
| + allowed: [ 'none', 'metadata' ] |
| + } |
| + }, |
| + { |
| + name: 'cellular connections with Data Saver', |
| + conditions: { |
| + dataSaver: true, |
| + cellular: true, |
| + lowEndDevice: false, |
| + }, |
| + expectations: { |
| + default: 'none', |
| + allowed: [ 'none' ] |
| + } |
| + }, |
| + { |
| + name: 'Data Saver', |
| + conditions: { |
| + dataSaver: true, |
| + cellular: false, |
| + lowEndDevice: false, |
| + }, |
| + expectations: { |
| + default: 'none', |
| + allowed: [ 'none' ] |
| + } |
| + }, |
| + { |
| + name: 'low end device', |
| + conditions: { |
| + dataSaver: false, |
| + cellular: false, |
| + lowEndDevice: true, |
| + }, |
| + expectations: { |
| + default: 'none', |
| + allowed: [ 'none' ] |
| + } |
| + }, |
| +]; |
| + |
| +function checkPreloadAttribute(media, value, expected) { |
| + // Use IDL attribute. |
| + media.removeAttribute("preload"); |
| + media.preload = value; |
| + assert_equals(media.getAttribute("preload"), value); |
| + assert_equals(media.preload, expected); |
| + |
| + // Use. content attribute. |
| + media.removeAttribute("preload"); |
| + media.setAttribute("preload", value); |
| + assert_equals(media.preload, expected); |
| + assert_equals(media.getAttribute("preload"), value); |
| +} |
| + |
| +var asyncTests = []; |
| +tests.forEach(test => { |
| + asyncTests.push(async_test('Testing preload behaviour for ' + test.name)); |
| +}); |
| + |
| +var currentTest = 0; |
| +function runNextTest() { |
| + asyncTests[currentTest].done(); |
| + |
| + ++currentTest; |
| + if (currentTest == tests.length) { |
| + internals.settings.setDataSaverEnabled(false); |
| + internals.clearNetworkConnectionInfoOverride(); |
| + internals.settings.setForcePreloadNoneForMediaElements(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 media = document.createElement('video'); |
| + |
| + // Test IDL without any value. |
| + assert_equals(media.preload, test.expectations.default); |
| + 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.
|
| + |
| + // Test allowed values. |
| + [ '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.
|
| + 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 :)
|
| + ? preload : test.expectations.default; |
| + checkPreloadAttribute(media, preload, expected); |
| + })); |
| + |
| + // Test not allowed values. |
| + [ 'default', 'something', 'foo' ].forEach(t.step_func(preload => { |
| + checkPreloadAttribute(media, preload, test.expectations.default); |
| + })); |
| + |
| + // Test loading events. |
| + 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.
|
| + [ '', '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.
|
| + var media = document.createElement('video'); |
| + media.preload = preload; |
| + media.src = findMediaFile('video', 'content/test'); |
| + |
| + switch (media.preload) { |
| + case 'none': |
| + media.onloadedmetadata = t.unreached_func(); |
| + media.onprogress = t.unreached_func(); |
| + |
| + media.onsuspend = t.step_func(_ => { |
| + assert_equals(media.readyState, HTMLMediaElement.HAVE_NOTHING); |
| + --expectedLoading; |
| + if (expectedLoading == 0) |
| + runNextTest(); |
| + }); |
| + break; |
| + case 'metadata': |
| + 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.
|
| + --expectedLoading; |
| + break; |
| + } |
| + |
| + media.onloadedmetadata = t.step_func(_ => { |
| + assert_equals(media.readyState, HTMLMediaElement.HAVE_METADATA); |
| + --expectedLoading; |
| + if (expectedLoading == 0) |
| + runNextTest(); |
| + }); |
| + break; |
| + case 'auto': |
| + if (media.readyState == HTMLMediaElement.HAVE_ENOUGH_DATA) { |
| + --expectedLoading; |
| + break; |
| + } |
| + |
| + media.oncanplaythrough = t.step_func(_ => { |
| + assert_equals(media.readyState, HTMLMediaElement.HAVE_ENOUGH_DATA); |
| + --expectedLoading; |
| + if (expectedLoading == 0) |
| + runNextTest(); |
| + }); |
| + break; |
| + } |
| + })) |
| +} |
| + |
| +asyncTests[currentTest].step_func(runTest(asyncTests[currentTest], tests[currentTest])); |
| + |
| +</script> |