Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: chrome/browser/chromeos/login/google_authenticator_unittest.cc

Issue 3061019: Make canceled login fail over to offline, instead of just failing (Closed)
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 &GoogleAuthenticator::LoadLocalaccount, 126 &GoogleAuthenticator::LoadLocalaccount,
127 filename)); 127 filename));
128 } 128 }
129 129
130 void PrepForLogin(GoogleAuthenticator* auth) { 130 void PrepForLogin(GoogleAuthenticator* auth) {
131 auth->set_password_hash(hash_ascii_); 131 auth->set_password_hash(hash_ascii_);
132 auth->set_username(username_); 132 auth->set_username(username_);
133 auth->SetLocalaccount(""); 133 auth->SetLocalaccount("");
134 } 134 }
135 135
136 void CancelLogin(GoogleAuthenticator* auth) {
137 ChromeThread::PostDelayedTask(
138 ChromeThread::UI,
139 FROM_HERE,
140 NewRunnableMethod(auth,
141 &GoogleAuthenticator::CancelClientLogin),
142 50);
143 }
144
136 unsigned char fake_hash_[32]; 145 unsigned char fake_hash_[32];
137 std::string hash_ascii_; 146 std::string hash_ascii_;
138 std::string username_; 147 std::string username_;
139 GaiaAuthConsumer::ClientLoginResult result_; 148 GaiaAuthConsumer::ClientLoginResult result_;
140 // Mocks, destroyed by CrosLibrary class. 149 // Mocks, destroyed by CrosLibrary class.
141 MockCryptohomeLibrary* mock_library_; 150 MockCryptohomeLibrary* mock_library_;
142 MockLibraryLoader* loader_; 151 MockLibraryLoader* loader_;
143 char raw_bytes_[2]; 152 char raw_bytes_[2];
144 std::string bytes_as_ascii_; 153 std::string bytes_as_ascii_;
145 }; 154 };
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 // Run remaining events, until OnLoginSuccess or OnLoginFailure is called. 539 // Run remaining events, until OnLoginSuccess or OnLoginFailure is called.
531 message_loop.Run(); 540 message_loop.Run();
532 541
533 // Cleanup. 542 // Cleanup.
534 Delete(tmp_file_path, false); 543 Delete(tmp_file_path, false);
535 } 544 }
536 545
537 TEST_F(GoogleAuthenticatorTest, FullLogin) { 546 TEST_F(GoogleAuthenticatorTest, FullLogin) {
538 MessageLoopForUI message_loop; 547 MessageLoopForUI message_loop;
539 ChromeThread ui_thread(ChromeThread::UI, &message_loop); 548 ChromeThread ui_thread(ChromeThread::UI, &message_loop);
540 GURL source(AuthResponseHandler::kTokenAuthUrl);
541 URLRequestStatus status(URLRequestStatus::SUCCESS, 0);
542 chromeos::CryptohomeBlob salt_v(fake_hash_, fake_hash_ + sizeof(fake_hash_)); 549 chromeos::CryptohomeBlob salt_v(fake_hash_, fake_hash_ + sizeof(fake_hash_));
543 550
544 MockConsumer consumer; 551 MockConsumer consumer;
545 EXPECT_CALL(consumer, OnLoginSuccess(username_, result_)) 552 EXPECT_CALL(consumer, OnLoginSuccess(username_, result_))
546 .Times(1) 553 .Times(1)
547 .RetiresOnSaturation(); 554 .RetiresOnSaturation();
548 EXPECT_CALL(*mock_library_, Mount(username_, _, _)) 555 EXPECT_CALL(*mock_library_, Mount(username_, _, _))
549 .WillOnce(Return(true)) 556 .WillOnce(Return(true))
550 .RetiresOnSaturation(); 557 .RetiresOnSaturation();
551 558
552 ON_CALL(*mock_library_, GetSystemSalt())
553 .WillByDefault(Return(salt_v));
554 EXPECT_CALL(*mock_library_, GetSystemSalt()) 559 EXPECT_CALL(*mock_library_, GetSystemSalt())
555 .Times(1) 560 .WillOnce(Return(salt_v))
556 .RetiresOnSaturation(); 561 .RetiresOnSaturation();
557 562
558 TestingProfile profile; 563 TestingProfile profile;
559 564
560 MockFactory factory; 565 MockFactory factory;
561 URLFetcher::set_factory(&factory); 566 URLFetcher::set_factory(&factory);
562 567
563 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); 568 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer));
564 auth->AuthenticateToLogin( 569 auth->AuthenticateToLogin(
565 &profile, username_, hash_ascii_, std::string(), std::string()); 570 &profile, username_, hash_ascii_, std::string(), std::string());
566 571
567 URLFetcher::set_factory(NULL); 572 URLFetcher::set_factory(NULL);
568 message_loop.RunAllPending(); 573 message_loop.RunAllPending();
569 } 574 }
570 575
576 TEST_F(GoogleAuthenticatorTest, CancelLogin) {
577 MessageLoopForUI message_loop;
578 ChromeThread ui_thread(ChromeThread::UI, &message_loop);
579 chromeos::CryptohomeBlob salt_v(fake_hash_, fake_hash_ + sizeof(fake_hash_));
580
581 MockConsumer consumer;
582 EXPECT_CALL(consumer, OnLoginFailure(_))
583 .Times(1)
584 .RetiresOnSaturation();
585
586 EXPECT_CALL(*mock_library_, GetSystemSalt())
587 .WillOnce(Return(salt_v))
588 .RetiresOnSaturation();
589 EXPECT_CALL(*mock_library_, CheckKey(username_, _))
590 .WillOnce(Return(false))
591 .RetiresOnSaturation();
592
593 TestingProfile profile;
594
595 MockFactory factory;
596 factory.set_success(false);
597 URLFetcher::set_factory(&factory);
598
599 scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer));
600 ReadLocalaccountFile(auth.get(), ""); // No localaccount file.
601 auth->AuthenticateToLogin(
602 &profile, username_, hash_ascii_, std::string(), std::string());
603 CancelLogin(auth.get());
604 URLFetcher::set_factory(NULL);
605 message_loop.RunAllPending();
606 }
607
571 } // namespace chromeos 608 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698