| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 } | 315 } |
| 316 | 316 |
| 317 void FinishLoading() { | 317 void FinishLoading() { |
| 318 EXPECT_TRUE(url_loader()); | 318 EXPECT_TRUE(url_loader()); |
| 319 if (!url_loader()) | 319 if (!url_loader()) |
| 320 return; | 320 return; |
| 321 data_provider()->didFinishLoading(url_loader(), 0, -1); | 321 data_provider()->didFinishLoading(url_loader(), 0, -1); |
| 322 message_loop_.RunUntilIdle(); | 322 message_loop_.RunUntilIdle(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void FailLoading() { |
| 326 data_provider()->didFail(url_loader(), |
| 327 response_generator_->GenerateError()); |
| 328 message_loop_.RunUntilIdle(); |
| 329 } |
| 330 |
| 325 void Restart() { | 331 void Restart() { |
| 326 EXPECT_TRUE(data_provider()); | 332 EXPECT_TRUE(data_provider()); |
| 327 EXPECT_FALSE(active_loader_allownull()); | 333 EXPECT_FALSE(active_loader_allownull()); |
| 328 if (!data_provider()) | 334 if (!data_provider()) |
| 329 return; | 335 return; |
| 330 data_provider()->Start(); | 336 data_provider()->Start(); |
| 331 } | 337 } |
| 332 | 338 |
| 333 MOCK_METHOD1(ReadCallback, void(int size)); | 339 MOCK_METHOD1(ReadCallback, void(int size)); |
| 334 | 340 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 EXPECT_TRUE(loading()); | 792 EXPECT_TRUE(loading()); |
| 787 Stop(); | 793 Stop(); |
| 788 } | 794 } |
| 789 | 795 |
| 790 TEST_F(MultibufferDataSourceTest, Http_TooManyRetries) { | 796 TEST_F(MultibufferDataSourceTest, Http_TooManyRetries) { |
| 791 InitializeWith206Response(); | 797 InitializeWith206Response(); |
| 792 | 798 |
| 793 // Make sure there's a pending read -- we'll expect it to error. | 799 // Make sure there's a pending read -- we'll expect it to error. |
| 794 ReadAt(kDataSize); | 800 ReadAt(kDataSize); |
| 795 | 801 |
| 796 // It'll try three times. | 802 for (int i = 0; i < ResourceMultiBufferDataProvider::kMaxRetries; i++) { |
| 797 FinishLoading(); | 803 FailLoading(); |
| 798 Restart(); | 804 data_provider()->Start(); |
| 799 Respond(response_generator_->Generate206(kDataSize)); | 805 Respond(response_generator_->Generate206(kDataSize)); |
| 806 } |
| 800 | 807 |
| 801 FinishLoading(); | 808 // Stop() will also cause the readback to be called with kReadError, but |
| 802 Restart(); | 809 // we want to make sure it was called during FailLoading(). |
| 803 Respond(response_generator_->Generate206(kDataSize)); | 810 bool failed_ = false; |
| 804 | 811 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)) |
| 805 FinishLoading(); | 812 .WillOnce(Assign(&failed_, true)); |
| 806 Restart(); | 813 FailLoading(); |
| 807 Respond(response_generator_->Generate206(kDataSize)); | 814 EXPECT_TRUE(failed_); |
| 808 | |
| 809 // It'll error after this. | |
| 810 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | |
| 811 FinishLoading(); | |
| 812 | |
| 813 EXPECT_FALSE(loading()); | 815 EXPECT_FALSE(loading()); |
| 814 Stop(); | 816 Stop(); |
| 815 } | 817 } |
| 816 | 818 |
| 817 TEST_F(MultibufferDataSourceTest, File_TooManyRetries) { | 819 TEST_F(MultibufferDataSourceTest, File_TooManyRetries) { |
| 818 InitializeWithFileResponse(); | 820 InitializeWithFileResponse(); |
| 819 | 821 |
| 820 // Make sure there's a pending read -- we'll expect it to error. | 822 // Make sure there's a pending read -- we'll expect it to error. |
| 821 ReadAt(kDataSize); | 823 ReadAt(kDataSize); |
| 822 | 824 |
| 823 // It'll try three times. | 825 for (int i = 0; i < ResourceMultiBufferDataProvider::kMaxRetries; i++) { |
| 824 FinishLoading(); | 826 FailLoading(); |
| 825 Restart(); | 827 data_provider()->Start(); |
| 826 Respond(response_generator_->GenerateFileResponse(0)); | 828 Respond(response_generator_->Generate206(kDataSize)); |
| 829 } |
| 827 | 830 |
| 828 FinishLoading(); | 831 // Stop() will also cause the readback to be called with kReadError, but |
| 829 Restart(); | 832 // we want to make sure it was called during FailLoading(). |
| 830 Respond(response_generator_->GenerateFileResponse(0)); | 833 bool failed_ = false; |
| 831 | 834 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)) |
| 832 FinishLoading(); | 835 .WillOnce(Assign(&failed_, true)); |
| 833 Restart(); | 836 FailLoading(); |
| 834 Respond(response_generator_->GenerateFileResponse(0)); | 837 EXPECT_TRUE(failed_); |
| 835 | |
| 836 // It'll error after this. | |
| 837 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | |
| 838 FinishLoading(); | |
| 839 | |
| 840 EXPECT_FALSE(loading()); | 838 EXPECT_FALSE(loading()); |
| 841 Stop(); | 839 Stop(); |
| 842 } | 840 } |
| 843 | 841 |
| 844 TEST_F(MultibufferDataSourceTest, File_InstanceSizeUnknown) { | 842 TEST_F(MultibufferDataSourceTest, File_InstanceSizeUnknown) { |
| 845 Initialize(kFileUrl, false); | 843 Initialize(kFileUrl, false); |
| 846 | 844 |
| 847 Respond( | 845 Respond( |
| 848 response_generator_->GenerateFileResponse(media::DataSource::kReadError)); | 846 response_generator_->GenerateFileResponse(media::DataSource::kReadError)); |
| 849 ReceiveData(kDataSize); | 847 ReceiveData(kDataSize); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 data_provider()->willFollowRedirect(url_loader(), request, response); | 1270 data_provider()->willFollowRedirect(url_loader(), request, response); |
| 1273 Respond(response_generator_->Generate206(kDataSize)); | 1271 Respond(response_generator_->Generate206(kDataSize)); |
| 1274 ReceiveData(kDataSize); | 1272 ReceiveData(kDataSize); |
| 1275 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 3)); | 1273 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 3)); |
| 1276 FinishLoading(); | 1274 FinishLoading(); |
| 1277 EXPECT_FALSE(loading()); | 1275 EXPECT_FALSE(loading()); |
| 1278 Stop(); | 1276 Stop(); |
| 1279 } | 1277 } |
| 1280 | 1278 |
| 1281 } // namespace media | 1279 } // namespace media |
| OLD | NEW |