| 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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 virtual base::TaskRunner* GetWorkerThreadRunner() OVERRIDE { | 140 virtual base::TaskRunner* GetWorkerThreadRunner() OVERRIDE { |
| 141 return message_loop_proxy_.get(); | 141 return message_loop_proxy_.get(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 scoped_ptr<InputStreamReader> stream_reader_; | 144 scoped_ptr<InputStreamReader> stream_reader_; |
| 145 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 145 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 class AndroidStreamReaderURLRequestJobTest : public Test { | 148 class AndroidStreamReaderURLRequestJobTest : public Test { |
| 149 public: | 149 public: |
| 150 AndroidStreamReaderURLRequestJobTest() : loop_(base::MessageLoop::TYPE_IO) {} | 150 AndroidStreamReaderURLRequestJobTest() {} |
| 151 | 151 |
| 152 protected: | 152 protected: |
| 153 virtual void SetUp() { | 153 virtual void SetUp() { |
| 154 context_.set_job_factory(&factory_); | 154 context_.set_job_factory(&factory_); |
| 155 context_.set_network_delegate(&network_delegate_); | 155 context_.set_network_delegate(&network_delegate_); |
| 156 req_.reset(new TestURLRequest(GURL("content://foo"), | 156 req_.reset(new TestURLRequest(GURL("content://foo"), |
| 157 net::DEFAULT_PRIORITY, | 157 net::DEFAULT_PRIORITY, |
| 158 &url_request_delegate_, | 158 &url_request_delegate_, |
| 159 &context_)); | 159 &context_)); |
| 160 req_->set_method("GET"); | 160 req_->set_method("GET"); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 188 protocol_handler->set_main_intercept_job(test_stream_reader_job); | 188 protocol_handler->set_main_intercept_job(test_stream_reader_job); |
| 189 bool set_protocol = factory_.SetProtocolHandler("http", protocol_handler); | 189 bool set_protocol = factory_.SetProtocolHandler("http", protocol_handler); |
| 190 DCHECK(set_protocol); | 190 DCHECK(set_protocol); |
| 191 | 191 |
| 192 protocol_handler = new TestJobInterceptor; | 192 protocol_handler = new TestJobInterceptor; |
| 193 protocol_handler->set_main_intercept_job(test_stream_reader_job); | 193 protocol_handler->set_main_intercept_job(test_stream_reader_job); |
| 194 set_protocol = factory_.SetProtocolHandler("content", protocol_handler); | 194 set_protocol = factory_.SetProtocolHandler("content", protocol_handler); |
| 195 DCHECK(set_protocol); | 195 DCHECK(set_protocol); |
| 196 } | 196 } |
| 197 | 197 |
| 198 base::MessageLoop loop_; | 198 base::MessageLoopForIO loop_; |
| 199 TestURLRequestContext context_; | 199 TestURLRequestContext context_; |
| 200 android_webview::AwURLRequestJobFactory factory_; | 200 android_webview::AwURLRequestJobFactory factory_; |
| 201 TestDelegate url_request_delegate_; | 201 TestDelegate url_request_delegate_; |
| 202 TestNetworkDelegate network_delegate_; | 202 TestNetworkDelegate network_delegate_; |
| 203 scoped_ptr<TestURLRequest> req_; | 203 scoped_ptr<TestURLRequest> req_; |
| 204 }; | 204 }; |
| 205 | 205 |
| 206 TEST_F(AndroidStreamReaderURLRequestJobTest, ReadEmptyStream) { | 206 TEST_F(AndroidStreamReaderURLRequestJobTest, ReadEmptyStream) { |
| 207 scoped_ptr<StrictMock<MockInputStreamReader> > stream_reader( | 207 scoped_ptr<StrictMock<MockInputStreamReader> > stream_reader( |
| 208 new StrictMock<MockInputStreamReader>()); | 208 new StrictMock<MockInputStreamReader>()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 348 |
| 349 SetRange(req_.get(), offset, bytes_available); | 349 SetRange(req_.get(), offset, bytes_available); |
| 350 req_->Start(); | 350 req_->Start(); |
| 351 | 351 |
| 352 loop.Run(); | 352 loop.Run(); |
| 353 | 353 |
| 354 EXPECT_EQ(0, network_delegate_.completed_requests()); | 354 EXPECT_EQ(0, network_delegate_.completed_requests()); |
| 355 req_->Cancel(); | 355 req_->Cancel(); |
| 356 EXPECT_EQ(1, network_delegate_.completed_requests()); | 356 EXPECT_EQ(1, network_delegate_.completed_requests()); |
| 357 } | 357 } |
| OLD | NEW |