| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "media/base/media_log.h" | 6 #include "media/base/media_log.h" |
| 7 #include "media/base/mock_callback.h" | 7 #include "media/base/mock_callback.h" |
| 8 #include "media/base/mock_filter_host.h" | 8 #include "media/base/mock_filter_host.h" |
| 9 #include "media/base/mock_filters.h" | 9 #include "media/base/mock_filters.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 12 #include "webkit/media/buffered_data_source.h" | 12 #include "webkit/media/buffered_data_source.h" |
| 13 #include "webkit/mocks/mock_webframeclient.h" | 13 #include "webkit/mocks/mock_webframeclient.h" |
| 14 #include "webkit/mocks/mock_weburlloader.h" | 14 #include "webkit/mocks/mock_weburlloader.h" |
| 15 #include "webkit/media/test_response_generator.h" | 15 #include "webkit/media/test_response_generator.h" |
| 16 | 16 |
| 17 using ::testing::_; | 17 using ::testing::_; |
| 18 using ::testing::Assign; | 18 using ::testing::Assign; |
| 19 using ::testing::Invoke; | 19 using ::testing::Invoke; |
| 20 using ::testing::Mock; | |
| 21 using ::testing::StrictMock; | 20 using ::testing::StrictMock; |
| 22 using ::testing::NiceMock; | 21 using ::testing::NiceMock; |
| 23 | 22 |
| 24 using WebKit::WebFrame; | 23 using WebKit::WebFrame; |
| 25 using WebKit::WebURLLoader; | 24 using WebKit::WebURLLoader; |
| 26 using WebKit::WebURLResponse; | 25 using WebKit::WebURLResponse; |
| 27 using WebKit::WebView; | 26 using WebKit::WebView; |
| 28 | 27 |
| 29 using webkit_glue::MockWebFrameClient; | 28 using webkit_glue::MockWebFrameClient; |
| 30 using webkit_glue::MockWebURLLoader; | 29 using webkit_glue::MockWebURLLoader; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 49 BufferedDataSource::CreateResourceLoader(first_byte_position, | 48 BufferedDataSource::CreateResourceLoader(first_byte_position, |
| 50 last_byte_position); | 49 last_byte_position); |
| 51 | 50 |
| 52 // Keep track of active loading state via loadAsynchronously() and cancel(). | 51 // Keep track of active loading state via loadAsynchronously() and cancel(). |
| 53 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); | 52 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); |
| 54 ON_CALL(*url_loader, loadAsynchronously(_, _)) | 53 ON_CALL(*url_loader, loadAsynchronously(_, _)) |
| 55 .WillByDefault(Assign(&loading_, true)); | 54 .WillByDefault(Assign(&loading_, true)); |
| 56 ON_CALL(*url_loader, cancel()) | 55 ON_CALL(*url_loader, cancel()) |
| 57 .WillByDefault(Assign(&loading_, false)); | 56 .WillByDefault(Assign(&loading_, false)); |
| 58 | 57 |
| 59 // TODO(scherkus): this is a real leak detected by http://crbug.com/100914 | |
| 60 // but the fix will have to wait for a more invasive follow up patch. | |
| 61 // | |
| 62 // If you're curious what the fix is, we no longer need the reference | |
| 63 // counting added to BufferedResourceLoader in r23274 since we started | |
| 64 // using WebURLLoader in r69429. | |
| 65 Mock::AllowLeak(url_loader); | |
| 66 | |
| 67 loader->SetURLLoaderForTest(url_loader); | 58 loader->SetURLLoaderForTest(url_loader); |
| 68 return loader; | 59 return loader; |
| 69 } | 60 } |
| 70 | 61 |
| 71 bool loading() { return loading_; } | 62 bool loading() { return loading_; } |
| 72 void set_loading(bool loading) { loading_ = loading; } | 63 void set_loading(bool loading) { loading_ = loading; } |
| 73 | 64 |
| 74 private: | 65 private: |
| 75 // Whether the resource load has starting loading but yet to been cancelled. | 66 // Whether the resource load has starting loading but yet to been cancelled. |
| 76 bool loading_; | 67 bool loading_; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 MOCK_METHOD1(ReadCallback, void(size_t size)); | 147 MOCK_METHOD1(ReadCallback, void(size_t size)); |
| 157 | 148 |
| 158 void ReadAt(int64 position) { | 149 void ReadAt(int64 position) { |
| 159 data_source_->Read(position, kDataSize, buffer_, | 150 data_source_->Read(position, kDataSize, buffer_, |
| 160 base::Bind(&BufferedDataSourceTest::ReadCallback, | 151 base::Bind(&BufferedDataSourceTest::ReadCallback, |
| 161 base::Unretained(this))); | 152 base::Unretained(this))); |
| 162 message_loop_->RunAllPending(); | 153 message_loop_->RunAllPending(); |
| 163 } | 154 } |
| 164 | 155 |
| 165 // Accessors for private variables on |data_source_|. | 156 // Accessors for private variables on |data_source_|. |
| 166 BufferedResourceLoader* loader() { return data_source_->loader_.get(); } | 157 BufferedResourceLoader* loader() { |
| 167 WebURLLoader* url_loader() { return loader()->url_loader_.get(); } | 158 return data_source_->loader_.get(); |
| 159 } |
| 160 WebURLLoader* url_loader() { |
| 161 return loader()->active_loader_->loader_.get(); |
| 162 } |
| 168 | 163 |
| 169 media::Preload preload() { return data_source_->preload_; } | 164 media::Preload preload() { return data_source_->preload_; } |
| 170 BufferedResourceLoader::DeferStrategy defer_strategy() { | 165 BufferedResourceLoader::DeferStrategy defer_strategy() { |
| 171 return loader()->defer_strategy_; | 166 return loader()->defer_strategy_; |
| 172 } | 167 } |
| 173 int data_source_bitrate() { return data_source_->bitrate_; } | 168 int data_source_bitrate() { return data_source_->bitrate_; } |
| 174 int data_source_playback_rate() { return data_source_->playback_rate_; } | 169 int data_source_playback_rate() { return data_source_->playback_rate_; } |
| 175 int loader_bitrate() { return loader()->bitrate_; } | 170 int loader_bitrate() { return loader()->bitrate_; } |
| 176 int loader_playback_rate() { return loader()->playback_rate_; } | 171 int loader_playback_rate() { return loader()->playback_rate_; } |
| 177 | 172 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // Read so far ahead to cause the loader to get recreated. | 397 // Read so far ahead to cause the loader to get recreated. |
| 403 BufferedResourceLoader* old_loader = loader(); | 398 BufferedResourceLoader* old_loader = loader(); |
| 404 ExpectCreateResourceLoader(); | 399 ExpectCreateResourceLoader(); |
| 405 ReadAt(kFarReadPosition); | 400 ReadAt(kFarReadPosition); |
| 406 Respond(response_generator_.Generate206(kFarReadPosition)); | 401 Respond(response_generator_.Generate206(kFarReadPosition)); |
| 407 | 402 |
| 408 // Verify loader changed but still has same bitrate. | 403 // Verify loader changed but still has same bitrate. |
| 409 EXPECT_NE(old_loader, loader()); | 404 EXPECT_NE(old_loader, loader()); |
| 410 EXPECT_EQ(1234, loader_bitrate()); | 405 EXPECT_EQ(1234, loader_bitrate()); |
| 411 | 406 |
| 407 // During teardown we'll also report our final network status. |
| 408 EXPECT_CALL(host_, SetBufferedBytes(4000000)); |
| 409 |
| 412 EXPECT_TRUE(data_source_->loading()); | 410 EXPECT_TRUE(data_source_->loading()); |
| 413 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 411 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
| 414 Stop(); | 412 Stop(); |
| 415 } | 413 } |
| 416 | 414 |
| 417 TEST_F(BufferedDataSourceTest, SetPlaybackRate) { | 415 TEST_F(BufferedDataSourceTest, SetPlaybackRate) { |
| 418 InitializeWith206Response(); | 416 InitializeWith206Response(); |
| 419 | 417 |
| 420 data_source_->SetPlaybackRate(2.0f); | 418 data_source_->SetPlaybackRate(2.0f); |
| 421 message_loop_->RunAllPending(); | 419 message_loop_->RunAllPending(); |
| 422 EXPECT_EQ(2.0f, data_source_playback_rate()); | 420 EXPECT_EQ(2.0f, data_source_playback_rate()); |
| 423 EXPECT_EQ(2.0f, loader_playback_rate()); | 421 EXPECT_EQ(2.0f, loader_playback_rate()); |
| 424 | 422 |
| 425 // Read so far ahead to cause the loader to get recreated. | 423 // Read so far ahead to cause the loader to get recreated. |
| 426 BufferedResourceLoader* old_loader = loader(); | 424 BufferedResourceLoader* old_loader = loader(); |
| 427 ExpectCreateResourceLoader(); | 425 ExpectCreateResourceLoader(); |
| 428 ReadAt(kFarReadPosition); | 426 ReadAt(kFarReadPosition); |
| 429 Respond(response_generator_.Generate206(kFarReadPosition)); | 427 Respond(response_generator_.Generate206(kFarReadPosition)); |
| 430 | 428 |
| 431 // Verify loader changed but still has same playback rate. | 429 // Verify loader changed but still has same playback rate. |
| 432 EXPECT_NE(old_loader, loader()); | 430 EXPECT_NE(old_loader, loader()); |
| 433 | 431 |
| 432 // During teardown we'll also report our final network status. |
| 433 EXPECT_CALL(host_, SetBufferedBytes(4000000)); |
| 434 |
| 434 EXPECT_TRUE(data_source_->loading()); | 435 EXPECT_TRUE(data_source_->loading()); |
| 435 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); | 436 EXPECT_CALL(*this, ReadCallback(media::DataSource::kReadError)); |
| 436 Stop(); | 437 Stop(); |
| 437 } | 438 } |
| 438 | 439 |
| 439 TEST_F(BufferedDataSourceTest, Read) { | 440 TEST_F(BufferedDataSourceTest, Read) { |
| 440 InitializeWith206Response(); | 441 InitializeWith206Response(); |
| 441 | 442 |
| 442 ReadAt(0); | 443 ReadAt(0); |
| 443 | 444 |
| 444 // When the read completes we'll update our network status. | 445 // When the read completes we'll update our network status. |
| 445 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); | 446 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); |
| 446 EXPECT_CALL(host_, SetNetworkActivity(true)); | 447 EXPECT_CALL(host_, SetNetworkActivity(true)); |
| 447 EXPECT_CALL(*this, ReadCallback(kDataSize)); | 448 EXPECT_CALL(*this, ReadCallback(kDataSize)); |
| 448 FinishRead(); | 449 FinishRead(); |
| 449 | 450 |
| 450 // During teardown we'll also report our final network status. | 451 // During teardown we'll also report our final network status. |
| 451 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); | 452 EXPECT_CALL(host_, SetBufferedBytes(kDataSize)); |
| 452 EXPECT_CALL(host_, SetNetworkActivity(false)); | 453 EXPECT_CALL(host_, SetNetworkActivity(false)); |
| 453 | 454 |
| 454 EXPECT_TRUE(data_source_->loading()); | 455 EXPECT_TRUE(data_source_->loading()); |
| 455 Stop(); | 456 Stop(); |
| 456 } | 457 } |
| 457 | 458 |
| 458 } // namespace webkit_media | 459 } // namespace webkit_media |
| OLD | NEW |