| 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 "chrome/common/net/test_url_fetcher_factory.h" | 5 #include "chrome/common/net/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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 Fetchers::const_iterator i = fetchers_.find(id); | 80 Fetchers::const_iterator i = fetchers_.find(id); |
| 81 return i == fetchers_.end() ? NULL : i->second; | 81 return i == fetchers_.end() ? NULL : i->second; |
| 82 } | 82 } |
| 83 | 83 |
| 84 void TestURLFetcherFactory::RemoveFetcherFromMap(int id) { | 84 void TestURLFetcherFactory::RemoveFetcherFromMap(int id) { |
| 85 Fetchers::iterator i = fetchers_.find(id); | 85 Fetchers::iterator i = fetchers_.find(id); |
| 86 DCHECK(i != fetchers_.end()); | 86 DCHECK(i != fetchers_.end()); |
| 87 fetchers_.erase(i); | 87 fetchers_.erase(i); |
| 88 } | 88 } |
| 89 | 89 |
| 90 const GURL& TestURLFetcher::url() const { |
| 91 return fake_url_; |
| 92 } |
| 93 |
| 94 const net::URLRequestStatus& TestURLFetcher::status() const { |
| 95 return fake_status_; |
| 96 } |
| 97 |
| 98 int TestURLFetcher::response_code() const { |
| 99 return fake_response_code_; |
| 100 } |
| 101 |
| 90 // This class is used by the FakeURLFetcherFactory below. | 102 // This class is used by the FakeURLFetcherFactory below. |
| 91 class FakeURLFetcher : public URLFetcher { | 103 class FakeURLFetcher : public URLFetcher { |
| 92 public: | 104 public: |
| 93 // Normal URL fetcher constructor but also takes in a pre-baked response. | 105 // Normal URL fetcher constructor but also takes in a pre-baked response. |
| 94 FakeURLFetcher(const GURL& url, RequestType request_type, Delegate* d, | 106 FakeURLFetcher(const GURL& url, RequestType request_type, Delegate* d, |
| 95 const std::string& response_data, bool success) | 107 const std::string& response_data, bool success) |
| 96 : URLFetcher(url, request_type, d), | 108 : URLFetcher(url, request_type, d), |
| 97 url_(url), | 109 url_(url), |
| 98 response_data_(response_data), | 110 response_data_(response_data), |
| 99 success_(success), | 111 success_(success), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, | 168 void FakeURLFetcherFactory::SetFakeResponse(const std::string& url, |
| 157 const std::string& response_data, | 169 const std::string& response_data, |
| 158 bool success) { | 170 bool success) { |
| 159 // Overwrite existing URL if it already exists. | 171 // Overwrite existing URL if it already exists. |
| 160 fake_responses_[GURL(url)] = std::make_pair(response_data, success); | 172 fake_responses_[GURL(url)] = std::make_pair(response_data, success); |
| 161 } | 173 } |
| 162 | 174 |
| 163 void FakeURLFetcherFactory::ClearFakeReponses() { | 175 void FakeURLFetcherFactory::ClearFakeReponses() { |
| 164 fake_responses_.clear(); | 176 fake_responses_.clear(); |
| 165 } | 177 } |
| OLD | NEW |