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/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
14 #include "net/http/http_byte_range.h" | 15 #include "net/http/http_byte_range.h" |
15 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 17 #include "net/url_request/url_request.h" |
16 #include "net/url_request/url_request_job_factory_impl.h" | 18 #include "net/url_request/url_request_job_factory_impl.h" |
17 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
18 | 20 |
19 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 | 23 |
22 using android_webview::InputStream; | 24 using android_webview::InputStream; |
23 using android_webview::InputStreamReader; | 25 using android_webview::InputStreamReader; |
24 using net::TestDelegate; | 26 using net::TestDelegate; |
25 using net::TestJobInterceptor; | 27 using net::TestJobInterceptor; |
26 using net::TestNetworkDelegate; | 28 using net::TestNetworkDelegate; |
27 using net::TestURLRequestContext; | 29 using net::TestURLRequestContext; |
28 using net::TestURLRequest; | 30 using net::URLRequest; |
29 using testing::DoAll; | 31 using testing::DoAll; |
30 using testing::Ge; | 32 using testing::Ge; |
31 using testing::Gt; | 33 using testing::Gt; |
32 using testing::InSequence; | 34 using testing::InSequence; |
33 using testing::Invoke; | 35 using testing::Invoke; |
34 using testing::InvokeWithoutArgs; | 36 using testing::InvokeWithoutArgs; |
35 using testing::NotNull; | 37 using testing::NotNull; |
36 using testing::Return; | 38 using testing::Return; |
37 using testing::SaveArg; | 39 using testing::SaveArg; |
38 using testing::SetArgPointee; | 40 using testing::SetArgPointee; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 }; | 183 }; |
182 | 184 |
183 class AndroidStreamReaderURLRequestJobTest : public Test { | 185 class AndroidStreamReaderURLRequestJobTest : public Test { |
184 public: | 186 public: |
185 AndroidStreamReaderURLRequestJobTest() {} | 187 AndroidStreamReaderURLRequestJobTest() {} |
186 | 188 |
187 protected: | 189 protected: |
188 virtual void SetUp() { | 190 virtual void SetUp() { |
189 context_.set_job_factory(&factory_); | 191 context_.set_job_factory(&factory_); |
190 context_.set_network_delegate(&network_delegate_); | 192 context_.set_network_delegate(&network_delegate_); |
191 req_.reset(new TestURLRequest(GURL("content://foo"), | 193 req_ = context_.CreateRequest(GURL("content://foo"), |
192 net::DEFAULT_PRIORITY, | 194 net::DEFAULT_PRIORITY, |
193 &url_request_delegate_, | 195 &url_request_delegate_, |
194 &context_)); | 196 NULL); |
195 req_->set_method("GET"); | 197 req_->set_method("GET"); |
196 } | 198 } |
197 | 199 |
198 void SetRange(net::URLRequest* req, int first_byte, int last_byte) { | 200 void SetRange(net::URLRequest* req, int first_byte, int last_byte) { |
199 net::HttpRequestHeaders headers; | 201 net::HttpRequestHeaders headers; |
200 headers.SetHeader(net::HttpRequestHeaders::kRange, | 202 headers.SetHeader(net::HttpRequestHeaders::kRange, |
201 net::HttpByteRange::Bounded( | 203 net::HttpByteRange::Bounded( |
202 first_byte, last_byte).GetHeaderValue()); | 204 first_byte, last_byte).GetHeaderValue()); |
203 req->SetExtraRequestHeaders(headers); | 205 req->SetExtraRequestHeaders(headers); |
204 } | 206 } |
(...skipping 23 matching lines...) Expand all Loading... |
228 protocol_handler->set_main_intercept_job(test_stream_reader_job); | 230 protocol_handler->set_main_intercept_job(test_stream_reader_job); |
229 set_protocol = factory_.SetProtocolHandler("content", protocol_handler); | 231 set_protocol = factory_.SetProtocolHandler("content", protocol_handler); |
230 DCHECK(set_protocol); | 232 DCHECK(set_protocol); |
231 } | 233 } |
232 | 234 |
233 base::MessageLoopForIO loop_; | 235 base::MessageLoopForIO loop_; |
234 TestURLRequestContext context_; | 236 TestURLRequestContext context_; |
235 android_webview::AwURLRequestJobFactory factory_; | 237 android_webview::AwURLRequestJobFactory factory_; |
236 TestDelegate url_request_delegate_; | 238 TestDelegate url_request_delegate_; |
237 TestNetworkDelegate network_delegate_; | 239 TestNetworkDelegate network_delegate_; |
238 scoped_ptr<TestURLRequest> req_; | 240 scoped_ptr<URLRequest> req_; |
239 }; | 241 }; |
240 | 242 |
241 TEST_F(AndroidStreamReaderURLRequestJobTest, ReadEmptyStream) { | 243 TEST_F(AndroidStreamReaderURLRequestJobTest, ReadEmptyStream) { |
242 scoped_ptr<StrictMock<MockInputStreamReader> > stream_reader( | 244 scoped_ptr<StrictMock<MockInputStreamReader> > stream_reader( |
243 new StrictMock<MockInputStreamReader>()); | 245 new StrictMock<MockInputStreamReader>()); |
244 { | 246 { |
245 InSequence s; | 247 InSequence s; |
246 EXPECT_CALL(*stream_reader, Seek(_)) | 248 EXPECT_CALL(*stream_reader, Seek(_)) |
247 .WillOnce(Return(0)); | 249 .WillOnce(Return(0)); |
248 EXPECT_CALL(*stream_reader, ReadRawData(NotNull(), Gt(0))) | 250 EXPECT_CALL(*stream_reader, ReadRawData(NotNull(), Gt(0))) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 414 |
413 SetRange(req_.get(), offset, bytes_available); | 415 SetRange(req_.get(), offset, bytes_available); |
414 req_->Start(); | 416 req_->Start(); |
415 | 417 |
416 loop.Run(); | 418 loop.Run(); |
417 | 419 |
418 EXPECT_EQ(0, network_delegate_.completed_requests()); | 420 EXPECT_EQ(0, network_delegate_.completed_requests()); |
419 req_->Cancel(); | 421 req_->Cancel(); |
420 EXPECT_EQ(1, network_delegate_.completed_requests()); | 422 EXPECT_EQ(1, network_delegate_.completed_requests()); |
421 } | 423 } |
OLD | NEW |