Chromium Code Reviews| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #include "media/base/media_log.h" | 9 #include "media/base/media_log.h" |
| 10 #include "media/base/mock_callback.h" | 10 #include "media/base/mock_callback.h" |
| 11 #include "media/base/mock_filter_host.h" | 11 #include "media/base/mock_filter_host.h" |
| 12 #include "media/base/mock_filters.h" | 12 #include "media/base/mock_filters.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 17 #include "webkit/media/buffered_data_source.h" | 17 #include "webkit/media/buffered_data_source.h" |
| 18 #include "webkit/mocks/mock_webframeclient.h" | 18 #include "webkit/mocks/mock_webframeclient.h" |
| 19 #include "webkit/mocks/mock_weburlloader.h" | 19 #include "webkit/mocks/mock_weburlloader.h" |
| 20 | 20 |
| 21 using ::testing::_; | 21 using ::testing::_; |
| 22 using ::testing::Assign; | 22 using ::testing::Assign; |
| 23 using ::testing::AtLeast; | 23 using ::testing::AtLeast; |
| 24 using ::testing::DeleteArg; | |
| 25 using ::testing::DoAll; | 24 using ::testing::DoAll; |
| 26 using ::testing::InSequence; | 25 using ::testing::InSequence; |
| 27 using ::testing::Invoke; | 26 using ::testing::Invoke; |
| 28 using ::testing::InvokeWithoutArgs; | 27 using ::testing::InvokeWithoutArgs; |
| 29 using ::testing::NotNull; | 28 using ::testing::NotNull; |
|
scherkus (not reviewing)
2011/12/01 17:42:18
sanity check: can we remove any more?
Ami GONE FROM CHROMIUM
2011/12/01 18:11:26
Done.
| |
| 30 using ::testing::Return; | 29 using ::testing::Return; |
| 31 using ::testing::ReturnRef; | 30 using ::testing::ReturnRef; |
| 32 using ::testing::SetArgumentPointee; | 31 using ::testing::SetArgumentPointee; |
| 33 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
| 34 using ::testing::NiceMock; | 33 using ::testing::NiceMock; |
| 35 using ::testing::WithArgs; | 34 using ::testing::WithArgs; |
| 36 | 35 |
| 37 using WebKit::WebFrame; | 36 using WebKit::WebFrame; |
| 38 using WebKit::WebString; | 37 using WebKit::WebString; |
| 39 using WebKit::WebURLError; | 38 using WebKit::WebURLError; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource); | 76 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource); |
| 78 }; | 77 }; |
| 79 | 78 |
| 80 class MockBufferedResourceLoader : public BufferedResourceLoader { | 79 class MockBufferedResourceLoader : public BufferedResourceLoader { |
| 81 public: | 80 public: |
| 82 MockBufferedResourceLoader() | 81 MockBufferedResourceLoader() |
| 83 : BufferedResourceLoader(GURL(), 0, 0, kThresholdDefer, | 82 : BufferedResourceLoader(GURL(), 0, 0, kThresholdDefer, |
| 84 0, 0, new media::MediaLog()) { | 83 0, 0, new media::MediaLog()) { |
| 85 } | 84 } |
| 86 | 85 |
| 87 MOCK_METHOD3(Start, void(net::OldCompletionCallback* read_callback, | 86 MOCK_METHOD3(Start, void(const net::CompletionCallback& read_callback, |
| 88 const base::Closure& network_callback, | 87 const base::Closure& network_callback, |
| 89 WebFrame* frame)); | 88 WebFrame* frame)); |
| 90 MOCK_METHOD0(Stop, void()); | 89 MOCK_METHOD0(Stop, void()); |
| 91 MOCK_METHOD4(Read, void(int64 position, int read_size, uint8* buffer, | 90 MOCK_METHOD4(Read, void(int64 position, int read_size, uint8* buffer, |
| 92 net::OldCompletionCallback* callback)); | 91 const net::CompletionCallback& callback)); |
| 93 MOCK_METHOD0(content_length, int64()); | 92 MOCK_METHOD0(content_length, int64()); |
| 94 MOCK_METHOD0(instance_size, int64()); | 93 MOCK_METHOD0(instance_size, int64()); |
| 95 MOCK_METHOD0(range_supported, bool()); | 94 MOCK_METHOD0(range_supported, bool()); |
| 96 MOCK_METHOD0(network_activity, bool()); | 95 MOCK_METHOD0(network_activity, bool()); |
| 97 MOCK_METHOD0(url, const GURL&()); | 96 MOCK_METHOD0(url, const GURL&()); |
| 98 MOCK_METHOD0(GetBufferedFirstBytePosition, int64()); | 97 MOCK_METHOD0(GetBufferedFirstBytePosition, int64()); |
| 99 MOCK_METHOD0(GetBufferedLastBytePosition, int64()); | 98 MOCK_METHOD0(GetBufferedLastBytePosition, int64()); |
| 100 | 99 |
| 101 protected: | 100 protected: |
| 102 ~MockBufferedResourceLoader() {} | 101 ~MockBufferedResourceLoader() {} |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 117 } | 116 } |
| 118 | 117 |
| 119 virtual ~BufferedDataSourceTest() { | 118 virtual ~BufferedDataSourceTest() { |
| 120 view_->close(); | 119 view_->close(); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void ExpectCreateAndStartResourceLoader(int start_error) { | 122 void ExpectCreateAndStartResourceLoader(int start_error) { |
| 124 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) | 123 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) |
| 125 .WillOnce(Return(loader_.get())); | 124 .WillOnce(Return(loader_.get())); |
| 126 | 125 |
| 127 EXPECT_CALL(*loader_, Start(NotNull(), _, NotNull())) | 126 EXPECT_CALL(*loader_, Start(_, _, NotNull())) |
| 128 .WillOnce( | 127 .WillOnce( |
| 129 DoAll(Assign(&error_, start_error), | 128 DoAll(Assign(&error_, start_error), |
| 130 Invoke(this, | 129 Invoke(this, |
| 131 &BufferedDataSourceTest::InvokeStartCallback))); | 130 &BufferedDataSourceTest::InvokeStartCallback))); |
| 132 } | 131 } |
| 133 | 132 |
| 134 void InitializeDataSource(const char* url, int error, | 133 void InitializeDataSource(const char* url, int error, |
| 135 bool partial_response, int64 instance_size, | 134 bool partial_response, int64 instance_size, |
| 136 NetworkState networkState) { | 135 NetworkState networkState) { |
| 137 // Saves the url first. | 136 // Saves the url first. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 166 | 165 |
| 167 // Create and start. Make sure Start() is called on the new loader. | 166 // Create and start. Make sure Start() is called on the new loader. |
| 168 ExpectCreateAndStartResourceLoader(net::OK); | 167 ExpectCreateAndStartResourceLoader(net::OK); |
| 169 | 168 |
| 170 // Update initialization variable since we know the second loader will | 169 // Update initialization variable since we know the second loader will |
| 171 // return OK. | 170 // return OK. |
| 172 initialized_ok = true; | 171 initialized_ok = true; |
| 173 } | 172 } |
| 174 } | 173 } |
| 175 | 174 |
| 176 // Attach a static function that deletes the memory referred by the | |
| 177 // "callback" parameter. | |
| 178 ON_CALL(*loader_, Read(_, _, _ , _)) | |
| 179 .WillByDefault(DeleteArg<3>()); | |
| 180 | |
| 181 ON_CALL(*loader_, instance_size()) | 175 ON_CALL(*loader_, instance_size()) |
| 182 .WillByDefault(Return(instance_size)); | 176 .WillByDefault(Return(instance_size)); |
| 183 | 177 |
| 184 // range_supported() return true if we expect to get a partial response. | 178 // range_supported() return true if we expect to get a partial response. |
| 185 ON_CALL(*loader_, range_supported()) | 179 ON_CALL(*loader_, range_supported()) |
| 186 .WillByDefault(Return(partial_response)); | 180 .WillByDefault(Return(partial_response)); |
| 187 | 181 |
| 188 ON_CALL(*loader_, url()) | 182 ON_CALL(*loader_, url()) |
| 189 .WillByDefault(ReturnRef(gurl_)); | 183 .WillByDefault(ReturnRef(gurl_)); |
| 190 media::PipelineStatus expected_init_status = media::PIPELINE_OK; | 184 media::PipelineStatus expected_init_status = media::PIPELINE_OK; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 if (loader_) { | 223 if (loader_) { |
| 230 InSequence s; | 224 InSequence s; |
| 231 EXPECT_CALL(*loader_, Stop()); | 225 EXPECT_CALL(*loader_, Stop()); |
| 232 } | 226 } |
| 233 | 227 |
| 234 data_source_->Stop(media::NewExpectedClosure()); | 228 data_source_->Stop(media::NewExpectedClosure()); |
| 235 message_loop_->RunAllPending(); | 229 message_loop_->RunAllPending(); |
| 236 } | 230 } |
| 237 | 231 |
| 238 void InvokeStartCallback( | 232 void InvokeStartCallback( |
| 239 net::OldCompletionCallback* callback, | 233 const net::CompletionCallback& callback, |
| 240 const base::Closure& network_callback, | 234 const base::Closure& network_callback, |
|
scherkus (not reviewing)
2011/12/01 17:42:18
net callback -> callback
closure -> net callback
Ami GONE FROM CHROMIUM
2011/12/01 18:11:26
Done.
| |
| 241 WebFrame* frame) { | 235 WebFrame* frame) { |
| 242 callback->RunWithParams(Tuple1<int>(error_)); | 236 callback.Run(error_); |
| 243 delete callback; | |
| 244 // TODO(hclam): Save network_callback. | 237 // TODO(hclam): Save network_callback. |
| 245 } | 238 } |
| 246 | 239 |
| 247 void InvokeReadCallback(int64 position, int size, uint8* buffer, | 240 void InvokeReadCallback(int64 position, int size, uint8* buffer, |
| 248 net::OldCompletionCallback* callback) { | 241 const net::CompletionCallback& callback) { |
| 249 if (error_ > 0) | 242 if (error_ > 0) |
| 250 memcpy(buffer, data_ + static_cast<int>(position), error_); | 243 memcpy(buffer, data_ + static_cast<int>(position), error_); |
| 251 callback->RunWithParams(Tuple1<int>(error_)); | 244 callback.Run(error_); |
| 252 delete callback; | |
| 253 } | 245 } |
| 254 | 246 |
| 255 void ReadDataSourceHit(int64 position, int size, int read_size) { | 247 void ReadDataSourceHit(int64 position, int size, int read_size) { |
| 256 EXPECT_TRUE(loader_); | 248 EXPECT_TRUE(loader_); |
| 257 | 249 |
| 258 InSequence s; | 250 InSequence s; |
| 259 // Expect the read is delegated to the resource loader. | 251 // Expect the read is delegated to the resource loader. |
| 260 EXPECT_CALL(*loader_, Read(position, size, NotNull(), NotNull())) | 252 EXPECT_CALL(*loader_, Read(position, size, NotNull(), _)) |
| 261 .WillOnce(DoAll(Assign(&error_, read_size), | 253 .WillOnce(DoAll(Assign(&error_, read_size), |
| 262 Invoke(this, | 254 Invoke(this, |
| 263 &BufferedDataSourceTest::InvokeReadCallback))); | 255 &BufferedDataSourceTest::InvokeReadCallback))); |
| 264 | 256 |
| 265 // The read has succeeded, so read callback will be called. | 257 // The read has succeeded, so read callback will be called. |
| 266 EXPECT_CALL(*this, ReadCallback(read_size)); | 258 EXPECT_CALL(*this, ReadCallback(read_size)); |
| 267 | 259 |
| 268 data_source_->Read( | 260 data_source_->Read( |
| 269 position, size, buffer_, | 261 position, size, buffer_, |
| 270 base::Bind(&BufferedDataSourceTest::ReadCallback, | 262 base::Bind(&BufferedDataSourceTest::ReadCallback, |
| 271 base::Unretained(this))); | 263 base::Unretained(this))); |
| 272 message_loop_->RunAllPending(); | 264 message_loop_->RunAllPending(); |
| 273 | 265 |
| 274 // Make sure data is correct. | 266 // Make sure data is correct. |
| 275 EXPECT_EQ(0, | 267 EXPECT_EQ(0, |
| 276 memcmp(buffer_, data_ + static_cast<int>(position), read_size)); | 268 memcmp(buffer_, data_ + static_cast<int>(position), read_size)); |
| 277 } | 269 } |
| 278 | 270 |
| 279 void ReadDataSourceHang(int64 position, int size) { | 271 void ReadDataSourceHang(int64 position, int size) { |
| 280 EXPECT_TRUE(loader_); | 272 EXPECT_TRUE(loader_); |
| 281 | 273 |
| 282 // Expect a call to read, but the call never returns. | 274 // Expect a call to read, but the call never returns. |
| 283 EXPECT_CALL(*loader_, Read(position, size, NotNull(), NotNull())); | 275 EXPECT_CALL(*loader_, Read(position, size, NotNull(), _)); |
| 284 data_source_->Read( | 276 data_source_->Read( |
| 285 position, size, buffer_, | 277 position, size, buffer_, |
| 286 base::Bind(&BufferedDataSourceTest::ReadCallback, | 278 base::Bind(&BufferedDataSourceTest::ReadCallback, |
| 287 base::Unretained(this))); | 279 base::Unretained(this))); |
| 288 message_loop_->RunAllPending(); | 280 message_loop_->RunAllPending(); |
| 289 | 281 |
| 290 // Now expect the read to return after aborting the data source. | 282 // Now expect the read to return after aborting the data source. |
| 291 EXPECT_CALL(*this, ReadCallback(_)); | 283 EXPECT_CALL(*this, ReadCallback(_)); |
| 292 EXPECT_CALL(*loader_, Stop()); | 284 EXPECT_CALL(*loader_, Stop()); |
| 293 data_source_->Abort(); | 285 data_source_->Abort(); |
| 294 message_loop_->RunAllPending(); | 286 message_loop_->RunAllPending(); |
| 295 | 287 |
| 296 // The loader has now been stopped. Set this to null so that when the | 288 // The loader has now been stopped. Set this to null so that when the |
| 297 // DataSource is stopped, it does not expect a call to stop the loader. | 289 // DataSource is stopped, it does not expect a call to stop the loader. |
| 298 loader_ = NULL; | 290 loader_ = NULL; |
| 299 } | 291 } |
| 300 | 292 |
| 301 void ReadDataSourceMiss(int64 position, int size, int start_error) { | 293 void ReadDataSourceMiss(int64 position, int size, int start_error) { |
| 302 EXPECT_TRUE(loader_); | 294 EXPECT_TRUE(loader_); |
| 303 | 295 |
| 304 // 1. Reply with a cache miss for the read. | 296 // 1. Reply with a cache miss for the read. |
| 305 { | 297 { |
| 306 InSequence s; | 298 InSequence s; |
| 307 EXPECT_CALL(*loader_, Read(position, size, NotNull(), NotNull())) | 299 EXPECT_CALL(*loader_, Read(position, size, NotNull(), _)) |
| 308 .WillOnce(DoAll(Assign(&error_, net::ERR_CACHE_MISS), | 300 .WillOnce(DoAll(Assign(&error_, net::ERR_CACHE_MISS), |
| 309 Invoke(this, | 301 Invoke(this, |
| 310 &BufferedDataSourceTest::InvokeReadCallback))); | 302 &BufferedDataSourceTest::InvokeReadCallback))); |
| 311 EXPECT_CALL(*loader_, Stop()); | 303 EXPECT_CALL(*loader_, Stop()); |
| 312 } | 304 } |
| 313 | 305 |
| 314 // 2. Then the current loader will be stop and destroyed. | 306 // 2. Then the current loader will be stop and destroyed. |
| 315 NiceMock<MockBufferedResourceLoader> *new_loader = | 307 NiceMock<MockBufferedResourceLoader> *new_loader = |
| 316 new NiceMock<MockBufferedResourceLoader>(); | 308 new NiceMock<MockBufferedResourceLoader>(); |
| 317 EXPECT_CALL(*data_source_, CreateResourceLoader(position, -1)) | 309 EXPECT_CALL(*data_source_, CreateResourceLoader(position, -1)) |
| 318 .WillOnce(Return(new_loader)); | 310 .WillOnce(Return(new_loader)); |
| 319 | 311 |
| 320 // 3. Then the new loader will be started. | 312 // 3. Then the new loader will be started. |
| 321 EXPECT_CALL(*new_loader, Start(NotNull(), _, NotNull())) | 313 EXPECT_CALL(*new_loader, Start(_, _, NotNull())) |
| 322 .WillOnce(DoAll(Assign(&error_, start_error), | 314 .WillOnce(DoAll(Assign(&error_, start_error), |
| 323 Invoke(this, | 315 Invoke(this, |
| 324 &BufferedDataSourceTest::InvokeStartCallback))); | 316 &BufferedDataSourceTest::InvokeStartCallback))); |
| 325 | 317 |
| 326 if (start_error == net::OK) { | 318 if (start_error == net::OK) { |
| 327 EXPECT_CALL(*new_loader, range_supported()) | 319 EXPECT_CALL(*new_loader, range_supported()) |
| 328 .WillRepeatedly(Return(loader_->range_supported())); | 320 .WillRepeatedly(Return(loader_->range_supported())); |
| 329 | 321 |
| 330 // 4a. Then again a read request is made to the new loader. | 322 // 4a. Then again a read request is made to the new loader. |
| 331 EXPECT_CALL(*new_loader, Read(position, size, NotNull(), NotNull())) | 323 EXPECT_CALL(*new_loader, Read(position, size, NotNull(), _)) |
| 332 .WillOnce(DoAll(Assign(&error_, size), | 324 .WillOnce(DoAll(Assign(&error_, size), |
| 333 Invoke(this, | 325 Invoke(this, |
| 334 &BufferedDataSourceTest::InvokeReadCallback))); | 326 &BufferedDataSourceTest::InvokeReadCallback))); |
| 335 | 327 |
| 336 EXPECT_CALL(*this, ReadCallback(size)); | 328 EXPECT_CALL(*this, ReadCallback(size)); |
| 337 } else { | 329 } else { |
| 338 // 4b. The read callback is called with an error because Start() on the | 330 // 4b. The read callback is called with an error because Start() on the |
| 339 // new loader returned an error. | 331 // new loader returned an error. |
| 340 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 332 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
| 341 } | 333 } |
| 342 | 334 |
| 343 data_source_->Read( | 335 data_source_->Read( |
| 344 position, size, buffer_, | 336 position, size, buffer_, |
| 345 base::Bind(&BufferedDataSourceTest::ReadCallback, | 337 base::Bind(&BufferedDataSourceTest::ReadCallback, |
| 346 base::Unretained(this))); | 338 base::Unretained(this))); |
| 347 message_loop_->RunAllPending(); | 339 message_loop_->RunAllPending(); |
| 348 | 340 |
| 349 // Make sure data is correct. | 341 // Make sure data is correct. |
| 350 if (start_error == net::OK) | 342 if (start_error == net::OK) |
| 351 EXPECT_EQ(0, memcmp(buffer_, data_ + static_cast<int>(position), size)); | 343 EXPECT_EQ(0, memcmp(buffer_, data_ + static_cast<int>(position), size)); |
| 352 | 344 |
| 353 loader_ = new_loader; | 345 loader_ = new_loader; |
| 354 } | 346 } |
| 355 | 347 |
| 356 void ReadDataSourceFailed(int64 position, int size, int error) { | 348 void ReadDataSourceFailed(int64 position, int size, int error) { |
| 357 EXPECT_TRUE(loader_); | 349 EXPECT_TRUE(loader_); |
| 358 | 350 |
| 359 // 1. Expect the read is delegated to the resource loader. | 351 // 1. Expect the read is delegated to the resource loader. |
| 360 EXPECT_CALL(*loader_, Read(position, size, NotNull(), NotNull())) | 352 EXPECT_CALL(*loader_, Read(position, size, NotNull(), _)) |
| 361 .WillOnce(DoAll(Assign(&error_, error), | 353 .WillOnce(DoAll(Assign(&error_, error), |
| 362 Invoke(this, | 354 Invoke(this, |
| 363 &BufferedDataSourceTest::InvokeReadCallback))); | 355 &BufferedDataSourceTest::InvokeReadCallback))); |
| 364 | 356 |
| 365 // 2. Host will then receive an error. | 357 // 2. Host will then receive an error. |
| 366 EXPECT_CALL(*loader_, Stop()); | 358 EXPECT_CALL(*loader_, Stop()); |
| 367 | 359 |
| 368 // 3. The read has failed, so read callback will be called. | 360 // 3. The read has failed, so read callback will be called. |
| 369 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 361 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
| 370 | 362 |
| 371 data_source_->Read( | 363 data_source_->Read( |
| 372 position, size, buffer_, | 364 position, size, buffer_, |
| 373 base::Bind(&BufferedDataSourceTest::ReadCallback, | 365 base::Bind(&BufferedDataSourceTest::ReadCallback, |
| 374 base::Unretained(this))); | 366 base::Unretained(this))); |
| 375 | 367 |
| 376 message_loop_->RunAllPending(); | 368 message_loop_->RunAllPending(); |
| 377 } | 369 } |
| 378 | 370 |
| 379 BufferedResourceLoader* InvokeCacheMissCreateResourceLoader(int64 start, | 371 BufferedResourceLoader* InvokeCacheMissCreateResourceLoader(int64 start, |
| 380 int64 end) { | 372 int64 end) { |
| 381 NiceMock<MockBufferedResourceLoader>* new_loader = | 373 NiceMock<MockBufferedResourceLoader>* new_loader = |
| 382 new NiceMock<MockBufferedResourceLoader>(); | 374 new NiceMock<MockBufferedResourceLoader>(); |
| 383 | 375 |
| 384 EXPECT_CALL(*new_loader, Start(NotNull(), _, NotNull())) | 376 EXPECT_CALL(*new_loader, Start(_, _, NotNull())) |
| 385 .WillOnce(DoAll(Assign(&error_, net::OK), | 377 .WillOnce(DoAll(Assign(&error_, net::OK), |
| 386 Invoke(this, | 378 Invoke(this, |
| 387 &BufferedDataSourceTest::InvokeStartCallback))); | 379 &BufferedDataSourceTest::InvokeStartCallback))); |
| 388 | 380 |
| 389 EXPECT_CALL(*new_loader, range_supported()) | 381 EXPECT_CALL(*new_loader, range_supported()) |
| 390 .WillRepeatedly(Return(loader_->range_supported())); | 382 .WillRepeatedly(Return(loader_->range_supported())); |
| 391 | 383 |
| 392 int error = net::ERR_FAILED; | 384 int error = net::ERR_FAILED; |
| 393 if (cache_miss_count_ < kMaxCacheMissesBeforeFailTest) { | 385 if (cache_miss_count_ < kMaxCacheMissesBeforeFailTest) { |
| 394 cache_miss_count_++; | 386 cache_miss_count_++; |
| 395 error = net::ERR_CACHE_MISS; | 387 error = net::ERR_CACHE_MISS; |
| 396 } | 388 } |
| 397 | 389 |
| 398 EXPECT_CALL(*new_loader, Read(start, _, NotNull(), NotNull())) | 390 EXPECT_CALL(*new_loader, Read(start, _, NotNull(), _)) |
| 399 .WillOnce(DoAll(Assign(&error_, error), | 391 .WillOnce(DoAll(Assign(&error_, error), |
| 400 Invoke(this, | 392 Invoke(this, |
| 401 &BufferedDataSourceTest::InvokeReadCallback))); | 393 &BufferedDataSourceTest::InvokeReadCallback))); |
| 402 | 394 |
| 403 loader_ = new_loader; | 395 loader_ = new_loader; |
| 404 return new_loader; | 396 return new_loader; |
| 405 } | 397 } |
| 406 | 398 |
| 407 void ReadDataSourceAlwaysCacheMiss(int64 position, int size) { | 399 void ReadDataSourceAlwaysCacheMiss(int64 position, int size) { |
| 408 cache_miss_count_ = 0; | 400 cache_miss_count_ = 0; |
| 409 | 401 |
| 410 EXPECT_CALL(*data_source_, CreateResourceLoader(position, -1)) | 402 EXPECT_CALL(*data_source_, CreateResourceLoader(position, -1)) |
| 411 .WillRepeatedly(Invoke( | 403 .WillRepeatedly(Invoke( |
| 412 this, | 404 this, |
| 413 &BufferedDataSourceTest::InvokeCacheMissCreateResourceLoader)); | 405 &BufferedDataSourceTest::InvokeCacheMissCreateResourceLoader)); |
| 414 | 406 |
| 415 EXPECT_CALL(*loader_, Read(position, size, NotNull(), NotNull())) | 407 EXPECT_CALL(*loader_, Read(position, size, NotNull(), _)) |
| 416 .WillOnce(DoAll(Assign(&error_, net::ERR_CACHE_MISS), | 408 .WillOnce(DoAll(Assign(&error_, net::ERR_CACHE_MISS), |
| 417 Invoke(this, | 409 Invoke(this, |
| 418 &BufferedDataSourceTest::InvokeReadCallback))); | 410 &BufferedDataSourceTest::InvokeReadCallback))); |
| 419 | 411 |
| 420 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 412 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
| 421 | 413 |
| 422 data_source_->Read( | 414 data_source_->Read( |
| 423 position, size, buffer_, | 415 position, size, buffer_, |
| 424 base::Bind(&BufferedDataSourceTest::ReadCallback, | 416 base::Bind(&BufferedDataSourceTest::ReadCallback, |
| 425 base::Unretained(this))); | 417 base::Unretained(this))); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 } | 544 } |
| 553 | 545 |
| 554 TEST_F(BufferedDataSourceTest, AbortDuringPendingRead) { | 546 TEST_F(BufferedDataSourceTest, AbortDuringPendingRead) { |
| 555 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); | 547 InitializeDataSource(kFileUrl, net::OK, true, 1024, LOADED); |
| 556 | 548 |
| 557 // Setup a way to verify that Read() is not called on the loader. | 549 // Setup a way to verify that Read() is not called on the loader. |
| 558 // We are doing this to make sure that the ReadTask() is still on | 550 // We are doing this to make sure that the ReadTask() is still on |
| 559 // the message loop queue when Abort() is called. | 551 // the message loop queue when Abort() is called. |
| 560 bool read_called = false; | 552 bool read_called = false; |
| 561 ON_CALL(*loader_, Read(_, _, _ , _)) | 553 ON_CALL(*loader_, Read(_, _, _ , _)) |
| 562 .WillByDefault(DoAll(Assign(&read_called, true), | 554 .WillByDefault(Assign(&read_called, true)); |
| 563 DeleteArg<3>())); | |
| 564 | 555 |
| 565 // Initiate a Read() on the data source, but don't allow the | 556 // Initiate a Read() on the data source, but don't allow the |
| 566 // message loop to run. | 557 // message loop to run. |
| 567 data_source_->Read( | 558 data_source_->Read( |
| 568 0, 10, buffer_, | 559 0, 10, buffer_, |
| 569 base::Bind(&BufferedDataSourceTest::ReadCallback, | 560 base::Bind(&BufferedDataSourceTest::ReadCallback, |
| 570 base::Unretained(static_cast<BufferedDataSourceTest*>(this)))); | 561 base::Unretained(static_cast<BufferedDataSourceTest*>(this)))); |
| 571 | 562 |
| 572 // Call Abort() with the read pending. | 563 // Call Abort() with the read pending. |
| 573 EXPECT_CALL(*this, ReadCallback(-1)); | 564 EXPECT_CALL(*this, ReadCallback(-1)); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 message_loop_->RunAllPending(); | 774 message_loop_->RunAllPending(); |
| 784 | 775 |
| 785 // Verify loader changed but still has same bitrate. | 776 // Verify loader changed but still has same bitrate. |
| 786 EXPECT_NE(old_loader, data_source_->loader().get()); | 777 EXPECT_NE(old_loader, data_source_->loader().get()); |
| 787 EXPECT_EQ(2.0f, loader_playback_rate()); | 778 EXPECT_EQ(2.0f, loader_playback_rate()); |
| 788 | 779 |
| 789 StopDataSource(); | 780 StopDataSource(); |
| 790 } | 781 } |
| 791 | 782 |
| 792 } // namespace webkit_media | 783 } // namespace webkit_media |
| OLD | NEW |