| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/download_rate_monitor.h" | 5 #include "media/base/download_rate_monitor.h" |
| 6 | 6 |
| 7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 using ::testing::Mock; | 10 using ::testing::Mock; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 static const int media_bitrate = 1024 * 1024 * 8; | 113 static const int media_bitrate = 1024 * 1024 * 8; |
| 114 | 114 |
| 115 // Simulate downloading at half the media's bitrate. | 115 // Simulate downloading at half the media's bitrate. |
| 116 EXPECT_CALL(*this, CanPlayThrough()) | 116 EXPECT_CALL(*this, CanPlayThrough()) |
| 117 .Times(0); | 117 .Times(0); |
| 118 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, | 118 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, |
| 119 base::Unretained(this)), media_bitrate); | 119 base::Unretained(this)), media_bitrate); |
| 120 SimulateNetwork(1, 0, media_bitrate / 8 / 2, 1000, 10); | 120 SimulateNetwork(1, 0, media_bitrate / 8 / 2, 1000, 10); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TEST_F(DownloadRateMonitorTest, MediaIsLoaded) { | 123 TEST_F(DownloadRateMonitorTest, MediaSourceIsLocal) { |
| 124 static const int media_bitrate = 1024 * 1024 * 8; | 124 static const int media_bitrate = 1024 * 1024 * 8; |
| 125 | 125 |
| 126 monitor_.set_loaded(true); | 126 monitor_.set_local_source(true); |
| 127 | 127 |
| 128 // Simulate no data downloaded (source is already loaded). | 128 // Simulate no data downloaded. |
| 129 EXPECT_CALL(*this, CanPlayThrough()); | 129 EXPECT_CALL(*this, CanPlayThrough()); |
| 130 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, | 130 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, |
| 131 base::Unretained(this)), media_bitrate); | 131 base::Unretained(this)), media_bitrate); |
| 132 SimulateNetwork(1, 0, 0, 1000, 10); | 132 } |
| 133 |
| 134 TEST_F(DownloadRateMonitorTest, MediaSourceIsStreaming) { |
| 135 static const int media_bitrate = 1024 * 1024 * 8; |
| 136 |
| 137 monitor_.set_streaming(true); |
| 138 |
| 139 // Simulate downloading at the media's bitrate while streaming. |
| 140 EXPECT_CALL(*this, CanPlayThrough()); |
| 141 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, |
| 142 base::Unretained(this)), media_bitrate); |
| 143 SimulateNetwork(1, 0, media_bitrate / 8, 1000, 10); |
| 133 } | 144 } |
| 134 | 145 |
| 135 TEST_F(DownloadRateMonitorTest, VeryFastDownloadRate) { | 146 TEST_F(DownloadRateMonitorTest, VeryFastDownloadRate) { |
| 136 static const int media_bitrate = 1024 * 1024 * 8; | 147 static const int media_bitrate = 1024 * 1024 * 8; |
| 137 | 148 |
| 138 // Simulate downloading half the video very quickly in one chunk. | 149 // Simulate downloading half the video very quickly in one chunk. |
| 139 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, | 150 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, |
| 140 base::Unretained(this)), media_bitrate); | 151 base::Unretained(this)), media_bitrate); |
| 141 EXPECT_CALL(*this, CanPlayThrough()); | 152 EXPECT_CALL(*this, CanPlayThrough()); |
| 142 SimulateNetwork(1, 0, kMediaSizeInBytes / 2, 10, 1); | 153 SimulateNetwork(1, 0, kMediaSizeInBytes / 2, 10, 1); |
| 143 } | 154 } |
| 144 | 155 |
| 145 TEST_F(DownloadRateMonitorTest, DownloadEntireVideo) { | 156 TEST_F(DownloadRateMonitorTest, DownloadEntireVideo) { |
| 146 static const int seconds_of_data = 20; | 157 static const int seconds_of_data = 20; |
| 147 static const int media_bitrate = kMediaSizeInBytes * 8 / seconds_of_data; | 158 static const int media_bitrate = kMediaSizeInBytes * 8 / seconds_of_data; |
| 148 | 159 |
| 149 // Simulate downloading entire video at half the bitrate of the video. | 160 // Simulate downloading entire video at half the bitrate of the video. |
| 150 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, | 161 monitor_.Start(base::Bind(&DownloadRateMonitorTest::CanPlayThrough, |
| 151 base::Unretained(this)), media_bitrate); | 162 base::Unretained(this)), media_bitrate); |
| 152 EXPECT_CALL(*this, CanPlayThrough()); | 163 EXPECT_CALL(*this, CanPlayThrough()); |
| 153 SimulateNetwork(1, 0, media_bitrate / 8 / 2, 1000, seconds_of_data * 2); | 164 SimulateNetwork(1, 0, media_bitrate / 8 / 2, 1000, seconds_of_data * 2); |
| 154 } | 165 } |
| 155 | 166 |
| 156 } // namespace media | 167 } // namespace media |
| OLD | NEW |