| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 static const int kMinBufferCapacity = 2 * 1024 * 1024; | 275 static const int kMinBufferCapacity = 2 * 1024 * 1024; |
| 276 EXPECT_GE(loader_->buffer_.forward_capacity(), kMinBufferCapacity); | 276 EXPECT_GE(loader_->buffer_.forward_capacity(), kMinBufferCapacity); |
| 277 EXPECT_GE(loader_->buffer_.backward_capacity(), kMinBufferCapacity); | 277 EXPECT_GE(loader_->buffer_.backward_capacity(), kMinBufferCapacity); |
| 278 | 278 |
| 279 // Corresponds to value defined in buffered_resource_loader.cc. | 279 // Corresponds to value defined in buffered_resource_loader.cc. |
| 280 static const int kMaxBufferCapacity = 20 * 1024 * 1024; | 280 static const int kMaxBufferCapacity = 20 * 1024 * 1024; |
| 281 EXPECT_LE(loader_->buffer_.forward_capacity(), kMaxBufferCapacity); | 281 EXPECT_LE(loader_->buffer_.forward_capacity(), kMaxBufferCapacity); |
| 282 EXPECT_LE(loader_->buffer_.backward_capacity(), kMaxBufferCapacity); | 282 EXPECT_LE(loader_->buffer_.backward_capacity(), kMaxBufferCapacity); |
| 283 } | 283 } |
| 284 | 284 |
| 285 bool HasActiveLoader() { return loader_->active_loader_; } |
| 286 |
| 285 MOCK_METHOD1(StartCallback, void(BufferedResourceLoader::Status)); | 287 MOCK_METHOD1(StartCallback, void(BufferedResourceLoader::Status)); |
| 286 MOCK_METHOD2(ReadCallback, void(BufferedResourceLoader::Status, int)); | 288 MOCK_METHOD2(ReadCallback, void(BufferedResourceLoader::Status, int)); |
| 287 MOCK_METHOD1(LoadingCallback, void(BufferedResourceLoader::LoadingState)); | 289 MOCK_METHOD1(LoadingCallback, void(BufferedResourceLoader::LoadingState)); |
| 288 MOCK_METHOD1(ProgressCallback, void(int64)); | 290 MOCK_METHOD1(ProgressCallback, void(int64)); |
| 289 | 291 |
| 290 protected: | 292 protected: |
| 291 GURL gurl_; | 293 GURL gurl_; |
| 292 int64 first_position_; | 294 int64 first_position_; |
| 293 int64 last_position_; | 295 int64 last_position_; |
| 294 | 296 |
| (...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 ExpectContentRangeFailure("bytes -300/400"); | 1123 ExpectContentRangeFailure("bytes -300/400"); |
| 1122 ExpectContentRangeFailure("bytes 20-10/400"); | 1124 ExpectContentRangeFailure("bytes 20-10/400"); |
| 1123 | 1125 |
| 1124 ExpectContentRangeSuccess("bytes 0-499/500", 0, 499, 500); | 1126 ExpectContentRangeSuccess("bytes 0-499/500", 0, 499, 500); |
| 1125 ExpectContentRangeSuccess("bytes 0-0/500", 0, 0, 500); | 1127 ExpectContentRangeSuccess("bytes 0-0/500", 0, 0, 500); |
| 1126 ExpectContentRangeSuccess("bytes 10-11/50", 10, 11, 50); | 1128 ExpectContentRangeSuccess("bytes 10-11/50", 10, 11, 50); |
| 1127 ExpectContentRangeSuccess("bytes 10-11/*", 10, 11, | 1129 ExpectContentRangeSuccess("bytes 10-11/*", 10, 11, |
| 1128 kPositionNotSpecified); | 1130 kPositionNotSpecified); |
| 1129 } | 1131 } |
| 1130 | 1132 |
| 1133 // Tests the data buffering logic of ReadThenDefer strategy. |
| 1134 TEST_F(BufferedResourceLoaderTest, CancelAfterDeferral) { |
| 1135 Initialize(kHttpUrl, 10, 99); |
| 1136 SetLoaderBuffer(10, 20); |
| 1137 loader_->UpdateDeferStrategy(BufferedResourceLoader::kReadThenDefer); |
| 1138 loader_->CancelUponDeferral(); |
| 1139 Start(); |
| 1140 PartialResponse(10, 99, 100); |
| 1141 |
| 1142 uint8 buffer[10]; |
| 1143 |
| 1144 // Make an outstanding read request. |
| 1145 ReadLoader(10, 10, buffer); |
| 1146 |
| 1147 // Receive almost enough data to cover, shouldn't defer. |
| 1148 WriteLoader(10, 9); |
| 1149 EXPECT_TRUE(HasActiveLoader()); |
| 1150 |
| 1151 // As soon as we have received enough data to fulfill the read, defer. |
| 1152 EXPECT_CALL(*this, LoadingCallback(BufferedResourceLoader::kLoadingDeferred)); |
| 1153 EXPECT_CALL(*this, ReadCallback(BufferedResourceLoader::kOk, 10)); |
| 1154 WriteLoader(19, 1); |
| 1155 VerifyBuffer(buffer, 10, 10); |
| 1156 EXPECT_FALSE(HasActiveLoader()); |
| 1157 } |
| 1158 |
| 1131 } // namespace media | 1159 } // namespace media |
| OLD | NEW |