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/public/common/url_constants.h" |
8 #include "content/renderer/media/buffered_data_source.h" | 8 #include "content/renderer/media/buffered_data_source.h" |
9 #include "content/renderer/media/test_response_generator.h" | 9 #include "content/renderer/media/test_response_generator.h" |
10 #include "content/test/mock_webframeclient.h" | 10 #include "content/test/mock_webframeclient.h" |
11 #include "content/test/mock_weburlloader.h" | 11 #include "content/test/mock_weburlloader.h" |
12 #include "media/base/media_log.h" | 12 #include "media/base/media_log.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/WebLocalFrame.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::WebLocalFrame; |
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 { | 34 class MockBufferedDataSourceHost : public BufferedDataSourceHost { |
35 public: | 35 public: |
36 MockBufferedDataSourceHost() {} | 36 MockBufferedDataSourceHost() {} |
37 virtual ~MockBufferedDataSourceHost() {} | 37 virtual ~MockBufferedDataSourceHost() {} |
38 | 38 |
39 MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes)); | 39 MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes)); |
40 MOCK_METHOD2(AddBufferedByteRange, void(int64 start, int64 end)); | 40 MOCK_METHOD2(AddBufferedByteRange, void(int64 start, int64 end)); |
41 | 41 |
42 private: | 42 private: |
43 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost); | 43 DISALLOW_COPY_AND_ASSIGN(MockBufferedDataSourceHost); |
44 }; | 44 }; |
45 | 45 |
46 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. | 46 // Overrides CreateResourceLoader() to permit injecting a MockWebURLLoader. |
47 // Also keeps track of whether said MockWebURLLoader is actively loading. | 47 // Also keeps track of whether said MockWebURLLoader is actively loading. |
48 class MockBufferedDataSource : public BufferedDataSource { | 48 class MockBufferedDataSource : public BufferedDataSource { |
49 public: | 49 public: |
50 MockBufferedDataSource( | 50 MockBufferedDataSource( |
51 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 51 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
52 WebFrame* frame, | 52 WebLocalFrame* frame, |
53 BufferedDataSourceHost* host) | 53 BufferedDataSourceHost* host) |
54 : BufferedDataSource(message_loop, frame, new media::MediaLog(), host, | 54 : BufferedDataSource(message_loop, frame, new media::MediaLog(), host, |
55 base::Bind(&MockBufferedDataSource::set_downloading, | 55 base::Bind(&MockBufferedDataSource::set_downloading, |
56 base::Unretained(this))), | 56 base::Unretained(this))), |
57 downloading_(false), | 57 downloading_(false), |
58 loading_(false) { | 58 loading_(false) { |
59 } | 59 } |
60 virtual ~MockBufferedDataSource() {} | 60 virtual ~MockBufferedDataSource() {} |
61 | 61 |
62 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); | 62 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 static const int64 kFileSize = 5000000; | 98 static const int64 kFileSize = 5000000; |
99 static const int64 kFarReadPosition = 4000000; | 99 static const int64 kFarReadPosition = 4000000; |
100 static const int kDataSize = 1024; | 100 static const int kDataSize = 1024; |
101 | 101 |
102 static const char kHttpUrl[] = "http://localhost/foo.webm"; | 102 static const char kHttpUrl[] = "http://localhost/foo.webm"; |
103 static const char kFileUrl[] = "file:///tmp/bar.webm"; | 103 static const char kFileUrl[] = "file:///tmp/bar.webm"; |
104 | 104 |
105 class BufferedDataSourceTest : public testing::Test { | 105 class BufferedDataSourceTest : public testing::Test { |
106 public: | 106 public: |
107 BufferedDataSourceTest() | 107 BufferedDataSourceTest() |
108 : view_(WebView::create(NULL)), frame_(WebFrame::create(&client_)) { | 108 : view_(WebView::create(NULL)), frame_(WebLocalFrame::create(&client_)) { |
109 view_->setMainFrame(frame_); | 109 view_->setMainFrame(frame_); |
110 | 110 |
111 data_source_.reset(new MockBufferedDataSource( | 111 data_source_.reset( |
112 message_loop_.message_loop_proxy(), view_->mainFrame(), &host_)); | 112 new MockBufferedDataSource(message_loop_.message_loop_proxy(), |
| 113 view_->mainFrame()->toWebLocalFrame(), |
| 114 &host_)); |
113 } | 115 } |
114 | 116 |
115 virtual ~BufferedDataSourceTest() { | 117 virtual ~BufferedDataSourceTest() { |
116 view_->close(); | 118 view_->close(); |
117 frame_->close(); | 119 frame_->close(); |
118 } | 120 } |
119 | 121 |
120 MOCK_METHOD1(OnInitialize, void(bool)); | 122 MOCK_METHOD1(OnInitialize, void(bool)); |
121 | 123 |
122 void Initialize(const char* url, bool expected) { | 124 void Initialize(const char* url, bool expected) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 int data_source_bitrate() { return data_source_->bitrate_; } | 217 int data_source_bitrate() { return data_source_->bitrate_; } |
216 int data_source_playback_rate() { return data_source_->playback_rate_; } | 218 int data_source_playback_rate() { return data_source_->playback_rate_; } |
217 int loader_bitrate() { return loader()->bitrate_; } | 219 int loader_bitrate() { return loader()->bitrate_; } |
218 int loader_playback_rate() { return loader()->playback_rate_; } | 220 int loader_playback_rate() { return loader()->playback_rate_; } |
219 | 221 |
220 scoped_ptr<MockBufferedDataSource> data_source_; | 222 scoped_ptr<MockBufferedDataSource> data_source_; |
221 | 223 |
222 scoped_ptr<TestResponseGenerator> response_generator_; | 224 scoped_ptr<TestResponseGenerator> response_generator_; |
223 MockWebFrameClient client_; | 225 MockWebFrameClient client_; |
224 WebView* view_; | 226 WebView* view_; |
225 WebFrame* frame_; | 227 WebLocalFrame* frame_; |
226 | 228 |
227 StrictMock<MockBufferedDataSourceHost> host_; | 229 StrictMock<MockBufferedDataSourceHost> host_; |
228 base::MessageLoop message_loop_; | 230 base::MessageLoop message_loop_; |
229 | 231 |
230 private: | 232 private: |
231 // Used for calling BufferedDataSource::Read(). | 233 // Used for calling BufferedDataSource::Read(). |
232 uint8 buffer_[kDataSize]; | 234 uint8 buffer_[kDataSize]; |
233 | 235 |
234 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); | 236 DISALLOW_COPY_AND_ASSIGN(BufferedDataSourceTest); |
235 }; | 237 }; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 InitializeWithFileResponse(); | 662 InitializeWithFileResponse(); |
661 | 663 |
662 EXPECT_FALSE(data_source_->downloading()); | 664 EXPECT_FALSE(data_source_->downloading()); |
663 FinishLoading(); | 665 FinishLoading(); |
664 EXPECT_FALSE(data_source_->downloading()); | 666 EXPECT_FALSE(data_source_->downloading()); |
665 | 667 |
666 Stop(); | 668 Stop(); |
667 } | 669 } |
668 | 670 |
669 } // namespace content | 671 } // namespace content |
OLD | NEW |