| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 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 GURL& url, |
| 51 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 52 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 52 WebLocalFrame* frame, | 53 WebLocalFrame* frame, |
| 53 BufferedDataSourceHost* host) | 54 BufferedDataSourceHost* host) |
| 54 : BufferedDataSource(message_loop, frame, new media::MediaLog(), host, | 55 : BufferedDataSource(url, |
| 56 BufferedResourceLoader::kUnspecified, |
| 57 message_loop, frame, new media::MediaLog(), host, |
| 55 base::Bind(&MockBufferedDataSource::set_downloading, | 58 base::Bind(&MockBufferedDataSource::set_downloading, |
| 56 base::Unretained(this))), | 59 base::Unretained(this))), |
| 57 downloading_(false), | 60 downloading_(false), |
| 58 loading_(false) { | 61 loading_(false) { |
| 59 } | 62 } |
| 60 virtual ~MockBufferedDataSource() {} | 63 virtual ~MockBufferedDataSource() {} |
| 61 | 64 |
| 62 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); | 65 MOCK_METHOD2(CreateResourceLoader, BufferedResourceLoader*(int64, int64)); |
| 63 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, | 66 BufferedResourceLoader* CreateMockResourceLoader(int64 first_byte_position, |
| 64 int64 last_byte_position) { | 67 int64 last_byte_position) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 static const int kDataSize = 1024; | 103 static const int kDataSize = 1024; |
| 101 | 104 |
| 102 static const char kHttpUrl[] = "http://localhost/foo.webm"; | 105 static const char kHttpUrl[] = "http://localhost/foo.webm"; |
| 103 static const char kFileUrl[] = "file:///tmp/bar.webm"; | 106 static const char kFileUrl[] = "file:///tmp/bar.webm"; |
| 104 | 107 |
| 105 class BufferedDataSourceTest : public testing::Test { | 108 class BufferedDataSourceTest : public testing::Test { |
| 106 public: | 109 public: |
| 107 BufferedDataSourceTest() | 110 BufferedDataSourceTest() |
| 108 : view_(WebView::create(NULL)), frame_(WebLocalFrame::create(&client_)) { | 111 : view_(WebView::create(NULL)), frame_(WebLocalFrame::create(&client_)) { |
| 109 view_->setMainFrame(frame_); | 112 view_->setMainFrame(frame_); |
| 110 | |
| 111 data_source_.reset( | |
| 112 new MockBufferedDataSource(message_loop_.message_loop_proxy(), | |
| 113 view_->mainFrame()->toWebLocalFrame(), | |
| 114 &host_)); | |
| 115 } | 113 } |
| 116 | 114 |
| 117 virtual ~BufferedDataSourceTest() { | 115 virtual ~BufferedDataSourceTest() { |
| 118 view_->close(); | 116 view_->close(); |
| 119 frame_->close(); | 117 frame_->close(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 MOCK_METHOD1(OnInitialize, void(bool)); | 120 MOCK_METHOD1(OnInitialize, void(bool)); |
| 123 | 121 |
| 124 void Initialize(const char* url, bool expected) { | 122 void Initialize(const char* url, bool expected) { |
| 125 GURL gurl(url); | 123 GURL gurl(url); |
| 124 data_source_.reset( |
| 125 new MockBufferedDataSource(gurl, |
| 126 message_loop_.message_loop_proxy(), |
| 127 view_->mainFrame()->toWebLocalFrame(), |
| 128 &host_)); |
| 129 |
| 126 response_generator_.reset(new TestResponseGenerator(gurl, kFileSize)); | 130 response_generator_.reset(new TestResponseGenerator(gurl, kFileSize)); |
| 127 | |
| 128 ExpectCreateResourceLoader(); | 131 ExpectCreateResourceLoader(); |
| 129 EXPECT_CALL(*this, OnInitialize(expected)); | 132 EXPECT_CALL(*this, OnInitialize(expected)); |
| 130 data_source_->Initialize( | 133 data_source_->Initialize(base::Bind( |
| 131 gurl, BufferedResourceLoader::kUnspecified, base::Bind( | 134 &BufferedDataSourceTest::OnInitialize, base::Unretained(this))); |
| 132 &BufferedDataSourceTest::OnInitialize, base::Unretained(this))); | |
| 133 message_loop_.RunUntilIdle(); | 135 message_loop_.RunUntilIdle(); |
| 134 | 136 |
| 135 bool is_http = | 137 bool is_http = gurl.SchemeIsHTTPOrHTTPS(); |
| 136 gurl.SchemeIs(url::kHttpScheme) || gurl.SchemeIs(url::kHttpsScheme); | |
| 137 EXPECT_EQ(data_source_->downloading(), is_http); | 138 EXPECT_EQ(data_source_->downloading(), is_http); |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Helper to initialize tests with a valid 206 response. | 141 // Helper to initialize tests with a valid 206 response. |
| 141 void InitializeWith206Response() { | 142 void InitializeWith206Response() { |
| 142 Initialize(kHttpUrl, true); | 143 Initialize(kHttpUrl, true); |
| 143 | 144 |
| 144 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); | 145 EXPECT_CALL(host_, SetTotalBytes(response_generator_->content_length())); |
| 145 Respond(response_generator_->Generate206(0)); | 146 Respond(response_generator_->Generate206(0)); |
| 146 } | 147 } |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 InitializeWithFileResponse(); | 664 InitializeWithFileResponse(); |
| 664 | 665 |
| 665 EXPECT_FALSE(data_source_->downloading()); | 666 EXPECT_FALSE(data_source_->downloading()); |
| 666 FinishLoading(); | 667 FinishLoading(); |
| 667 EXPECT_FALSE(data_source_->downloading()); | 668 EXPECT_FALSE(data_source_->downloading()); |
| 668 | 669 |
| 669 Stop(); | 670 Stop(); |
| 670 } | 671 } |
| 671 | 672 |
| 672 } // namespace content | 673 } // namespace content |
| OLD | NEW |