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 complete set of unit tests for GaiaAuthFetcher. | 5 // A complete set of unit tests for GaiaAuthFetcher. |
6 // Originally ported from GoogleAuthenticator tests. | 6 // Originally ported from GoogleAuthenticator tests. |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 auth.OnURLFetchComplete(NULL, | 152 auth.OnURLFetchComplete(NULL, |
153 issue_auth_token_source_, | 153 issue_auth_token_source_, |
154 status, | 154 status, |
155 0, | 155 0, |
156 cookies_, | 156 cookies_, |
157 std::string()); | 157 std::string()); |
158 } | 158 } |
159 | 159 |
160 | 160 |
161 TEST_F(GaiaAuthFetcherTest, LoginDenied) { | 161 TEST_F(GaiaAuthFetcherTest, LoginDenied) { |
162 std::string data("Error: NO!"); | 162 std::string data("Error=BadAuthentication"); |
163 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); | 163 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); |
164 | 164 |
165 GoogleServiceAuthError expected_error( | 165 GoogleServiceAuthError expected_error( |
166 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 166 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
167 | 167 |
168 MockGaiaConsumer consumer; | 168 MockGaiaConsumer consumer; |
169 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error)) | 169 EXPECT_CALL(consumer, OnClientLoginFailure(expected_error)) |
170 .Times(1); | 170 .Times(1); |
171 | 171 |
172 GaiaAuthFetcher auth(&consumer, std::string(), | 172 GaiaAuthFetcher auth(&consumer, std::string(), |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 TEST_F(GaiaAuthFetcherTest, AccountDisabledError) { | 309 TEST_F(GaiaAuthFetcherTest, AccountDisabledError) { |
310 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); | 310 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); |
311 std::string data = "Error=AccountDisabled\n"; | 311 std::string data = "Error=AccountDisabled\n"; |
312 GoogleServiceAuthError error = | 312 GoogleServiceAuthError error = |
313 GaiaAuthFetcher::GenerateAuthError(data, status); | 313 GaiaAuthFetcher::GenerateAuthError(data, status); |
314 EXPECT_EQ(error.state(), GoogleServiceAuthError::ACCOUNT_DISABLED); | 314 EXPECT_EQ(error.state(), GoogleServiceAuthError::ACCOUNT_DISABLED); |
315 } | 315 } |
316 | 316 |
| 317 TEST_F(GaiaAuthFetcherTest,BadAuthenticationError) { |
| 318 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); |
| 319 std::string data = "Error=BadAuthentication\n"; |
| 320 GoogleServiceAuthError error = |
| 321 GaiaAuthFetcher::GenerateAuthError(data, status); |
| 322 EXPECT_EQ(error.state(), GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
| 323 } |
| 324 |
| 325 TEST_F(GaiaAuthFetcherTest,IncomprehensibleError) { |
| 326 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); |
| 327 std::string data = "Error=Gobbledygook\n"; |
| 328 GoogleServiceAuthError error = |
| 329 GaiaAuthFetcher::GenerateAuthError(data, status); |
| 330 EXPECT_EQ(error.state(), GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
| 331 } |
| 332 |
317 TEST_F(GaiaAuthFetcherTest,ServiceUnavailableError) { | 333 TEST_F(GaiaAuthFetcherTest,ServiceUnavailableError) { |
318 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); | 334 URLRequestStatus status(URLRequestStatus::SUCCESS, 0); |
319 std::string data = "Error=ServiceUnavailable\n"; | 335 std::string data = "Error=ServiceUnavailable\n"; |
320 GoogleServiceAuthError error = | 336 GoogleServiceAuthError error = |
321 GaiaAuthFetcher::GenerateAuthError(data, status); | 337 GaiaAuthFetcher::GenerateAuthError(data, status); |
322 EXPECT_EQ(error.state(), GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 338 EXPECT_EQ(error.state(), GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
323 } | 339 } |
324 | 340 |
325 TEST_F(GaiaAuthFetcherTest, FullLogin) { | 341 TEST_F(GaiaAuthFetcherTest, FullLogin) { |
326 MockGaiaConsumer consumer; | 342 MockGaiaConsumer consumer; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 URLFetcher::set_factory(NULL); | 452 URLFetcher::set_factory(NULL); |
437 EXPECT_TRUE(auth.HasPendingFetch()); | 453 EXPECT_TRUE(auth.HasPendingFetch()); |
438 auth.OnURLFetchComplete(NULL, | 454 auth.OnURLFetchComplete(NULL, |
439 issue_auth_token_source_, | 455 issue_auth_token_source_, |
440 URLRequestStatus(URLRequestStatus::SUCCESS, 0), | 456 URLRequestStatus(URLRequestStatus::SUCCESS, 0), |
441 RC_FORBIDDEN, | 457 RC_FORBIDDEN, |
442 cookies_, | 458 cookies_, |
443 ""); | 459 ""); |
444 EXPECT_FALSE(auth.HasPendingFetch()); | 460 EXPECT_FALSE(auth.HasPendingFetch()); |
445 } | 461 } |
OLD | NEW |