OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <title>Tests that the user's preferred languages are honored.</title> |
3 <head> | 3 <video></video> |
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 <script> |
| 8 async_test(function(t) { |
| 9 var video = document.querySelector("video"); |
5 | 10 |
6 <style> | 11 // Set user preferred languages. |
7 video { background-color: yellow; width: 320px; height: 240px;} | 12 internals.setUserPreferredLanguages(['jp', 'es-ES', 'en', 'fr']); |
8 </style> | 13 internals.settings.setTextTrackKindUserPreference('captions'); |
9 <script src=../media-file.js></script> | |
10 <!-- TODO(philipj): Convert test to testharness.js. crbug.com/588956 | |
11 (Please avoid writing new tests using video-test.js) --> | |
12 <script src=../video-test.js></script> | |
13 <script> | |
14 | 14 |
15 var timer = null; | 15 var timer; |
16 var expectedLanguage; | 16 var expectedLanguage; |
17 var testList = | 17 var testList = |
| 18 { |
| 19 currentTestIndex : -1, |
| 20 tests : |
| 21 [ |
18 { | 22 { |
19 current : -1, | 23 // A track language matches one of the user's preferred language
s exactly. |
20 tests : | 24 languages : ['fr', 'en', 'jp'], |
21 [ | 25 expectedLanguage : "jp" |
22 { | 26 }, |
23 description: "a track language matches one of the user's
preferred languages exactly", | 27 { |
24 languages : ['fr', 'en', 'jp'], | 28 // A track language without locale exactly matches |
25 expectedLanguage : "jp", | 29 // one of the user's preferred languages. |
26 }, | 30 languages : ['fr-CH', 'da'], |
27 { | 31 expectedLanguage : "fr-CH" |
28 description: "a track language without locale exactly ma
tches one of the user's preferred languages", | 32 }, |
29 languages : ['fr-CH', 'da'], | 33 { |
30 expectedLanguage : "fr-CH", | 34 // A track language without locale matches one of |
31 }, | 35 // the user's preferred languages without locale. |
32 { | 36 languages : ['fr', 'es-MX'], |
33 description: "a track language without locale matches on
e of the user's preferred languages without locale", | 37 expectedLanguage : "es-MX" |
34 languages : ['fr', 'es-MX'], | 38 }, |
35 expectedLanguage : "es-MX", | 39 { |
36 }, | 40 // No track language matches any of the user's preferred languag
es. |
37 { | 41 languages : ['fa', 'ru', 'no'], |
38 description: "no track language matches any of the user'
s preferred languages", | 42 expectedLanguage : "fa" |
39 languages : ['fa', 'ru', 'no'], | 43 } |
40 expectedLanguage : "fa", | 44 ] |
41 }, | 45 }; |
42 ] | |
43 }; | |
44 | 46 |
45 function runNextTest() | 47 runNextTest(); |
46 { | |
47 consoleWrite(""); | |
48 testList.current++; | |
49 if (testList.current >= testList.tests.length) { | |
50 var tracks = document.querySelectorAll('track'); | |
51 testExpected("video.textTracks.length", tracks.length); | |
52 endTest(); | |
53 return; | |
54 } | |
55 | 48 |
56 consoleWrite("<b>Test: </b> <em>"+ testList.tests[testList.curre
nt].description + ".</em>"); | 49 function runNextTest() { |
57 createTrackElements(testList.tests[testList.current].languages); | 50 testList.currentTestIndex++; |
58 } | 51 if (testList.currentTestIndex >= testList.tests.length) { |
| 52 var tracks = document.querySelectorAll('track'); |
| 53 assert_equals(video.textTracks.length, tracks.length); |
| 54 t.done(); |
| 55 return; |
| 56 } |
59 | 57 |
60 function trackLoaded() | 58 createTrackElements(testList.tests[testList.currentTestIndex].languages)
; |
61 { | 59 } |
62 consoleWrite("EVENT(load)"); | |
63 | 60 |
64 // Don't log the event name because the order of the two events
in not predictable. | 61 function createTrackElements(languages) { |
65 track = event.target; | 62 var tracks = document.querySelectorAll('track'); |
66 testExpected("track.readyState", HTMLTrackElement.LOADED); | 63 for (var index = 0; index < tracks.length; ++index) |
67 testExpected("track.srclang", testList.tests[testList.current].e
xpectedLanguage); | 64 video.removeChild(tracks[index]); |
68 | 65 |
69 timer = setTimeout(runNextTest, 200); | 66 for (var index = 0; index < languages.length; ++index) |
70 } | 67 createTrackElement(languages[index], "captions-webvtt/tc004-webvtt-f
ile.vtt"); |
| 68 } |
71 | 69 |
72 function setPreferences() | 70 function createTrackElement(language, src) { |
73 { | 71 var track = document.createElement('track'); |
74 if (!window.internals) { | 72 track.setAttribute('kind', "captions"); |
75 consoleWrite("<b>** This test only works in DRT! **<" + "/b>
"); | 73 track.setAttribute('src', src); |
76 return; | 74 track.setAttribute('srclang', language); |
77 } | 75 track.onload = t.step_func(trackLoaded); |
| 76 video.appendChild(track); |
| 77 } |
78 | 78 |
79 consoleWrite("<i>**Set user preferred languages<" + "/i>"); | 79 function trackLoaded() { |
80 run("internals.setUserPreferredLanguages(['jp', 'es-ES', 'en', '
fr'])"); | 80 var track = event.target; |
81 window.internals.settings.setTextTrackKindUserPreference('captio
ns'); | 81 assert_equals(track.readyState, HTMLTrackElement.LOADED); |
82 } | 82 assert_equals(track.srclang, testList.tests[testList.currentTestIndex].e
xpectedLanguage); |
83 | 83 |
84 function createTrackElement(language, src) | 84 timer = setTimeout(runNextTest, 200); |
85 { | 85 } |
86 var track = document.createElement('track'); | 86 }); |
87 track.setAttribute('kind', "captions"); | 87 </script> |
88 track.setAttribute('src', src); | |
89 track.setAttribute('srclang', language); | |
90 track.setAttribute('onload', 'trackLoaded()'); | |
91 video.appendChild(track); | |
92 } | |
93 | |
94 function createTrackElements(languages) | |
95 { | |
96 var tracks = document.querySelectorAll('track'); | |
97 for (var ndx = 0; ndx < tracks.length; ++ndx) | |
98 video.removeChild(tracks[ndx]); | |
99 | |
100 consoleWrite("<i>- creating tracks for: [" + languages + "].<" +
"/i>"); | |
101 for (var ndx = 0; ndx < languages.length; ++ndx) | |
102 createTrackElement(languages[ndx], "captions-webvtt/tc004-we
bvtt-file.vtt"); | |
103 } | |
104 | |
105 function setup() | |
106 { | |
107 findMediaElement(); | |
108 | |
109 setPreferences(); | |
110 | |
111 runNextTest(); | |
112 } | |
113 | |
114 </script> | |
115 </head> | |
116 <body onload="setup()"> | |
117 <p>Tests that the user's preferred languages are honored.</p> | |
118 <video> | |
119 </video> | |
120 </body> | |
121 </html> | |
OLD | NEW |