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 complete set of unit tests for GaiaOAuthFetcher. | 5 // A complete set of unit tests for GaiaOAuthFetcher. |
6 // Originally ported from GaiaAuthFetcher tests. | 6 // Originally ported from GaiaAuthFetcher tests. |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 MOCK_METHOD3(OnOAuthWrapBridgeSuccess, | 67 MOCK_METHOD3(OnOAuthWrapBridgeSuccess, |
68 void(const std::string& service_scope, | 68 void(const std::string& service_scope, |
69 const std::string& token, | 69 const std::string& token, |
70 const std::string& expires_in)); | 70 const std::string& expires_in)); |
71 MOCK_METHOD2(OnOAuthWrapBridgeFailure, | 71 MOCK_METHOD2(OnOAuthWrapBridgeFailure, |
72 void(const std::string& service_scope, | 72 void(const std::string& service_scope, |
73 const GoogleServiceAuthError& error)); | 73 const GoogleServiceAuthError& error)); |
74 | 74 |
75 MOCK_METHOD1(OnUserInfoSuccess, void(const std::string& email)); | 75 MOCK_METHOD1(OnUserInfoSuccess, void(const std::string& email)); |
76 MOCK_METHOD1(OnUserInfoFailure, void(const GoogleServiceAuthError& error)); | 76 MOCK_METHOD1(OnUserInfoFailure, void(const GoogleServiceAuthError& error)); |
| 77 |
| 78 MOCK_METHOD0(OnOAuthRevokeTokenSuccess, void()); |
| 79 MOCK_METHOD1(OnOAuthRevokeTokenFailure, |
| 80 void(const GoogleServiceAuthError& error)); |
77 }; | 81 }; |
78 | 82 |
79 class MockGaiaOAuthFetcher : public GaiaOAuthFetcher { | 83 class MockGaiaOAuthFetcher : public GaiaOAuthFetcher { |
80 public: | 84 public: |
81 MockGaiaOAuthFetcher(GaiaOAuthConsumer* consumer, | 85 MockGaiaOAuthFetcher(GaiaOAuthConsumer* consumer, |
82 net::URLRequestContextGetter* getter, | 86 net::URLRequestContextGetter* getter, |
83 Profile* profile, | 87 Profile* profile, |
84 const std::string& service_scope) | 88 const std::string& service_scope) |
85 : GaiaOAuthFetcher( | 89 : GaiaOAuthFetcher( |
86 consumer, getter, profile, service_scope) {} | 90 consumer, getter, profile, service_scope) {} |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 "&wrap_access_token_expires_in=3600"); | 197 "&wrap_access_token_expires_in=3600"); |
194 | 198 |
195 MockGaiaOAuthConsumer consumer; | 199 MockGaiaOAuthConsumer consumer; |
196 EXPECT_CALL(consumer, | 200 EXPECT_CALL(consumer, |
197 OnOAuthWrapBridgeSuccess("service_scope-0fL85iOi", | 201 OnOAuthWrapBridgeSuccess("service_scope-0fL85iOi", |
198 wrap_token, | 202 wrap_token, |
199 expires_in)).Times(1); | 203 expires_in)).Times(1); |
200 | 204 |
201 TestingProfile profile; | 205 TestingProfile profile; |
202 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 206 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
203 profile .GetRequestContext(), | 207 profile.GetRequestContext(), |
204 &profile, | 208 &profile, |
205 "service_scope-0fL85iOi"); | 209 "service_scope-0fL85iOi"); |
206 EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); | 210 EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); |
207 | 211 |
208 net::ResponseCookies cookies; | 212 net::ResponseCookies cookies; |
209 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 213 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
210 oauth_fetcher.OnURLFetchComplete(NULL, | 214 oauth_fetcher.OnURLFetchComplete(NULL, |
211 GURL(kOAuthWrapBridgeUrl), | 215 GURL(kOAuthWrapBridgeUrl), |
212 status, | 216 status, |
213 RC_REQUEST_OK, | 217 RC_REQUEST_OK, |
214 cookies, | 218 cookies, |
215 data); | 219 data); |
216 } | 220 } |
217 | 221 |
218 TEST_F(GaiaOAuthFetcherTest, UserInfo) { | 222 TEST_F(GaiaOAuthFetcherTest, UserInfo) { |
219 const std::string email_address = "someone@somewhere.net"; | 223 const std::string email_address = "someone@somewhere.net"; |
220 const std::string wrap_token = | 224 const std::string wrap_token = |
221 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 225 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
222 const std::string expires_in = "3600"; | 226 const std::string expires_in = "3600"; |
223 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" | 227 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" |
224 " \"verified_email\": true\n}\n"); | 228 " \"verified_email\": true\n}\n"); |
225 MockGaiaOAuthConsumer consumer; | 229 MockGaiaOAuthConsumer consumer; |
226 EXPECT_CALL(consumer, | 230 EXPECT_CALL(consumer, |
227 OnUserInfoSuccess(email_address)).Times(1); | 231 OnUserInfoSuccess(email_address)).Times(1); |
228 | 232 |
229 TestingProfile profile; | 233 TestingProfile profile; |
230 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 234 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
231 profile .GetRequestContext(), | 235 profile.GetRequestContext(), |
232 &profile, | 236 &profile, |
233 "service_scope-Nrj4LmgU"); | 237 "service_scope-Nrj4LmgU"); |
234 | 238 |
235 net::ResponseCookies cookies; | 239 net::ResponseCookies cookies; |
236 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 240 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
237 oauth_fetcher.OnURLFetchComplete(NULL, | 241 oauth_fetcher.OnURLFetchComplete(NULL, |
238 GURL(kUserInfoUrl), | 242 GURL(kUserInfoUrl), |
239 status, | 243 status, |
240 RC_REQUEST_OK, | 244 RC_REQUEST_OK, |
241 cookies, | 245 cookies, |
242 data); | 246 data); |
243 } | 247 } |
| 248 |
| 249 TEST_F(GaiaOAuthFetcherTest, OAuthRevokeToken) { |
| 250 const std::string token = "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
| 251 MockGaiaOAuthConsumer consumer; |
| 252 EXPECT_CALL(consumer, |
| 253 OnOAuthRevokeTokenSuccess()).Times(1); |
| 254 |
| 255 TestingProfile profile; |
| 256 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
| 257 profile.GetRequestContext(), |
| 258 &profile, |
| 259 "service_scope-Nrj4LmgU"); |
| 260 |
| 261 net::ResponseCookies cookies; |
| 262 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 263 GURL url(GaiaUrls::GetInstance()->oauth_revoke_token_url()); |
| 264 oauth_fetcher.OnURLFetchComplete(NULL, url, status, |
| 265 RC_REQUEST_OK, cookies, std::string()); |
| 266 } |
OLD | NEW |