[Mac] "automatic" track selection should only select a track that matches user language
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Apr 2013 20:29:58 +0000 (20:29 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Apr 2013 20:29:58 +0000 (20:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=114976

Reviewed by Jer Noble.

Source/WebCore:

Test: media/track/track-automatic-subtitles.html

* page/CaptionUserPreferencesMac.mm:
(WebCore::CaptionUserPreferencesMac::textTrackSelectionScore): When in "automatic" mode, only
    consider text tracks that match the user's preferred language when the primary audio track
    does not.

LayoutTests:

* media/track/track-automatic-subtitles-expected.txt: Added.
* media/track/track-automatic-subtitles.html: Added.
* platform/mac/TestExpectations: Skip track-user-preferences.html, the logic is no longer
     correct for the Mac port.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@148907 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/media/track/track-automatic-subtitles-expected.txt [new file with mode: 0644]
LayoutTests/media/track/track-automatic-subtitles.html [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/CaptionUserPreferencesMac.mm

index 7f6c5e93dc73d6c60abe2bfaa4b7f61fedebf6ac..a868b1be314386a6177881ca83738c646d9cb724 100644 (file)
@@ -1,3 +1,15 @@
+2013-04-22  Eric Carlson  <eric.carlson@apple.com>
+
+        [Mac] "automatic" track selection should only select a track that matches user language
+        https://bugs.webkit.org/show_bug.cgi?id=114976
+
+        Reviewed by Jer Noble.
+
+        * media/track/track-automatic-subtitles-expected.txt: Added.
+        * media/track/track-automatic-subtitles.html: Added.
+        * platform/mac/TestExpectations: Skip track-user-preferences.html, the logic is no longer
+             correct for the Mac port.
+
 2013-04-22  Andy Estes  <aestes@apple.com>
 
         Range.getClientRects() should not include rects for partially selected elements
diff --git a/LayoutTests/media/track/track-automatic-subtitles-expected.txt b/LayoutTests/media/track/track-automatic-subtitles-expected.txt
new file mode 100644 (file)
index 0000000..d7cc796
--- /dev/null
@@ -0,0 +1,27 @@
+Tests "Automatic" mode track selection.
+
+RUN(internals.settings.setShouldDisplayTrackKind('Captions', false))
+RUN(internals.settings.setShouldDisplayTrackKind('Subtitles', true))
+
+EVENT(canplaythrough)
+
+Test 1: 'ru' track selected because mode is automatic and no audio track is available in user language
+RUN(internals.setCaptionDisplayMode('Automatic'))
+RUN(internals.setPrimaryAudioTrackLanguageOverride('fr'))
+RUN(internals.setUserPreferredLanguages(['ru']))
+- creating tracks for: [en,ru,en-au,jp].
+
+EVENT(load)
+EXPECTED (event.target.srclang == 'ru') OK
+EXPECTED (event.target.readyState == '2') OK
+
+Test 2: no track selected because none matches user language
+RUN(internals.setUserPreferredLanguages(['se']))
+- creating tracks for: [en,ru,en-au,jp].
+EXPECTED (video.textTracks[0].mode == 'disabled') OK
+EXPECTED (video.textTracks[1].mode == 'disabled') OK
+EXPECTED (video.textTracks[2].mode == 'disabled') OK
+EXPECTED (video.textTracks[3].mode == 'disabled') OK
+
+END OF TEST
+
diff --git a/LayoutTests/media/track/track-automatic-subtitles.html b/LayoutTests/media/track/track-automatic-subtitles.html
new file mode 100644 (file)
index 0000000..da146b1
--- /dev/null
@@ -0,0 +1,115 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=../media-controls.js></script>
+        <script src="../media-file.js"></script>
+        <script src=../trackmenu-test.js></script>
+        <script src=../video-test.js></script>
+        <script>
+            var timer = null;
+            var expectedLanguage;
+            var testStage = 0;
+            var trackLanguages = [];
+
+            function testTracks()
+            {
+                for (var ndx = 0; ndx < trackLanguages.length; ++ndx) {
+                    testExpected("video.textTracks[" + ndx + "].language", trackLanguages[ndx]);
+                    testExpected("video.textTracks[" + ndx + "].kind", "subtitles");
+                    testExpected("video.textTracks[" + ndx + "].mode", expectedLanguage == trackLanguages[ndx] ? "showing" : "disabled");
+                    consoleWrite("");
+                }
+            }
+
+            function trackLoaded()
+            {
+                consoleWrite("EVENT(load)");
+                if (expectedLanguage == "") {
+                    failTest("'" + event.target.srclang + "' track loaded unexpectedly.");
+                    return;
+                }
+                testExpected("event.target.srclang", expectedLanguage);
+                testExpected("event.target.readyState", HTMLTrackElement.LOADED);
+
+                timer = setTimeout(nextStep, 200);
+            }
+
+            function createTrackElement(language, isDefault)
+            {
+                var track = document.createElement('track');
+                track.setAttribute('kind', "captions");
+                track.src = 'data:text/vtt,' + encodeURIComponent("WEBVTT\n\n00:00:00.000 --> 00:00:01.000\nCaption 1\n");
+                track.setAttribute('srclang', language);
+                track.setAttribute('onload', 'trackLoaded()');
+                if (isDefault) {
+                    consoleWrite("-- '" + language + "' track marked as default.");
+                    track.setAttribute('default', 'default');
+                }
+                video.appendChild(track);
+            }
+
+            function createTrackElements(languages, defaultIndex)
+            {
+                trackLanguages = languages;
+                var tracks = document.querySelectorAll('track');
+                for (var ndx = 0; ndx < tracks.length; ++ndx)
+                    video.removeChild(tracks[ndx]);
+
+                consoleWrite("- creating tracks for: [" + languages + "].");
+                for (var ndx = 0; ndx < languages.length; ++ndx)
+                    createTrackElement(languages[ndx], ndx == defaultIndex);
+            }
+
+            function nextStep()
+            {
+                ++testStage;
+                switch (testStage) {
+                case 1:
+                    consoleWrite("<br>Test 1: 'ru' track selected because mode is automatic and no audio track is available in user language");
+                    run("internals.setCaptionDisplayMode('Automatic')");
+                    run("internals.setPrimaryAudioTrackLanguageOverride('fr')");
+                    run("internals.setUserPreferredLanguages(['ru'])");
+                    expectedLanguage = "ru";
+                    createTrackElements(['en', 'ru', 'en-au', 'jp']);
+                    consoleWrite("");
+
+                    break;
+
+                case 2:
+                    consoleWrite("<br>Test 2: no track selected because none matches user language");
+                    expectedLanguage = "";
+                    run("internals.setUserPreferredLanguages(['se'])");
+                    createTrackElements(['en', 'ru', 'en-au', 'jp']);
+                    timer = setTimeout(nextStep, 100);
+                    break;
+
+                case 3:
+                    for (var ndx = 0; ndx < video.textTracks.length; ++ndx)
+                        testExpected("video.textTracks[" + ndx + "].mode", "disabled");
+
+                    consoleWrite("");
+                    endTest();
+                    return;
+                }
+            }
+
+            function setup()
+            {
+                findMediaElement();
+                run("internals.settings.setShouldDisplayTrackKind('Captions', false)");
+                run("internals.settings.setShouldDisplayTrackKind('Subtitles', true)");
+                video.src = findMediaFile('video', '../content/test');
+                waitForEvent('canplaythrough', nextStep);
+                consoleWrite("");
+            }
+
+        </script>
+    </head>
+    <body onload="setup()">
+        <p>Tests "Automatic" mode track selection.</p>
+        <video width="500" height="300" controls>
+        </video>
+    </body>
+</html>
index 77454254c655291f1416c5c7101fb5d7d79562c7..139306a1f6fe0fff4fb7cea86ee322b907f30953 100644 (file)
@@ -1367,6 +1367,9 @@ webkit.org/b/103663 [ MountainLion Lion SnowLeopard ] media/track/track-forced-s
 webkit.org/b/112492 media/track/track-language-preference.html [ Failure Pass ]
 webkit.org/b/112492 media/track/track-prefer-captions.html [ Failure Pass ]
 
+# The logic in this test is no longer correct for Apple ports
+webkit.org/b/112492 media/track/track-user-preferences.html [ Skip ]
+
 webkit.org/b/104104 fast/overflow/scrollbar-click-retains-focus.html [ Failure ]
 
 webkit.org/b/104949 fast/spatial-navigation/snav-unit-overflow-and-scroll-in-direction.html [ Failure ]
index 0e321071cffca98acb6d4cb172c0d9c7322a3446..2a5ea3569bf9cb5782f23e0a781d20e73ea5f18f 100644 (file)
@@ -1,3 +1,17 @@
+2013-04-22  Eric Carlson  <eric.carlson@apple.com>
+
+        [Mac] "automatic" track selection should only select a track that matches user language
+        https://bugs.webkit.org/show_bug.cgi?id=114976
+
+        Reviewed by Jer Noble.
+
+        Test: media/track/track-automatic-subtitles.html
+
+        * page/CaptionUserPreferencesMac.mm:
+        (WebCore::CaptionUserPreferencesMac::textTrackSelectionScore): When in "automatic" mode, only
+            consider text tracks that match the user's preferred language when the primary audio track
+            does not.
+
 2013-04-22  Jer Noble  <jer.noble@apple.com>
 
         Cancelling load may cause deadlock in -[AVPlayerItem release]
index bf5c4d17eb9d477dcc7d4a66aae936d9f279a350..929632151405466adb108f530eacf08314bd7355 100644 (file)
@@ -635,11 +635,14 @@ int CaptionUserPreferencesMac::textTrackSelectionScore(TextTrack* track, HTMLMed
         if (!mediaElement || !mediaElement->player())
             return 0;
 
-        String audioTrackLanguage;
+        String textTrackLanguage = track->language();
+        if (textTrackLanguage.isEmpty())
+            return 0;
 
         Vector<String> languageList;
         languageList.reserveCapacity(1);
 
+        String audioTrackLanguage;
         if (testingMode())
             audioTrackLanguage = primaryAudioTrackLanguageOverride();
         else
@@ -649,19 +652,22 @@ int CaptionUserPreferencesMac::textTrackSelectionScore(TextTrack* track, HTMLMed
             return 0;
 
         if (displayMode == Automatic) {
-            // Only enable a text track if the current audio track is not in the user's preferred language.
             languageList.append(defaultLanguage());
+
+            // Only enable a text track if the current audio track is NOT in the user's preferred language ...
             size_t offset = indexOfBestMatchingLanguageInList(audioTrackLanguage, languageList);
+            if (!offset)
+                return 0;
+
+            // and the text track matches the user's preferred language.
+            offset = indexOfBestMatchingLanguageInList(textTrackLanguage, languageList);
             if (offset)
                 return 0;
         } else {
-            // Only consider a forced-only track if it is in the same language as the primary audio track.
-            String trackLanguage = track->language();
-            if (trackLanguage.isEmpty())
-                return 0;
-
             languageList.append(audioTrackLanguage);
-            size_t offset = indexOfBestMatchingLanguageInList(trackLanguage, languageList);
+            size_t offset = indexOfBestMatchingLanguageInList(textTrackLanguage, languageList);
+
+            // Only consider a forced-only track if it IS in the same language as the primary audio track.
             if (offset)
                 return 0;
         }