[Modern Media Controls] Turn media/modern-media-controls/ios-inline-media-controls...
[WebKit-https.git] / LayoutTests / media / video-controls-captions-trackmenu-sorted.html
1 <!DOCTYPE html><!-- webkit-test-runner [ enableModernMediaControls=false ] -->
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", "Auto (Recommended)");
45                     testExpected("trackMenuItems[2].textContent", "u (English)");
46                     testExpected("trackMenuItems[3].textContent", "y (English-Australia)");
47                     testExpected("trackMenuItems[4].textContent", "v (English)");
48                     testExpected("trackMenuItems[5].textContent", "x (English-Australia)");
49                     testExpected("trackMenuItems[6].textContent", "w (Japanese)");
50                     testExpected("trackMenuItems[7].textContent", "z (Japanese)");
51                     testExpected("video.textTracks.length", 6);
52                     testExpected("trackMenuItems.length", 8);
53
54                     consoleWrite("<br><i>** Change preferred language to Japanese, change preference to subtitles<" + "/i>");
55                     run("internals.setUserPreferredLanguages(['ja'])");
56                     run("internals.settings.setShouldDisplayTrackKind('Captions', false)");
57                     run("internals.settings.setShouldDisplayTrackKind('Subtitles', true)");
58
59                     window.setTimeout(testSortedMenu, 0);
60                 break;
61
62                 case 2:
63                     trackMenuItems = textTrackMenuItems();
64                     testExpected("trackMenuItems[0].textContent", "Off");
65                     testExpected("trackMenuItems[1].textContent", "Auto (Recommended)");
66                     testExpected("trackMenuItems[2].textContent", "z (Japanese)");
67                     testExpected("trackMenuItems[3].textContent", "v (English)");
68                     testExpected("trackMenuItems[4].textContent", "x (English-Australia)");
69                     testExpected("video.textTracks.length", 6);
70                     testExpected("trackMenuItems.length", 5);
71
72                     consoleWrite("");
73                     endTest();
74                 break;
75                 }
76
77                 ++test;
78             }
79
80             function start()
81             {
82                 findMediaElement();
83                 video.src = findMediaFile('video', 'content/test');
84                 waitForEvent('canplaythrough', function () { startTrackMenuTest(testSortedMenu); });
85             }
86         </script>
87     </head>
88
89     <body onload="start()">
90         <p>Test that captions and subtitles are sorted in the menu according to user preferences.</p>
91         <video width="500" height="300" controls>
92             <track label="z" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
93             <track label="y" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
94             <track label="x" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
95             <track label="w" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
96             <track label="v" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
97             <track label="u" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
98         </video>
99     </body>
100 </html>
101