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/blink/buffered_data_source_host_impl.h"
6 #include "testing/gtest/include/gtest/gtest.h"
10 class BufferedDataSourceHostImplTest
: public testing::Test
{
12 BufferedDataSourceHostImplTest() {}
15 host_
.AddBufferedTimeRanges(&ranges_
, base::TimeDelta::FromSeconds(10));
19 BufferedDataSourceHostImpl host_
;
20 Ranges
<base::TimeDelta
> ranges_
;
22 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImplTest
);
25 TEST_F(BufferedDataSourceHostImplTest
, Empty
) {
26 EXPECT_FALSE(host_
.DidLoadingProgress());
28 EXPECT_EQ(0u, ranges_
.size());
31 TEST_F(BufferedDataSourceHostImplTest
, AddBufferedTimeRanges
) {
32 host_
.AddBufferedByteRange(10, 20);
33 host_
.SetTotalBytes(100);
35 EXPECT_EQ(1u, ranges_
.size());
36 EXPECT_EQ(base::TimeDelta::FromSeconds(1), ranges_
.start(0));
37 EXPECT_EQ(base::TimeDelta::FromSeconds(2), ranges_
.end(0));
40 TEST_F(BufferedDataSourceHostImplTest
, AddBufferedTimeRanges_Merges
) {
41 ranges_
.Add(base::TimeDelta::FromSeconds(0), base::TimeDelta::FromSeconds(1));
42 host_
.AddBufferedByteRange(10, 20);
43 host_
.SetTotalBytes(100);
45 EXPECT_EQ(1u, ranges_
.size());
46 EXPECT_EQ(base::TimeDelta::FromSeconds(0), ranges_
.start(0));
47 EXPECT_EQ(base::TimeDelta::FromSeconds(2), ranges_
.end(0));
50 TEST_F(BufferedDataSourceHostImplTest
, AddBufferedTimeRanges_Snaps
) {
51 host_
.AddBufferedByteRange(5, 995);
52 host_
.SetTotalBytes(1000);
54 EXPECT_EQ(1u, ranges_
.size());
55 EXPECT_EQ(base::TimeDelta::FromSeconds(0), ranges_
.start(0));
56 EXPECT_EQ(base::TimeDelta::FromSeconds(10), ranges_
.end(0));
59 TEST_F(BufferedDataSourceHostImplTest
, SetTotalBytes
) {
60 host_
.AddBufferedByteRange(10, 20);
62 EXPECT_EQ(0u, ranges_
.size());
64 host_
.SetTotalBytes(100);
66 EXPECT_EQ(1u, ranges_
.size());
69 TEST_F(BufferedDataSourceHostImplTest
, DidLoadingProgress
) {
70 host_
.AddBufferedByteRange(10, 20);
71 EXPECT_TRUE(host_
.DidLoadingProgress());
72 EXPECT_FALSE(host_
.DidLoadingProgress());