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 // A collection of classes that are useful when testing things that use a | 5 // A collection of classes that are useful when testing things that use a |
6 // GaiaAuthFetcher. | 6 // GaiaAuthFetcher. |
7 | 7 |
8 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ | 8 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ |
9 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ | 9 #define CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ |
10 #pragma once | 10 #pragma once |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 14 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
15 #include "chrome/common/net/http_return.h" | 15 #include "chrome/common/net/http_return.h" |
16 #include "content/common/net/url_fetcher.h" | 16 #include "content/common/net/url_fetcher.h" |
17 #include "content/test/test_url_fetcher_factory.h" | 17 #include "content/test/test_url_fetcher_factory.h" |
18 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
19 | 19 |
20 namespace content { | |
21 class URLFetcherDelegate; | |
22 } | |
23 | |
24 // Responds as though ClientLogin returned from the server. | 20 // Responds as though ClientLogin returned from the server. |
25 class MockFetcher : public URLFetcher { | 21 class MockFetcher : public TestURLFetcher { |
26 public: | 22 public: |
27 MockFetcher(bool success, | 23 MockFetcher(bool success, |
28 const GURL& url, | 24 const GURL& url, |
29 const std::string& results, | 25 const std::string& results, |
30 URLFetcher::RequestType request_type, | 26 content::URLFetcher::RequestType request_type, |
31 content::URLFetcherDelegate* d); | 27 content::URLFetcherDelegate* d); |
32 | 28 |
33 MockFetcher(const GURL& url, | 29 MockFetcher(const GURL& url, |
34 const net::URLRequestStatus& status, | 30 const net::URLRequestStatus& status, |
35 int response_code, | 31 int response_code, |
36 const net::ResponseCookies& cookies, | 32 const net::ResponseCookies& cookies, |
37 const std::string& results, | 33 const std::string& results, |
38 URLFetcher::RequestType request_type, | 34 content::URLFetcher::RequestType request_type, |
39 content::URLFetcherDelegate* d); | 35 content::URLFetcherDelegate* d); |
40 | 36 |
41 virtual ~MockFetcher(); | 37 virtual ~MockFetcher(); |
42 | 38 |
43 virtual void Start(); | 39 virtual void Start(); |
44 | 40 |
45 virtual const GURL& GetUrl() const OVERRIDE; | |
46 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; | |
47 virtual int GetResponseCode() const OVERRIDE; | |
48 virtual const net::ResponseCookies& GetCookies() const OVERRIDE; | |
49 virtual bool GetResponseAsString(std::string* out_response_string) const; | |
50 | |
51 private: | 41 private: |
52 GURL url_; | |
53 net::URLRequestStatus status_; | |
54 int response_code_; | |
55 net::ResponseCookies cookies_; | |
56 std::string results_; | |
57 DISALLOW_COPY_AND_ASSIGN(MockFetcher); | 42 DISALLOW_COPY_AND_ASSIGN(MockFetcher); |
58 }; | 43 }; |
59 | 44 |
60 template<typename T> | 45 template<typename T> |
61 class MockFactory : public URLFetcher::Factory, | 46 class MockFactory : public content::URLFetcherFactory, |
62 public ScopedURLFetcherFactory { | 47 public ScopedURLFetcherFactory { |
63 public: | 48 public: |
64 MockFactory() | 49 MockFactory() |
65 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 50 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
66 success_(true) { | 51 success_(true) { |
67 } | 52 } |
68 ~MockFactory() {} | 53 ~MockFactory() {} |
69 URLFetcher* CreateURLFetcher(int id, | 54 content::URLFetcher* CreateURLFetcher( |
70 const GURL& url, | 55 int id, |
71 URLFetcher::RequestType request_type, | 56 const GURL& url, |
72 content::URLFetcherDelegate* d) { | 57 content::URLFetcher::RequestType request_type, |
| 58 content::URLFetcherDelegate* d) OVERRIDE { |
73 return new T(success_, url, results_, request_type, d); | 59 return new T(success_, url, results_, request_type, d); |
74 } | 60 } |
75 void set_success(bool success) { | 61 void set_success(bool success) { |
76 success_ = success; | 62 success_ = success; |
77 } | 63 } |
78 void set_results(const std::string& results) { | 64 void set_results(const std::string& results) { |
79 results_ = results; | 65 results_ = results; |
80 } | 66 } |
81 private: | 67 private: |
82 bool success_; | 68 bool success_; |
83 std::string results_; | 69 std::string results_; |
84 DISALLOW_COPY_AND_ASSIGN(MockFactory); | 70 DISALLOW_COPY_AND_ASSIGN(MockFactory); |
85 }; | 71 }; |
86 | 72 |
87 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ | 73 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTH_FETCHER_UNITTEST_H_ |
OLD | NEW |