Update HTMLMediaElement's index of cues when TextTrack.mode changes to
authorannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2012 20:29:50 +0000 (20:29 +0000)
committerannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2012 20:29:50 +0000 (20:29 +0000)
and from TextTrack::DISABLED.
https://bugs.webkit.org/show_bug.cgi?id=83377

Reviewed by Eric Carlson.

Source/WebCore:

No new tests. Instead updated media/track/track-mode.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::textTrackModeChanged):
    Add the track's cues to the index when the mode changes to HIDDEN or SHOWING.

* html/HTMLTrackElement.cpp:
(WebCore::HTMLTrackElement::textTrackRemoveCues):
    Fix a copy pasta error.

* html/track/TextTrack.cpp:
(WebCore::TextTrack::setMode):
    Remove the track's cues from the index when the mode changes to DISABLED.

LayoutTests:

* media/track/track-mode-expected.txt:
* media/track/track-mode.html:

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

LayoutTests/ChangeLog
LayoutTests/media/track/captions-webvtt/captions-fast.vtt [new file with mode: 0644]
LayoutTests/media/track/track-mode-expected.txt
LayoutTests/media/track/track-mode.html
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLTrackElement.cpp
Source/WebCore/html/track/TextTrack.cpp

index 5095fac..bf7f020 100644 (file)
@@ -1,3 +1,14 @@
+2012-04-12  Anna Cavender  <annacc@chromium.org>
+
+        Update HTMLMediaElement's index of cues when TextTrack.mode changes to
+        and from TextTrack::DISABLED.
+        https://bugs.webkit.org/show_bug.cgi?id=83377
+
+        Reviewed by Eric Carlson.
+
+        * media/track/track-mode-expected.txt:
+        * media/track/track-mode.html:
+
 2012-04-12  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r114005.
diff --git a/LayoutTests/media/track/captions-webvtt/captions-fast.vtt b/LayoutTests/media/track/captions-webvtt/captions-fast.vtt
new file mode 100644 (file)
index 0000000..d30477d
--- /dev/null
@@ -0,0 +1,17 @@
+WEBVTT
+
+1
+00:00:00.000 --> 00:00:00.200
+Lorem
+
+2
+00:00:00.200 --> 00:00:00.500
+ipsum
+
+3
+00:00:00.500 --> 00:00:00.800
+dolor
+
+4
+00:00:00.800 --> 00:00:01.000
+sit
index 0ae9ced..165a4c9 100644 (file)
@@ -15,16 +15,30 @@ EXPECTED (video.textTracks[0].mode == '2') OK
 RUN(textTrack.mode = '0')
 EXPECTED (textTrack.mode == '0') OK
 EXPECTED (video.textTracks[0].mode == '0') OK
+EXPECTED (textTrack.cues == 'null') OK
+
+++ 0 events expected while mode = TextTrack.DISABLED
 
 ++ 'TextTrack.HIDDEN'
 RUN(textTrack.mode = '1')
+EVENT(cuechange)
+EXPECTED (textTrack.activeCues.length == '1'), OBSERVED '0' FAIL
 EXPECTED (textTrack.mode == '1') OK
 EXPECTED (video.textTracks[0].mode == '1') OK
+EXPECTED (textTrack.cues.length == '4') OK
 
 ++ 'TextTrack.SHOWING'
 RUN(textTrack.mode = '2')
 EXPECTED (textTrack.mode == '2') OK
 EXPECTED (video.textTracks[0].mode == '2') OK
-
+EXPECTED (textTrack.cues.length == '4') OK
+
+++ 3 events expected while mode = TextTrack.SHOWING
+EVENT(cuechange)
+EXPECTED (textTrack.activeCues.length == '1') OK
+EVENT(cuechange)
+EXPECTED (textTrack.activeCues.length == '1') OK
+EVENT(cuechange)
+EXPECTED (textTrack.activeCues.length == '1') OK
 END OF TEST
 
index 552ea42..15be36a 100644 (file)
@@ -7,17 +7,24 @@
         <script>
 
             var textTrack;
