Revert of Cleanup NQE (patchset #5 id:80001 of https://codereview.chromium.org/127748...
[chromium-blink-merge.git] / media / base / text_ranges_unittest.cc
blob7de051452f48f2847609d319fed35e5bfd8c4b2b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/base/text_ranges.h"
7 #include "base/time/time.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace media {
12 class TextRangesTest : public ::testing::Test {
13 protected:
14 bool AddCue(int seconds) {
15 return ranges_.AddCue(base::TimeDelta::FromSeconds(seconds));
18 void Reset() {
19 ranges_.Reset();
22 size_t RangeCount() {
23 return ranges_.RangeCountForTesting();
26 TextRanges ranges_;
29 TEST_F(TextRangesTest, TestEmptyRanges) {
30 // Create a new active range, with t=5.
31 EXPECT_TRUE(AddCue(5));
33 // Create a new active range, with t=2.
34 Reset();
35 EXPECT_TRUE(AddCue(2));
37 // Create a new active range, with t=8.
38 Reset();
39 EXPECT_TRUE(AddCue(8));
41 Reset();
43 // Make range [2, 2] active.
44 EXPECT_FALSE(AddCue(2));
45 EXPECT_EQ(RangeCount(), 3U);
47 // Coalesce first two ranges: [2, 5].
48 EXPECT_FALSE(AddCue(5));
49 EXPECT_EQ(RangeCount(), 2U);
51 // Coalesce first two ranges: [2, 8].
52 EXPECT_FALSE(AddCue(8));
53 EXPECT_EQ(RangeCount(), 1U);
55 // Add new cue to end of (only) range.
56 EXPECT_TRUE(AddCue(9));
57 EXPECT_EQ(RangeCount(), 1U);
60 TEST_F(TextRangesTest, TestOneRange) {
61 // Create a new active range, with t=0.
62 EXPECT_TRUE(AddCue(0));
64 // Add cues to end of existing range.
65 EXPECT_TRUE(AddCue(1));
66 EXPECT_TRUE(AddCue(4));
68 Reset();
69 EXPECT_FALSE(AddCue(2));
70 EXPECT_FALSE(AddCue(3));
71 EXPECT_FALSE(AddCue(4));
74 TEST_F(TextRangesTest, TestDuplicateLast) {
75 // Create a new active range, with t=0.
76 EXPECT_TRUE(AddCue(0));
77 EXPECT_TRUE(AddCue(1));
79 Reset();
80 EXPECT_FALSE(AddCue(1));
81 EXPECT_TRUE(AddCue(1));
84 TEST_F(TextRangesTest, TestTwoRanges) {
85 // Create a new active range, with t=0.
86 EXPECT_TRUE(AddCue(0));
88 // Add cue to end of existing range.
89 EXPECT_TRUE(AddCue(2));
91 Reset();
93 // Create a new active range, with t=4.
94 EXPECT_TRUE(AddCue(4));
96 // Add a new cue to end of last (active) range.
97 EXPECT_TRUE(AddCue(5));
99 Reset();
101 // Make first range active.
102 EXPECT_FALSE(AddCue(0));
103 EXPECT_FALSE(AddCue(2));
105 // Expand first range.
106 EXPECT_TRUE(AddCue(3));
108 // Coalesce first and second ranges.
109 EXPECT_FALSE(AddCue(4));
110 EXPECT_EQ(RangeCount(), 1U);
113 TEST_F(TextRangesTest, TestThreeRanges) {
114 // Create a new active range, with t=0.
115 EXPECT_TRUE(AddCue(0));
117 // Add cue to end of existing range.
118 EXPECT_TRUE(AddCue(2));
120 Reset();
122 // Create a new active range, with t=4.
123 EXPECT_TRUE(AddCue(4));
125 // Add a new cue to end of last (active) range.
126 EXPECT_TRUE(AddCue(5));
128 Reset();
130 // Create a new active range, in between the other two.
131 EXPECT_TRUE(AddCue(3));
133 // Coalesce middle and last ranges.
134 EXPECT_FALSE(AddCue(4));
136 Reset();
138 // Make first range active.
139 EXPECT_FALSE(AddCue(0));
140 EXPECT_FALSE(AddCue(2));
142 // Coalesce first and last ranges.
143 EXPECT_FALSE(AddCue(3));
144 EXPECT_EQ(RangeCount(), 1U);
147 } // namespace media