| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/blink/buffered_data_source_host_impl.h" |
| 6 |
| 7 #include "base/bind.h" |
| 5 #include "base/macros.h" | 8 #include "base/macros.h" |
| 6 #include "media/blink/buffered_data_source_host_impl.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 10 |
| 9 namespace media { | 11 namespace media { |
| 10 | 12 |
| 11 class BufferedDataSourceHostImplTest : public testing::Test { | 13 class BufferedDataSourceHostImplTest : public testing::Test { |
| 12 public: | 14 public: |
| 13 BufferedDataSourceHostImplTest() {} | 15 BufferedDataSourceHostImplTest() |
| 16 : host_(base::Bind(&BufferedDataSourceHostImplTest::ProgressCallback, |
| 17 base::Unretained(this))) {} |
| 14 | 18 |
| 15 void Add() { | 19 void Add() { |
| 16 host_.AddBufferedTimeRanges(&ranges_, base::TimeDelta::FromSeconds(10)); | 20 host_.AddBufferedTimeRanges(&ranges_, base::TimeDelta::FromSeconds(10)); |
| 17 } | 21 } |
| 18 | 22 |
| 23 void ProgressCallback() { progress_callback_calls_++; } |
| 24 |
| 19 protected: | 25 protected: |
| 26 int progress_callback_calls_ = 0; |
| 20 BufferedDataSourceHostImpl host_; | 27 BufferedDataSourceHostImpl host_; |
| 21 Ranges<base::TimeDelta> ranges_; | 28 Ranges<base::TimeDelta> ranges_; |
| 22 | 29 |
| 23 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImplTest); | 30 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceHostImplTest); |
| 24 }; | 31 }; |
| 25 | 32 |
| 26 TEST_F(BufferedDataSourceHostImplTest, Empty) { | 33 TEST_F(BufferedDataSourceHostImplTest, Empty) { |
| 27 EXPECT_FALSE(host_.DidLoadingProgress()); | 34 EXPECT_FALSE(host_.DidLoadingProgress()); |
| 28 Add(); | 35 Add(); |
| 29 EXPECT_EQ(0u, ranges_.size()); | 36 EXPECT_EQ(0u, ranges_.size()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 Add(); | 73 Add(); |
| 67 EXPECT_EQ(1u, ranges_.size()); | 74 EXPECT_EQ(1u, ranges_.size()); |
| 68 } | 75 } |
| 69 | 76 |
| 70 TEST_F(BufferedDataSourceHostImplTest, DidLoadingProgress) { | 77 TEST_F(BufferedDataSourceHostImplTest, DidLoadingProgress) { |
| 71 host_.AddBufferedByteRange(10, 20); | 78 host_.AddBufferedByteRange(10, 20); |
| 72 EXPECT_TRUE(host_.DidLoadingProgress()); | 79 EXPECT_TRUE(host_.DidLoadingProgress()); |
| 73 EXPECT_FALSE(host_.DidLoadingProgress()); | 80 EXPECT_FALSE(host_.DidLoadingProgress()); |
| 74 } | 81 } |
| 75 | 82 |
| 83 TEST_F(BufferedDataSourceHostImplTest, CanPlayThrough) { |
| 84 host_.SetTotalBytes(100000); |
| 85 host_.AddBufferedByteRange(0, 10000); |
| 86 host_.AddBufferedByteRange(10000, 20000); |
| 87 host_.AddBufferedByteRange(20000, 30000); |
| 88 host_.AddBufferedByteRange(30000, 40000); |
| 89 host_.AddBufferedByteRange(40000, 50000); |
| 90 host_.AddBufferedByteRange(50000, 60000); |
| 91 host_.AddBufferedByteRange(60000, 70000); |
| 92 host_.AddBufferedByteRange(70000, 80000); |
| 93 host_.AddBufferedByteRange(80000, 90000); |
| 94 EXPECT_EQ(9, progress_callback_calls_); |
| 95 EXPECT_TRUE(host_.CanPlayThrough(base::TimeDelta(), |
| 96 base::TimeDelta::FromSecondsD(1000.0), 1.0)); |
| 97 } |
| 98 |
| 76 } // namespace media | 99 } // namespace media |
| OLD | NEW |