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 "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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 fake_response_destination_ = TEMP_FILE; | 212 fake_response_destination_ = TEMP_FILE; |
213 fake_response_file_path_ = path; | 213 fake_response_file_path_ = path; |
214 } | 214 } |
215 | 215 |
216 TestURLFetcherFactory::TestURLFetcherFactory() | 216 TestURLFetcherFactory::TestURLFetcherFactory() |
217 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 217 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
218 } | 218 } |
219 | 219 |
220 TestURLFetcherFactory::~TestURLFetcherFactory() {} | 220 TestURLFetcherFactory::~TestURLFetcherFactory() {} |
221 | 221 |
222 content::URLFetcher* TestURLFetcherFactory::CreateURLFetcher( | 222 net::URLFetcher* TestURLFetcherFactory::CreateURLFetcher( |
223 int id, | 223 int id, |
224 const GURL& url, | 224 const GURL& url, |
225 content::URLFetcher::RequestType request_type, | 225 net::URLFetcher::RequestType request_type, |
226 net::URLFetcherDelegate* d) { | 226 net::URLFetcherDelegate* d) { |
227 TestURLFetcher* fetcher = new TestURLFetcher(id, url, d); | 227 TestURLFetcher* fetcher = new TestURLFetcher(id, url, d); |
228 fetchers_[id] = fetcher; | 228 fetchers_[id] = fetcher; |
229 return fetcher; | 229 return fetcher; |
230 } | 230 } |
231 | 231 |
232 TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const { | 232 TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const { |
233 Fetchers::const_iterator i = fetchers_.find(id); | 233 Fetchers::const_iterator i = fetchers_.find(id); |
234 return i == fetchers_.end() ? NULL : i->second; | 234 return i == fetchers_.end() ? NULL : i->second; |
235 } | 235 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 290 } |
291 | 291 |
292 FakeURLFetcherFactory::FakeURLFetcherFactory( | 292 FakeURLFetcherFactory::FakeURLFetcherFactory( |
293 content::URLFetcherFactory* default_factory) | 293 content::URLFetcherFactory* default_factory) |
294 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 294 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
295 default_factory_(default_factory) { | 295 default_factory_(default_factory) { |
296 } | 296 } |
297 | 297 |
298 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} | 298 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} |
299 | 299 |
300 content::URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( | 300 net::URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( |
301 int id, | 301 int id, |
302 const GURL& url, | 302 const GURL& url, |
303 content::URLFetcher::RequestType request_type, | 303 net::URLFetcher::RequestType request_type, |
304 net::URLFetcherDelegate* d) { | 304 net::URLFetcherDelegate* d) { |
305 FakeResponseMap::const_iterator it = fake_responses_.find(url); | 305 FakeResponseMap::const_iterator it = fake_responses_.find(url); |
306 if (it == fake_responses_.end()) { | 306 if (it == fake_responses_.end()) { |
307 if (default_factory_ == NULL) { | 307 if (default_factory_ == NULL) { |
308 // If we don't have a baked response for that URL we return NULL. | 308 // If we don't have a baked response for that URL we return NULL. |
309 DLOG(ERROR) << "No baked response for URL: " << url.spec(); | 309 DLOG(ERROR) << "No baked response for URL: " << url.spec(); |
310 return NULL; | 310 return NULL; |
311 } else { | 311 } else { |
312 return default_factory_->CreateURLFetcher(id, url, request_type, d); | 312 return default_factory_->CreateURLFetcher(id, url, request_type, d); |
313 } | 313 } |
314 } | 314 } |
315 return new FakeURLFetcher(url, d, it->second.first, it->second.second); | 315 return new FakeURLFetcher(url, d, it->second.first, it->second.second); |
316 } | 316 } |
317 | 317 |
318 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, | 318 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, |
319 const std::string& response_data, | 319 const std::string& response_data, |
320 bool success) { | 320 bool success) { |
321 // Overwrite existing URL if it already exists. | 321 // Overwrite existing URL if it already exists. |
322 fake_responses_[GURL(url)] = std::make_pair(response_data, success); | 322 fake_responses_[GURL(url)] = std::make_pair(response_data, success); |
323 } | 323 } |
324 | 324 |
325 void FakeURLFetcherFactory::ClearFakeResponses() { | 325 void FakeURLFetcherFactory::ClearFakeResponses() { |
326 fake_responses_.clear(); | 326 fake_responses_.clear(); |
327 } | 327 } |
328 | 328 |
329 URLFetcherImplFactory::URLFetcherImplFactory() {} | 329 URLFetcherImplFactory::URLFetcherImplFactory() {} |
330 | 330 |
331 URLFetcherImplFactory::~URLFetcherImplFactory() {} | 331 URLFetcherImplFactory::~URLFetcherImplFactory() {} |
332 | 332 |
333 content::URLFetcher* URLFetcherImplFactory::CreateURLFetcher( | 333 net::URLFetcher* URLFetcherImplFactory::CreateURLFetcher( |
334 int id, | 334 int id, |
335 const GURL& url, | 335 const GURL& url, |
336 content::URLFetcher::RequestType request_type, | 336 net::URLFetcher::RequestType request_type, |
337 net::URLFetcherDelegate* d) { | 337 net::URLFetcherDelegate* d) { |
338 return new URLFetcherImpl(url, request_type, d); | 338 return new URLFetcherImpl(url, request_type, d); |
339 } | 339 } |
OLD | NEW |