[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.

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: http://svn.webkit.org/repository/webkit/trunk@148907 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0001b28a
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
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
<!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>
......@@ -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 ]
......
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]
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment