Handle empty lines in the 'TimingsAndSettings' state in the WebVTTParser

As per the WebVTT parsing specification, step 27 ("If line is the empty
string, then discard cue and jump to the step labeled cue loop."), the
cue should be discarded and the cue loop restarted if an "identifier"
line is followed by an empty line. Transitioning to the 'BadCue' state
will lose the transition, so we need to transition explicitly from the
'TimingsAndSettings' state (to the 'Id' state.)

BUG=314056

Review URL: https://codereview.chromium.org/55853002

git-svn-id: svn://svn.chromium.org/blink/trunk@161184 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/third_party/WebKit/LayoutTests/media/track/captions-webvtt/tc030-interspersed-non-cue.vtt b/third_party/WebKit/LayoutTests/media/track/captions-webvtt/tc030-interspersed-non-cue.vtt
new file mode 100644
index 0000000..c825ab3
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/media/track/captions-webvtt/tc030-interspersed-non-cue.vtt
@@ -0,0 +1,9 @@
+WEBVTT
+
+00:00.000 --> 00:01.000
+First
+
+Stray Id or other non-cue content
+
+00:02.000 --> 00:03.000
+Second
diff --git a/third_party/WebKit/LayoutTests/media/track/track-webvtt-tc030-interspersed-non-cue-expected.txt b/third_party/WebKit/LayoutTests/media/track/track-webvtt-tc030-interspersed-non-cue-expected.txt
new file mode 100644
index 0000000..714bbd6
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/media/track/track-webvtt-tc030-interspersed-non-cue-expected.txt
@@ -0,0 +1,9 @@
+Tests that an empty line after an identifier line discards the current cue and restarts the cue loop.
+
+
+*** Testing text track 0
+EXPECTED (cues.length == '2') OK
+EXPECTED (cues[0].text == 'First') OK
+EXPECTED (cues[1].text == 'Second') OK
+END OF TEST
+
diff --git a/third_party/WebKit/LayoutTests/media/track/track-webvtt-tc030-interspersed-non-cue.html b/third_party/WebKit/LayoutTests/media/track/track-webvtt-tc030-interspersed-non-cue.html
new file mode 100644
index 0000000..ab8d206
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/media/track/track-webvtt-tc030-interspersed-non-cue.html
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+        <script src=../media-file.js></script>
+        <script src=../video-test.js></script>
+        <script>
+
+            numberOfTrackTests = 1;
+
+            function trackLoaded()
+            {
+                numberOfTracksLoaded++;
+                if (numberOfTracksLoaded == numberOfTrackTests) {
+                    testTrack0();
+                }
+            }
+
+            function testTrack0()
+            {
+                findMediaElement();
+                var expected =
+                {
+                    length: 2,
+                    tests:
+                    [
+                        {
+                            property: "text",
+                            values:
+                            [
+                                'First',
+                                'Second',
+                            ],
+                        },
+                    ],
+                };
+                testCues(0, expected);
+
+                allTestsEnded();
+            }
+        </script>
+    </head>
+    <body onload="enableAllTextTracks()">
+      <p>Tests that an empty line after an identifier line discards the current cue and restarts the cue loop.</p>
+        <video>
+            <track src="captions-webvtt/tc030-interspersed-non-cue.vtt" onload="trackLoaded()">
+        </video>
+    </body>
+</html>
diff --git a/third_party/WebKit/Source/core/html/track/WebVTTParser.cpp b/third_party/WebKit/Source/core/html/track/WebVTTParser.cpp
index 32d0bbe..c0b9283c 100644
--- a/third_party/WebKit/Source/core/html/track/WebVTTParser.cpp
+++ b/third_party/WebKit/Source/core/html/track/WebVTTParser.cpp
@@ -180,6 +180,11 @@
             break;
 
         case TimingsAndSettings:
+            if (line.isEmpty()) {
+                m_state = Id;
+                break;
+            }
+
             // 40 - Collect cue timings and settings.
             m_state = collectTimingsAndSettings(line);
             break;