+            var cueCount;
+
             function setMode(value)
             {
                 run("textTrack.mode = '" + value + "'");
                 testExpected("textTrack.mode", value);
                 testExpected("video.textTracks[0].mode", value);
+                if (value == TextTrack.DISABLED)
+                    testExpected("textTrack.cues", null);
+                else
+                    testExpected("textTrack.cues.length", textTrack.cues.length);
                 consoleWrite("");
             }
 
             function start()
             {
                 findMediaElement();
+                cueCount = 0;
                 consoleWrite("");
 
                 textTrack = document.getElementById('track_1').track;
                 consoleWrite("<b>++ 'TextTrack.DISABLED'</b>");
                 setMode(TextTrack.DISABLED);
 
+                video.src = findMediaFile("video", "../content/test");
+                video.play();
+                // Wait for end of first cue (no events should fire while track is disabled).
+                setTimeout(testHiddenAndShowing, 300);
+                consoleWrite("++ 0 events expected while mode = TextTrack.DISABLED");
+                consoleWrite("");
+            }
+            
+            function testHiddenAndShowing()
+            {
                 consoleWrite("<b>++ 'TextTrack.HIDDEN'</b>");
                 setMode(TextTrack.HIDDEN);
 
                 consoleWrite("<b>++ 'TextTrack.SHOWING'</b>");
                 setMode(TextTrack.SHOWING);
 
-                endTest();
+                consoleWrite("++ " + (textTrack.cues.length - 1) + " events expected while mode = TextTrack.SHOWING");
             }
+            
+            waitForEvent('cuechange',
+                function ()
+                {
+                    testExpected("textTrack.activeCues.length", 1);
+                    cueCount++;
+                    if (cueCount == textTrack.cues.length)
+                        endTest();
 
+                }
+            );
+            
         </script>
     </head>
     <body>
         <p>Tests that the TextTrack mode attribute is appropriately set.</p>
         <video>
-            <track id=track_1 src="captions-webvtt/captions.vtt" onload="start()" default>
+            <track id=track_1 src="captions-webvtt/captions-fast.vtt" onload="start()" default>
         </video>
     </body>
 </html>
index ba1fc60..b5bd805 100644 (file)
@@ -1,3 +1,25 @@
+2012-04-12  Anna Cavender  <annacc@chromium.org>
+
+        Update HTMLMediaElement's index of cues when TextTrack.mode changes to
+        and from TextTrack::DISABLED.
+        https://bugs.webkit.org/show_bug.cgi?id=83377
+
+        Reviewed by Eric Carlson.
+
+        No new tests. Instead updated media/track/track-mode.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::textTrackModeChanged):
+            Add the track's cues to the index when the mode changes to HIDDEN or SHOWING.
+
+        * html/HTMLTrackElement.cpp:
+        (WebCore::HTMLTrackElement::textTrackRemoveCues):
+            Fix a copy pasta error.
+
+        * html/track/TextTrack.cpp:
+        (WebCore::TextTrack::setMode):
+            Remove the track's cues from the index when the mode changes to DISABLED.
+
 2012-04-12  Cem Kocagil  <cem.kocagil@gmail.com>
 
         Allow certain Char events in fullscreen
index f9998a6..0214dd2 100644 (file)
@@ -1255,8 +1255,12 @@ void HTMLMediaElement::textTrackModeChanged(TextTrack* track)
             
             // Mark this track as "configured" so configureNewTextTracks won't change the mode again.
             trackElement->setHasBeenConfigured(true);
-            if (track->mode() != TextTrack::DISABLED && trackElement->readyState() == HTMLTrackElement::NONE)
-                trackElement->scheduleLoad();
+            if (track->mode() != TextTrack::DISABLED) {
+                if (trackElement->readyState() == HTMLTrackElement::LOADED)
+                    textTrackAddCues(track, track->cues());
+                else if (trackElement->readyState() == HTMLTrackElement::NONE)
+                    trackElement->scheduleLoad();
+            }
             break;
         }
     }
index 6005799..f80ceea 100644 (file)
@@ -315,7 +315,7 @@ void HTMLTrackElement::textTrackAddCues(TextTrack* track, const TextTrackCueList
 void HTMLTrackElement::textTrackRemoveCues(TextTrack* track, const TextTrackCueList* cues)
 {
     if (HTMLMediaElement* parent = mediaElement())
-        return parent->textTrackAddCues(track, cues);
+        return parent->textTrackRemoveCues(track, cues);
 }
     
 void HTMLTrackElement::textTrackAddCue(TextTrack* track, PassRefPtr<TextTrackCue> cue)
index a8d2634..53d5ee5 100644 (file)
@@ -139,6 +139,11 @@ void TextTrack::setMode(unsigned short mode, ExceptionCode& ec)
     if (m_mode == static_cast<Mode>(mode))
         return;
 
+    // If mode changes to disabled, remove this track's cues from the client
+    // because they will no longer be accessible from the cues() function.
+    if (mode == TextTrack::DISABLED && m_client && m_cues)
+         m_client->textTrackRemoveCues(this, m_cues.get());
+
     //  ... Note: If the mode had been showing by default, this will change it to showing, 
     // even though the value of mode would appear not to change.
     m_mode = static_cast<Mode>(mode);