| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "net/base/request_priority.h" | 8 #include "net/base/request_priority.h" |
| 9 #include "net/url_request/url_request_job.h" | 9 #include "net/url_request/url_request_job.h" |
| 10 #include "net/url_request/url_request_job_factory.h" | 10 #include "net/url_request/url_request_job_factory.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class MockSimpleJob : public URLRequestSimpleJob { | 28 class MockSimpleJob : public URLRequestSimpleJob { |
| 29 public: | 29 public: |
| 30 MockSimpleJob(URLRequest* request, NetworkDelegate* network_delegate) | 30 MockSimpleJob(URLRequest* request, NetworkDelegate* network_delegate) |
| 31 : URLRequestSimpleJob(request, network_delegate) { | 31 : URLRequestSimpleJob(request, network_delegate) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 protected: | 34 protected: |
| 35 virtual int GetData(std::string* mime_type, | 35 virtual int GetData(std::string* mime_type, |
| 36 std::string* charset, | 36 std::string* charset, |
| 37 std::string* data, | 37 std::string* data, |
| 38 const CompletionCallback& callback) const OVERRIDE { | 38 const CompletionCallback& callback) const override { |
| 39 mime_type->assign("text/plain"); | 39 mime_type->assign("text/plain"); |
| 40 charset->assign("US-ASCII"); | 40 charset->assign("US-ASCII"); |
| 41 data->assign(kTestData); | 41 data->assign(kTestData); |
| 42 return OK; | 42 return OK; |
| 43 } | 43 } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 virtual ~MockSimpleJob() {} | 46 virtual ~MockSimpleJob() {} |
| 47 | 47 |
| 48 std::string data_; | 48 std::string data_; |
| 49 | 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(MockSimpleJob); | 50 DISALLOW_COPY_AND_ASSIGN(MockSimpleJob); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 class SimpleJobProtocolHandler : | 53 class SimpleJobProtocolHandler : |
| 54 public URLRequestJobFactory::ProtocolHandler { | 54 public URLRequestJobFactory::ProtocolHandler { |
| 55 public: | 55 public: |
| 56 virtual URLRequestJob* MaybeCreateJob( | 56 virtual URLRequestJob* MaybeCreateJob( |
| 57 URLRequest* request, | 57 URLRequest* request, |
| 58 NetworkDelegate* network_delegate) const OVERRIDE { | 58 NetworkDelegate* network_delegate) const override { |
| 59 return new MockSimpleJob(request, network_delegate); | 59 return new MockSimpleJob(request, network_delegate); |
| 60 } | 60 } |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 class URLRequestSimpleJobTest : public ::testing::Test { | 63 class URLRequestSimpleJobTest : public ::testing::Test { |
| 64 public: | 64 public: |
| 65 URLRequestSimpleJobTest() : context_(true) { | 65 URLRequestSimpleJobTest() : context_(true) { |
| 66 job_factory_.SetProtocolHandler("data", new SimpleJobProtocolHandler()); | 66 job_factory_.SetProtocolHandler("data", new SimpleJobProtocolHandler()); |
| 67 context_.set_job_factory(&job_factory_); | 67 context_.set_job_factory(&job_factory_); |
| 68 context_.Init(); | 68 context_.Init(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 "bytes=%d-%d", kRangeLastPosition, kRangeFirstPosition); | 133 "bytes=%d-%d", kRangeLastPosition, kRangeFirstPosition); |
| 134 headers.SetHeader(HttpRequestHeaders::kRange, range); | 134 headers.SetHeader(HttpRequestHeaders::kRange, range); |
| 135 | 135 |
| 136 StartRequest(&headers); | 136 StartRequest(&headers); |
| 137 | 137 |
| 138 ASSERT_TRUE(request_->status().is_success()); | 138 ASSERT_TRUE(request_->status().is_success()); |
| 139 EXPECT_EQ(kTestData, delegate_.data_received()); | 139 EXPECT_EQ(kTestData, delegate_.data_received()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace net | 142 } // namespace net |
| OLD | NEW |