12f8e9ebd2e8d9cd92e009b4a3a835eec75aa31d
[WebKit-https.git] / LayoutTests / media / video-controls-captions-trackmenu-sorted.html
1 <!DOCTYPE html>
2 <html>
3     <head>
4         <title>Testing that the list of tracks is sorted</title>
5         <script src="media-controls.js"></script>
6         <script src="media-file.js"></script>
7         <script src="video-test.js"></script>
8         <script src="trackmenu-test.js"></script>
9         <script>
10             var test = 0;
11             if (window.testRunner)
12                 testRunner.dumpAsText();
13
14             function textTrackMenuItems()
15             {
16                 // Show and hide the menu to force a recalculation.
17                 clickCCButton();
18                 clickCCButton();
19
20                 var trackListElement = getTrackListElement();
21                 if (!trackListElement)
22                     return;
23                 var trackListSection = trackListElement.querySelector("ul");
24                 if (!trackListSection) {
25                     failTest("There should be a ul element in track list menu");
26                     return;
27                 }
28                 return trackListSection.querySelectorAll("li");
29             }
30
31             function testSortedMenu()
32             {
33                 switch (test)
34                 {
35                 case 0:
36                     consoleWrite("<br><i>** Test with preferred language set to English, track type set to captions<" + "/i>");
37                     run("internals.settings.setShouldDisplayTrackKind('Captions', true)");
38                     window.setTimeout(testSortedMenu, 0);
39                     break;
40
41                 case 1:
42                     trackMenuItems = textTrackMenuItems();
43                     testExpected("trackMenuItems[0].textContent", "Off");
44                     testExpected("trackMenuItems[1].textContent", "u (English) SDH");
45                     testExpected("trackMenuItems[2].textContent", "y (English-Australia) SDH");
46                     testExpected("trackMenuItems[3].textContent", "v (English)");
47                     testExpected("trackMenuItems[4].textContent", "x (English-Australia)");
48                     testExpected("trackMenuItems[5].textContent", "w (Japanese) SDH");
49                     testExpected("trackMenuItems[6].textContent", "z (Japanese)");
50                     testExpected("video.textTracks.length", 6);
51                     testExpected("trackMenuItems.length", 7);
52
53                     consoleWrite("<br><i>** Change preferred language to Japanese, change preference to subtitles<" + "/i>");
54                     run("internals.setUserPreferredLanguages(['ja'])");
55                     run("internals.settings.setShouldDisplayTrackKind('Captions', false)");
56                     run("internals.settings.setShouldDisplayTrackKind('Subtitles', true)");
57
58                     window.setTimeout(testSortedMenu, 0);
59                 break;
60
61                 case 2:
62                     trackMenuItems = textTrackMenuItems();
63                     testExpected("trackMenuItems[0].textContent", "Off");
64                     testExpected("trackMenuItems[1].textContent", "z (Japanese)");
65                     testExpected("trackMenuItems[2].textContent", "v (English)");
66                     testExpected("trackMenuItems[3].textContent", "x (English-Australia)");
67                     testExpected("video.textTracks.length", 6);
68                     testExpected("trackMenuItems.length", 4);
69
70                     consoleWrite("");
71                     endTest();
72                 break;
73                 }
74
75                 ++test;
76             }
77
78             function start()
79             {
80                 findMediaElement();
81                 video.src = findMediaFile('video', 'content/test');
82                 waitForEvent('canplaythrough', function () { startTrackMenuTest(testSortedMenu); });
83             }
84         </script>
85     </head>
86
87     <body onload="start()">
88         <p>Test that captions and subtitles are sorted in the menu according to user preferences.</p>
89         <video width="500" height="300" controls>
90             <track label="z" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
91             <track label="y" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
92             <track label="x" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
93             <track label="w" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
94             <track label="v" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
95             <track label="u" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
96         </video>
97     </body>
98 </html>
99