Not all subtitle tracks are SDH
[WebKit-https.git] / LayoutTests / media / video-controls-captions-trackmenu-sorted.html
index 0e96216..6105371 100644 (file)
@@ -5,97 +5,96 @@
         <script src="media-controls.js"></script>
         <script src="media-file.js"></script>
         <script src="video-test.js"></script>
+        <script src="trackmenu-test.js"></script>
         <script>
-            var captionsButtonCoordinates;
-
+            var test = 0;
             if (window.testRunner)
                 testRunner.dumpAsText();
 
-            function clickCCButton()
-            {
-                eventSender.mouseMoveTo(captionsButtonCoordinates[0], captionsButtonCoordinates[1]);
-                eventSender.mouseDown();
-                eventSender.mouseUp();
-            }
-
-            function startTest()
+            function textTrackMenuItems()
             {
-                if (window.eventSender) {
-                    consoleWrite("<br>*** Set the user language preference.");
-                    run("internals.setUserPreferredLanguages(['en'])");
+                // Show and hide the menu to force a recalculation.
+                clickCCButton();
+                clickCCButton();
 
-                    try {
-                        captionsButtonCoordinates = mediaControlsButtonCoordinates(video, "toggle-closed-captions-button");
-                    } catch (exception) {
-                        failTest(exception.description);
-                        return;
-                    }
-                    clickCCButton();
-                    window.setTimeout(testSortedMenu, 100);
+                var trackListElement = getTrackListElement();
+                if (!trackListElement)
+                    return;
+                var trackListSection = trackListElement.querySelector("ul");
+                if (!trackListSection) {
+                    failTest("There should be a ul element in track list menu");
+                    return;
                 }
+                return trackListSection.querySelectorAll("li");
             }
 
             function testSortedMenu()
             {
-                var trackListElement;
-                try {
-                    trackListElement = mediaControlsElement(internals.shadowRoot(video).firstChild, "-webkit-media-controls-closed-captions-track-list");
-                } catch (exception) {
-                    failTest(exception.description);
-                    return;
-                }
-                // Track list should have two <ul> elements.
-                var trackListSections = trackListElement.querySelectorAll("ul");
-                if (!trackListSections || trackListSections.length != 2) {
-                    failTest("There should be two ul elements in track list menu");
-                    return;
-                }
-                for (var i = 0; i < trackListSections.length; i++) {
-                    consoleWrite("<br>*** Test menu section " + i + ".");
-                    var lastTrackLabel = null;
-                    var trackListItems = trackListSections[i].querySelectorAll("li");
-                    if (!trackListItems || trackListItems.length != 5) {
-                        failTest("There should be five li elements in this section");
-                        return;
-                    }
-                    for (var j = 0; j < trackListItems.length; j++) {
-                        var item = trackListItems[j];
-                        if (j == 0)
-                            logResult(item.textContent == "Off", "First item should be labelled off");
-                        else {
-                            if (lastTrackLabel)
-                                logResult(item.textContent > lastTrackLabel, lastTrackLabel + " comes before " + item.textContent);
-                            else
-                                logResult(true, item.textContent + " is the first real item in the list");
-                            lastTrackLabel = item.textContent;
-                        }
-                    }
-                    consoleWrite("Menu section " + i + " was ok.<br>");
+                switch (test)
+                {
+                case 0:
+                    consoleWrite("<br><i>** Test with preferred language set to English, track type set to captions<" + "/i>");
+                    run("internals.settings.setShouldDisplayTrackKind('Captions', true)");
+                    window.setTimeout(testSortedMenu, 0);
+                    break;
+
+                case 1:
+                    trackMenuItems = textTrackMenuItems();
+                    testExpected("trackMenuItems[0].textContent", "Off");
+                    testExpected("trackMenuItems[1].textContent", "Auto (Recommended)");
+                    testExpected("trackMenuItems[2].textContent", "u (English)");
+                    testExpected("trackMenuItems[3].textContent", "y (English-Australia)");
+                    testExpected("trackMenuItems[4].textContent", "v (English)");
+                    testExpected("trackMenuItems[5].textContent", "x (English-Australia)");
+                    testExpected("trackMenuItems[6].textContent", "w (Japanese)");
+                    testExpected("trackMenuItems[7].textContent", "z (Japanese)");
+                    testExpected("video.textTracks.length", 6);
+                    testExpected("trackMenuItems.length", 8);
+
+                    consoleWrite("<br><i>** Change preferred language to Japanese, change preference to subtitles<" + "/i>");
+                    run("internals.setUserPreferredLanguages(['ja'])");
+                    run("internals.settings.setShouldDisplayTrackKind('Captions', false)");
+                    run("internals.settings.setShouldDisplayTrackKind('Subtitles', true)");
+
+                    window.setTimeout(testSortedMenu, 0);
+                break;
+
+                case 2:
+                    trackMenuItems = textTrackMenuItems();
+                    testExpected("trackMenuItems[0].textContent", "Off");
+                    testExpected("trackMenuItems[1].textContent", "Auto (Recommended)");
+                    testExpected("trackMenuItems[2].textContent", "z (Japanese)");
+                    testExpected("trackMenuItems[3].textContent", "v (English)");
+                    testExpected("trackMenuItems[4].textContent", "x (English-Australia)");
+                    testExpected("video.textTracks.length", 6);
+                    testExpected("trackMenuItems.length", 5);
+
+                    consoleWrite("");
+                    endTest();
+                break;
                 }
-                endTest();
+
+                ++test;
             }
 
             function start()
             {
                 findMediaElement();
-                waitForEvent('canplaythrough', startTest);
+                video.src = findMediaFile('video', 'content/test');
+                waitForEvent('canplaythrough', function () { startTrackMenuTest(testSortedMenu); });
             }
         </script>
     </head>
 
     <body onload="start()">
-        <p>Test that captions and subtitles are sorted in the menu.</p>
+        <p>Test that captions and subtitles are sorted in the menu according to user preferences.</p>
         <video width="500" height="300" controls>
-            <source src="content/test.mp4" type="video/mp4">
-            <source src="content/test.ogv" type="video/ogg">
-            <track label="c" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
-            <track label="b" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
-            <track label="a" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
-            <track label="d" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
-            <track label="b" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
-            <track label="a" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
-            <track label="c" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
-            <track label="d" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
+            <track label="z" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
+            <track label="y" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
+            <track label="x" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en-au">
+            <track label="w" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="ja">
+            <track label="v" kind="subtitles" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
+            <track label="u" kind="captions" src="track/captions-webvtt/captions-fast.vtt" srclang="en">
         </video>
     </body>
 </html>