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 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 auth->SkipPasswordChange(result_); | 311 auth->SkipPasswordChange(result_); |
312 } | 312 } |
313 | 313 |
314 TEST_F(GoogleAuthenticatorTest, LoginNetFailure) { | 314 TEST_F(GoogleAuthenticatorTest, LoginNetFailure) { |
315 MessageLoopForUI message_loop; | 315 MessageLoopForUI message_loop; |
316 ChromeThread ui_thread(ChromeThread::UI, &message_loop); | 316 ChromeThread ui_thread(ChromeThread::UI, &message_loop); |
317 | 317 |
318 int error_no = net::ERR_CONNECTION_RESET; | 318 int error_no = net::ERR_CONNECTION_RESET; |
319 std::string data(net::ErrorToString(error_no)); | 319 std::string data(net::ErrorToString(error_no)); |
320 | 320 |
321 GaiaAuthConsumer::ClientLoginError error; | 321 GaiaAuthConsumer::GaiaAuthError error; |
322 error.code = GaiaAuthConsumer::NETWORK_ERROR; | 322 error.code = GaiaAuthConsumer::NETWORK_ERROR; |
323 error.network_error = error_no; | 323 error.network_error = error_no; |
324 | 324 |
325 MockConsumer consumer; | 325 MockConsumer consumer; |
326 EXPECT_CALL(consumer, OnLoginFailure(data)) | 326 EXPECT_CALL(consumer, OnLoginFailure(data)) |
327 .Times(1); | 327 .Times(1); |
328 EXPECT_CALL(*mock_library_, CheckKey(username_, hash_ascii_)) | 328 EXPECT_CALL(*mock_library_, CheckKey(username_, hash_ascii_)) |
329 .WillOnce(Return(false)); | 329 .WillOnce(Return(false)); |
330 | 330 |
331 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); | 331 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); |
332 PrepForLogin(auth.get()); | 332 PrepForLogin(auth.get()); |
333 auth->OnClientLoginFailure(error); | 333 auth->OnClientLoginFailure(error); |
334 message_loop.RunAllPending(); | 334 message_loop.RunAllPending(); |
335 } | 335 } |
336 | 336 |
337 TEST_F(GoogleAuthenticatorTest, LoginDenied) { | 337 TEST_F(GoogleAuthenticatorTest, LoginDenied) { |
338 MessageLoopForUI message_loop; | 338 MessageLoopForUI message_loop; |
339 ChromeThread ui_thread(ChromeThread::UI, &message_loop); | 339 ChromeThread ui_thread(ChromeThread::UI, &message_loop); |
340 | 340 |
341 GaiaAuthConsumer::ClientLoginError error; | 341 GaiaAuthConsumer::GaiaAuthError error; |
342 error.code = GaiaAuthConsumer::PERMISSION_DENIED; | 342 error.code = GaiaAuthConsumer::PERMISSION_DENIED; |
343 | 343 |
344 MockConsumer consumer; | 344 MockConsumer consumer; |
345 EXPECT_CALL(consumer, OnLoginFailure(_)) | 345 EXPECT_CALL(consumer, OnLoginFailure(_)) |
346 .Times(1); | 346 .Times(1); |
347 | 347 |
348 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); | 348 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); |
349 PrepForLogin(auth.get()); | 349 PrepForLogin(auth.get()); |
350 auth->OnClientLoginFailure(error); | 350 auth->OnClientLoginFailure(error); |
351 message_loop.RunAllPending(); | 351 message_loop.RunAllPending(); |
352 } | 352 } |
353 | 353 |
354 TEST_F(GoogleAuthenticatorTest, CaptchaErrorOutputted) { | 354 TEST_F(GoogleAuthenticatorTest, CaptchaErrorOutputted) { |
355 MessageLoopForUI message_loop; | 355 MessageLoopForUI message_loop; |
356 ChromeThread ui_thread(ChromeThread::UI, &message_loop); | 356 ChromeThread ui_thread(ChromeThread::UI, &message_loop); |
357 | 357 |
358 // TODO(chron): Swap out this captcha passing for actual captcha parsing. | 358 // TODO(chron): Swap out this captcha passing for actual captcha parsing. |
359 GaiaAuthConsumer::ClientLoginError error; | 359 GaiaAuthConsumer::GaiaAuthError error; |
360 error.code = GaiaAuthConsumer::PERMISSION_DENIED; | 360 error.code = GaiaAuthConsumer::PERMISSION_DENIED; |
361 error.data = "Url=http://www.google.com/login/captcha\n" | 361 error.data = "Url=http://www.google.com/login/captcha\n" |
362 "Error=CaptchaRequired\n" | 362 "Error=CaptchaRequired\n" |
363 "CaptchaToken=DQAAAGgA...dkI1LK9\n" | 363 "CaptchaToken=DQAAAGgA...dkI1LK9\n" |
364 "CaptchaUrl=Captcha?ctoken=...\n"; | 364 "CaptchaUrl=Captcha?ctoken=...\n"; |
365 | 365 |
366 MockConsumer consumer; | 366 MockConsumer consumer; |
367 EXPECT_CALL(consumer, OnLoginFailure(error.data)) | 367 EXPECT_CALL(consumer, OnLoginFailure(error.data)) |
368 .Times(1); | 368 .Times(1); |
369 | 369 |
370 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); | 370 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); |
371 PrepForLogin(auth.get()); | 371 PrepForLogin(auth.get()); |
372 auth->OnClientLoginFailure(error); | 372 auth->OnClientLoginFailure(error); |
373 message_loop.RunAllPending(); | 373 message_loop.RunAllPending(); |
374 } | 374 } |
375 | 375 |
376 TEST_F(GoogleAuthenticatorTest, OfflineLogin) { | 376 TEST_F(GoogleAuthenticatorTest, OfflineLogin) { |
377 MessageLoopForUI message_loop; | 377 MessageLoopForUI message_loop; |
378 ChromeThread ui_thread(ChromeThread::UI, &message_loop); | 378 ChromeThread ui_thread(ChromeThread::UI, &message_loop); |
379 | 379 |
380 GaiaAuthConsumer::ClientLoginError error; | 380 GaiaAuthConsumer::GaiaAuthError error; |
381 error.code = GaiaAuthConsumer::NETWORK_ERROR; | 381 error.code = GaiaAuthConsumer::NETWORK_ERROR; |
382 error.network_error = net::ERR_CONNECTION_RESET; | 382 error.network_error = net::ERR_CONNECTION_RESET; |
383 | 383 |
384 MockConsumer consumer; | 384 MockConsumer consumer; |
385 EXPECT_CALL(consumer, OnLoginSuccess(username_, result_)) | 385 EXPECT_CALL(consumer, OnLoginSuccess(username_, result_)) |
386 .Times(1); | 386 .Times(1); |
387 EXPECT_CALL(*mock_library_, CheckKey(username_, hash_ascii_)) | 387 EXPECT_CALL(*mock_library_, CheckKey(username_, hash_ascii_)) |
388 .WillOnce(Return(true)); | 388 .WillOnce(Return(true)); |
389 EXPECT_CALL(*mock_library_, Mount(username_, hash_ascii_, _)) | 389 EXPECT_CALL(*mock_library_, Mount(username_, hash_ascii_, _)) |
390 .WillOnce(Return(true)); | 390 .WillOnce(Return(true)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 453 |
454 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); | 454 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); |
455 auth->AuthenticateToLogin( | 455 auth->AuthenticateToLogin( |
456 &profile, username_, hash_ascii_, std::string(), std::string()); | 456 &profile, username_, hash_ascii_, std::string(), std::string()); |
457 | 457 |
458 URLFetcher::set_factory(NULL); | 458 URLFetcher::set_factory(NULL); |
459 message_loop.RunAllPending(); | 459 message_loop.RunAllPending(); |
460 } | 460 } |
461 | 461 |
462 } // namespace chromeos | 462 } // namespace chromeos |
OLD | NEW |