| 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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "net/base/request_priority.h" |
| 13 #include "net/url_request/url_request_job_factory_impl.h" | 14 #include "net/url_request/url_request_job_factory_impl.h" |
| 14 #include "net/url_request/url_request_test_util.h" | 15 #include "net/url_request/url_request_test_util.h" |
| 15 | 16 |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using android_webview::InputStream; | 20 using android_webview::InputStream; |
| 20 using android_webview::InputStreamReader; | 21 using android_webview::InputStreamReader; |
| 22 using net::DEFAULT_PRIORITY; |
| 21 using net::TestDelegate; | 23 using net::TestDelegate; |
| 22 using net::TestJobInterceptor; | 24 using net::TestJobInterceptor; |
| 23 using net::TestNetworkDelegate; | 25 using net::TestNetworkDelegate; |
| 24 using net::TestURLRequestContext; | 26 using net::TestURLRequestContext; |
| 25 using net::TestURLRequest; | 27 using net::TestURLRequest; |
| 26 using testing::DoAll; | 28 using testing::DoAll; |
| 27 using testing::Ge; | 29 using testing::Ge; |
| 28 using testing::Gt; | 30 using testing::Gt; |
| 29 using testing::InSequence; | 31 using testing::InSequence; |
| 30 using testing::Invoke; | 32 using testing::Invoke; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 }; | 146 }; |
| 145 | 147 |
| 146 class AndroidStreamReaderURLRequestJobTest : public Test { | 148 class AndroidStreamReaderURLRequestJobTest : public Test { |
| 147 public: | 149 public: |
| 148 AndroidStreamReaderURLRequestJobTest() : loop_(base::MessageLoop::TYPE_IO) {} | 150 AndroidStreamReaderURLRequestJobTest() : loop_(base::MessageLoop::TYPE_IO) {} |
| 149 | 151 |
| 150 protected: | 152 protected: |
| 151 virtual void SetUp() { | 153 virtual void SetUp() { |
| 152 context_.set_job_factory(&factory_); | 154 context_.set_job_factory(&factory_); |
| 153 context_.set_network_delegate(&network_delegate_); | 155 context_.set_network_delegate(&network_delegate_); |
| 154 req_.reset( | 156 req_.reset(new TestURLRequest(GURL("content://foo"), |
| 155 new TestURLRequest(GURL("content://foo"), | 157 DEFAULT_PRIORITY, |
| 156 &url_request_delegate_, | 158 &url_request_delegate_, |
| 157 &context_, | 159 &context_, |
| 158 &network_delegate_)); | 160 &network_delegate_)); |
| 159 req_->set_method("GET"); | 161 req_->set_method("GET"); |
| 160 } | 162 } |
| 161 | 163 |
| 162 void SetRange(net::URLRequest* req, int first_byte, int last_byte) { | 164 void SetRange(net::URLRequest* req, int first_byte, int last_byte) { |
| 163 net::HttpRequestHeaders headers; | 165 net::HttpRequestHeaders headers; |
| 164 headers.SetHeader(net::HttpRequestHeaders::kRange, | 166 headers.SetHeader(net::HttpRequestHeaders::kRange, |
| 165 base::StringPrintf( | 167 base::StringPrintf( |
| 166 "bytes=%" PRIuS "-%" PRIuS, | 168 "bytes=%" PRIuS "-%" PRIuS, |
| 167 first_byte, last_byte)); | 169 first_byte, last_byte)); |
| 168 req->SetExtraRequestHeaders(headers); | 170 req->SetExtraRequestHeaders(headers); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 350 |
| 349 SetRange(req_.get(), offset, bytes_available); | 351 SetRange(req_.get(), offset, bytes_available); |
| 350 req_->Start(); | 352 req_->Start(); |
| 351 | 353 |
| 352 loop.Run(); | 354 loop.Run(); |
| 353 | 355 |
| 354 EXPECT_EQ(0, network_delegate_.completed_requests()); | 356 EXPECT_EQ(0, network_delegate_.completed_requests()); |
| 355 req_->Cancel(); | 357 req_->Cancel(); |
| 356 EXPECT_EQ(1, network_delegate_.completed_requests()); | 358 EXPECT_EQ(1, network_delegate_.completed_requests()); |
| 357 } | 359 } |
| OLD | NEW |