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 "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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 WebURLLoader* url_loader() { | 227 WebURLLoader* url_loader() { |
228 return loader()->active_loader_->loader_.get(); | 228 return loader()->active_loader_->loader_.get(); |
229 } | 229 } |
230 | 230 |
231 BufferedDataSource::Preload preload() { return data_source_->preload_; } | 231 BufferedDataSource::Preload preload() { return data_source_->preload_; } |
232 void set_preload(BufferedDataSource::Preload preload) { preload_ = preload; } | 232 void set_preload(BufferedDataSource::Preload preload) { preload_ = preload; } |
233 BufferedResourceLoader::DeferStrategy defer_strategy() { | 233 BufferedResourceLoader::DeferStrategy defer_strategy() { |
234 return loader()->defer_strategy_; | 234 return loader()->defer_strategy_; |
235 } | 235 } |
236 int data_source_bitrate() { return data_source_->bitrate_; } | 236 int data_source_bitrate() { return data_source_->bitrate_; } |
237 int data_source_playback_rate() { return data_source_->playback_rate_; } | 237 double data_source_playback_rate() { return data_source_->playback_rate_; } |
238 int loader_bitrate() { return loader()->bitrate_; } | 238 int loader_bitrate() { return loader()->bitrate_; } |
239 int loader_playback_rate() { return loader()->playback_rate_; } | 239 double loader_playback_rate() { return loader()->playback_rate_; } |
240 bool is_local_source() { return data_source_->assume_fully_buffered(); } | 240 bool is_local_source() { return data_source_->assume_fully_buffered(); } |
241 void set_might_be_reused_from_cache_in_future(bool value) { | 241 void set_might_be_reused_from_cache_in_future(bool value) { |
242 loader()->might_be_reused_from_cache_in_future_ = value; | 242 loader()->might_be_reused_from_cache_in_future_ = value; |
243 } | 243 } |
244 | 244 |
245 scoped_ptr<MockBufferedDataSource> data_source_; | 245 scoped_ptr<MockBufferedDataSource> data_source_; |
246 | 246 |
247 scoped_ptr<TestResponseGenerator> response_generator_; | 247 scoped_ptr<TestResponseGenerator> response_generator_; |
248 MockWebFrameClient client_; | 248 MockWebFrameClient client_; |
249 WebView* view_; | 249 WebView* view_; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 } | 553 } |
554 | 554 |
555 TEST_F(BufferedDataSourceTest, DefaultValues) { | 555 TEST_F(BufferedDataSourceTest, DefaultValues) { |
556 InitializeWith206Response(); | 556 InitializeWith206Response(); |
557 | 557 |
558 // Ensure we have sane values for default loading scenario. | 558 // Ensure we have sane values for default loading scenario. |
559 EXPECT_EQ(BufferedDataSource::AUTO, preload()); | 559 EXPECT_EQ(BufferedDataSource::AUTO, preload()); |
560 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); | 560 EXPECT_EQ(BufferedResourceLoader::kCapacityDefer, defer_strategy()); |
561 | 561 |
562 EXPECT_EQ(0, data_source_bitrate()); | 562 EXPECT_EQ(0, data_source_bitrate()); |
563 EXPECT_EQ(0.0f, data_source_playback_rate()); | 563 EXPECT_EQ(0.0, data_source_playback_rate()); |
564 EXPECT_EQ(0, loader_bitrate()); | 564 EXPECT_EQ(0, loader_bitrate()); |
565 EXPECT_EQ(0.0f, loader_playback_rate()); | 565 EXPECT_EQ(0.0, loader_playback_rate()); |
566 | 566 |
567 EXPECT_TRUE(data_source_->loading()); | 567 EXPECT_TRUE(data_source_->loading()); |
568 Stop(); | 568 Stop(); |
569 } | 569 } |
570 | 570 |
571 TEST_F(BufferedDataSourceTest, SetBitrate) { | 571 TEST_F(BufferedDataSourceTest, SetBitrate) { |
572 InitializeWith206Response(); | 572 InitializeWith206Response(); |
573 | 573 |
574 data_source_->SetBitrate(1234); | 574 data_source_->SetBitrate(1234); |
575 message_loop_.RunUntilIdle(); | 575 message_loop_.RunUntilIdle(); |
(...skipping 11 matching lines...) Expand all Loading... |
587 EXPECT_EQ(1234, loader_bitrate()); | 587 EXPECT_EQ(1234, loader_bitrate()); |
588 | 588 |
589 EXPECT_TRUE(data_source_->loading()); | 589 EXPECT_TRUE(data_source_->loading()); |
590 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 590 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
591 Stop(); | 591 Stop(); |
592 } | 592 } |
593 | 593 |
594 TEST_F(BufferedDataSourceTest, MediaPlaybackRateChanged) { | 594 TEST_F(BufferedDataSourceTest, MediaPlaybackRateChanged) { |
595 InitializeWith206Response(); | 595 InitializeWith206Response(); |
596 | 596 |
597 data_source_->MediaPlaybackRateChanged(2.0f); | 597 data_source_->MediaPlaybackRateChanged(2.0); |
598 message_loop_.RunUntilIdle(); | 598 message_loop_.RunUntilIdle(); |
599 EXPECT_EQ(2.0f, data_source_playback_rate()); | 599 EXPECT_EQ(2.0, data_source_playback_rate()); |
600 EXPECT_EQ(2.0f, loader_playback_rate()); | 600 EXPECT_EQ(2.0, loader_playback_rate()); |
601 | 601 |
602 // Read so far ahead to cause the loader to get recreated. | 602 // Read so far ahead to cause the loader to get recreated. |
603 BufferedResourceLoader* old_loader = loader(); | 603 BufferedResourceLoader* old_loader = loader(); |
604 ExpectCreateResourceLoader(); | 604 ExpectCreateResourceLoader(); |
605 ReadAt(kFarReadPosition); | 605 ReadAt(kFarReadPosition); |
606 Respond(response_generator_->Generate206(kFarReadPosition)); | 606 Respond(response_generator_->Generate206(kFarReadPosition)); |
607 | 607 |
608 // Verify loader changed but still has same playback rate. | 608 // Verify loader changed but still has same playback rate. |
609 EXPECT_NE(old_loader, loader()); | 609 EXPECT_NE(old_loader, loader()); |
610 | 610 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 // Read a bit from the beginning. | 843 // Read a bit from the beginning. |
844 ReadAt(0); | 844 ReadAt(0); |
845 EXPECT_CALL(*this, ReadCallback(kDataSize)); | 845 EXPECT_CALL(*this, ReadCallback(kDataSize)); |
846 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); | 846 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); |
847 ReceiveData(kDataSize); | 847 ReceiveData(kDataSize); |
848 | 848 |
849 EXPECT_FALSE(active_loader()); | 849 EXPECT_FALSE(active_loader()); |
850 } | 850 } |
851 | 851 |
852 } // namespace media | 852 } // namespace media |
OLD | NEW |