summaryrefslogtreecommitdiffstats
path: root/media/base/text_ranges_unittest.cc
diff options
context:
space:
mode:
authormatthewjheaney@chromium.org <matthewjheaney@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-07 23:16:07 +0000
committermatthewjheaney@chromium.org <matthewjheaney@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-07 23:16:07 +0000
commitcde623ad57a1cccfb621269f92b61a2eab666509 (patch)
treea2236785001f8ef5bfd34255d29c79ac97aa5281 /media/base/text_ranges_unittest.cc
parent58a27877b639f06d18f912580b0220de2f32034b (diff)
downloadchromium_src-cde623ad57a1cccfb621269f92b61a2eab666509.zip
chromium_src-cde623ad57a1cccfb621269f92b61a2eab666509.tar.gz
chromium_src-cde623ad57a1cccfb621269f92b61a2eab666509.tar.bz2
TextRenderer only pushes new cues downstream
The TextTrack subsystem in Blink unconditionally satisfies a request to add a new text cue to the text track cue list, relying on the upstream demuxers to filter out cues that have already been added to that list. The TextRenderer now manages a map of time range objects, to keep track of which cues (based on their start times) have already been pushed downstream prior to the current seek. BUG=230708 Review URL: https://codereview.chromium.org/151103005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@249845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/text_ranges_unittest.cc')
-rw-r--r--media/base/text_ranges_unittest.cc147
1 files changed, 147 insertions, 0 deletions
diff --git a/media/base/text_ranges_unittest.cc b/media/base/text_ranges_unittest.cc
new file mode 100644
index 0000000..7de0514
--- /dev/null
+++ b/media/base/text_ranges_unittest.cc
@@ -0,0 +1,147 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/base/text_ranges.h"
+
+#include "base/time/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace media {
+
+class TextRangesTest : public ::testing::Test {
+ protected:
+ bool AddCue(int seconds) {
+ return ranges_.AddCue(base::TimeDelta::FromSeconds(seconds));
+ }
+
+ void Reset() {
+ ranges_.Reset();
+ }
+
+ size_t RangeCount() {
+ return ranges_.RangeCountForTesting();
+ }
+
+ TextRanges ranges_;
+};
+
+TEST_F(TextRangesTest, TestEmptyRanges) {
+ // Create a new active range, with t=5.
+ EXPECT_TRUE(AddCue(5));
+
+ // Create a new active range, with t=2.
+ Reset();
+ EXPECT_TRUE(AddCue(2));
+
+ // Create a new active range, with t=8.
+ Reset();
+ EXPECT_TRUE(AddCue(8));
+
+ Reset();
+
+ // Make range [2, 2] active.
+ EXPECT_FALSE(AddCue(2));
+ EXPECT_EQ(RangeCount(), 3U);
+
+ // Coalesce first two ranges: [2, 5].
+ EXPECT_FALSE(AddCue(5));
+ EXPECT_EQ(RangeCount(), 2U);
+
+ // Coalesce first two ranges: [2, 8].
+ EXPECT_FALSE(AddCue(8));
+ EXPECT_EQ(RangeCount(), 1U);
+
+ // Add new cue to end of (only) range.
+ EXPECT_TRUE(AddCue(9));
+ EXPECT_EQ(RangeCount(), 1U);
+}
+
+TEST_F(TextRangesTest, TestOneRange) {
+ // Create a new active range, with t=0.
+ EXPECT_TRUE(AddCue(0));
+
+ // Add cues to end of existing range.
+ EXPECT_TRUE(AddCue(1));
+ EXPECT_TRUE(AddCue(4));
+
+ Reset();
+ EXPECT_FALSE(AddCue(2));
+ EXPECT_FALSE(AddCue(3));
+ EXPECT_FALSE(AddCue(4));
+}
+
+TEST_F(TextRangesTest, TestDuplicateLast) {
+ // Create a new active range, with t=0.
+ EXPECT_TRUE(AddCue(0));
+ EXPECT_TRUE(AddCue(1));
+
+ Reset();
+ EXPECT_FALSE(AddCue(1));
+ EXPECT_TRUE(AddCue(1));
+}
+
+TEST_F(TextRangesTest, TestTwoRanges) {
+ // Create a new active range, with t=0.
+ EXPECT_TRUE(AddCue(0));
+
+ // Add cue to end of existing range.
+ EXPECT_TRUE(AddCue(2));
+
+ Reset();
+
+ // Create a new active range, with t=4.
+ EXPECT_TRUE(AddCue(4));
+
+ // Add a new cue to end of last (active) range.
+ EXPECT_TRUE(AddCue(5));
+
+ Reset();
+
+ // Make first range active.
+ EXPECT_FALSE(AddCue(0));
+ EXPECT_FALSE(AddCue(2));
+
+ // Expand first range.
+ EXPECT_TRUE(AddCue(3));
+
+ // Coalesce first and second ranges.
+ EXPECT_FALSE(AddCue(4));
+ EXPECT_EQ(RangeCount(), 1U);
+}
+
+TEST_F(TextRangesTest, TestThreeRanges) {
+ // Create a new active range, with t=0.
+ EXPECT_TRUE(AddCue(0));
+
+ // Add cue to end of existing range.
+ EXPECT_TRUE(AddCue(2));
+
+ Reset();
+
+ // Create a new active range, with t=4.
+ EXPECT_TRUE(AddCue(4));
+
+ // Add a new cue to end of last (active) range.
+ EXPECT_TRUE(AddCue(5));
+
+ Reset();
+
+ // Create a new active range, in between the other two.
+ EXPECT_TRUE(AddCue(3));
+
+ // Coalesce middle and last ranges.
+ EXPECT_FALSE(AddCue(4));
+
+ Reset();
+
+ // Make first range active.
+ EXPECT_FALSE(AddCue(0));
+ EXPECT_FALSE(AddCue(2));
+
+ // Coalesce first and last ranges.
+ EXPECT_FALSE(AddCue(3));
+ EXPECT_EQ(RangeCount(), 1U);
+}
+
+} // namespace media