Track menu should be sorted
[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>
9             var captionsButtonCoordinates;
10
11             if (window.testRunner)
12                 testRunner.dumpAsText();
13
14             function clickCCButton()
15             {
16                 eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
17                 eventSender.mouseDown();
18                 eventSender.mouseUp();
19             }
20
21             function startTest()
22             {
23                 if (window.eventSender) {
24                     consoleWrite("<br>*** Set the user language preference.");
25                     run("internals.setUserPreferredLanguages(['en'])");
26
27                     try {
28                         captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggle-closed-captions-button");
29                     } catch (exception) {
30                         failTest(exception.description);
31                         return;
32                     }
33                     clickCCButton();
34                     window.setTimeout(testSortedMenu, 100);
35                 }
36             }
37
38             function testSortedMenu()
39             {
40                 var trackListElement;
41                 try {
42                     trackListElement = mediaControlsElement(internals.shadowRoot(video).firstChild, "-webkit-media-controls-closed-captions-track-list");
43                 } catch (exception) {
44                     failTest(exception.description);
45                     return;
46                 }
47                 // Track list should have two <ul> elements.
48                 var trackListSections = trackListElement.querySelectorAll("ul");
49                 if (!trackListSections || trackListSections.length != 2) {
50                     failTest("There should be two ul elements in track list menu");
51                     return;
52                 }
53                 for (var i = 0; i < trackListSections.length; i++) {
54                     consoleWrite("<br>*** Test menu section " + i + ".");
55                     var lastTrackLabel = null;
56                     var trackListItems = trackListSections[i].querySelectorAll("li");
57                     if (!trackListItems || trackListItems.length != 5) {
58                         failTest("There should be five li elements in this section");
59                         return;
60                     }
61                     for (var j = 0; j < trackListItems.length; j++) {
62                         var item = trackListItems[j];
63                         if (j == 0)
64                             logResult(item.textContent == "Off", "First item should be labelled off");
65                         else {
66                             if (lastTrackLabel)
67                                 logResult(item.textContent > lastTrackLabel, lastTrackLabel + " comes before " + item.textContent);
68                             else
69                                 logResult(true, item.textContent + " is the first real item in the list");
70                             lastTrackLabel = item.textContent;
71                         }
72                     }
73                     consoleWrite("Menu section " + i + " was ok.<br>");
74                 }
75                 endTest();
76             }
77
78             function start()
79             {
80                 findMediaElement();
81                 waitForEvent('canplaythrough', startTest);
82             }
83         </script>
84     </head>
85
86     <body onload="start()">
87         <p>Test that captions and subtitles are sorted in the menu.</p>
88         <video width="500" height="300" controls>
89             <source src="content/test.mp4" type="video/mp4">
90             <source src="content/test.ogv" type="video/ogg">
91             <track label="c" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
92             <track label="b" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
93             <track label="a" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
94             <track label="d" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
95             <track label="b" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
96             <track label="a" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
97             <track label="c" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
98             <track label="d" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
99         </video>
100     </body>
101 </html>
102