[Mac] .webkitClosedCaptionsVisible doesn't work with "Automatic" caption mode
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Jul 2013 20:35:11 +0000 (20:35 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Jul 2013 20:35:11 +0000 (20:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=118319

Reviewed by Jer Noble.

Source/WebCore:

Track when captions are enabled with the old 'webkitClosedCaptionsVisible' attribute and
consider that when determining which track should be enabled.

Test: media/track/track-legacyapi-with-automatic-mode.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_webkitLegacyClosedCaptionOverride.
(WebCore::HTMLMediaElement::setWebkitClosedCaptionsVisible): Set m_webkitLegacyClosedCaptionOverride.
(WebCore::HTMLMediaElement::webkitClosedCaptionsVisible): Return m_webkitLegacyClosedCaptionOverride.
* html/HTMLMediaElement.h:

* page/CaptionUserPreferencesMediaAF.cpp:
(WebCore::CaptionUserPreferencesMediaAF::textTrackSelectionScore): Don't apply "automatic"
    logic when captions were enabled with .webkitClosedCaptionsVisible.

LayoutTests:

* media/track/track-legacyapi-with-automatic-mode-expected.txt: Added.
* media/track/track-legacyapi-with-automatic-mode.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/media/track/track-legacyapi-with-automatic-mode-expected.txt [new file with mode: 0644]
LayoutTests/media/track/track-legacyapi-with-automatic-mode.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp

index ea4c040..884fed0 100644 (file)
@@ -1,3 +1,13 @@
+2013-07-05  Eric Carlson  <eric.carlson@apple.com>
+
+        [Mac] .webkitClosedCaptionsVisible doesn't work with "Automatic" caption mode
+        https://bugs.webkit.org/show_bug.cgi?id=118319
+
+        Reviewed by Jer Noble.
+
+        * media/track/track-legacyapi-with-automatic-mode-expected.txt: Added.
+        * media/track/track-legacyapi-with-automatic-mode.html: Added.
+
 2013-07-05  Mario Sanchez Prada  <mario.prada@samsung.com>
 
         Unreviewed gardening. Updated TestExpectations file.
diff --git a/LayoutTests/media/track/track-legacyapi-with-automatic-mode-expected.txt b/LayoutTests/media/track/track-legacyapi-with-automatic-mode-expected.txt
new file mode 100644 (file)
index 0000000..f83ccef
--- /dev/null
@@ -0,0 +1,30 @@
+Test that enabling a track with .webkitClosedCaptionsVisible succeeds when in "automatic" mode.
+
+
+** Setup
+RUN(internals.setCaptionDisplayMode('Automatic'))
+RUN(trackElement = document.createElement('track'))
+RUN(trackElement.kind = 'captions')
+RUN(trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt')
+RUN(video.appendChild(trackElement))
+
+EVENT(canplaythrough)
+
+** Test initial state
+EXPECTED (video.textTracks.length == '1') OK
+EXPECTED (video.textTracks[0].mode == 'disabled') OK
+
+** Enable cues, allow them to load
+RUN(video.webkitClosedCaptionsVisible = true)
+EVENT(load)
+EXPECTED (track.readyState == '2') OK
+RUN(video.currentTime = 0.5)
+
+EVENT(seeked)
+
+** Check to make sure captions are displaying
+EXPECTED (video.textTracks[0].cues != 'null') OK
+EXPECTED (textTrackDisplayElement(video, 'cue').textContent != 'null') OK
+
+END OF TEST
+
diff --git a/LayoutTests/media/track/track-legacyapi-with-automatic-mode.html b/LayoutTests/media/track/track-legacyapi-with-automatic-mode.html
new file mode 100644 (file)
index 0000000..e221118
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <title>Enabling a track with legacy API succeeds when in "Automatic" mode</title>
+
+        <script src=../media-file.js></script>
+        <script src=../video-test.js></script>
+        <script src=../trackmenu-test.js></script>
+        <script src=../media-controls.js></script>
+        <script>
+
+            function seeked()
+            {
+                consoleWrite("<br><i>** Check to make sure captions are displaying<" + "/i>");
+
+                testExpected("video.textTracks[0].cues", null, '!=');
+                testExpected("textTrackDisplayElement(video, 'cue').textContent", null, '!=');
+
+                consoleWrite("");
+                endTest();
+            }
+
+            function trackLoaded()
+            {
+                consoleWrite("EVENT(load)");
+                track = event.target;
+                testExpected("track.readyState", HTMLTrackElement.LOADED);
+                run("video.currentTime = 0.5");
+                waitForEvent('seeked', seeked);
+                consoleWrite("");
+            }
+
+            function canplaythrough()
+            {
+                consoleWrite("<br><i>** Test initial state<" + "/i>");
+                testExpected("video.textTracks.length", 1);
+                testExpected("video.textTracks[0].mode", "disabled");
+
+                consoleWrite("<br><i>** Enable cues, allow them to load<" + "/i>");
+                run("video.webkitClosedCaptionsVisible = true");
+            }
+
+            function setup()
+            {
+                consoleWrite("<br><i>** Setup<" + "/i>");
+                findMediaElement();
+
+                if (window.internals)
+                    run("internals.setCaptionDisplayMode('Automatic')");
+                run("trackElement = document.createElement('track')");
+                run("trackElement.kind = 'captions'");
+                run("trackElement.src = 'captions-webvtt/tc004-webvtt-file.vtt'");
+                run("video.appendChild(trackElement)");
+
+                video.src = findMediaFile('video', '../content/test');
+                trackElement.setAttribute('onload', 'trackLoaded()');
+                waitForEvent('canplaythrough', canplaythrough);
+                consoleWrite("");
+            }
+
+        </script>
+    </head>
+    <body onload="setup()">
+        <video controls width=500></video>
+        <p>Test that enabling a track with .webkitClosedCaptionsVisible succeeds when in "automatic" mode.</p>
+    </body>
+</html>
index 9a63eca..d699702 100644 (file)
@@ -1,3 +1,25 @@
+2013-07-05  Eric Carlson  <eric.carlson@apple.com>
+
+        [Mac] .webkitClosedCaptionsVisible doesn't work with "Automatic" caption mode
+        https://bugs.webkit.org/show_bug.cgi?id=118319
+
+        Reviewed by Jer Noble.
+
+        Track when captions are enabled with the old 'webkitClosedCaptionsVisible' attribute and
+        consider that when determining which track should be enabled.
+
+        Test: media/track/track-legacyapi-with-automatic-mode.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_webkitLegacyClosedCaptionOverride.
+        (WebCore::HTMLMediaElement::setWebkitClosedCaptionsVisible): Set m_webkitLegacyClosedCaptionOverride.
+        (WebCore::HTMLMediaElement::webkitClosedCaptionsVisible): Return m_webkitLegacyClosedCaptionOverride.
+        * html/HTMLMediaElement.h:
+
+        * page/CaptionUserPreferencesMediaAF.cpp:
+        (WebCore::CaptionUserPreferencesMediaAF::textTrackSelectionScore): Don't apply "automatic"
+            logic when captions were enabled with .webkitClosedCaptionsVisible.
+
 2013-07-05  Benjamin Dupont   <bdupont@nds.com>
 
         Segmentation fault occurred when ICU data library doesn't embed the expected encoding.
index 893776e..c2a0399 100644 (file)
@@ -298,6 +298,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
     , m_sendProgressEvents(true)
     , m_isFullscreen(false)
     , m_closedCaptionsVisible(false)
+    , m_webkitLegacyClosedCaptionOverride(false)
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     , m_needWidgetUpdate(false)
 #endif
@@ -4526,12 +4527,13 @@ void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
 
 void HTMLMediaElement::setWebkitClosedCaptionsVisible(bool visible)
 {
+    m_webkitLegacyClosedCaptionOverride = visible;
     setClosedCaptionsVisible(visible);
 }
 
 bool HTMLMediaElement::webkitClosedCaptionsVisible() const
 {
-    return m_closedCaptionsVisible;
+    return m_webkitLegacyClosedCaptionOverride && m_closedCaptionsVisible;
 }
 
 
index 41de3a1..6fa78d5 100644 (file)
@@ -710,6 +710,7 @@ private:
 
     bool m_isFullscreen : 1;
     bool m_closedCaptionsVisible : 1;
+    bool m_webkitLegacyClosedCaptionOverride : 1;
 
 #if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     bool m_needWidgetUpdate : 1;
index 45184f6..7d67e0e 100644 (file)
@@ -680,7 +680,7 @@ int CaptionUserPreferencesMediaAF::textTrackSelectionScore(TextTrack* track, HTM
 
     Vector<String> userPreferredCaptionLanguages = preferredLanguages();
 
-    if (displayMode == Automatic || trackHasOnlyForcedSubtitles) {
+    if ((displayMode == Automatic && !legacyOverride) || trackHasOnlyForcedSubtitles) {
 
         if (!mediaElement || !mediaElement->player())
             return 0;