| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 6 #include "base/message_loop.h" |
| 7 #include "media/base/media_log.h" | 7 #include "media/base/media_log.h" |
| 8 #include "media/base/mock_callback.h" | 8 #include "media/base/mock_callback.h" |
| 9 #include "media/base/mock_data_source_host.h" | 9 #include "media/base/mock_data_source_host.h" |
| 10 #include "media/base/mock_filters.h" | 10 #include "media/base/mock_filters.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 using webkit_glue::MockWebFrameClient; | 30 using webkit_glue::MockWebFrameClient; |
| 31 using webkit_glue::MockWebURLLoader; | 31 using webkit_glue::MockWebURLLoader; |
| 32 | 32 |
| 33 namespace webkit_media { | 33 namespace webkit_media { |
| 34 | 34 |
| 35 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. | 35 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. |
| 36 // Also keeps track of whether said MockWebURLLoader is actively loading. | 36 // Also keeps track of whether said MockWebURLLoader is actively loading. |
| 37 class MockBufferedDataSource : public BufferedDataSource { | 37 class MockBufferedDataSource : public BufferedDataSource { |
| 38 public: | 38 public: |
| 39 MockBufferedDataSource(MessageLoop* message_loop, WebFrame* frame) | 39 MockBufferedDataSource(MessageLoop* message_loop, WebFrame* frame) |
| 40 : BufferedDataSource(message_loop, frame, new media::MediaLog()), | 40 : BufferedDataSource(message_loop, frame, new media::MediaLog(), |
| 41 base::Bind(&MockBufferedDataSource::set_downloading, |
| 42 base::Unretained(this))), |
| 43 downloading_(false), |
| 41 loading_(false) { | 44 loading_(false) { |
| 42 } | 45 } |
| 43 | 46 |
| 44 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); | 47 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); |
| 45 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, | 48 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, |
| 46 int64 last_byte_position) { | 49 int64 last_byte_position) { |
| 47 CHECK(!loading_) << "Previous resource load wasn't cancelled"; | 50 CHECK(!loading_) << "Previous resource load wasn't cancelled"; |
| 48 | 51 |
| 49 BufferedResourceLoader* loader = | 52 BufferedResourceLoader* loader = |
| 50 BufferedDataSource::CreateResourceLoader(first_byte_position, | 53 BufferedDataSource::CreateResourceLoader(first_byte_position, |
| 51 last_byte_position); | 54 last_byte_position); |
| 52 | 55 |
| 53 // Keep track of active loading state via loadAsynchronously() and cancel(). | 56 // Keep track of active loading state via loadAsynchronously() and cancel(). |
| 54 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); | 57 NiceMock<MockWebURLLoader>* url_loader = new NiceMock<MockWebURLLoader>(); |
| 55 ON_CALL(*url_loader, loadAsynchronously(_, _)) | 58 ON_CALL(*url_loader, loadAsynchronously(_, _)) |
| 56 .WillByDefault(Assign(&loading_, true)); | 59 .WillByDefault(Assign(&loading_, true)); |
| 57 ON_CALL(*url_loader, cancel()) | 60 ON_CALL(*url_loader, cancel()) |
| 58 .WillByDefault(Assign(&loading_, false)); | 61 .WillByDefault(Assign(&loading_, false)); |
| 59 | 62 |
| 60 // |test_loader_| will be used when Start() is called. | 63 // |test_loader_| will be used when Start() is called. |
| 61 loader->test_loader_ = scoped_ptr<WebURLLoader>(url_loader); | 64 loader->test_loader_ = scoped_ptr<WebURLLoader>(url_loader); |
| 62 return loader; | 65 return loader; |
| 63 } | 66 } |
| 64 | 67 |
| 65 bool loading() { return loading_; } | 68 bool loading() { return loading_; } |
| 66 void set_loading(bool loading) { loading_ = loading; } | 69 void set_loading(bool loading) { loading_ = loading; } |
| 70 bool downloading() { return downloading_; } |
| 71 void set_downloading(bool downloading) { downloading_ = downloading; } |
| 67 | 72 |
| 68 private: | 73 private: |
| 69 virtual ~MockBufferedDataSource() {} | 74 virtual ~MockBufferedDataSource() {} |
| 70 | 75 |
| 76 // Whether the resource is downloading or deferred. |
| 77 bool downloading_; |
| 78 |
| 71 // Whether the resource load has starting loading but yet to been cancelled. | 79 // Whether the resource load has starting loading but yet to been cancelled. |
| 72 bool loading_; | 80 bool loading_; |
| 73 | 81 |
| 74 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource); | 82 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSource); |
| 75 }; | 83 }; |
| 76 | 84 |
| 77 static const int64 kFileSize = 5000000; | 85 static const int64 kFileSize = 5000000; |
| 78 static const int64 kFarReadPosition = 4000000; | 86 static const int64 kFarReadPosition = 4000000; |
| 79 static const int kDataSize = 1024; | 87 static const int kDataSize = 1024; |
| 80 | 88 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 174 |
| 167 Preload preload() { return data_source_->preload_; } | 175 Preload preload() { return data_source_->preload_; } |
| 168 BufferedResourceLoader::DeferStrategy defer_strategy() { | 176 BufferedResourceLoader::DeferStrategy defer_strategy() { |
| 169 return loader()->defer_strategy_; | 177 return loader()->defer_strategy_; |
| 170 } | 178 } |
| 171 int data_source_bitrate() { return data_source_->bitrate_; } | 179 int data_source_bitrate() { return data_source_->bitrate_; } |
| 172 int data_source_playback_rate() { return data_source_->playback_rate_; } | 180 int data_source_playback_rate() { return data_source_->playback_rate_; } |
| 173 int loader_bitrate() { return loader()->bitrate_; } | 181 int loader_bitrate() { return loader()->bitrate_; } |
| 174 int loader_playback_rate() { return loader()->playback_rate_; } | 182 int loader_playback_rate() { return loader()->playback_rate_; } |
| 175 | 183 |
| 176 | |
| 177 scoped_refptr<MockBufferedDataSource> data_source_; | 184 scoped_refptr<MockBufferedDataSource> data_source_; |
| 178 | 185 |
| 179 TestResponseGenerator response_generator_; | 186 TestResponseGenerator response_generator_; |
| 180 MockWebFrameClient client_; | 187 MockWebFrameClient client_; |
| 181 WebView* view_; | 188 WebView* view_; |
| 182 | 189 |
| 183 StrictMock<media::MockDataSourceHost> host_; | 190 StrictMock<media::MockDataSourceHost> host_; |
| 184 MessageLoop message_loop_; | 191 MessageLoop message_loop_; |
| 185 | 192 |
| 186 private: | 193 private: |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 Stop(); | 432 Stop(); |
| 426 } | 433 } |
| 427 | 434 |
| 428 TEST_F(BufferedDataSourceTest, Read) { | 435 TEST_F(BufferedDataSourceTest, Read) { |
| 429 InitializeWith206Response(); | 436 InitializeWith206Response(); |
| 430 | 437 |
| 431 ReadAt(0); | 438 ReadAt(0); |
| 432 | 439 |
| 433 // When the read completes we'll update our network status. | 440 // When the read completes we'll update our network status. |
| 434 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); | 441 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); |
| 435 EXPECT_CALL(host_, SetNetworkActivity(true)); | |
| 436 EXPECT_CALL(*this, ReadCallback(kDataSize)); | 442 EXPECT_CALL(*this, ReadCallback(kDataSize)); |
| 437 FinishRead(); | 443 FinishRead(); |
| 444 EXPECT_TRUE(data_source_->downloading()); |
| 438 | 445 |
| 439 // During teardown we'll also report our final network status. | 446 // During teardown we'll also report our final network status. |
| 440 EXPECT_CALL(host_, SetNetworkActivity(false)); | |
| 441 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); | 447 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); |
| 442 | 448 |
| 443 EXPECT_TRUE(data_source_->loading()); | 449 EXPECT_TRUE(data_source_->downloading()); |
| 444 Stop(); | 450 Stop(); |
| 451 EXPECT_FALSE(data_source_->downloading()); |
| 445 } | 452 } |
| 446 | 453 |
| 447 } // namespace webkit_media | 454 } // namespace webkit_media |
| OLD | NEW |