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)); | |
81 }; | 77 }; |
82 | 78 |
83 class MockGaiaOAuthFetcher : public GaiaOAuthFetcher { | 79 class MockGaiaOAuthFetcher : public GaiaOAuthFetcher { |
84 public: | 80 public: |
85 MockGaiaOAuthFetcher(GaiaOAuthConsumer* consumer, | 81 MockGaiaOAuthFetcher(GaiaOAuthConsumer* consumer, |
86 net::URLRequestContextGetter* getter, | 82 net::URLRequestContextGetter* getter, |
87 Profile* profile, | 83 Profile* profile, |
88 const std::string& service_scope) | 84 const std::string& service_scope) |
89 : GaiaOAuthFetcher( | 85 : GaiaOAuthFetcher( |
90 consumer, getter, profile, service_scope) {} | 86 consumer, getter, profile, service_scope) {} |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 "&wrap_access_token_expires_in=3600"); | 193 "&wrap_access_token_expires_in=3600"); |
198 | 194 |
199 MockGaiaOAuthConsumer consumer; | 195 MockGaiaOAuthConsumer consumer; |
200 EXPECT_CALL(consumer, | 196 EXPECT_CALL(consumer, |
201 OnOAuthWrapBridgeSuccess("service_scope-0fL85iOi", | 197 OnOAuthWrapBridgeSuccess("service_scope-0fL85iOi", |
202 wrap_token, | 198 wrap_token, |
203 expires_in)).Times(1); | 199 expires_in)).Times(1); |
204 | 200 |
205 TestingProfile profile; | 201 TestingProfile profile; |
206 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 202 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
207 profile.GetRequestContext(), | 203 profile .GetRequestContext(), |
208 &profile, | 204 &profile, |
209 "service_scope-0fL85iOi"); | 205 "service_scope-0fL85iOi"); |
210 EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); | 206 EXPECT_CALL(oauth_fetcher, StartUserInfo(wrap_token)).Times(1); |
211 | 207 |
212 net::ResponseCookies cookies; | 208 net::ResponseCookies cookies; |
213 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 209 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
214 oauth_fetcher.OnURLFetchComplete(NULL, | 210 oauth_fetcher.OnURLFetchComplete(NULL, |
215 GURL(kOAuthWrapBridgeUrl), | 211 GURL(kOAuthWrapBridgeUrl), |
216 status, | 212 status, |
217 RC_REQUEST_OK, | 213 RC_REQUEST_OK, |
218 cookies, | 214 cookies, |
219 data); | 215 data); |
220 } | 216 } |
221 | 217 |
222 TEST_F(GaiaOAuthFetcherTest, UserInfo) { | 218 TEST_F(GaiaOAuthFetcherTest, UserInfo) { |
223 const std::string email_address = "someone@somewhere.net"; | 219 const std::string email_address = "someone@somewhere.net"; |
224 const std::string wrap_token = | 220 const std::string wrap_token = |
225 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; | 221 "1/OAuth2-Access_Token-nopqrstuvwxyz1234567890"; |
226 const std::string expires_in = "3600"; | 222 const std::string expires_in = "3600"; |
227 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" | 223 const std::string data("{\n \"email\": \"someone@somewhere.net\",\n" |
228 " \"verified_email\": true\n}\n"); | 224 " \"verified_email\": true\n}\n"); |
229 MockGaiaOAuthConsumer consumer; | 225 MockGaiaOAuthConsumer consumer; |
230 EXPECT_CALL(consumer, | 226 EXPECT_CALL(consumer, |
231 OnUserInfoSuccess(email_address)).Times(1); | 227 OnUserInfoSuccess(email_address)).Times(1); |
232 | 228 |
233 TestingProfile profile; | 229 TestingProfile profile; |
234 MockGaiaOAuthFetcher oauth_fetcher(&consumer, | 230 MockGaiaOAuthFetcher oauth_fetcher(&consumer, |
235 profile.GetRequestContext(), | 231 profile .GetRequestContext(), |
236 &profile, | 232 &profile, |
237 "service_scope-Nrj4LmgU"); | 233 "service_scope-Nrj4LmgU"); |
238 | 234 |
239 net::ResponseCookies cookies; | 235 net::ResponseCookies cookies; |
240 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 236 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
241 oauth_fetcher.OnURLFetchComplete(NULL, | 237 oauth_fetcher.OnURLFetchComplete(NULL, |
242 GURL(kUserInfoUrl), | 238 GURL(kUserInfoUrl), |
243 status, | 239 status, |
244 RC_REQUEST_OK, | 240 RC_REQUEST_OK, |
245 cookies, | 241 cookies, |
246 data); | 242 data); |
247 } | 243 } |
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 |