Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/common/net/gaia/gaia_authenticator2_unittest.h

Issue 3024002: Add IssueAuthToken support to the TokenService. (Closed)
Patch Set: Code review fixes Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/net/gaia/gaia_authenticator2.cc ('k') | chrome/common/net/gaia/gaia_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string>
12
11 #include "chrome/common/net/gaia/gaia_authenticator2.h" 13 #include "chrome/common/net/gaia/gaia_authenticator2.h"
12 #include "chrome/common/net/url_fetcher.h" 14 #include "chrome/common/net/url_fetcher.h"
13 #include "chrome/common/net/http_return.h" 15 #include "chrome/common/net/http_return.h"
14 #include "net/url_request/url_request_status.h" 16 #include "net/url_request/url_request_status.h"
15 17
16 // Responds as though ClientLogin returned from the server. 18 // Responds as though ClientLogin returned from the server.
17 class MockFetcher : public URLFetcher { 19 class MockFetcher : public URLFetcher {
18 public: 20 public:
19 MockFetcher(bool success, 21 MockFetcher(bool success,
20 const GURL& url, 22 const GURL& url,
23 const std::string & results,
21 URLFetcher::RequestType request_type, 24 URLFetcher::RequestType request_type,
22 URLFetcher::Delegate* d) 25 URLFetcher::Delegate* d)
23 : URLFetcher(url, request_type, d), 26 : URLFetcher(url, request_type, d),
24 success_(success), 27 success_(success),
25 url_(url) {} 28 url_(url),
29 results_(results) {}
26 ~MockFetcher() {} 30 ~MockFetcher() {}
27 void Start() { 31 void Start() {
28 URLRequestStatus::Status code; 32 URLRequestStatus::Status code;
29 int http_code; 33 int http_code;
30 if (success_) { 34 if (success_) {
31 http_code = RC_REQUEST_OK; 35 http_code = RC_REQUEST_OK;
32 code = URLRequestStatus::SUCCESS; 36 code = URLRequestStatus::SUCCESS;
33 } else { 37 } else {
34 http_code = RC_FORBIDDEN; 38 http_code = RC_FORBIDDEN;
35 code = URLRequestStatus::FAILED; 39 code = URLRequestStatus::FAILED;
36 } 40 }
37 41
38 URLRequestStatus status(code, 0); 42 URLRequestStatus status(code, 0);
39 delegate()->OnURLFetchComplete(NULL, 43 delegate()->OnURLFetchComplete(NULL,
40 url_, 44 url_,
41 status, 45 status,
42 http_code, 46 http_code,
43 ResponseCookies(), 47 ResponseCookies(),
44 std::string()); 48 results_);
45 } 49 }
46 private: 50 private:
47 bool success_; 51 bool success_;
48 GURL url_; 52 GURL url_;
53 std::string results_;
49 DISALLOW_COPY_AND_ASSIGN(MockFetcher); 54 DISALLOW_COPY_AND_ASSIGN(MockFetcher);
50 }; 55 };
51 56
52 class MockFactory : public URLFetcher::Factory { 57 class MockFactory : public URLFetcher::Factory {
53 public: 58 public:
54 MockFactory() 59 MockFactory()
55 : success_(true) {} 60 : success_(true) {}
56 ~MockFactory() {} 61 ~MockFactory() {}
57 URLFetcher* CreateURLFetcher(int id, 62 URLFetcher* CreateURLFetcher(int id,
58 const GURL& url, 63 const GURL& url,
59 URLFetcher::RequestType request_type, 64 URLFetcher::RequestType request_type,
60 URLFetcher::Delegate* d) { 65 URLFetcher::Delegate* d) {
61 return new MockFetcher(success_, url, request_type, d); 66 return new MockFetcher(success_, url, results_, request_type, d);
62 } 67 }
63 void set_success(bool success) { 68 void set_success(bool success) {
64 success_ = success; 69 success_ = success;
65 } 70 }
71 void set_results(const std::string& results) {
72 results_ = results;
73 }
66 private: 74 private:
67 bool success_; 75 bool success_;
76 std::string results_;
68 DISALLOW_COPY_AND_ASSIGN(MockFactory); 77 DISALLOW_COPY_AND_ASSIGN(MockFactory);
69 }; 78 };
70 79
71 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR2_UNITTEST_H_ 80 #endif // CHROME_COMMON_NET_GAIA_GAIA_AUTHENTICATOR2_UNITTEST_H_
OLDNEW
« no previous file with comments | « chrome/common/net/gaia/gaia_authenticator2.cc ('k') | chrome/common/net/gaia/gaia_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698