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

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

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "media/base/media_log.h" 8 #include "media/base/media_log.h"
9 #include "media/base/mock_filters.h" 9 #include "media/base/mock_filters.h"
10 #include "media/base/test_helpers.h" 10 #include "media/base/test_helpers.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 private: 156 private:
157 scoped_refptr<TestUrlData> last_url_data_; 157 scoped_refptr<TestUrlData> last_url_data_;
158 }; 158 };
159 159
160 class MockBufferedDataSourceHost : public BufferedDataSourceHost { 160 class MockBufferedDataSourceHost : public BufferedDataSourceHost {
161 public: 161 public:
162 MockBufferedDataSourceHost() {} 162 MockBufferedDataSourceHost() {}
163 virtual ~MockBufferedDataSourceHost() {} 163 virtual ~MockBufferedDataSourceHost() {}
164 164
165 MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes)); 165 MOCK_METHOD1(SetTotalBytes, void(int64_t total_bytes));
166 MOCK_METHOD2(AddBufferedByteRange, void(int64 start, int64 end)); 166 MOCK_METHOD2(AddBufferedByteRange, void(int64_t start, int64_t end));
167 167
168 private: 168 private:
169 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost); 169 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost);
170 }; 170 };
171 171
172 class MockMultibufferDataSource : public MultibufferDataSource { 172 class MockMultibufferDataSource : public MultibufferDataSource {
173 public: 173 public:
174 MockMultibufferDataSource( 174 MockMultibufferDataSource(
175 const GURL& url, 175 const GURL& url,
176 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 176 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
(...skipping 19 matching lines...) Expand all
196 private: 196 private:
197 // Whether the resource is downloading or deferred. 197 // Whether the resource is downloading or deferred.
198 bool downloading_; 198 bool downloading_;
199 199
200 // Whether the resource load has starting loading but yet to been cancelled. 200 // Whether the resource load has starting loading but yet to been cancelled.
201 bool loading_; 201 bool loading_;
202 202
203 DISALLOW_COPY_AND_ASSIGN(MockMultibufferDataSource); 203 DISALLOW_COPY_AND_ASSIGN(MockMultibufferDataSource);
204 }; 204 };
205 205
206 static const int64 kFileSize = 5000000; 206 static const int64_t kFileSize = 5000000;
207 static const int64 kFarReadPosition = 3997696; 207 static const int64_t kFarReadPosition = 3997696;
208 static const int kDataSize = 32 << 10; 208 static const int kDataSize = 32 << 10;
209 209
210 static const char kHttpUrl[] = "http://localhost/foo.webm"; 210 static const char kHttpUrl[] = "http://localhost/foo.webm";
211 static const char kFileUrl[] = "file:///tmp/bar.webm"; 211 static const char kFileUrl[] = "file:///tmp/bar.webm";
212 static const char kHttpDifferentPathUrl[] = "http://localhost/bar.webm"; 212 static const char kHttpDifferentPathUrl[] = "http://localhost/bar.webm";
213 static const char kHttpDifferentOriginUrl[] = "http://127.0.0.1/foo.webm"; 213 static const char kHttpDifferentOriginUrl[] = "http://127.0.0.1/foo.webm";
214 214
215 class MultibufferDataSourceTest : public testing::Test { 215 class MultibufferDataSourceTest : public testing::Test {
216 public: 216 public:
217 MultibufferDataSourceTest() 217 MultibufferDataSourceTest()
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 void Restart() { 324 void Restart() {
325 EXPECT_TRUE(data_provider()); 325 EXPECT_TRUE(data_provider());
326 EXPECT_FALSE(active_loader_allownull()); 326 EXPECT_FALSE(active_loader_allownull());
327 if (!data_provider()) 327 if (!data_provider())
328 return; 328 return;
329 data_provider()->Start(); 329 data_provider()->Start();
330 } 330 }
331 331
332 MOCK_METHOD1(ReadCallback, void(int size)); 332 MOCK_METHOD1(ReadCallback, void(int size));
333 333
334 void ReadAt(int64 position, int64 howmuch = kDataSize) { 334 void ReadAt(int64_t position, int64_t howmuch = kDataSize) {
335 data_source_->Read(position, howmuch, buffer_, 335 data_source_->Read(position, howmuch, buffer_,
336 base::Bind(&MultibufferDataSourceTest::ReadCallback, 336 base::Bind(&MultibufferDataSourceTest::ReadCallback,
337 base::Unretained(this))); 337 base::Unretained(this)));
338 message_loop_.RunUntilIdle(); 338 message_loop_.RunUntilIdle();
339 } 339 }
340 340
341 void ExecuteMixedResponseSuccessTest(const WebURLResponse& response1, 341 void ExecuteMixedResponseSuccessTest(const WebURLResponse& response1,
342 const WebURLResponse& response2) { 342 const WebURLResponse& response2) {
343 EXPECT_CALL(host_, SetTotalBytes(kFileSize)); 343 EXPECT_CALL(host_, SetTotalBytes(kFileSize));
344 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2)); 344 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 return nullptr; 422 return nullptr;
423 return active_loader()->loader_.get(); 423 return active_loader()->loader_.get();
424 } 424 }
425 425
426 bool loading() { return multibuffer()->loading(); } 426 bool loading() { return multibuffer()->loading(); }
427 427
428 MultibufferDataSource::Preload preload() { return data_source_->preload_; } 428 MultibufferDataSource::Preload preload() { return data_source_->preload_; }
429 void set_preload(MultibufferDataSource::Preload preload) { 429 void set_preload(MultibufferDataSource::Preload preload) {
430 preload_ = preload; 430 preload_ = preload;
431 } 431 }
432 int64 preload_high() { 432 int64_t preload_high() {
433 CHECK(loader()); 433 CHECK(loader());
434 return loader()->preload_high(); 434 return loader()->preload_high();
435 } 435 }
436 int64 preload_low() { 436 int64_t preload_low() {
437 CHECK(loader()); 437 CHECK(loader());
438 return loader()->preload_low(); 438 return loader()->preload_low();
439 } 439 }
440 int data_source_bitrate() { return data_source_->bitrate_; } 440 int data_source_bitrate() { return data_source_->bitrate_; }
441 double data_source_playback_rate() { return data_source_->playback_rate_; } 441 double data_source_playback_rate() { return data_source_->playback_rate_; }
442 bool is_local_source() { return data_source_->assume_fully_buffered(); } 442 bool is_local_source() { return data_source_->assume_fully_buffered(); }
443 void set_might_be_reused_from_cache_in_future(bool value) { 443 void set_might_be_reused_from_cache_in_future(bool value) {
444 data_source_->url_data_->set_cacheable(value); 444 data_source_->url_data_->set_cacheable(value);
445 } 445 }
446 446
447 protected: 447 protected:
448 MockWebFrameClient client_; 448 MockWebFrameClient client_;
449 WebView* view_; 449 WebView* view_;
450 WebLocalFrame* frame_; 450 WebLocalFrame* frame_;
451 MultibufferDataSource::Preload preload_; 451 MultibufferDataSource::Preload preload_;
452 linked_ptr<TestUrlIndex> url_index_; 452 linked_ptr<TestUrlIndex> url_index_;
453 453
454 scoped_ptr<MockMultibufferDataSource> data_source_; 454 scoped_ptr<MockMultibufferDataSource> data_source_;
455 455
456 scoped_ptr<TestResponseGenerator> response_generator_; 456 scoped_ptr<TestResponseGenerator> response_generator_;
457 457
458 StrictMock<MockBufferedDataSourceHost> host_; 458 StrictMock<MockBufferedDataSourceHost> host_;
459 base::MessageLoop message_loop_; 459 base::MessageLoop message_loop_;
460 460
461 // Used for calling MultibufferDataSource::Read(). 461 // Used for calling MultibufferDataSource::Read().
462 uint8 buffer_[kDataSize * 2]; 462 uint8_t buffer_[kDataSize * 2];
463 463
464 DISALLOW_COPY_AND_ASSIGN(MultibufferDataSourceTest); 464 DISALLOW_COPY_AND_ASSIGN(MultibufferDataSourceTest);
465 }; 465 };
466 466
467 TEST_F(MultibufferDataSourceTest, Range_Supported) { 467 TEST_F(MultibufferDataSourceTest, Range_Supported) {
468 InitializeWith206Response(); 468 InitializeWith206Response();
469 469
470 EXPECT_TRUE(loading()); 470 EXPECT_TRUE(loading());
471 EXPECT_FALSE(data_source_->IsStreaming()); 471 EXPECT_FALSE(data_source_->IsStreaming());
472 Stop(); 472 Stop();
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 InitializeWithFileResponse(); 856 InitializeWithFileResponse();
857 857
858 EXPECT_TRUE(loading()); 858 EXPECT_TRUE(loading());
859 EXPECT_FALSE(data_source_->IsStreaming()); 859 EXPECT_FALSE(data_source_->IsStreaming());
860 Stop(); 860 Stop();
861 } 861 }
862 862
863 TEST_F(MultibufferDataSourceTest, StopDuringRead) { 863 TEST_F(MultibufferDataSourceTest, StopDuringRead) {
864 InitializeWith206Response(); 864 InitializeWith206Response();
865 865
866 uint8 buffer[256]; 866 uint8_t buffer[256];
867 data_source_->Read(0, arraysize(buffer), buffer, 867 data_source_->Read(0, arraysize(buffer), buffer,
868 base::Bind(&MultibufferDataSourceTest::ReadCallback, 868 base::Bind(&MultibufferDataSourceTest::ReadCallback,
869 base::Unretained(this))); 869 base::Unretained(this)));
870 870
871 // The outstanding read should fail before the stop callback runs. 871 // The outstanding read should fail before the stop callback runs.
872 { 872 {
873 InSequence s; 873 InSequence s;
874 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); 874 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError));
875 data_source_->Stop(); 875 data_source_->Stop();
876 } 876 }
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 ASSERT_TRUE(active_loader()); 1208 ASSERT_TRUE(active_loader());
1209 1209
1210 EXPECT_CALL(*this, ReadCallback(kDataSize)); 1210 EXPECT_CALL(*this, ReadCallback(kDataSize));
1211 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2)); 1211 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize * 2));
1212 ReceiveData(kDataSize); 1212 ReceiveData(kDataSize);
1213 1213
1214 EXPECT_FALSE(active_loader_allownull()); 1214 EXPECT_FALSE(active_loader_allownull());
1215 } 1215 }
1216 1216
1217 } // namespace media 1217 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698