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

Side by Side Diff: third_party/WebKit/LayoutTests/media/track/track-kind-user-preference.html

Issue 1937483002: Convert track-kind* tests to testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comment Created 4 years, 7 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 <script src=../media-file.js></script> 2 <title>Test that user preference for text track kind is honored.</title>
3 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 3 <script src="../media-file.js"></script>
4 (Please avoid writing new tests using video-test.js) --> 4 <script src="../media-controls.js"></script>
5 <script src=../video-test.js></script> 5 <script src="../../resources/testharness.js"></script>
6 <script src=../media-controls.js></script> 6 <script src="../../resources/testharnessreport.js"></script>
7 <script>
8
9 var tracks;
10 var expectedTrack;
11 function setPreferences() {
12 if (!window.internals) {
13 consoleWrite("<b>** This test only works in DRT! **<" + "/b>");
14 return;
15 }
16 run("internals.setUserPreferredLanguages(['jp', 'es', 'en', 'fr'])");
17 }
18
19 function checkExpected(mode, kind, language) {
20 testExpected("expectedTrack.mode", mode);
21 testExpected("expectedTrack.kind", kind);
22 testExpected("expectedTrack.language", language);
23 }
24
25 function runTests() {
26 consoleWrite("");
27 tracks = video.textTracks;
28 testExpected("tracks.length", 7);
29 testUserPrefersDefault();
30 testUserPrefersSubtitles();
31 testUserPrefersCaptions();
32 }
33
34 function testUserPrefersDefault() {
35 consoleWrite("");
36 // User preference is initialized to pick tracks marked as default.
37 // When multiple default tracks exist, pick the first default track.
38 expectedTrack = tracks[5];
39 checkExpected("showing", "subtitles", "ar");
40 }
41
42 function testUserPrefersSubtitles() {
43 if (window.internals)
44 internals.settings.setTextTrackKindUserPreference("subtitles");
45 consoleWrite("");
46 // Displays subtitle track over caption track when both exist in the sam e language.
47 expectedTrack = tracks[4];
48 checkExpected("showing", "subtitles", "es");
49 }
50
51 function testUserPrefersCaptions() {
52 if (window.internals)
53 internals.settings.setTextTrackKindUserPreference("captions");
54 consoleWrite("");
55 expectedTrack = tracks[1];
56 checkExpected("showing", "captions", "es");
57
58 consoleWrite("");
59 // Add a subtitle track in user's first preferred language "jp". This tr ack must
60 // be displayed over a caption track with a language less preferred by t he user.
61 var track = document.createElement('track');
62 track.setAttribute('kind', "subtitles");
63 track.setAttribute('src', "captions-webvtt/styling.vtt");
64 track.setAttribute('srclang', "jp");
65 track.setAttribute('onload', 'trackLoaded()');
66 video.appendChild(track);
67 }
68
69 function trackLoaded() {
70 consoleWrite("EVENT(load)");
71
72 // Don't log the event name because the order of the two events in not p redictable.
73 track = event.target;
74 expectedTrack = track.track;
75 testExpected("track.readyState", HTMLTrackElement.LOADED);
76 checkExpected("showing", "subtitles", "jp");
77 consoleWrite("");
78 endTest();
79 }
80
81 window.onload = function() {
82 consoleWrite("Test that user preference for text track kind is honored") ;
83 findMediaElement();
84 setPreferences();
85 video.src = findMediaFile('video', '../content/test');
86 video.currentTime = 0.1;
87 waitForEvent('canplaythrough', runTests);
88 }
89 </script>
90 <video> 7 <video>
91 <track src="captions-webvtt/styling.vtt" kind="captions" srclang="de"> 8 <track src="captions-webvtt/styling.vtt" kind="captions" srclang="de">
92 <track src="captions-webvtt/styling.vtt" kind="captions" srclang="es"> 9 <track src="captions-webvtt/styling.vtt" kind="captions" srclang="es">
93 <track src="captions-webvtt/styling.vtt" kind="captions" srclang="en"> 10 <track src="captions-webvtt/styling.vtt" kind="captions" srclang="en">
94 <track src="captions-webvtt/styling.vtt" kind="subtitles" srclang="fr"> 11 <track src="captions-webvtt/styling.vtt" kind="subtitles" srclang="fr">
95 <track src="captions-webvtt/styling.vtt" kind="subtitles" srclang="es"> 12 <track src="captions-webvtt/styling.vtt" kind="subtitles" srclang="es">
96 <track src="captions-webvtt/styling.vtt" kind="subtitles" srclang="ar" defau lt> 13 <track src="captions-webvtt/styling.vtt" kind="subtitles" srclang="ar" defau lt>
97 <track src="captions-webvtt/styling.vtt" kind="captions" srclang="fr" defaul t> 14 <track src="captions-webvtt/styling.vtt" kind="captions" srclang="fr" defaul t>
98 </video> 15 </video>
16 <script>
17 async_test(function(t) {
18 var video = document.querySelector("video");
19 internals.setUserPreferredLanguages(["jp", "es", "en", "fr"]);
20 video.src = findMediaFile("video", "../content/test");
21
22 var tracks;
23 var expectedTrack;
24 video.oncanplaythrough = t.step_func(function() {
25 tracks = video.textTracks;
26 assert_equals(tracks.length, 7);
27 testUserPreferencesDefault();
28 testUserPreferencesSubtitles();
29 testUserPreferencesCaptions();
30 });
31
32 function testUserPreferencesDefault() {
33 // User preference is initialized to pick tracks marked as default.
34 // When multiple default tracks exist, pick the first default track.
35 expectedTrack = tracks[5];
36 checkExpected("showing", "subtitles", "ar");
37 }
38
39 function testUserPreferencesSubtitles() {
40 internals.settings.setTextTrackKindUserPreference("subtitles");
41 // Displays subtitle track over caption track when both exist in the sam e language.
42 expectedTrack = tracks[4];
43 checkExpected("showing", "subtitles", "es");
44 }
45
46 function testUserPreferencesCaptions() {
47 internals.settings.setTextTrackKindUserPreference("captions");
48 expectedTrack = tracks[1];
49 checkExpected("showing", "captions", "es");
50
51 // Add a subtitle track in user"s first preferred language "jp".
52 // This track must be displayed over a caption track with a
53 // language less preferred by the user.
54 var track = document.createElement("track");
55 track.setAttribute("kind", "subtitles");
56 track.setAttribute("src", "captions-webvtt/styling.vtt");
57 track.setAttribute("srclang", "jp");
58
59 track.onload = t.step_func_done(trackLoaded);
60 video.appendChild(track);
61 }
62
63 function trackLoaded() {
64 track = event.target;
65 expectedTrack = track.track;
66 assert_equals(track.readyState, HTMLTrackElement.LOADED);
67 checkExpected("showing", "subtitles", "jp");
68 }
69
70 function checkExpected(mode, kind, language) {
71 assert_equals(expectedTrack.mode, mode);
72 assert_equals(expectedTrack.kind, kind);
73 assert_equals(expectedTrack.language, language);
74 }
75 });
76 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698