| 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 "net/url_request/test_url_fetcher_factory.h" | 5 #include "net/url_request/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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 default_factory_(default_factory) { | 333 default_factory_(default_factory) { |
| 334 } | 334 } |
| 335 | 335 |
| 336 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} | 336 FakeURLFetcherFactory::~FakeURLFetcherFactory() {} |
| 337 | 337 |
| 338 URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( | 338 URLFetcher* FakeURLFetcherFactory::CreateURLFetcher( |
| 339 int id, | 339 int id, |
| 340 const GURL& url, | 340 const GURL& url, |
| 341 URLFetcher::RequestType request_type, | 341 URLFetcher::RequestType request_type, |
| 342 URLFetcherDelegate* d) { | 342 URLFetcherDelegate* d) { |
| 343 FakeResponseMap::const_iterator it = fake_responses_.find(url); | 343 TestURLFetcher* fake_url_fetcher_ = |
| 344 if (it == fake_responses_.end()) { | 344 CreateFakeURLFetcher(url, request_type, d); |
| 345 |
| 346 if (fake_url_fetcher_ == NULL) { |
| 345 if (default_factory_ == NULL) { | 347 if (default_factory_ == NULL) { |
| 346 // If we don't have a baked response for that URL we return NULL. | 348 // If we don't have a baked response for that URL we return NULL. |
| 347 DLOG(ERROR) << "No baked response for URL: " << url.spec(); | 349 DLOG(ERROR) << "No baked response for URL: " << url.spec(); |
| 348 return NULL; | 350 return NULL; |
| 349 } else { | 351 } else { |
| 350 return default_factory_->CreateURLFetcher(id, url, request_type, d); | 352 return default_factory_->CreateURLFetcher(id, url, request_type, d); |
| 351 } | 353 } |
| 352 } | 354 } |
| 355 return fake_url_fetcher_; |
| 356 } |
| 357 |
| 358 |
| 359 TestURLFetcher* FakeURLFetcherFactory::CreateFakeURLFetcher( |
| 360 const GURL& url, |
| 361 URLFetcher::RequestType request_type, |
| 362 URLFetcherDelegate* d) { |
| 363 FakeResponseMap::const_iterator it = fake_responses_.find(url); |
| 364 if (it == fake_responses_.end()) { |
| 365 return NULL; |
| 366 } |
| 353 return new FakeURLFetcher(url, d, it->second.first, it->second.second); | 367 return new FakeURLFetcher(url, d, it->second.first, it->second.second); |
| 354 } | 368 } |
| 355 | 369 |
| 356 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, | 370 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, |
| 357 const std::string& response_data, | 371 const std::string& response_data, |
| 358 bool success) { | 372 bool success) { |
| 359 // Overwrite existing URL if it already exists. | 373 // Overwrite existing URL if it already exists. |
| 360 fake_responses_[GURL(url)] = std::make_pair(response_data, success); | 374 fake_responses_[GURL(url)] = std::make_pair(response_data, success); |
| 361 } | 375 } |
| 362 | 376 |
| 363 void FakeURLFetcherFactory::ClearFakeResponses() { | 377 void FakeURLFetcherFactory::ClearFakeResponses() { |
| 364 fake_responses_.clear(); | 378 fake_responses_.clear(); |
| 365 } | 379 } |
| 366 | 380 |
| 367 URLFetcherImplFactory::URLFetcherImplFactory() {} | 381 URLFetcherImplFactory::URLFetcherImplFactory() {} |
| 368 | 382 |
| 369 URLFetcherImplFactory::~URLFetcherImplFactory() {} | 383 URLFetcherImplFactory::~URLFetcherImplFactory() {} |
| 370 | 384 |
| 371 URLFetcher* URLFetcherImplFactory::CreateURLFetcher( | 385 URLFetcher* URLFetcherImplFactory::CreateURLFetcher( |
| 372 int id, | 386 int id, |
| 373 const GURL& url, | 387 const GURL& url, |
| 374 URLFetcher::RequestType request_type, | 388 URLFetcher::RequestType request_type, |
| 375 URLFetcherDelegate* d) { | 389 URLFetcherDelegate* d) { |
| 376 return new URLFetcherImpl(url, request_type, d); | 390 return new URLFetcherImpl(url, request_type, d); |
| 377 } | 391 } |
| 378 | 392 |
| 379 } // namespace net | 393 } // namespace net |
| OLD | NEW |