| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/test/test_url_fetcher_factory.h" | 5 #include "content/test/test_url_fetcher_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 TestURLFetcher::~TestURLFetcher() { | 35 TestURLFetcher::~TestURLFetcher() { |
| 36 } | 36 } |
| 37 | 37 |
| 38 void TestURLFetcher::AppendChunkToUpload(const std::string& data, | 38 void TestURLFetcher::AppendChunkToUpload(const std::string& data, |
| 39 bool is_last_chunk) { | 39 bool is_last_chunk) { |
| 40 DCHECK(!did_receive_last_chunk_); | 40 DCHECK(!did_receive_last_chunk_); |
| 41 did_receive_last_chunk_ = is_last_chunk; | 41 did_receive_last_chunk_ = is_last_chunk; |
| 42 chunks_.push_back(data); | 42 chunks_.push_back(data); |
| 43 } | 43 } |
| 44 | 44 |
| 45 const GURL& TestURLFetcher::original_url() const { | 45 const GURL& TestURLFetcher::GetOriginalUrl() const { |
| 46 return original_url_; | 46 return original_url_; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void TestURLFetcher::set_status(const net::URLRequestStatus& status) { | 49 void TestURLFetcher::set_status(const net::URLRequestStatus& status) { |
| 50 fake_status_ = status; | 50 fake_status_ = status; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void TestURLFetcher::set_was_fetched_via_proxy(bool flag) { | 53 void TestURLFetcher::set_was_fetched_via_proxy(bool flag) { |
| 54 URLFetcher::set_was_fetched_via_proxy(flag); | 54 URLFetcher::set_was_fetched_via_proxy(flag); |
| 55 } | 55 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 Fetchers::const_iterator i = fetchers_.find(id); | 107 Fetchers::const_iterator i = fetchers_.find(id); |
| 108 return i == fetchers_.end() ? NULL : i->second; | 108 return i == fetchers_.end() ? NULL : i->second; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void TestURLFetcherFactory::RemoveFetcherFromMap(int id) { | 111 void TestURLFetcherFactory::RemoveFetcherFromMap(int id) { |
| 112 Fetchers::iterator i = fetchers_.find(id); | 112 Fetchers::iterator i = fetchers_.find(id); |
| 113 DCHECK(i != fetchers_.end()); | 113 DCHECK(i != fetchers_.end()); |
| 114 fetchers_.erase(i); | 114 fetchers_.erase(i); |
| 115 } | 115 } |
| 116 | 116 |
| 117 const GURL& TestURLFetcher::url() const { | 117 const GURL& TestURLFetcher::GetUrl() const { |
| 118 return fake_url_; | 118 return fake_url_; |
| 119 } | 119 } |
| 120 | 120 |
| 121 const net::URLRequestStatus& TestURLFetcher::status() const { | 121 const net::URLRequestStatus& TestURLFetcher::GetStatus() const { |
| 122 return fake_status_; | 122 return fake_status_; |
| 123 } | 123 } |
| 124 | 124 |
| 125 int TestURLFetcher::response_code() const { | 125 int TestURLFetcher::GetResponseCode() const { |
| 126 return fake_response_code_; | 126 return fake_response_code_; |
| 127 } | 127 } |
| 128 | 128 |
| 129 const net::ResponseCookies& TestURLFetcher::cookies() const { | 129 const net::ResponseCookies& TestURLFetcher::GetCookies() const { |
| 130 return fake_cookies_; | 130 return fake_cookies_; |
| 131 } | 131 } |
| 132 | 132 |
| 133 // This class is used by the FakeURLFetcherFactory below. | 133 // This class is used by the FakeURLFetcherFactory below. |
| 134 class FakeURLFetcher : public URLFetcher { | 134 class FakeURLFetcher : public URLFetcher { |
| 135 public: | 135 public: |
| 136 // Normal URL fetcher constructor but also takes in a pre-baked response. | 136 // Normal URL fetcher constructor but also takes in a pre-baked response. |
| 137 FakeURLFetcher(const GURL& url, RequestType request_type, | 137 FakeURLFetcher(const GURL& url, RequestType request_type, |
| 138 content::URLFetcherDelegate* d, | 138 content::URLFetcherDelegate* d, |
| 139 const std::string& response_data, bool success) | 139 const std::string& response_data, bool success) |
| 140 : URLFetcher(url, request_type, d), | 140 : URLFetcher(url, request_type, d), |
| 141 url_(url), | 141 url_(url), |
| 142 response_data_(response_data), | 142 response_data_(response_data), |
| 143 success_(success), | 143 success_(success), |
| 144 status_(success ? net::URLRequestStatus::SUCCESS : | 144 status_(success ? net::URLRequestStatus::SUCCESS : |
| 145 net::URLRequestStatus::FAILED, 0), | 145 net::URLRequestStatus::FAILED, 0), |
| 146 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 146 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Start the request. This will call the given delegate asynchronously | 149 // Start the request. This will call the given delegate asynchronously |
| 150 // with the pre-baked response as parameter. | 150 // with the pre-baked response as parameter. |
| 151 virtual void Start() OVERRIDE { | 151 virtual void Start() OVERRIDE { |
| 152 MessageLoop::current()->PostTask( | 152 MessageLoop::current()->PostTask( |
| 153 FROM_HERE, | 153 FROM_HERE, |
| 154 method_factory_.NewRunnableMethod(&FakeURLFetcher::RunDelegate)); | 154 method_factory_.NewRunnableMethod(&FakeURLFetcher::RunDelegate)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // These methods are overriden so we can use the version of | 157 // These methods are overriden so we can use the version of |
| 158 // OnURLFetchComplete that only has a single URLFetcher argument. | 158 // OnURLFetchComplete that only has a single URLFetcher argument. |
| 159 virtual const net::ResponseCookies& cookies() const OVERRIDE { | 159 virtual const net::ResponseCookies& GetCookies() const OVERRIDE { |
| 160 return cookies_; | 160 return cookies_; |
| 161 } | 161 } |
| 162 | 162 |
| 163 virtual bool GetResponseAsString( | 163 virtual bool GetResponseAsString( |
| 164 std::string* out_response_string) const OVERRIDE { | 164 std::string* out_response_string) const OVERRIDE { |
| 165 *out_response_string = response_data_; | 165 *out_response_string = response_data_; |
| 166 return true; | 166 return true; |
| 167 } | 167 } |
| 168 | 168 |
| 169 virtual int response_code() const OVERRIDE { | 169 virtual int GetResponseCode() const OVERRIDE { |
| 170 return success_ ? 200 : 500; | 170 return success_ ? 200 : 500; |
| 171 } | 171 } |
| 172 | 172 |
| 173 virtual const net::URLRequestStatus& status() const OVERRIDE { | 173 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE { |
| 174 return status_; | 174 return status_; |
| 175 } | 175 } |
| 176 | 176 |
| 177 virtual const GURL& url() const OVERRIDE { | 177 virtual const GURL& GetUrl() const OVERRIDE { |
| 178 return url_; | 178 return url_; |
| 179 } | 179 } |
| 180 | 180 |
| 181 private: | 181 private: |
| 182 virtual ~FakeURLFetcher() { | 182 virtual ~FakeURLFetcher() { |
| 183 } | 183 } |
| 184 | 184 |
| 185 // This is the method which actually calls the delegate that is passed in the | 185 // This is the method which actually calls the delegate that is passed in the |
| 186 // constructor. | 186 // constructor. |
| 187 void RunDelegate() { | 187 void RunDelegate() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 URLFetcherFactory::~URLFetcherFactory() {} | 249 URLFetcherFactory::~URLFetcherFactory() {} |
| 250 | 250 |
| 251 URLFetcher* URLFetcherFactory::CreateURLFetcher( | 251 URLFetcher* URLFetcherFactory::CreateURLFetcher( |
| 252 int id, | 252 int id, |
| 253 const GURL& url, | 253 const GURL& url, |
| 254 URLFetcher::RequestType request_type, | 254 URLFetcher::RequestType request_type, |
| 255 content::URLFetcherDelegate* d) { | 255 content::URLFetcherDelegate* d) { |
| 256 return new URLFetcher(url, request_type, d); | 256 return new URLFetcher(url, request_type, d); |
| 257 } | 257 } |
| OLD | NEW |