OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/sync/signin_manager.h" |
| 6 |
| 7 #include "chrome/browser/net/gaia/token_service.h" |
| 8 #include "chrome/browser/net/gaia/token_service_unittest.h" |
| 9 #include "chrome/browser/password_manager/encryptor.h" |
| 10 #include "chrome/browser/webdata/web_data_service.h" |
| 11 #include "chrome/common/net/test_url_fetcher_factory.h" |
| 12 #include "chrome/test/testing_profile.h" |
| 13 #include "chrome/test/signaling_task.h" |
| 14 |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 class SigninManagerTest : public TokenServiceTestHarness { |
| 18 public: |
| 19 virtual void SetUp() { |
| 20 TokenServiceTestHarness::SetUp(); |
| 21 manager_.reset(new SigninManager()); |
| 22 google_login_success_.ListenFor(NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, |
| 23 Source<SigninManager>(manager_.get())); |
| 24 google_login_failure_.ListenFor(NotificationType::GOOGLE_SIGNIN_FAILED, |
| 25 Source<SigninManager>(manager_.get())); |
| 26 |
| 27 URLFetcher::set_factory(&factory_); |
| 28 } |
| 29 |
| 30 TestURLFetcherFactory factory_; |
| 31 scoped_ptr<SigninManager> manager_; |
| 32 TestNotificationTracker google_login_success_; |
| 33 TestNotificationTracker google_login_failure_; |
| 34 }; |
| 35 |
| 36 TEST_F(SigninManagerTest, SignIn) { |
| 37 manager_->Initialize(profile_.get()); |
| 38 EXPECT_TRUE(manager_->GetUsername().empty()); |
| 39 |
| 40 manager_->StartSignIn("username", "password", "", ""); |
| 41 EXPECT_FALSE(manager_->GetUsername().empty()); |
| 42 |
| 43 // Should go into token service and stop. |
| 44 manager_->OnClientLoginSuccess(credentials_); |
| 45 EXPECT_EQ(1U, google_login_success_.size()); |
| 46 EXPECT_EQ(0U, google_login_failure_.size()); |
| 47 |
| 48 // Should persist across resets. |
| 49 manager_.reset(new SigninManager()); |
| 50 manager_->Initialize(profile_.get()); |
| 51 EXPECT_FALSE(manager_->GetUsername().empty()); |
| 52 } |
| 53 |
| 54 TEST_F(SigninManagerTest, SignOut) { |
| 55 manager_->Initialize(profile_.get()); |
| 56 manager_->StartSignIn("username", "password", "", ""); |
| 57 manager_->OnClientLoginSuccess(credentials_); |
| 58 |
| 59 EXPECT_FALSE(manager_->GetUsername().empty()); |
| 60 manager_->SignOut(); |
| 61 EXPECT_TRUE(manager_->GetUsername().empty()); |
| 62 // Should not be persisted anymore |
| 63 manager_.reset(new SigninManager()); |
| 64 manager_->Initialize(profile_.get()); |
| 65 EXPECT_TRUE(manager_->GetUsername().empty()); |
| 66 } |
| 67 |
| 68 TEST_F(SigninManagerTest, SignInFailure) { |
| 69 manager_->Initialize(profile_.get()); |
| 70 manager_->StartSignIn("username", "password", "", ""); |
| 71 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); |
| 72 manager_->OnClientLoginFailure(error); |
| 73 |
| 74 EXPECT_EQ(0U, google_login_success_.size()); |
| 75 EXPECT_EQ(1U, google_login_failure_.size()); |
| 76 |
| 77 EXPECT_TRUE(manager_->GetUsername().empty()); |
| 78 |
| 79 // Should not be persisted |
| 80 manager_.reset(new SigninManager()); |
| 81 manager_->Initialize(profile_.get()); |
| 82 EXPECT_TRUE(manager_->GetUsername().empty()); |
| 83 } |
| 84 |
| 85 TEST_F(SigninManagerTest, SignOutMidConnect) { |
| 86 manager_->Initialize(profile_.get()); |
| 87 manager_->StartSignIn("username", "password", "", ""); |
| 88 manager_->SignOut(); |
| 89 EXPECT_EQ(0U, google_login_success_.size()); |
| 90 EXPECT_EQ(0U, google_login_failure_.size()); |
| 91 |
| 92 EXPECT_TRUE(manager_->GetUsername().empty()); |
| 93 } |
OLD | NEW |