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. 4 5 #include "media/blink/buffered_data_source_host_impl.h" 6 #include "testing/gtest/include/gtest/gtest.h" 7 8 namespace media { 9 10 class BufferedDataSourceHostImplTest : public testing::Test { 11 public: 12 BufferedDataSourceHostImplTest() {} 13 14 void Add() { 15 host_.AddBufferedTimeRanges(&ranges_, base::TimeDelta::FromSeconds(10)); 16 } 17 18 protected: 19 BufferedDataSourceHostImpl host_; 20 Ranges<base::TimeDelta> ranges_; 21 22 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImplTest); 23 }; 24 25 TEST_F(BufferedDataSourceHostImplTest, Empty) { 26 EXPECT_FALSE(host_.DidLoadingProgress()); 27 Add(); 28 EXPECT_EQ(0u, ranges_.size()); 29 } 30 31 TEST_F(BufferedDataSourceHostImplTest, AddBufferedTimeRanges) { 32 host_.AddBufferedByteRange(10, 20); 33 host_.SetTotalBytes(100); 34 Add(); 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)); 38 } 39 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); 44 Add(); 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)); 48 } 49 50 TEST_F(BufferedDataSourceHostImplTest, AddBufferedTimeRanges_Snaps) { 51 host_.AddBufferedByteRange(5, 995); 52 host_.SetTotalBytes(1000); 53 Add(); 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)); 57 } 58 59 TEST_F(BufferedDataSourceHostImplTest, SetTotalBytes) { 60 host_.AddBufferedByteRange(10, 20); 61 Add(); 62 EXPECT_EQ(0u, ranges_.size()); 63 64 host_.SetTotalBytes(100); 65 Add(); 66 EXPECT_EQ(1u, ranges_.size()); 67 } 68 69 TEST_F(BufferedDataSourceHostImplTest, DidLoadingProgress) { 70 host_.AddBufferedByteRange(10, 20); 71 EXPECT_TRUE(host_.DidLoadingProgress()); 72 EXPECT_FALSE(host_.DidLoadingProgress()); 73 } 74 75 } // namespace media 76