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 #ifndef CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ | 5 #ifndef CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ |
6 #define CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ | 6 #define CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 URLFetcher::Delegate* d) OVERRIDE; | 203 URLFetcher::Delegate* d) OVERRIDE; |
204 | 204 |
205 // Sets the fake response for a given URL. If success is true we will serve | 205 // Sets the fake response for a given URL. If success is true we will serve |
206 // an HTTP/200 and an HTTP/500 otherwise. The |response_data| may be empty. | 206 // an HTTP/200 and an HTTP/500 otherwise. The |response_data| may be empty. |
207 void SetFakeResponse(const std::string& url, | 207 void SetFakeResponse(const std::string& url, |
208 const std::string& response_data, | 208 const std::string& response_data, |
209 bool success); | 209 bool success); |
210 | 210 |
211 // Clear all the fake responses that were previously set via | 211 // Clear all the fake responses that were previously set via |
212 // SetFakeResponse(). | 212 // SetFakeResponse(). |
213 void ClearFakeReponses(); | 213 void ClearFakeResponses(); |
214 | 214 |
215 private: | 215 private: |
216 typedef std::map<GURL, std::pair<std::string, bool> > FakeResponseMap; | 216 typedef std::map<GURL, std::pair<std::string, bool> > FakeResponseMap; |
217 FakeResponseMap fake_responses_; | 217 FakeResponseMap fake_responses_; |
218 URLFetcher::Factory* default_factory_; | 218 URLFetcher::Factory* default_factory_; |
219 | 219 |
220 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory); | 220 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory); |
221 }; | 221 }; |
222 | 222 |
223 // This is an implementation of URLFetcher::Factory that will create a real | 223 // This is an implementation of URLFetcher::Factory that will create a real |
224 // URLFetcher. It can be use in conjunction with a FakeURLFetcherFactory in | 224 // URLFetcher. It can be use in conjunction with a FakeURLFetcherFactory in |
225 // integration tests to control the behavior of some requests but execute | 225 // integration tests to control the behavior of some requests but execute |
226 // all the other ones. | 226 // all the other ones. |
227 class URLFetcherFactory : public URLFetcher::Factory { | 227 class URLFetcherFactory : public URLFetcher::Factory { |
228 public: | 228 public: |
229 URLFetcherFactory(); | 229 URLFetcherFactory(); |
230 virtual ~URLFetcherFactory(); | 230 virtual ~URLFetcherFactory(); |
231 | 231 |
232 // This method will create a real URLFetcher. | 232 // This method will create a real URLFetcher. |
233 virtual URLFetcher* CreateURLFetcher(int id, | 233 virtual URLFetcher* CreateURLFetcher(int id, |
234 const GURL& url, | 234 const GURL& url, |
235 URLFetcher::RequestType request_type, | 235 URLFetcher::RequestType request_type, |
236 URLFetcher::Delegate* d) OVERRIDE; | 236 URLFetcher::Delegate* d) OVERRIDE; |
237 | 237 |
238 }; | 238 }; |
239 | 239 |
240 #endif // CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ | 240 #endif // CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ |
OLD | NEW |