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

Side by Side Diff: third_party/WebKit/LayoutTests/media/track/regions-webvtt/vtt-region-display.html

Issue 1854553003: Convert webvtt regions tests from video-test.js to testharness.js based (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address more comments Created 4 years, 8 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
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <title>Tests default rendering for TextTrackCues that belong to a VTTRegion.</ti tle>
3 <head> 3 <script src="../../media-controls.js"></script>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 4 <script src="../../media-file.js"></script>
5 <script src="../../../resources/testharness.js"></script>
6 <script src="../../../resources/testharnessreport.js"></script>
7 <video controls></video>
8 <script>
9 var region;
10 var seekTimes = [0.2, 0.5, 1.0, 2.3, 3.0];
11 var seekTimeIndex = 0;
5 12
6 <script src=../../media-controls.js></script> 13 function countVisibleLines(cueElement)
7 <script src=../../media-file.js></script> 14 {
8 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 15 var cueRect = cueElement.getBoundingClientRect();
9 (Please avoid writing new tests using video-test.js) --> 16 var regionRect = region.getBoundingClientRect();
10 <script src=../../video-test.js></script>
11 <script>
12 var testTrack;
13 var region;
14 var container;
15 var totalVisibleLines;
16 17
17 var seekTimes = [0.2, 0.5, 1.0, 2.3, 3.0]; 18 var linesMatch = cueElement.textContent.match(/\n/g);
18 var crtSeekTime = 0; 19 var linesCount = 1 + (linesMatch == null ? 0 : linesMatch.length);
20 var lineHeight = cueRect.height / linesCount;
19 21
20 function countVisibleLines(cueElement) 22 var visibleLines = 0;
21 { 23 for (i = 0; i < linesCount; ++i) {
22 var cueRect = cueElement.getBoundingClientRect(); 24 var lineTop = cueRect.top + i * lineHeight;
23 var regionRect = region.getBoundingClientRect(); 25 var lineBottom = cueRect.top + (i+1) * lineHeight;
24 26
25 var linesMatch = cueElement.textContent.match(/\n/g); 27 if (lineTop >= regionRect.top && lineBottom <= regionRect.bottom)
26 var linesCount = 1 + (linesMatch == null ? 0 : linesMatch.length); 28 visibleLines++;
27 var lineHeight = cueRect.height / linesCount; 29 }
28 30
29 var visibleLines = 0; 31 return visibleLines;
30 for (i = 0; i < linesCount; ++i) { 32 }
31 var lineTop = cueRect.top + i * lineHeight;
32 var lineBottom = cueRect.top + (i+1) * lineHeight;
33 33
34 if (lineTop >= regionRect.top && lineBottom <= regionRect.bottom) 34 async_test(function() {
35 visibleLines++; 35 var video = document.querySelector('video');
36 } 36 video.src = findMediaFile('video', '../../content/test');
37 var testTrack = document.createElement('track');
38 testTrack.onload = this.step_func(function() {
39 video.oncanplaythrough = this.step_func(function() {
40 track = video.textTracks[0];
37 41
38 return visibleLines; 42 assert_equals(track.regions.length, 1);
39 }
40 43
41 function testRegionsDisplay() 44 region = textTrackDisplayElement(video, 'region');
42 { 45 var container = textTrackDisplayElement(video, 'region-container');
43 video.removeEventListener('canplaythrough', testRegionsDisplay);
44 46
45 testTrack = video.textTracks[0]; 47 video.onseeked = this.step_func(function() {
48 var totalVisibleLines = 0;
46 49
47 consoleWrite("** The text track has only one region **"); 50 for (var i = 0; i < container.children.length; ++i) {
48 testExpected("testTrack.regions.length", 1); 51 var cue = container.children[i];
52 totalVisibleLines += countVisibleLines(cue);;
53 }
49 54
50 try { 55 assert_less_than_equal(totalVisibleLines, track.regions[0].heigh t);
51 region = textTrackDisplayElement(video, 'region');
52 container = textTrackDisplayElement(video, 'region-container');
53 } catch(e) {
54 consoleWrite(e);
55 }
56 56
57 consoleWrite("<br>** Inspecting cues displayed within region**"); 57 if (seekTimeIndex == seekTimes.length)
58 58 this.done();
59 waitForEvent("seeked", inspectRegionTree); 59 else
60 seekVideo(); 60 video.currentTime = seekTimes[seekTimeIndex++];
61 } 61 });
62 62 video.currentTime = seekTimes[seekTimeIndex++];
63 function seekVideo() 63 });
64 { 64 });
65 consoleWrite(""); 65 testTrack.src = '../captions-webvtt/captions-regions.vtt';
66 run("video.currentTime = " + seekTimes[crtSeekTime++]); 66 testTrack.kind = 'captions';
67 } 67 testTrack.default = true;
68 68 video.appendChild(testTrack);
69 function inspectRegionTree() 69 });
70 { 70 </script>
71 consoleWrite("Total cues in region: " + container.children.length);
72 totalVisibleLines = 0;
73
74 for (var i = 0; i < container.children.length; ++i) {
75 var cue = container.children[i];
76 var cueVisibleLines = countVisibleLines(cue);
77 consoleWrite("Cue content is: " + cue.textContent);
78 consoleWrite("Cue lines visible from this cue: " + cueVisibleLin es);
79
80 totalVisibleLines += cueVisibleLines;
81 }
82
83 testExpected("totalVisibleLines <= testTrack.regions[0].height", tru e);
84
85 if (crtSeekTime == seekTimes.length)
86 endTest();
87 else
88 seekVideo();
89 }
90
91 function startTest()
92 {
93 if (!window.VTTRegion) {
94 failTest();
95 return;
96 }
97
98 findMediaElement();
99
100 video.src = findMediaFile('video', '../../content/test');
101 video.addEventListener('canplaythrough', testRegionsDisplay);
102 }
103
104 </script>
105 </head>
106 <body>
107 <p>Tests default rendering for TextTrackCues that belong to a VTTRegion. </p>
108 <video controls>
109 <track src="../captions-webvtt/captions-regions.vtt" kind="captions" default onload="startTest()">
110 </video>
111 </body>
112 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698