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 CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "content/common/net/url_fetcher.h" | 14 #include "content/test/test_url_fetcher_factory.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class URLFetcherDelegate; | 19 class URLFetcherDelegate; |
20 } | 20 } |
21 | 21 |
22 namespace chromeos { | 22 namespace chromeos { |
23 | 23 |
24 // Simulates a URL fetch by posting a delayed task. This fetch expects to be | 24 // Simulates a URL fetch by posting a delayed task. This fetch expects to be |
25 // canceled, and fails the test if it is not | 25 // canceled, and fails the test if it is not |
26 class ExpectCanceledFetcher : public URLFetcher { | 26 class ExpectCanceledFetcher : public TestURLFetcher { |
27 public: | 27 public: |
28 ExpectCanceledFetcher(bool success, | 28 ExpectCanceledFetcher(bool success, |
29 const GURL& url, | 29 const GURL& url, |
30 const std::string& results, | 30 const std::string& results, |
31 URLFetcher::RequestType request_type, | 31 content::URLFetcher::RequestType request_type, |
32 content::URLFetcherDelegate* d); | 32 content::URLFetcherDelegate* d); |
33 virtual ~ExpectCanceledFetcher(); | 33 virtual ~ExpectCanceledFetcher(); |
34 | 34 |
35 virtual void Start(); | 35 virtual void Start(); |
36 | 36 |
37 void CompleteFetch(); | 37 void CompleteFetch(); |
38 | 38 |
39 private: | 39 private: |
40 base::WeakPtrFactory<ExpectCanceledFetcher> weak_factory_; | 40 base::WeakPtrFactory<ExpectCanceledFetcher> weak_factory_; |
41 DISALLOW_COPY_AND_ASSIGN(ExpectCanceledFetcher); | 41 DISALLOW_COPY_AND_ASSIGN(ExpectCanceledFetcher); |
42 }; | 42 }; |
43 | 43 |
44 class GotCanceledFetcher : public URLFetcher { | 44 class GotCanceledFetcher : public TestURLFetcher { |
45 public: | 45 public: |
46 GotCanceledFetcher(bool success, | 46 GotCanceledFetcher(bool success, |
47 const GURL& url, | 47 const GURL& url, |
48 const std::string& results, | 48 const std::string& results, |
49 URLFetcher::RequestType request_type, | 49 content::URLFetcher::RequestType request_type, |
50 content::URLFetcherDelegate* d); | 50 content::URLFetcherDelegate* d); |
51 virtual ~GotCanceledFetcher(); | 51 virtual ~GotCanceledFetcher(); |
52 | 52 |
53 virtual void Start(); | 53 virtual void Start(); |
54 | 54 |
55 virtual const GURL& GetUrl() const OVERRIDE; | |
56 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; | |
57 virtual int GetResponseCode() const OVERRIDE; | |
58 | |
59 private: | 55 private: |
60 GURL url_; | |
61 net::URLRequestStatus status_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(GotCanceledFetcher); | 56 DISALLOW_COPY_AND_ASSIGN(GotCanceledFetcher); |
64 }; | 57 }; |
65 | 58 |
66 class SuccessFetcher : public URLFetcher { | 59 class SuccessFetcher : public TestURLFetcher { |
67 public: | 60 public: |
68 SuccessFetcher(bool success, | 61 SuccessFetcher(bool success, |
69 const GURL& url, | 62 const GURL& url, |
70 const std::string& results, | 63 const std::string& results, |
71 URLFetcher::RequestType request_type, | 64 content::URLFetcher::RequestType request_type, |
72 content::URLFetcherDelegate* d); | 65 content::URLFetcherDelegate* d); |
73 virtual ~SuccessFetcher(); | 66 virtual ~SuccessFetcher(); |
74 | 67 |
75 virtual void Start(); | 68 virtual void Start(); |
76 | 69 |
77 virtual const GURL& GetUrl() const OVERRIDE; | |
78 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; | |
79 virtual int GetResponseCode() const OVERRIDE; | |
80 | |
81 private: | 70 private: |
82 GURL url_; | |
83 net::URLRequestStatus status_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(SuccessFetcher); | 71 DISALLOW_COPY_AND_ASSIGN(SuccessFetcher); |
86 }; | 72 }; |
87 | 73 |
88 class FailFetcher : public URLFetcher { | 74 class FailFetcher : public TestURLFetcher { |
89 public: | 75 public: |
90 FailFetcher(bool success, | 76 FailFetcher(bool success, |
91 const GURL& url, | 77 const GURL& url, |
92 const std::string& results, | 78 const std::string& results, |
93 URLFetcher::RequestType request_type, | 79 content::URLFetcher::RequestType request_type, |
94 content::URLFetcherDelegate* d); | 80 content::URLFetcherDelegate* d); |
95 virtual ~FailFetcher(); | 81 virtual ~FailFetcher(); |
96 | 82 |
97 virtual void Start(); | 83 virtual void Start(); |
98 | 84 |
99 virtual const GURL& GetUrl() const OVERRIDE; | |
100 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; | |
101 virtual int GetResponseCode() const OVERRIDE; | |
102 | |
103 private: | 85 private: |
104 GURL url_; | |
105 net::URLRequestStatus status_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(FailFetcher); | 86 DISALLOW_COPY_AND_ASSIGN(FailFetcher); |
108 }; | 87 }; |
109 | 88 |
110 class CaptchaFetcher : public URLFetcher { | 89 class CaptchaFetcher : public TestURLFetcher { |
111 public: | 90 public: |
112 CaptchaFetcher(bool success, | 91 CaptchaFetcher(bool success, |
113 const GURL& url, | 92 const GURL& url, |
114 const std::string& results, | 93 const std::string& results, |
115 URLFetcher::RequestType request_type, | 94 content::URLFetcher::RequestType request_type, |
116 content::URLFetcherDelegate* d); | 95 content::URLFetcherDelegate* d); |
117 virtual ~CaptchaFetcher(); | 96 virtual ~CaptchaFetcher(); |
118 | 97 |
119 static std::string GetCaptchaToken(); | 98 static std::string GetCaptchaToken(); |
120 static std::string GetCaptchaUrl(); | 99 static std::string GetCaptchaUrl(); |
121 static std::string GetUnlockUrl(); | 100 static std::string GetUnlockUrl(); |
122 | 101 |
123 virtual void Start(); | 102 virtual void Start(); |
124 | 103 |
125 virtual const GURL& GetUrl() const OVERRIDE; | |
126 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; | |
127 virtual int GetResponseCode() const OVERRIDE; | |
128 virtual bool GetResponseAsString( | |
129 std::string* out_response_string) const OVERRIDE; | |
130 | |
131 private: | 104 private: |
132 static const char kCaptchaToken[]; | 105 static const char kCaptchaToken[]; |
133 static const char kCaptchaUrlBase[]; | 106 static const char kCaptchaUrlBase[]; |
134 static const char kCaptchaUrlFragment[]; | 107 static const char kCaptchaUrlFragment[]; |
135 static const char kUnlockUrl[]; | 108 static const char kUnlockUrl[]; |
136 GURL url_; | |
137 net::URLRequestStatus status_; | |
138 std::string data_; | |
139 | |
140 DISALLOW_COPY_AND_ASSIGN(CaptchaFetcher); | 109 DISALLOW_COPY_AND_ASSIGN(CaptchaFetcher); |
141 }; | 110 }; |
142 | 111 |
143 class HostedFetcher : public URLFetcher { | 112 class HostedFetcher : public TestURLFetcher { |
144 public: | 113 public: |
145 HostedFetcher(bool success, | 114 HostedFetcher(bool success, |
146 const GURL& url, | 115 const GURL& url, |
147 const std::string& results, | 116 const std::string& results, |
148 URLFetcher::RequestType request_type, | 117 content::URLFetcher::RequestType request_type, |
149 content::URLFetcherDelegate* d); | 118 content::URLFetcherDelegate* d); |
150 virtual ~HostedFetcher(); | 119 virtual ~HostedFetcher(); |
151 | 120 |
152 virtual void Start(); | 121 virtual void Start(); |
153 | 122 |
154 virtual const GURL& GetUrl() const OVERRIDE; | |
155 virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; | |
156 virtual int GetResponseCode() const OVERRIDE; | |
157 virtual bool GetResponseAsString( | |
158 std::string* out_response_string) const OVERRIDE; | |
159 | |
160 private: | 123 private: |
161 GURL url_; | |
162 net::URLRequestStatus status_; | |
163 int response_code_; | |
164 std::string data_; | |
165 | |
166 DISALLOW_COPY_AND_ASSIGN(HostedFetcher); | 124 DISALLOW_COPY_AND_ASSIGN(HostedFetcher); |
167 }; | 125 }; |
168 | 126 |
169 } // namespace chromeos | 127 } // namespace chromeos |
170 | 128 |
171 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ | 129 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_URL_FETCHERS_H_ |
OLD | NEW |