OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // GaiaAuthenticator2. | 6 // GaiaAuthenticator2. |
7 | 7 |
8 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR2_UNITTEST_H_ | 8 #ifndef CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR2_UNITTEST_H_ |
9 #define CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR2_UNITTEST_H_ | 9 #define CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR2_UNITTEST_H_ |
10 | 10 |
11 #include "chrome/common/net/gaia/gaia_authenticator2.h" | 11 #include "chrome/common/net/gaia/gaia_authenticator2.h" |
12 #include "chrome/common/net/url_fetcher.h" | 12 #include "chrome/common/net/url_fetcher.h" |
13 #include "chrome/common/net/http_return.h" | 13 #include "chrome/common/net/http_return.h" |
14 #include "net/url_request/url_request_status.h" | 14 #include "net/url_request/url_request_status.h" |
15 | 15 |
16 // Responds as though ClientLogin returned from the server. | 16 // Responds as though ClientLogin returned from the server. |
17 class MockClientLoginFetcher : public URLFetcher { | 17 class MockFetcher : public URLFetcher { |
18 public: | 18 public: |
19 MockClientLoginFetcher(bool success, | 19 MockFetcher(bool success, |
20 const GURL& url, | 20 const GURL& url, |
21 URLFetcher::RequestType request_type, | 21 URLFetcher::RequestType request_type, |
22 URLFetcher::Delegate* d) | 22 URLFetcher::Delegate* d) |
23 : URLFetcher(url, request_type, d), | 23 : URLFetcher(url, request_type, d), |
24 success_(success) {} | 24 success_(success), |
25 ~MockClientLoginFetcher() {} | 25 url_(url) {} |
| 26 ~MockFetcher() {} |
26 void Start() { | 27 void Start() { |
27 GURL source(GaiaAuthenticator2::kClientLoginUrl); | |
28 URLRequestStatus::Status code; | 28 URLRequestStatus::Status code; |
29 int http_code; | 29 int http_code; |
30 if (success_) { | 30 if (success_) { |
31 http_code = RC_REQUEST_OK; | 31 http_code = RC_REQUEST_OK; |
32 code = URLRequestStatus::SUCCESS; | 32 code = URLRequestStatus::SUCCESS; |
33 } else { | 33 } else { |
34 http_code = RC_FORBIDDEN; | 34 http_code = RC_FORBIDDEN; |
35 code = URLRequestStatus::FAILED; | 35 code = URLRequestStatus::FAILED; |
36 } | 36 } |
37 | 37 |
38 URLRequestStatus status(code, 0); | 38 URLRequestStatus status(code, 0); |
39 delegate()->OnURLFetchComplete(NULL, | 39 delegate()->OnURLFetchComplete(NULL, |
40 source, | 40 url_, |
41 status, | 41 status, |
42 http_code, | 42 http_code, |
43 ResponseCookies(), | 43 ResponseCookies(), |
44 std::string()); | 44 std::string()); |
45 } | 45 } |
46 private: | 46 private: |
47 bool success_; | 47 bool success_; |
48 DISALLOW_COPY_AND_ASSIGN(MockClientLoginFetcher); | 48 GURL url_; |
| 49 DISALLOW_COPY_AND_ASSIGN(MockFetcher); |
49 }; | 50 }; |
50 | 51 |
51 class MockFactory : public URLFetcher::Factory { | 52 class MockFactory : public URLFetcher::Factory { |
52 public: | 53 public: |
53 MockFactory() | 54 MockFactory() |
54 : success_(true) {} | 55 : success_(true) {} |
55 ~MockFactory() {} | 56 ~MockFactory() {} |
56 URLFetcher* CreateURLFetcher(int id, | 57 URLFetcher* CreateURLFetcher(int id, |
57 const GURL& url, | 58 const GURL& url, |
58 URLFetcher::RequestType request_type, | 59 URLFetcher::RequestType request_type, |
59 URLFetcher::Delegate* d) { | 60 URLFetcher::Delegate* d) { |
60 return new MockClientLoginFetcher(success_, url, request_type, d); | 61 return new MockFetcher(success_, url, request_type, d); |
61 } | 62 } |
62 void set_success(bool success) { | 63 void set_success(bool success) { |
63 success_ = success; | 64 success_ = success; |
64 } | 65 } |
65 private: | 66 private: |
66 bool success_; | 67 bool success_; |
67 DISALLOW_COPY_AND_ASSIGN(MockFactory); | 68 DISALLOW_COPY_AND_ASSIGN(MockFactory); |
68 }; | 69 }; |
69 | 70 |
70 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR2_UNITTEST_H_ | 71 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR2_UNITTEST_H_ |
OLD | NEW |