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 "content/public/common/url_constants.h" |
7 #include "content/renderer/media/buffered_data_source.h" | 8 #include "content/renderer/media/buffered_data_source.h" |
8 #include "content/renderer/media/test_response_generator.h" | 9 #include "content/renderer/media/test_response_generator.h" |
9 #include "content/test/mock_webframeclient.h" | 10 #include "content/test/mock_webframeclient.h" |
10 #include "content/test/mock_weburlloader.h" | 11 #include "content/test/mock_weburlloader.h" |
11 #include "media/base/media_log.h" | 12 #include "media/base/media_log.h" |
12 #include "media/base/mock_data_source_host.h" | |
13 #include "media/base/mock_filters.h" | 13 #include "media/base/mock_filters.h" |
14 #include "media/base/test_helpers.h" | 14 #include "media/base/test_helpers.h" |
15 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 15 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
16 #include "third_party/WebKit/public/web/WebFrame.h" | 16 #include "third_party/WebKit/public/web/WebFrame.h" |
17 #include "third_party/WebKit/public/web/WebView.h" | 17 #include "third_party/WebKit/public/web/WebView.h" |
18 | 18 |
19 using ::testing::_; | 19 using ::testing::_; |
20 using ::testing::Assign; | 20 using ::testing::Assign; |
21 using ::testing::Invoke; | 21 using ::testing::Invoke; |
22 using ::testing::InSequence; | 22 using ::testing::InSequence; |
23 using ::testing::NiceMock; | 23 using ::testing::NiceMock; |
24 using ::testing::StrictMock; | 24 using ::testing::StrictMock; |
25 | 25 |
26 using blink::WebFrame; | 26 using blink::WebFrame; |
27 using blink::WebString; | 27 using blink::WebString; |
28 using blink::WebURLLoader; | 28 using blink::WebURLLoader; |
29 using blink::WebURLResponse; | 29 using blink::WebURLResponse; |
30 using blink::WebView; | 30 using blink::WebView; |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 | 33 |
| 34 class MockBufferedDataSourceHost : public BufferedDataSourceHost { |
| 35 public: |
| 36 MockBufferedDataSourceHost() {} |
| 37 virtual ~MockBufferedDataSourceHost() {} |
| 38 |
| 39 MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes)); |
| 40 MOCK_METHOD2(AddBufferedByteRange, void(int64 start, int64 end)); |
| 41 |
| 42 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost); |
| 44 }; |
| 45 |
34 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. | 46 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. |
35 // Also keeps track of whether said MockWebURLLoader is actively loading. | 47 // Also keeps track of whether said MockWebURLLoader is actively loading. |
36 class MockBufferedDataSource : public BufferedDataSource { | 48 class MockBufferedDataSource : public BufferedDataSource { |
37 public: | 49 public: |
38 MockBufferedDataSource( | 50 MockBufferedDataSource( |
39 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 51 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
40 WebFrame* frame, | 52 WebFrame* frame, |
41 media::DataSourceHost* host) | 53 BufferedDataSourceHost* host) |
42 : BufferedDataSource(message_loop, frame, new media::MediaLog(), host, | 54 : BufferedDataSource(message_loop, frame, new media::MediaLog(), host, |
43 base::Bind(&MockBufferedDataSource::set_downloading, | 55 base::Bind(&MockBufferedDataSource::set_downloading, |
44 base::Unretained(this))), | 56 base::Unretained(this))), |
45 downloading_(false), | 57 downloading_(false), |
46 loading_(false) { | 58 loading_(false) { |
47 } | 59 } |
48 virtual ~MockBufferedDataSource() {} | 60 virtual ~MockBufferedDataSource() {} |
49 | 61 |
50 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); | 62 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); |
51 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, | 63 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 int loader_bitrate() { return loader()->bitrate_; } | 217 int loader_bitrate() { return loader()->bitrate_; } |
206 int loader_playback_rate() { return loader()->playback_rate_; } | 218 int loader_playback_rate() { return loader()->playback_rate_; } |
207 | 219 |
208 scoped_ptr<MockBufferedDataSource> data_source_; | 220 scoped_ptr<MockBufferedDataSource> data_source_; |
209 | 221 |
210 scoped_ptr<TestResponseGenerator> response_generator_; | 222 scoped_ptr<TestResponseGenerator> response_generator_; |
211 MockWebFrameClient client_; | 223 MockWebFrameClient client_; |
212 WebView* view_; | 224 WebView* view_; |
213 WebFrame* frame_; | 225 WebFrame* frame_; |
214 | 226 |
215 StrictMock<media::MockDataSourceHost> host_; | 227 StrictMock<MockBufferedDataSourceHost> host_; |
216 base::MessageLoop message_loop_; | 228 base::MessageLoop message_loop_; |
217 | 229 |
218 private: | 230 private: |
219 // Used for calling BufferedDataSource::Read(). | 231 // Used for calling BufferedDataSource::Read(). |
220 uint8 buffer_[kDataSize]; | 232 uint8 buffer_[kDataSize]; |
221 | 233 |
222 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); | 234 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); |
223 }; | 235 }; |
224 | 236 |
225 TEST_F(BufferedDataSourceTest, Range_Supported) { | 237 TEST_F(BufferedDataSourceTest, Range_Supported) { |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 InitializeWithFileResponse(); | 660 InitializeWithFileResponse(); |
649 | 661 |
650 EXPECT_FALSE(data_source_->downloading()); | 662 EXPECT_FALSE(data_source_->downloading()); |
651 FinishLoading(); | 663 FinishLoading(); |
652 EXPECT_FALSE(data_source_->downloading()); | 664 EXPECT_FALSE(data_source_->downloading()); |
653 | 665 |
654 Stop(); | 666 Stop(); |
655 } | 667 } |
656 | 668 |
657 } // namespace content | 669 } // namespace content |
OLD | NEW |