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_loading, | |
scherkus (not reviewing)
2012/06/12 02:55:04
I think you need a downloading_ variable instead o
Ami GONE FROM CHROMIUM
2012/06/12 03:42:43
Done.
| |
42 base::Unretained(this))), | |
41 loading_(false) { | 43 loading_(false) { |
42 } | 44 } |
43 | 45 |
44 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); | 46 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); |
45 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, | 47 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, |
46 int64 last_byte_position) { | 48 int64 last_byte_position) { |
47 CHECK(!loading_) << "Previous resource load wasn't cancelled"; | 49 CHECK(!loading_) << "Previous resource load wasn't cancelled"; |
48 | 50 |
49 BufferedResourceLoader* loader = | 51 BufferedResourceLoader* loader = |
50 BufferedDataSource::CreateResourceLoader(first_byte_position, | 52 BufferedDataSource::CreateResourceLoader(first_byte_position, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 | 168 |
167 Preload preload() { return data_source_->preload_; } | 169 Preload preload() { return data_source_->preload_; } |
168 BufferedResourceLoader::DeferStrategy defer_strategy() { | 170 BufferedResourceLoader::DeferStrategy defer_strategy() { |
169 return loader()->defer_strategy_; | 171 return loader()->defer_strategy_; |
170 } | 172 } |
171 int data_source_bitrate() { return data_source_->bitrate_; } | 173 int data_source_bitrate() { return data_source_->bitrate_; } |
172 int data_source_playback_rate() { return data_source_->playback_rate_; } | 174 int data_source_playback_rate() { return data_source_->playback_rate_; } |
173 int loader_bitrate() { return loader()->bitrate_; } | 175 int loader_bitrate() { return loader()->bitrate_; } |
174 int loader_playback_rate() { return loader()->playback_rate_; } | 176 int loader_playback_rate() { return loader()->playback_rate_; } |
175 | 177 |
176 | |
177 scoped_refptr<MockBufferedDataSource> data_source_; | 178 scoped_refptr<MockBufferedDataSource> data_source_; |
178 | 179 |
179 TestResponseGenerator response_generator_; | 180 TestResponseGenerator response_generator_; |
180 MockWebFrameClient client_; | 181 MockWebFrameClient client_; |
181 WebView* view_; | 182 WebView* view_; |
182 | 183 |
183 StrictMock<media::MockDataSourceHost> host_; | 184 StrictMock<media::MockDataSourceHost> host_; |
184 MessageLoop message_loop_; | 185 MessageLoop message_loop_; |
185 | 186 |
186 private: | 187 private: |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 Stop(); | 426 Stop(); |
426 } | 427 } |
427 | 428 |
428 TEST_F(BufferedDataSourceTest, Read) { | 429 TEST_F(BufferedDataSourceTest, Read) { |
429 InitializeWith206Response(); | 430 InitializeWith206Response(); |
430 | 431 |
431 ReadAt(0); | 432 ReadAt(0); |
432 | 433 |
433 // When the read completes we'll update our network status. | 434 // When the read completes we'll update our network status. |
434 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); | 435 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); |
435 EXPECT_CALL(host_, SetNetworkActivity(true)); | |
436 EXPECT_CALL(*this, ReadCallback(kDataSize)); | 436 EXPECT_CALL(*this, ReadCallback(kDataSize)); |
437 FinishRead(); | 437 FinishRead(); |
438 EXPECT_TRUE(data_source_->loading()); | |
438 | 439 |
439 // During teardown we'll also report our final network status. | 440 // During teardown we'll also report our final network status. |
440 EXPECT_CALL(host_, SetNetworkActivity(false)); | |
441 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); | 441 EXPECT_CALL(host_, AddBufferedByteRange(0, kDataSize - 1)); |
442 | 442 |
443 EXPECT_TRUE(data_source_->loading()); | 443 EXPECT_TRUE(data_source_->loading()); |
444 Stop(); | 444 Stop(); |
445 EXPECT_FALSE(data_source_->loading()); | |
445 } | 446 } |
446 | 447 |
447 } // namespace webkit_media | 448 } // namespace webkit_media |
OLD | NEW |