| 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 "android_webview/browser/net/android_stream_reader_url_request_job.h" | 5 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "android_webview/browser/input_stream.h" | 10 #include "android_webview/browser/input_stream.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 // Required in order to create an instance of AndroidStreamReaderURLRequestJob. | 75 // Required in order to create an instance of AndroidStreamReaderURLRequestJob. |
| 76 class StreamReaderDelegate : | 76 class StreamReaderDelegate : |
| 77 public AndroidStreamReaderURLRequestJob::Delegate { | 77 public AndroidStreamReaderURLRequestJob::Delegate { |
| 78 public: | 78 public: |
| 79 StreamReaderDelegate() {} | 79 StreamReaderDelegate() {} |
| 80 | 80 |
| 81 std::unique_ptr<InputStream> OpenInputStream(JNIEnv* env, | 81 std::unique_ptr<InputStream> OpenInputStream(JNIEnv* env, |
| 82 const GURL& url) override { | 82 const GURL& url) override { |
| 83 return base::WrapUnique(new NotImplInputStream()); | 83 return base::MakeUnique<NotImplInputStream>(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void OnInputStreamOpenFailed(net::URLRequest* request, | 86 void OnInputStreamOpenFailed(net::URLRequest* request, |
| 87 bool* restart) override { | 87 bool* restart) override { |
| 88 *restart = false; | 88 *restart = false; |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool GetMimeType(JNIEnv* env, | 91 bool GetMimeType(JNIEnv* env, |
| 92 net::URLRequest* request, | 92 net::URLRequest* request, |
| 93 android_webview::InputStream* stream, | 93 android_webview::InputStream* stream, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 void SetRange(net::URLRequest* req, int first_byte, int last_byte) { | 204 void SetRange(net::URLRequest* req, int first_byte, int last_byte) { |
| 205 net::HttpRequestHeaders headers; | 205 net::HttpRequestHeaders headers; |
| 206 headers.SetHeader(net::HttpRequestHeaders::kRange, | 206 headers.SetHeader(net::HttpRequestHeaders::kRange, |
| 207 net::HttpByteRange::Bounded( | 207 net::HttpByteRange::Bounded( |
| 208 first_byte, last_byte).GetHeaderValue()); | 208 first_byte, last_byte).GetHeaderValue()); |
| 209 req->SetExtraRequestHeaders(headers); | 209 req->SetExtraRequestHeaders(headers); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void SetUpTestJob(std::unique_ptr<InputStreamReader> stream_reader) { | 212 void SetUpTestJob(std::unique_ptr<InputStreamReader> stream_reader) { |
| 213 SetUpTestJob(std::move(stream_reader), | 213 SetUpTestJob(std::move(stream_reader), |
| 214 base::WrapUnique(new StreamReaderDelegate())); | 214 base::MakeUnique<StreamReaderDelegate>()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void SetUpTestJob(std::unique_ptr<InputStreamReader> stream_reader, | 217 void SetUpTestJob(std::unique_ptr<InputStreamReader> stream_reader, |
| 218 std::unique_ptr<AndroidStreamReaderURLRequestJob::Delegate> | 218 std::unique_ptr<AndroidStreamReaderURLRequestJob::Delegate> |
| 219 stream_reader_delegate) { | 219 stream_reader_delegate) { |
| 220 std::unique_ptr<TestStreamReaderJob> test_stream_reader_job( | 220 std::unique_ptr<TestStreamReaderJob> test_stream_reader_job( |
| 221 new TestStreamReaderJob(req_.get(), &network_delegate_, | 221 new TestStreamReaderJob(req_.get(), &network_delegate_, |
| 222 std::move(stream_reader_delegate), | 222 std::move(stream_reader_delegate), |
| 223 std::move(stream_reader))); | 223 std::move(stream_reader))); |
| 224 // The Interceptor is owned by the |factory_|. | 224 // The Interceptor is owned by the |factory_|. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // The TestDelegate will quit the message loop on request completion. | 256 // The TestDelegate will quit the message loop on request completion. |
| 257 base::MessageLoop::current()->Run(); | 257 base::MessageLoop::current()->Run(); |
| 258 | 258 |
| 259 EXPECT_FALSE(url_request_delegate_.request_failed()); | 259 EXPECT_FALSE(url_request_delegate_.request_failed()); |
| 260 EXPECT_EQ(1, network_delegate_.completed_requests()); | 260 EXPECT_EQ(1, network_delegate_.completed_requests()); |
| 261 EXPECT_EQ(0, network_delegate_.error_count()); | 261 EXPECT_EQ(0, network_delegate_.error_count()); |
| 262 EXPECT_EQ(200, req_->GetResponseCode()); | 262 EXPECT_EQ(200, req_->GetResponseCode()); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST_F(AndroidStreamReaderURLRequestJobTest, ReadWithNullStream) { | 265 TEST_F(AndroidStreamReaderURLRequestJobTest, ReadWithNullStream) { |
| 266 SetUpTestJob(nullptr, base::WrapUnique(new NullStreamReaderDelegate())); | 266 SetUpTestJob(nullptr, base::MakeUnique<NullStreamReaderDelegate>()); |
| 267 req_->Start(); | 267 req_->Start(); |
| 268 | 268 |
| 269 // The TestDelegate will quit the message loop on request completion. | 269 // The TestDelegate will quit the message loop on request completion. |
| 270 base::MessageLoop::current()->Run(); | 270 base::MessageLoop::current()->Run(); |
| 271 | 271 |
| 272 // The request_failed() method is named confusingly but all it checks is | 272 // The request_failed() method is named confusingly but all it checks is |
| 273 // whether the request got as far as calling NotifyHeadersComplete. | 273 // whether the request got as far as calling NotifyHeadersComplete. |
| 274 EXPECT_FALSE(url_request_delegate_.request_failed()); | 274 EXPECT_FALSE(url_request_delegate_.request_failed()); |
| 275 EXPECT_EQ(1, network_delegate_.completed_requests()); | 275 EXPECT_EQ(1, network_delegate_.completed_requests()); |
| 276 // A null input stream shouldn't result in an error. See crbug.com/180950. | 276 // A null input stream shouldn't result in an error. See crbug.com/180950. |
| 277 EXPECT_EQ(0, network_delegate_.error_count()); | 277 EXPECT_EQ(0, network_delegate_.error_count()); |
| 278 EXPECT_EQ(404, req_->GetResponseCode()); | 278 EXPECT_EQ(404, req_->GetResponseCode()); |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST_F(AndroidStreamReaderURLRequestJobTest, ModifyHeadersAndStatus) { | 281 TEST_F(AndroidStreamReaderURLRequestJobTest, ModifyHeadersAndStatus) { |
| 282 SetUpTestJob(nullptr, | 282 SetUpTestJob(nullptr, base::MakeUnique<HeaderAlteringStreamReaderDelegate>()); |
| 283 base::WrapUnique(new HeaderAlteringStreamReaderDelegate())); | |
| 284 req_->Start(); | 283 req_->Start(); |
| 285 | 284 |
| 286 // The TestDelegate will quit the message loop on request completion. | 285 // The TestDelegate will quit the message loop on request completion. |
| 287 base::MessageLoop::current()->Run(); | 286 base::MessageLoop::current()->Run(); |
| 288 | 287 |
| 289 // The request_failed() method is named confusingly but all it checks is | 288 // The request_failed() method is named confusingly but all it checks is |
| 290 // whether the request got as far as calling NotifyHeadersComplete. | 289 // whether the request got as far as calling NotifyHeadersComplete. |
| 291 EXPECT_FALSE(url_request_delegate_.request_failed()); | 290 EXPECT_FALSE(url_request_delegate_.request_failed()); |
| 292 EXPECT_EQ(1, network_delegate_.completed_requests()); | 291 EXPECT_EQ(1, network_delegate_.completed_requests()); |
| 293 // A null input stream shouldn't result in an error. See crbug.com/180950. | 292 // A null input stream shouldn't result in an error. See crbug.com/180950. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 req_->Start(); | 410 req_->Start(); |
| 412 | 411 |
| 413 loop.Run(); | 412 loop.Run(); |
| 414 | 413 |
| 415 EXPECT_EQ(0, network_delegate_.completed_requests()); | 414 EXPECT_EQ(0, network_delegate_.completed_requests()); |
| 416 req_->Cancel(); | 415 req_->Cancel(); |
| 417 EXPECT_EQ(1, network_delegate_.completed_requests()); | 416 EXPECT_EQ(1, network_delegate_.completed_requests()); |
| 418 } | 417 } |
| 419 | 418 |
| 420 } // namespace android_webview | 419 } // namespace android_webview |
| OLD | NEW |