| 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/input_stream.h" | 5 #include "android_webview/browser/input_stream.h" |
| 6 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" | 6 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
| 7 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 7 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
| 8 #include "android_webview/browser/net/input_stream_reader.h" | 8 #include "android_webview/browser/net/input_stream_reader.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 15 #include "net/base/request_priority.h" | 15 #include "net/base/request_priority.h" |
| 16 #include "net/http/http_byte_range.h" | 16 #include "net/http/http_byte_range.h" |
| 17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 18 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 19 #include "net/url_request/url_request_job_factory_impl.h" | 19 #include "net/url_request/url_request_job_factory_impl.h" |
| 20 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 21 | 21 |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 using android_webview::InputStream; | |
| 26 using android_webview::InputStreamReader; | |
| 27 using net::TestDelegate; | 25 using net::TestDelegate; |
| 28 using net::TestJobInterceptor; | 26 using net::TestJobInterceptor; |
| 29 using net::TestNetworkDelegate; | 27 using net::TestNetworkDelegate; |
| 30 using net::TestURLRequestContext; | 28 using net::TestURLRequestContext; |
| 31 using net::URLRequest; | 29 using net::URLRequest; |
| 32 using testing::DoAll; | 30 using testing::DoAll; |
| 33 using testing::Ge; | 31 using testing::Ge; |
| 34 using testing::Gt; | 32 using testing::Gt; |
| 35 using testing::InSequence; | 33 using testing::InSequence; |
| 36 using testing::Invoke; | 34 using testing::Invoke; |
| 37 using testing::InvokeWithoutArgs; | 35 using testing::InvokeWithoutArgs; |
| 38 using testing::NotNull; | 36 using testing::NotNull; |
| 39 using testing::Return; | 37 using testing::Return; |
| 40 using testing::SaveArg; | 38 using testing::SaveArg; |
| 41 using testing::SetArgPointee; | 39 using testing::SetArgPointee; |
| 42 using testing::StrictMock; | 40 using testing::StrictMock; |
| 43 using testing::Test; | 41 using testing::Test; |
| 44 using testing::WithArg; | 42 using testing::WithArg; |
| 45 using testing::WithArgs; | 43 using testing::WithArgs; |
| 46 using testing::_; | 44 using testing::_; |
| 47 | 45 |
| 46 namespace android_webview { |
| 47 |
| 48 namespace { |
| 49 |
| 48 // Some of the classes will DCHECK on a null InputStream (which is desirable). | 50 // Some of the classes will DCHECK on a null InputStream (which is desirable). |
| 49 // The workaround is to use this class. None of the methods need to be | 51 // The workaround is to use this class. None of the methods need to be |
| 50 // implemented as the mock InputStreamReader should never forward calls to the | 52 // implemented as the mock InputStreamReader should never forward calls to the |
| 51 // InputStream. | 53 // InputStream. |
| 52 class NotImplInputStream : public InputStream { | 54 class NotImplInputStream : public InputStream { |
| 53 public: | 55 public: |
| 54 NotImplInputStream() {} | 56 NotImplInputStream() {} |
| 55 ~NotImplInputStream() override {} | 57 ~NotImplInputStream() override {} |
| 56 bool BytesAvailable(int* bytes_available) const override { | 58 bool BytesAvailable(int* bytes_available) const override { |
| 57 NOTIMPLEMENTED(); | 59 NOTIMPLEMENTED(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 ~TestStreamReaderJob() override {} | 174 ~TestStreamReaderJob() override {} |
| 173 | 175 |
| 174 base::TaskRunner* GetWorkerThreadRunner() override { | 176 base::TaskRunner* GetWorkerThreadRunner() override { |
| 175 return task_runner_.get(); | 177 return task_runner_.get(); |
| 176 } | 178 } |
| 177 | 179 |
| 178 scoped_ptr<InputStreamReader> stream_reader_; | 180 scoped_ptr<InputStreamReader> stream_reader_; |
| 179 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 181 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 180 }; | 182 }; |
| 181 | 183 |
| 184 } // namespace |
| 185 |
| 186 |
| 182 class AndroidStreamReaderURLRequestJobTest : public Test { | 187 class AndroidStreamReaderURLRequestJobTest : public Test { |
| 183 public: | 188 public: |
| 184 AndroidStreamReaderURLRequestJobTest() {} | 189 AndroidStreamReaderURLRequestJobTest() {} |
| 185 | 190 |
| 186 protected: | 191 protected: |
| 187 void SetUp() override { | 192 void SetUp() override { |
| 188 context_.set_job_factory(&factory_); | 193 context_.set_job_factory(&factory_); |
| 189 context_.set_network_delegate(&network_delegate_); | 194 context_.set_network_delegate(&network_delegate_); |
| 190 req_ = context_.CreateRequest(GURL("content://foo"), | 195 req_ = context_.CreateRequest(GURL("content://foo"), |
| 191 net::DEFAULT_PRIORITY, | 196 net::DEFAULT_PRIORITY, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 | 413 |
| 409 SetRange(req_.get(), offset, bytes_available); | 414 SetRange(req_.get(), offset, bytes_available); |
| 410 req_->Start(); | 415 req_->Start(); |
| 411 | 416 |
| 412 loop.Run(); | 417 loop.Run(); |
| 413 | 418 |
| 414 EXPECT_EQ(0, network_delegate_.completed_requests()); | 419 EXPECT_EQ(0, network_delegate_.completed_requests()); |
| 415 req_->Cancel(); | 420 req_->Cancel(); |
| 416 EXPECT_EQ(1, network_delegate_.completed_requests()); | 421 EXPECT_EQ(1, network_delegate_.completed_requests()); |
| 417 } | 422 } |
| 423 |
| 424 } // namespace android_webview |
| OLD | NEW |