OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "media/blink/resource_multibuffer_data_provider.h" | 5 #include "media/blink/resource_multibuffer_data_provider.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 gurl_ = GURL(url); | 85 gurl_ = GURL(url); |
86 url_data_ = url_index_->GetByUrl(gurl_, UrlData::CORS_UNSPECIFIED); | 86 url_data_ = url_index_->GetByUrl(gurl_, UrlData::CORS_UNSPECIFIED); |
87 DCHECK(url_data_); | 87 DCHECK(url_data_); |
88 DCHECK(url_data_->frame()); | 88 DCHECK(url_data_->frame()); |
89 url_data_->OnRedirect( | 89 url_data_->OnRedirect( |
90 base::Bind(&ResourceMultiBufferDataProviderTest::RedirectCallback, | 90 base::Bind(&ResourceMultiBufferDataProviderTest::RedirectCallback, |
91 base::Unretained(this))); | 91 base::Unretained(this))); |
92 | 92 |
93 first_position_ = first_position; | 93 first_position_ = first_position; |
94 | 94 |
95 scoped_ptr<ResourceMultiBufferDataProvider> loader( | 95 std::unique_ptr<ResourceMultiBufferDataProvider> loader( |
96 new ResourceMultiBufferDataProvider(url_data_.get(), first_position_)); | 96 new ResourceMultiBufferDataProvider(url_data_.get(), first_position_)); |
97 loader_ = loader.get(); | 97 loader_ = loader.get(); |
98 url_data_->multibuffer()->AddProvider(std::move(loader)); | 98 url_data_->multibuffer()->AddProvider(std::move(loader)); |
99 | 99 |
100 // |test_loader_| will be used when Start() is called. | 100 // |test_loader_| will be used when Start() is called. |
101 url_loader_ = new NiceMock<MockWebURLLoader>(); | 101 url_loader_ = new NiceMock<MockWebURLLoader>(); |
102 loader_->test_loader_ = scoped_ptr<blink::WebURLLoader>(url_loader_); | 102 loader_->test_loader_ = std::unique_ptr<blink::WebURLLoader>(url_loader_); |
103 } | 103 } |
104 | 104 |
105 void Start() { | 105 void Start() { |
106 InSequence s; | 106 InSequence s; |
107 EXPECT_CALL(*url_loader_, | 107 EXPECT_CALL(*url_loader_, |
108 loadAsynchronously(Truly(CorrectAcceptEncoding), loader_)); | 108 loadAsynchronously(Truly(CorrectAcceptEncoding), loader_)); |
109 | 109 |
110 loader_->Start(); | 110 loader_->Start(); |
111 } | 111 } |
112 | 112 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 url_data_ = nullptr; | 191 url_data_ = nullptr; |
192 } | 192 } |
193 | 193 |
194 // Helper method to write to |loader_| from |data_|. | 194 // Helper method to write to |loader_| from |data_|. |
195 void WriteLoader(int position, int size) { | 195 void WriteLoader(int position, int size) { |
196 loader_->didReceiveData( | 196 loader_->didReceiveData( |
197 url_loader_, reinterpret_cast<char*>(data_ + position), size, size); | 197 url_loader_, reinterpret_cast<char*>(data_ + position), size, size); |
198 } | 198 } |
199 | 199 |
200 void WriteData(int size) { | 200 void WriteData(int size) { |
201 scoped_ptr<char[]> data(new char[size]); | 201 std::unique_ptr<char[]> data(new char[size]); |
202 loader_->didReceiveData(url_loader_, data.get(), size, size); | 202 loader_->didReceiveData(url_loader_, data.get(), size, size); |
203 } | 203 } |
204 | 204 |
205 // Verifies that data in buffer[0...size] is equal to data_[pos...pos+size]. | 205 // Verifies that data in buffer[0...size] is equal to data_[pos...pos+size]. |
206 void VerifyBuffer(uint8_t* buffer, int pos, int size) { | 206 void VerifyBuffer(uint8_t* buffer, int pos, int size) { |
207 EXPECT_EQ(0, memcmp(buffer, data_ + pos, size)); | 207 EXPECT_EQ(0, memcmp(buffer, data_ + pos, size)); |
208 } | 208 } |
209 | 209 |
210 bool HasActiveLoader() { return loader_->active_loader_ != nullptr; } | 210 bool HasActiveLoader() { return loader_->active_loader_ != nullptr; } |
211 MOCK_METHOD1(RedirectCallback, void(const scoped_refptr<UrlData>&)); | 211 MOCK_METHOD1(RedirectCallback, void(const scoped_refptr<UrlData>&)); |
212 | 212 |
213 void SetUrlData(const scoped_refptr<UrlData>& new_url_data) { | 213 void SetUrlData(const scoped_refptr<UrlData>& new_url_data) { |
214 url_data_ = new_url_data; | 214 url_data_ = new_url_data; |
215 } | 215 } |
216 | 216 |
217 protected: | 217 protected: |
218 GURL gurl_; | 218 GURL gurl_; |
219 int64_t first_position_; | 219 int64_t first_position_; |
220 | 220 |
221 scoped_ptr<UrlIndex> url_index_; | 221 std::unique_ptr<UrlIndex> url_index_; |
222 scoped_refptr<UrlData> url_data_; | 222 scoped_refptr<UrlData> url_data_; |
223 scoped_refptr<UrlData> redirected_to_; | 223 scoped_refptr<UrlData> redirected_to_; |
224 // The loader is owned by the UrlData above. | 224 // The loader is owned by the UrlData above. |
225 ResourceMultiBufferDataProvider* loader_; | 225 ResourceMultiBufferDataProvider* loader_; |
226 NiceMock<MockWebURLLoader>* url_loader_; | 226 NiceMock<MockWebURLLoader>* url_loader_; |
227 | 227 |
228 MockWebFrameClient client_; | 228 MockWebFrameClient client_; |
229 WebView* view_; | 229 WebView* view_; |
230 WebLocalFrame* frame_; | 230 WebLocalFrame* frame_; |
231 | 231 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { | 325 TEST_F(ResourceMultiBufferDataProviderTest, TestRedirects) { |
326 // Test redirect. | 326 // Test redirect. |
327 Initialize(kHttpUrl, 0); | 327 Initialize(kHttpUrl, 0); |
328 Start(); | 328 Start(); |
329 Redirect(kHttpRedirect); | 329 Redirect(kHttpRedirect); |
330 FullResponse(1024); | 330 FullResponse(1024); |
331 StopWhenLoad(); | 331 StopWhenLoad(); |
332 } | 332 } |
333 | 333 |
334 } // namespace media | 334 } // namespace media |
OLD | NEW |