Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: media/blink/buffered_data_source_unittest.cc

Issue 2086353002: Remove calls to deprecated MessageLoop methods in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/text_renderer_unittest.cc ('k') | media/blink/multibuffer_data_source_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 data_source_.reset(new MockBufferedDataSource( 141 data_source_.reset(new MockBufferedDataSource(
142 gurl, cors_mode, message_loop_.task_runner(), 142 gurl, cors_mode, message_loop_.task_runner(),
143 view_->mainFrame()->toWebLocalFrame(), &host_)); 143 view_->mainFrame()->toWebLocalFrame(), &host_));
144 data_source_->SetPreload(preload_); 144 data_source_->SetPreload(preload_);
145 145
146 response_generator_.reset(new TestResponseGenerator(gurl, kFileSize)); 146 response_generator_.reset(new TestResponseGenerator(gurl, kFileSize));
147 ExpectCreateResourceLoader(); 147 ExpectCreateResourceLoader();
148 EXPECT_CALL(*this, OnInitialize(expected)); 148 EXPECT_CALL(*this, OnInitialize(expected));
149 data_source_->Initialize(base::Bind(&BufferedDataSourceTest::OnInitialize, 149 data_source_->Initialize(base::Bind(&BufferedDataSourceTest::OnInitialize,
150 base::Unretained(this))); 150 base::Unretained(this)));
151 message_loop_.RunUntilIdle(); 151 base::RunLoop().RunUntilIdle();
152 152
153 bool is_http = gurl.SchemeIsHTTPOrHTTPS(); 153 bool is_http = gurl.SchemeIsHTTPOrHTTPS();
154 EXPECT_EQ(data_source_->downloading(), is_http); 154 EXPECT_EQ(data_source_->downloading(), is_http);
155 } 155 }
156 156
157 void Initialize(const char* url, bool expected) { 157 void Initialize(const char* url, bool expected) {
158 InitializeWithCORS(url, expected, BufferedResourceLoader::kUnspecified); 158 InitializeWithCORS(url, expected, BufferedResourceLoader::kUnspecified);
159 } 159 }
160 160
161 // Helper to initialize tests with a valid 200 response. 161 // Helper to initialize tests with a valid 200 response.
(...skipping 21 matching lines...) Expand all
183 Respond(response_generator_->GenerateFileResponse(0)); 183 Respond(response_generator_->GenerateFileResponse(0));
184 } 184 }
185 185
186 // Stops any active loaders and shuts down the data source. 186 // Stops any active loaders and shuts down the data source.
187 // 187 //
188 // This typically happens when the page is closed and for our purposes is 188 // This typically happens when the page is closed and for our purposes is
189 // appropriate to do when tearing down a test. 189 // appropriate to do when tearing down a test.
190 void Stop() { 190 void Stop() {
191 if (data_source_->loading()) { 191 if (data_source_->loading()) {
192 loader()->didFail(url_loader(), response_generator_->GenerateError()); 192 loader()->didFail(url_loader(), response_generator_->GenerateError());
193 message_loop_.RunUntilIdle(); 193 base::RunLoop().RunUntilIdle();
194 } 194 }
195 195
196 data_source_->Stop(); 196 data_source_->Stop();
197 message_loop_.RunUntilIdle(); 197 base::RunLoop().RunUntilIdle();
198 } 198 }
199 199
200 void ExpectCreateResourceLoader() { 200 void ExpectCreateResourceLoader() {
201 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _)) 201 EXPECT_CALL(*data_source_, CreateResourceLoader(_, _))
202 .WillOnce(Invoke(data_source_.get(), 202 .WillOnce(Invoke(data_source_.get(),
203 &MockBufferedDataSource::CreateMockResourceLoader)); 203 &MockBufferedDataSource::CreateMockResourceLoader));
204 message_loop_.RunUntilIdle(); 204 base::RunLoop().RunUntilIdle();
205 bytes_received_ = 0; 205 bytes_received_ = 0;
206 } 206 }
207 207
208 void Respond(const WebURLResponse& response) { 208 void Respond(const WebURLResponse& response) {
209 loader()->didReceiveResponse(url_loader(), response); 209 loader()->didReceiveResponse(url_loader(), response);
210 message_loop_.RunUntilIdle(); 210 base::RunLoop().RunUntilIdle();
211 } 211 }
212 212
213 void ReceiveData(int size) { 213 void ReceiveData(int size) {
214 std::unique_ptr<char[]> data(new char[size]); 214 std::unique_ptr<char[]> data(new char[size]);
215 memset(data.get(), 0xA5, size); // Arbitrary non-zero value. 215 memset(data.get(), 0xA5, size); // Arbitrary non-zero value.
216 216
217 loader()->didReceiveData(url_loader(), data.get(), size, size); 217 loader()->didReceiveData(url_loader(), data.get(), size, size);
218 message_loop_.RunUntilIdle(); 218 base::RunLoop().RunUntilIdle();
219 bytes_received_ += size; 219 bytes_received_ += size;
220 EXPECT_EQ(bytes_received_, data_source_->GetMemoryUsage()); 220 EXPECT_EQ(bytes_received_, data_source_->GetMemoryUsage());
221 } 221 }
222 222
223 void FinishLoading() { 223 void FinishLoading() {
224 data_source_->set_loading(false); 224 data_source_->set_loading(false);
225 loader()->didFinishLoading(url_loader(), 0, -1); 225 loader()->didFinishLoading(url_loader(), 0, -1);
226 message_loop_.RunUntilIdle(); 226 base::RunLoop().RunUntilIdle();
227 } 227 }
228 228
229 MOCK_METHOD1(ReadCallback, void(int size)); 229 MOCK_METHOD1(ReadCallback, void(int size));
230 230
231 void ReadAt(int64_t position) { 231 void ReadAt(int64_t position) {
232 data_source_->Read(position, kDataSize, buffer_, 232 data_source_->Read(position, kDataSize, buffer_,
233 base::Bind(&BufferedDataSourceTest::ReadCallback, 233 base::Bind(&BufferedDataSourceTest::ReadCallback,
234 base::Unretained(this))); 234 base::Unretained(this)));
235 message_loop_.RunUntilIdle(); 235 base::RunLoop().RunUntilIdle();
236 } 236 }
237 237
238 void ExecuteMixedResponseSuccessTest(const WebURLResponse& response1, 238 void ExecuteMixedResponseSuccessTest(const WebURLResponse& response1,
239 const WebURLResponse& response2) { 239 const WebURLResponse& response2) {
240 EXPECT_CALL(host_, SetTotalBytes(kFileSize)); 240 EXPECT_CALL(host_, SetTotalBytes(kFileSize));
241 EXPECT_CALL(host_, AddBufferedByteRange(kDataSize, kDataSize * 2 - 1)); 241 EXPECT_CALL(host_, AddBufferedByteRange(kDataSize, kDataSize * 2 - 1));
242 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); 242 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1));
243 EXPECT_CALL(*this, ReadCallback(kDataSize)).Times(2); 243 EXPECT_CALL(*this, ReadCallback(kDataSize)).Times(2);
244 244
245 Respond(response1); 245 Respond(response1);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 420
421 TEST_F(BufferedDataSourceTest, Http_AbortWhileReading) { 421 TEST_F(BufferedDataSourceTest, Http_AbortWhileReading) {
422 InitializeWith206Response(); 422 InitializeWith206Response();
423 423
424 // Make sure there's a pending read -- we'll expect it to error. 424 // Make sure there's a pending read -- we'll expect it to error.
425 ReadAt(0); 425 ReadAt(0);
426 426
427 // Abort!!! 427 // Abort!!!
428 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 428 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
429 data_source_->Abort(); 429 data_source_->Abort();
430 message_loop_.RunUntilIdle(); 430 base::RunLoop().RunUntilIdle();
431 431
432 EXPECT_FALSE(data_source_->loading()); 432 EXPECT_FALSE(data_source_->loading());
433 Stop(); 433 Stop();
434 } 434 }
435 435
436 TEST_F(BufferedDataSourceTest, File_AbortWhileReading) { 436 TEST_F(BufferedDataSourceTest, File_AbortWhileReading) {
437 InitializeWithFileResponse(); 437 InitializeWithFileResponse();
438 438
439 // Make sure there's a pending read -- we'll expect it to error. 439 // Make sure there's a pending read -- we'll expect it to error.
440 ReadAt(0); 440 ReadAt(0);
441 441
442 // Abort!!! 442 // Abort!!!
443 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 443 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
444 data_source_->Abort(); 444 data_source_->Abort();
445 message_loop_.RunUntilIdle(); 445 base::RunLoop().RunUntilIdle();
446 446
447 EXPECT_FALSE(data_source_->loading()); 447 EXPECT_FALSE(data_source_->loading());
448 Stop(); 448 Stop();
449 } 449 }
450 450
451 TEST_F(BufferedDataSourceTest, Http_Retry) { 451 TEST_F(BufferedDataSourceTest, Http_Retry) {
452 InitializeWith206Response(); 452 InitializeWith206Response();
453 453
454 // Read to advance our position. 454 // Read to advance our position.
455 EXPECT_CALL(*this, ReadCallback(kDataSize)); 455 EXPECT_CALL(*this, ReadCallback(kDataSize));
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 uint8_t buffer[256]; 754 uint8_t buffer[256];
755 data_source_->Read(0, arraysize(buffer), buffer, base::Bind( 755 data_source_->Read(0, arraysize(buffer), buffer, base::Bind(
756 &BufferedDataSourceTest::ReadCallback, base::Unretained(this))); 756 &BufferedDataSourceTest::ReadCallback, base::Unretained(this)));
757 757
758 // The outstanding read should fail before the stop callback runs. 758 // The outstanding read should fail before the stop callback runs.
759 { 759 {
760 InSequence s; 760 InSequence s;
761 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 761 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
762 data_source_->Stop(); 762 data_source_->Stop();
763 } 763 }
764 message_loop_.RunUntilIdle(); 764 base::RunLoop().RunUntilIdle();
765 } 765 }
766 766
767 TEST_F(BufferedDataSourceTest, DefaultValues) { 767 TEST_F(BufferedDataSourceTest, DefaultValues) {
768 InitializeWith206Response(); 768 InitializeWith206Response();
769 769
770 // Ensure we have sane values for default loading scenario. 770 // Ensure we have sane values for default loading scenario.
771 EXPECT_EQ(BufferedDataSource::AUTO, preload()); 771 EXPECT_EQ(BufferedDataSource::AUTO, preload());
772 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); 772 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy());
773 773
774 EXPECT_EQ(0, data_source_bitrate()); 774 EXPECT_EQ(0, data_source_bitrate());
775 EXPECT_EQ(0.0, data_source_playback_rate()); 775 EXPECT_EQ(0.0, data_source_playback_rate());
776 EXPECT_EQ(0, loader_bitrate()); 776 EXPECT_EQ(0, loader_bitrate());
777 EXPECT_EQ(0.0, loader_playback_rate()); 777 EXPECT_EQ(0.0, loader_playback_rate());
778 778
779 EXPECT_TRUE(data_source_->loading()); 779 EXPECT_TRUE(data_source_->loading());
780 Stop(); 780 Stop();
781 } 781 }
782 782
783 TEST_F(BufferedDataSourceTest, SetBitrate) { 783 TEST_F(BufferedDataSourceTest, SetBitrate) {
784 InitializeWith206Response(); 784 InitializeWith206Response();
785 785
786 data_source_->SetBitrate(1234); 786 data_source_->SetBitrate(1234);
787 message_loop_.RunUntilIdle(); 787 base::RunLoop().RunUntilIdle();
788 EXPECT_EQ(1234, data_source_bitrate()); 788 EXPECT_EQ(1234, data_source_bitrate());
789 EXPECT_EQ(1234, loader_bitrate()); 789 EXPECT_EQ(1234, loader_bitrate());
790 790
791 // Read so far ahead to cause the loader to get recreated. 791 // Read so far ahead to cause the loader to get recreated.
792 BufferedResourceLoader* old_loader = loader(); 792 BufferedResourceLoader* old_loader = loader();
793 ExpectCreateResourceLoader(); 793 ExpectCreateResourceLoader();
794 ReadAt(kFarReadPosition); 794 ReadAt(kFarReadPosition);
795 Respond(response_generator_->Generate206(kFarReadPosition)); 795 Respond(response_generator_->Generate206(kFarReadPosition));
796 796
797 // Verify loader changed but still has same bitrate. 797 // Verify loader changed but still has same bitrate.
798 EXPECT_NE(old_loader, loader()); 798 EXPECT_NE(old_loader, loader());
799 EXPECT_EQ(1234, loader_bitrate()); 799 EXPECT_EQ(1234, loader_bitrate());
800 800
801 EXPECT_TRUE(data_source_->loading()); 801 EXPECT_TRUE(data_source_->loading());
802 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 802 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
803 Stop(); 803 Stop();
804 } 804 }
805 805
806 TEST_F(BufferedDataSourceTest, MediaPlaybackRateChanged) { 806 TEST_F(BufferedDataSourceTest, MediaPlaybackRateChanged) {
807 InitializeWith206Response(); 807 InitializeWith206Response();
808 808
809 data_source_->MediaPlaybackRateChanged(2.0); 809 data_source_->MediaPlaybackRateChanged(2.0);
810 message_loop_.RunUntilIdle(); 810 base::RunLoop().RunUntilIdle();
811 EXPECT_EQ(2.0, data_source_playback_rate()); 811 EXPECT_EQ(2.0, data_source_playback_rate());
812 EXPECT_EQ(2.0, loader_playback_rate()); 812 EXPECT_EQ(2.0, loader_playback_rate());
813 813
814 // Read so far ahead to cause the loader to get recreated. 814 // Read so far ahead to cause the loader to get recreated.
815 BufferedResourceLoader* old_loader = loader(); 815 BufferedResourceLoader* old_loader = loader();
816 ExpectCreateResourceLoader(); 816 ExpectCreateResourceLoader();
817 ReadAt(kFarReadPosition); 817 ReadAt(kFarReadPosition);
818 Respond(response_generator_->Generate206(kFarReadPosition)); 818 Respond(response_generator_->Generate206(kFarReadPosition));
819 819
820 // Verify loader changed but still has same playback rate. 820 // Verify loader changed but still has same playback rate.
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 while (active_loader() && !active_loader()->deferred()) { 1106 while (active_loader() && !active_loader()->deferred()) {
1107 ReceiveData(kDataSize); 1107 ReceiveData(kDataSize);
1108 bytes_received += kDataSize; 1108 bytes_received += kDataSize;
1109 } 1109 }
1110 EXPECT_GT(bytes_received, 0); 1110 EXPECT_GT(bytes_received, 0);
1111 EXPECT_LT(bytes_received + kDataSize, kFileSize); 1111 EXPECT_LT(bytes_received + kDataSize, kFileSize);
1112 EXPECT_FALSE(active_loader()); 1112 EXPECT_FALSE(active_loader());
1113 } 1113 }
1114 1114
1115 } // namespace media 1115 } // namespace media
OLDNEW
« no previous file with comments | « media/base/text_renderer_unittest.cc ('k') | media/blink/multibuffer_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698