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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/media/progress-events-generated-correctly.html

Issue 2258863002: Convert http media tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address nits Created 4 years, 4 months 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/media/progress-events-generated-correctly-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <video controls></video> 1 <!DOCTYPE html>
2 <p>Test that progress events are generated during loading of media resource.</p> 2 <title>Test that progress events are generated during loading of media resource. </title>
3 <!-- TODO(foolip): Convert test to testharness.js. crbug.com/588956 3 <script src="../resources/testharness.js"></script>
4 (Please avoid writing new tests using video-test.js) --> 4 <script src="../resources/testharnessreport.js"></script>
5 <script src=../../media-resources/video-test.js></script> 5 <script src="../../media-resources/media-file.js"></script>
6 <script src=../../media-resources/media-file.js></script> 6 <video></video>
7 <script> 7 <script>
8 waitForEventAndFail('error'); 8 async_test(function(t) {
9 var video = document.querySelector('video');
10 video.onerror = t.unreached_func();
9 11
10 // Given long enough duration, We should not reach ended playback state. 12 // Given long enough duration, We should not reach ended playback state.
11 waitForEventAndFail('ended'); 13 video.onended = t.unreached_func();
12 14
13 // Tuned throttling should not induce player stall or suspended load. 15 // Tuned throttling should not induce player stall or suspended load.
14 waitForEventAndFail('stalled'); 16 video.onstalled = t.unreached_func();
15 waitForEventAndFail('suspend'); 17 video.onsuspend = t.unreached_func();
16 waitForEventAndFail('waiting'); 18 video.onwaiting = t.unreached_func();
17 19
18 var progressCount = 0; 20 var progressCount = 0;
19 var lastProgressEventTime = 0; 21 var lastProgressEventTime = 0;
20 function progressListener(event) 22
21 { 23 video.onprogress = t.step_func(function() {
22 // Implementations can vary the frequency within tolerance, so we must p rotect against flaky logs. 24 // Implementations can vary the frequency within tolerance,
25 // so we must protect against flaky logs.
23 // Remain silent here unless failure detected. 26 // Remain silent here unless failure detected.
24 if (video.networkState != HTMLMediaElement.NETWORK_LOADING) { 27 assert_equals(video.networkState, HTMLMediaElement.NETWORK_LOADING);
25 failTest('Unexpected networkState ' + video.networkState +
26 ' when handling \'progress\' event. Is fetch completed or s uspending?');
27 return;
28 }
29
30 progressCount++; 28 progressCount++;
31 lastProgressEventTime = window.performance.now(); 29 lastProgressEventTime = window.performance.now();
32 }; 30 });
33 video.addEventListener('progress', progressListener);
34 31
35 function canplayListener(event) 32 video.oncanplay = t.step_func(function() {
36 { 33 video.oncanplay = null;
37 // Begin video playback to mitigate flakiness due to implementations sus pending loads 34 // Begin video playback to mitigate flakiness due to
38 // on limited buffer capacity. 35 // implementations suspending load on limited buffer capacity.
39 video.play(); 36 video.play();
40 video.removeEventListener('canplay', canplayListener); 37 });
41 }
42 video.addEventListener('canplay', canplayListener);
43 38
44 var progressCountAtLastCheck = 0; 39 var progressCountAtLastCheck = 0;
45 var checkCount = 0; 40 var checkCount = 0;
46 // Spec requires 350ms +/- 200ms minimum 'progress' event interval when load ing. 41 // Spec requires 350ms +/- 200ms minimum 'progress' event interval when load ing.
47 var maxProgressFiringIntervalInMS = 550; 42 var maxProgressFiringIntervalInMS = 550;
48 // Multiple 'progress' events may fire within spec's tolerance window. 43 // Multiple 'progress' events may fire within spec's tolerance window.
49 var maxProgressCountIncrease = 3; 44 var maxProgressCountIncrease = 3;
50 function checkProgressCount() 45 function checkProgressCount() {
51 {
52 checkCount++;
53
54 // Implementations can vary the frequency within tolerance, so we must p rotect against flakiness. 46 // Implementations can vary the frequency within tolerance, so we must p rotect against flakiness.
55 // Keep progressCount values involved in checks here out of report unles s failure detected. 47 // Keep progressCount values involved in checks here out of report unles s failure detected.
56 consoleWrite('Interval ' + checkCount + ' has elapsed. Checking progress event count delta.');
57 var progressCountDelta = progressCount - progressCountAtLastCheck; 48 var progressCountDelta = progressCount - progressCountAtLastCheck;
58 if (progressCountDelta <= 0) { 49 assert_greater_than(progressCountDelta, 0, 'at least one progress event was fired');
59 failTest('progressCount (' + progressCount + ') did not increase sin ce the last check.'); 50 assert_less_than_equal(progressCountDelta, maxProgressCountIncrease, 'to o many progress events were not fired');
60 return;
61 }
62 51
63 var surplusProgress = progressCountDelta - maxProgressCountIncrease; 52 if (++checkCount == 3) {
64 if (surplusProgress > 0) { 53 t.done();
65 failTest('Received at least ' + surplusProgress + ' too many progres s event(s) since the last check.');
66 return;
67 }
68
69 if (checkCount == 3) {
70 endTest();
71 return; 54 return;
72 } 55 }
73 56
74 progressCountAtLastCheck = progressCount; 57 progressCountAtLastCheck = progressCount;
75 var msSinceLastProgressEvent = window.performance.now() - lastProgressEv entTime; 58 var msSinceLastProgressEvent = window.performance.now() - lastProgressEv entTime;
76 var msUntilNextCheck = maxProgressFiringIntervalInMS - msSinceLastProgre ssEvent; 59 var msUntilNextCheck = maxProgressFiringIntervalInMS - msSinceLastProgre ssEvent;
60 assert_greater_than(msUntilNextCheck, 0, 'Progress Event delay');
77 61
78 if (msUntilNextCheck <= 0) { 62 setTimeout(t.step_func(checkProgressCount), msUntilNextCheck);
79 failTest('ProgressCheck scheduling error: msUntilNextCheck is ' + ms UntilNextCheck);
80 return;
81 }
82
83 setTimeout(checkProgressCount, msUntilNextCheck);
84 } 63 }
85 64
86 waitForEvent('loadstart', function() 65 video.onloadstart = t.step_func(function() {
87 {
88 // No 'progress' event should fire prior to 'loadstart'. 66 // No 'progress' event should fire prior to 'loadstart'.
89 testExpected('progressCount', 0, '=='); 67 assert_equals(progressCount, 0, 'No progress event fired before load eve nt');
90 setTimeout(checkProgressCount, maxProgressFiringIntervalInMS); 68 setTimeout(t.step_func(checkProgressCount), maxProgressFiringIntervalInM S);
91 }); 69 });
92 70
93 var mediaFile = findMediaFile('video', 'resources/test'); 71 var mediaFile = findMediaFile('video', 'resources/test');
94 var mimeType = mimeTypeForFile(mediaFile); 72 var mimeType = mimeTypeForFile(mediaFile);
95 // Assumes minimum file size selected is > 100 kB. 73 // Assumes minimum file size selected is > 100 kB.
96 // At least 4*maxProgressFiringIntervalInMS is how long we want to stretch t he full 74 // At least 4*maxProgressFiringIntervalInMS is how long we want to stretch t he full
97 // loading, because we perform checks after 3 of these intervals while still 75 // loading, because we perform checks after 3 of these intervals while still
98 // loading. 100 kB over 2.2 seconds is 45 kBps. 76 // loading. 100 kB over 2.2 seconds is 45 kBps.
99 var kBps = 45; 77 var kBps = 45;
100 78
101 video.src = 'video-throttled-load.cgi' + '?name=' + mediaFile + '&throttle=' + kBps + '&type=' + mimeType; 79 video.src = 'video-throttled-load.cgi' + '?name=' + mediaFile + '&throttle=' + kBps + '&type=' + mimeType;
102 </script> 80 });
81 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/media/progress-events-generated-correctly-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698