OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 complete set of unit tests for GaiaOAuthClient. | 5 // A complete set of unit tests for GaiaOAuthClient. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | |
8 | 9 |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 12 #include "base/values.h" |
12 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
13 #include "google_apis/gaia/gaia_oauth_client.h" | 14 #include "google_apis/gaia/gaia_oauth_client.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
16 #include "net/http/http_status_code.h" | 17 #include "net/http/http_status_code.h" |
17 #include "net/url_request/test_url_fetcher_factory.h" | 18 #include "net/url_request/test_url_fetcher_factory.h" |
18 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
19 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using ::testing::_; | 24 using ::testing::_; |
25 using ::testing::Eq; | |
26 using ::testing::HasSubstr; | |
27 using ::testing::Pointee; | |
28 using ::testing::SaveArg; | |
24 | 29 |
25 namespace { | 30 namespace { |
26 | 31 |
27 const char kGaiaOAuth2Url[] = "https://accounts.google.com/o/oauth2/token"; | |
28 | |
29 // Responds as though OAuth returned from the server. | 32 // Responds as though OAuth returned from the server. |
30 class MockOAuthFetcher : public net::TestURLFetcher { | 33 class MockOAuthFetcher : public net::TestURLFetcher { |
31 public: | 34 public: |
32 MockOAuthFetcher(int response_code, | 35 MockOAuthFetcher(int response_code, |
33 int max_failure_count, | 36 int max_failure_count, |
37 bool complete_immediately, | |
34 const GURL& url, | 38 const GURL& url, |
35 const std::string& results, | 39 const std::string& results, |
36 net::URLFetcher::RequestType request_type, | 40 net::URLFetcher::RequestType request_type, |
37 net::URLFetcherDelegate* d) | 41 net::URLFetcherDelegate* d) |
38 : net::TestURLFetcher(0, url, d), | 42 : net::TestURLFetcher(0, url, d), |
39 max_failure_count_(max_failure_count), | 43 max_failure_count_(max_failure_count), |
40 current_failure_count_(0) { | 44 current_failure_count_(0), |
45 complete_immediately_(complete_immediately) { | |
41 set_url(url); | 46 set_url(url); |
42 set_response_code(response_code); | 47 set_response_code(response_code); |
43 SetResponseString(results); | 48 SetResponseString(results); |
44 } | 49 } |
45 | 50 |
46 virtual ~MockOAuthFetcher() { } | 51 virtual ~MockOAuthFetcher() { } |
47 | 52 |
48 virtual void Start() OVERRIDE { | 53 virtual void Start() OVERRIDE { |
49 if ((GetResponseCode() != net::HTTP_OK) && (max_failure_count_ != -1) && | 54 if ((GetResponseCode() != net::HTTP_OK) && (max_failure_count_ != -1) && |
50 (current_failure_count_ == max_failure_count_)) { | 55 (current_failure_count_ == max_failure_count_)) { |
51 set_response_code(net::HTTP_OK); | 56 set_response_code(net::HTTP_OK); |
52 } | 57 } |
53 | 58 |
54 net::URLRequestStatus::Status code = net::URLRequestStatus::SUCCESS; | 59 net::URLRequestStatus::Status code = net::URLRequestStatus::SUCCESS; |
55 if (GetResponseCode() != net::HTTP_OK) { | 60 if (GetResponseCode() != net::HTTP_OK) { |
56 code = net::URLRequestStatus::FAILED; | 61 code = net::URLRequestStatus::FAILED; |
57 current_failure_count_++; | 62 current_failure_count_++; |
58 } | 63 } |
59 set_status(net::URLRequestStatus(code, 0)); | 64 set_status(net::URLRequestStatus(code, 0)); |
60 | 65 |
66 if (complete_immediately_) | |
67 delegate()->OnURLFetchComplete(this); | |
68 } | |
69 | |
70 void Finish() { | |
71 ASSERT_FALSE(complete_immediately_); | |
61 delegate()->OnURLFetchComplete(this); | 72 delegate()->OnURLFetchComplete(this); |
62 } | 73 } |
63 | 74 |
64 private: | 75 private: |
65 int max_failure_count_; | 76 int max_failure_count_; |
66 int current_failure_count_; | 77 int current_failure_count_; |
78 bool complete_immediately_; | |
67 DISALLOW_COPY_AND_ASSIGN(MockOAuthFetcher); | 79 DISALLOW_COPY_AND_ASSIGN(MockOAuthFetcher); |
68 }; | 80 }; |
69 | 81 |
70 class MockOAuthFetcherFactory : public net::URLFetcherFactory, | 82 class MockOAuthFetcherFactory : public net::URLFetcherFactory, |
71 public net::ScopedURLFetcherFactory { | 83 public net::ScopedURLFetcherFactory { |
72 public: | 84 public: |
73 MockOAuthFetcherFactory() | 85 MockOAuthFetcherFactory() |
74 : net::ScopedURLFetcherFactory(this), | 86 : net::ScopedURLFetcherFactory(this), |
75 response_code_(net::HTTP_OK) { | 87 response_code_(net::HTTP_OK), |
88 complete_immediately_(true) { | |
76 } | 89 } |
77 virtual ~MockOAuthFetcherFactory() {} | 90 virtual ~MockOAuthFetcherFactory() {} |
78 virtual net::URLFetcher* CreateURLFetcher( | 91 virtual net::URLFetcher* CreateURLFetcher( |
79 int id, | 92 int id, |
80 const GURL& url, | 93 const GURL& url, |
81 net::URLFetcher::RequestType request_type, | 94 net::URLFetcher::RequestType request_type, |
82 net::URLFetcherDelegate* d) OVERRIDE { | 95 net::URLFetcherDelegate* d) OVERRIDE { |
83 return new MockOAuthFetcher( | 96 url_fetcher_ = new MockOAuthFetcher( |
84 response_code_, | 97 response_code_, |
85 max_failure_count_, | 98 max_failure_count_, |
99 complete_immediately_, | |
86 url, | 100 url, |
87 results_, | 101 results_, |
88 request_type, | 102 request_type, |
89 d); | 103 d); |
104 return url_fetcher_; | |
90 } | 105 } |
91 void set_response_code(int response_code) { | 106 void set_response_code(int response_code) { |
92 response_code_ = response_code; | 107 response_code_ = response_code; |
93 } | 108 } |
94 void set_max_failure_count(int count) { | 109 void set_max_failure_count(int count) { |
95 max_failure_count_ = count; | 110 max_failure_count_ = count; |
96 } | 111 } |
97 void set_results(const std::string& results) { | 112 void set_results(const std::string& results) { |
98 results_ = results; | 113 results_ = results; |
99 } | 114 } |
115 MockOAuthFetcher* get_url_fetcher() { | |
116 return url_fetcher_; | |
117 } | |
118 void set_complete_immediately(bool complete_immediately) { | |
119 complete_immediately_ = complete_immediately; | |
120 } | |
100 private: | 121 private: |
122 MockOAuthFetcher* url_fetcher_; | |
101 int response_code_; | 123 int response_code_; |
124 bool complete_immediately_; | |
102 int max_failure_count_; | 125 int max_failure_count_; |
103 std::string results_; | 126 std::string results_; |
104 DISALLOW_COPY_AND_ASSIGN(MockOAuthFetcherFactory); | 127 DISALLOW_COPY_AND_ASSIGN(MockOAuthFetcherFactory); |
105 }; | 128 }; |
106 | 129 |
107 const std::string kTestAccessToken = "1/fFAGRNJru1FTz70BzhT3Zg"; | 130 const std::string kTestAccessToken = "1/fFAGRNJru1FTz70BzhT3Zg"; |
108 const std::string kTestRefreshToken = | 131 const std::string kTestRefreshToken = |
109 "1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ"; | 132 "1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ"; |
110 const std::string kTestUserEmail = "a_user@gmail.com"; | 133 const std::string kTestUserEmail = "a_user@gmail.com"; |
111 const int kTestExpiresIn = 3920; | 134 const int kTestExpiresIn = 3920; |
112 | 135 |
113 const std::string kDummyGetTokensResult = | 136 const std::string kDummyGetTokensResult = |
114 "{\"access_token\":\"" + kTestAccessToken + "\"," | 137 "{\"access_token\":\"" + kTestAccessToken + "\"," |
115 "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "," | 138 "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "," |
116 "\"refresh_token\":\"" + kTestRefreshToken + "\"}"; | 139 "\"refresh_token\":\"" + kTestRefreshToken + "\"}"; |
117 | 140 |
118 const std::string kDummyRefreshTokenResult = | 141 const std::string kDummyRefreshTokenResult = |
119 "{\"access_token\":\"" + kTestAccessToken + "\"," | 142 "{\"access_token\":\"" + kTestAccessToken + "\"," |
120 "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}"; | 143 "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}"; |
121 | 144 |
122 const std::string kDummyUserInfoResult = | 145 const std::string kDummyUserInfoResult = |
123 "{\"email\":\"" + kTestUserEmail + "\"}"; | 146 "{\"email\":\"" + kTestUserEmail + "\"}"; |
147 | |
148 const std::string kDummyTokenInfoResult = | |
149 "{\"issued_to\": \"1234567890.apps.googleusercontent.com\"," | |
150 "\"audience\": \"1234567890.apps.googleusercontent.com\"," | |
151 "\"scope\": \"https://googleapis.com/oauth2/v2/tokeninfo\"," | |
152 "\"expires_in\":" + base::IntToString(kTestExpiresIn) + "}"; | |
124 } | 153 } |
125 | 154 |
126 namespace gaia { | 155 namespace gaia { |
127 | 156 |
128 class GaiaOAuthClientTest : public testing::Test { | 157 class GaiaOAuthClientTest : public testing::Test { |
129 public: | 158 public: |
130 GaiaOAuthClientTest() {} | 159 GaiaOAuthClientTest() {} |
160 void SetUp() { | |
161 client_info_.client_id = "test_client_id"; | |
162 client_info_.client_secret = "test_client_secret"; | |
163 client_info_.redirect_uri = "test_redirect_uri"; | |
164 } OVERRIDE; | |
Roger Tawa OOO till Jul 10th
2013/06/21 18:22:41
The OVERRIDE macro should go at line 160 above.
David Roche
2013/06/21 18:40:45
Done.
| |
131 | 165 |
132 TestingProfile profile_; | 166 TestingProfile profile_; |
133 protected: | 167 protected: |
134 base::MessageLoop message_loop_; | 168 base::MessageLoop message_loop_; |
169 OAuthClientInfo client_info_; | |
135 }; | 170 }; |
136 | 171 |
137 class MockGaiaOAuthClientDelegate : public gaia::GaiaOAuthClient::Delegate { | 172 class MockGaiaOAuthClientDelegate : public gaia::GaiaOAuthClient::Delegate { |
138 public: | 173 public: |
139 MockGaiaOAuthClientDelegate() {} | 174 MockGaiaOAuthClientDelegate() {} |
140 ~MockGaiaOAuthClientDelegate() {} | 175 ~MockGaiaOAuthClientDelegate() {} |
141 | 176 |
142 MOCK_METHOD3(OnGetTokensResponse, void(const std::string& refresh_token, | 177 MOCK_METHOD3(OnGetTokensResponse, void(const std::string& refresh_token, |
143 const std::string& access_token, | 178 const std::string& access_token, |
144 int expires_in_seconds)); | 179 int expires_in_seconds)); |
145 MOCK_METHOD2(OnRefreshTokenResponse, void(const std::string& access_token, | 180 MOCK_METHOD2(OnRefreshTokenResponse, void(const std::string& access_token, |
146 int expires_in_seconds)); | 181 int expires_in_seconds)); |
147 MOCK_METHOD1(OnGetUserInfoResponse, void(const std::string& user_email)); | 182 MOCK_METHOD1(OnGetUserInfoResponse, void(const std::string& user_email)); |
148 MOCK_METHOD0(OnOAuthError, void()); | 183 MOCK_METHOD0(OnOAuthError, void()); |
149 MOCK_METHOD1(OnNetworkError, void(int response_code)); | 184 MOCK_METHOD1(OnNetworkError, void(int response_code)); |
185 | |
186 // gMock doesn't like methods that take or return scoped_ptr. A | |
187 // work-around is to create a mock method that takes a raw ptr, and | |
188 // override the problematic method to call through to it. | |
189 // https://groups.google.com/a/chromium.org/d/msg/chromium-dev/01sDxsJ1OYw/I_S 0xCBRF2oJ | |
190 MOCK_METHOD1(OnGetTokenInfoResponsePtr, | |
191 void(const DictionaryValue* token_info)); | |
192 virtual void OnGetTokenInfoResponse(scoped_ptr<DictionaryValue> token_info) { | |
Roger Tawa OOO till Jul 10th
2013/06/21 18:22:41
Need OVERRIDE macro.
David Roche
2013/06/21 18:40:45
Done.
| |
193 token_info_.reset(token_info.release()); | |
194 OnGetTokenInfoResponsePtr(token_info_.get()); | |
195 } | |
196 | |
197 private: | |
198 scoped_ptr<DictionaryValue> token_info_; | |
199 DISALLOW_COPY_AND_ASSIGN(MockGaiaOAuthClientDelegate); | |
150 }; | 200 }; |
151 | 201 |
152 TEST_F(GaiaOAuthClientTest, NetworkFailure) { | 202 TEST_F(GaiaOAuthClientTest, NetworkFailure) { |
153 int response_code = net::HTTP_INTERNAL_SERVER_ERROR; | 203 int response_code = net::HTTP_INTERNAL_SERVER_ERROR; |
154 | 204 |
155 MockGaiaOAuthClientDelegate delegate; | 205 MockGaiaOAuthClientDelegate delegate; |
156 EXPECT_CALL(delegate, OnNetworkError(response_code)) | 206 EXPECT_CALL(delegate, OnNetworkError(response_code)) |
157 .Times(1); | 207 .Times(1); |
158 | 208 |
159 TestingProfile profile; | |
160 | |
161 MockOAuthFetcherFactory factory; | 209 MockOAuthFetcherFactory factory; |
162 factory.set_response_code(response_code); | 210 factory.set_response_code(response_code); |
163 factory.set_max_failure_count(4); | 211 factory.set_max_failure_count(4); |
164 | 212 |
165 OAuthClientInfo client_info; | 213 GaiaOAuthClient auth(profile_.GetRequestContext()); |
166 client_info.client_id = "test_client_id"; | 214 auth.GetTokensFromAuthCode(client_info_, "auth_code", 2, &delegate); |
167 client_info.client_secret = "test_client_secret"; | |
168 client_info.redirect_uri = "test_redirect_uri"; | |
169 GaiaOAuthClient auth(kGaiaOAuth2Url, | |
170 profile_.GetRequestContext()); | |
171 auth.GetTokensFromAuthCode(client_info, "auth_code", 2, &delegate); | |
172 } | 215 } |
173 | 216 |
174 TEST_F(GaiaOAuthClientTest, NetworkFailureRecover) { | 217 TEST_F(GaiaOAuthClientTest, NetworkFailureRecover) { |
175 int response_code = net::HTTP_INTERNAL_SERVER_ERROR; | 218 int response_code = net::HTTP_INTERNAL_SERVER_ERROR; |
176 | 219 |
177 MockGaiaOAuthClientDelegate delegate; | 220 MockGaiaOAuthClientDelegate delegate; |
178 EXPECT_CALL(delegate, OnGetTokensResponse(kTestRefreshToken, kTestAccessToken, | 221 EXPECT_CALL(delegate, OnGetTokensResponse(kTestRefreshToken, kTestAccessToken, |
179 kTestExpiresIn)).Times(1); | 222 kTestExpiresIn)).Times(1); |
180 | 223 |
181 TestingProfile profile; | |
182 | |
183 MockOAuthFetcherFactory factory; | 224 MockOAuthFetcherFactory factory; |
184 factory.set_response_code(response_code); | 225 factory.set_response_code(response_code); |
185 factory.set_max_failure_count(4); | 226 factory.set_max_failure_count(4); |
186 factory.set_results(kDummyGetTokensResult); | 227 factory.set_results(kDummyGetTokensResult); |
187 | 228 |
188 OAuthClientInfo client_info; | 229 GaiaOAuthClient auth(profile_.GetRequestContext()); |
189 client_info.client_id = "test_client_id"; | 230 auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); |
190 client_info.client_secret = "test_client_secret"; | |
191 client_info.redirect_uri = "test_redirect_uri"; | |
192 GaiaOAuthClient auth(kGaiaOAuth2Url, | |
193 profile_.GetRequestContext()); | |
194 auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); | |
195 } | 231 } |
196 | 232 |
197 TEST_F(GaiaOAuthClientTest, OAuthFailure) { | 233 TEST_F(GaiaOAuthClientTest, OAuthFailure) { |
198 int response_code = net::HTTP_BAD_REQUEST; | 234 int response_code = net::HTTP_BAD_REQUEST; |
199 | 235 |
200 MockGaiaOAuthClientDelegate delegate; | 236 MockGaiaOAuthClientDelegate delegate; |
201 EXPECT_CALL(delegate, OnOAuthError()).Times(1); | 237 EXPECT_CALL(delegate, OnOAuthError()).Times(1); |
202 | 238 |
203 TestingProfile profile; | |
204 | |
205 MockOAuthFetcherFactory factory; | 239 MockOAuthFetcherFactory factory; |
206 factory.set_response_code(response_code); | 240 factory.set_response_code(response_code); |
207 factory.set_max_failure_count(-1); | 241 factory.set_max_failure_count(-1); |
208 factory.set_results(kDummyGetTokensResult); | 242 factory.set_results(kDummyGetTokensResult); |
209 | 243 |
210 OAuthClientInfo client_info; | 244 GaiaOAuthClient auth(profile_.GetRequestContext()); |
211 client_info.client_id = "test_client_id"; | 245 auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); |
212 client_info.client_secret = "test_client_secret"; | |
213 client_info.redirect_uri = "test_redirect_uri"; | |
214 GaiaOAuthClient auth(kGaiaOAuth2Url, | |
215 profile_.GetRequestContext()); | |
216 auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); | |
217 } | 246 } |
218 | 247 |
219 | 248 |
220 TEST_F(GaiaOAuthClientTest, GetTokensSuccess) { | 249 TEST_F(GaiaOAuthClientTest, GetTokensSuccess) { |
221 MockGaiaOAuthClientDelegate delegate; | 250 MockGaiaOAuthClientDelegate delegate; |
222 EXPECT_CALL(delegate, OnGetTokensResponse(kTestRefreshToken, kTestAccessToken, | 251 EXPECT_CALL(delegate, OnGetTokensResponse(kTestRefreshToken, kTestAccessToken, |
223 kTestExpiresIn)).Times(1); | 252 kTestExpiresIn)).Times(1); |
224 | 253 |
225 TestingProfile profile; | |
226 | |
227 MockOAuthFetcherFactory factory; | 254 MockOAuthFetcherFactory factory; |
228 factory.set_results(kDummyGetTokensResult); | 255 factory.set_results(kDummyGetTokensResult); |
229 | 256 |
230 OAuthClientInfo client_info; | 257 GaiaOAuthClient auth(profile_.GetRequestContext()); |
231 client_info.client_id = "test_client_id"; | 258 auth.GetTokensFromAuthCode(client_info_, "auth_code", -1, &delegate); |
232 client_info.client_secret = "test_client_secret"; | |
233 client_info.redirect_uri = "test_redirect_uri"; | |
234 GaiaOAuthClient auth(kGaiaOAuth2Url, | |
235 profile_.GetRequestContext()); | |
236 auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); | |
237 } | 259 } |
238 | 260 |
239 TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) { | 261 TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) { |
240 MockGaiaOAuthClientDelegate delegate; | 262 MockGaiaOAuthClientDelegate delegate; |
241 EXPECT_CALL(delegate, OnRefreshTokenResponse(kTestAccessToken, | 263 EXPECT_CALL(delegate, OnRefreshTokenResponse(kTestAccessToken, |
242 kTestExpiresIn)).Times(1); | 264 kTestExpiresIn)).Times(1); |
243 | 265 |
244 TestingProfile profile; | 266 MockOAuthFetcherFactory factory; |
267 factory.set_results(kDummyRefreshTokenResult); | |
268 factory.set_complete_immediately(false); | |
269 | |
270 GaiaOAuthClient auth(profile_.GetRequestContext()); | |
271 auth.RefreshToken(client_info_, "refresh_token", std::vector<std::string>(), | |
272 -1, &delegate); | |
273 EXPECT_THAT(factory.get_url_fetcher()->upload_data(), | |
274 Not(HasSubstr("scope"))); | |
275 factory.get_url_fetcher()->Finish(); | |
276 } | |
277 | |
278 TEST_F(GaiaOAuthClientTest, RefreshTokenDownscopingSuccess) { | |
279 MockGaiaOAuthClientDelegate delegate; | |
280 EXPECT_CALL(delegate, OnRefreshTokenResponse(kTestAccessToken, | |
281 kTestExpiresIn)).Times(1); | |
245 | 282 |
246 MockOAuthFetcherFactory factory; | 283 MockOAuthFetcherFactory factory; |
247 factory.set_results(kDummyRefreshTokenResult); | 284 factory.set_results(kDummyRefreshTokenResult); |
285 factory.set_complete_immediately(false); | |
248 | 286 |
249 OAuthClientInfo client_info; | 287 GaiaOAuthClient auth(profile_.GetRequestContext()); |
250 client_info.client_id = "test_client_id"; | 288 auth.RefreshToken(client_info_, "refresh_token", |
251 client_info.client_secret = "test_client_secret"; | 289 std::vector<std::string>(1, "scope4test"), -1, &delegate); |
252 client_info.redirect_uri = "test_redirect_uri"; | 290 EXPECT_THAT(factory.get_url_fetcher()->upload_data(), |
253 GaiaOAuthClient auth(kGaiaOAuth2Url, | 291 HasSubstr("&scope=scope4test")); |
254 profile_.GetRequestContext()); | 292 factory.get_url_fetcher()->Finish(); |
255 auth.RefreshToken(client_info, "refresh_token", -1, &delegate); | |
256 } | 293 } |
257 | 294 |
295 | |
258 TEST_F(GaiaOAuthClientTest, GetUserInfo) { | 296 TEST_F(GaiaOAuthClientTest, GetUserInfo) { |
259 MockGaiaOAuthClientDelegate delegate; | 297 MockGaiaOAuthClientDelegate delegate; |
260 EXPECT_CALL(delegate, OnGetUserInfoResponse(kTestUserEmail)).Times(1); | 298 EXPECT_CALL(delegate, OnGetUserInfoResponse(kTestUserEmail)).Times(1); |
261 | 299 |
262 TestingProfile profile; | |
263 | |
264 MockOAuthFetcherFactory factory; | 300 MockOAuthFetcherFactory factory; |
265 factory.set_results(kDummyUserInfoResult); | 301 factory.set_results(kDummyUserInfoResult); |
266 | 302 |
267 OAuthClientInfo client_info; | 303 GaiaOAuthClient auth(profile_.GetRequestContext()); |
268 client_info.client_id = "test_client_id"; | |
269 client_info.client_secret = "test_client_secret"; | |
270 client_info.redirect_uri = "test_redirect_uri"; | |
271 GaiaOAuthClient auth(kGaiaOAuth2Url, | |
272 profile_.GetRequestContext()); | |
273 auth.GetUserInfo("access_token", 1, &delegate); | 304 auth.GetUserInfo("access_token", 1, &delegate); |
274 } | 305 } |
275 | 306 |
307 TEST_F(GaiaOAuthClientTest, GetTokenInfo) { | |
308 const DictionaryValue* captured_result; | |
309 | |
310 MockGaiaOAuthClientDelegate delegate; | |
311 EXPECT_CALL(delegate, OnGetTokenInfoResponsePtr(_)) | |
312 .WillOnce(SaveArg<0>(&captured_result)); | |
313 | |
314 MockOAuthFetcherFactory factory; | |
315 factory.set_results(kDummyTokenInfoResult); | |
316 | |
317 GaiaOAuthClient auth(profile_.GetRequestContext()); | |
318 auth.GetTokenInfo("access_token", 1, &delegate); | |
319 | |
320 std::string issued_to; | |
321 ASSERT_TRUE(captured_result->GetString("issued_to", &issued_to)); | |
322 ASSERT_EQ("1234567890.apps.googleusercontent.com", issued_to); | |
323 } | |
324 | |
276 } // namespace gaia | 325 } // namespace gaia |
OLD | NEW |