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 #include "chrome/browser/sync/signin_manager.h" | 5 #include "chrome/browser/sync/signin_manager.h" |
| 6 #include "chrome/browser/sync/signin_manager_client_login.h" |
6 | 7 |
7 #include "chrome/browser/net/gaia/token_service.h" | 8 #include "chrome/browser/net/gaia/token_service.h" |
8 #include "chrome/browser/net/gaia/token_service_unittest.h" | 9 #include "chrome/browser/net/gaia/token_service_unittest.h" |
9 #include "chrome/browser/password_manager/encryptor.h" | 10 #include "chrome/browser/password_manager/encryptor.h" |
10 #include "chrome/browser/webdata/web_data_service.h" | 11 #include "chrome/browser/webdata/web_data_service.h" |
11 #include "chrome/common/net/test_url_fetcher_factory.h" | 12 #include "chrome/common/net/test_url_fetcher_factory.h" |
| 13 #include "chrome/test/signaling_task.h" |
12 #include "chrome/test/testing_profile.h" | 14 #include "chrome/test/testing_profile.h" |
13 #include "chrome/test/signaling_task.h" | |
14 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
15 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
16 | 17 |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 class SigninManagerTest : public TokenServiceTestHarness { | 20 class SigninManagerTest : public TokenServiceTestHarness { |
20 public: | 21 public: |
21 virtual void SetUp() { | 22 virtual void SetUp() { |
22 TokenServiceTestHarness::SetUp(); | 23 TokenServiceTestHarness::SetUp(); |
23 manager_.reset(new SigninManager()); | 24 manager_.reset(SigninManager::CreateSigninManager()); |
24 google_login_success_.ListenFor(NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, | 25 google_login_success_.ListenFor(NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, |
25 Source<Profile>(profile_.get())); | 26 Source<Profile>(profile_.get())); |
26 google_login_failure_.ListenFor(NotificationType::GOOGLE_SIGNIN_FAILED, | 27 google_login_failure_.ListenFor(NotificationType::GOOGLE_SIGNIN_FAILED, |
27 Source<Profile>(profile_.get())); | 28 Source<Profile>(profile_.get())); |
28 | 29 |
29 URLFetcher::set_factory(&factory_); | 30 URLFetcher::set_factory(&factory_); |
30 } | 31 } |
31 | 32 |
32 void SimulateValidResponse() { | 33 void SimulateValidResponse() { |
33 // Simulate the correct ClientLogin response. | 34 // Simulate the correct ClientLogin response. |
(...skipping 30 matching lines...) Expand all Loading... |
64 manager_->StartSignIn("username", "password", "", ""); | 65 manager_->StartSignIn("username", "password", "", ""); |
65 EXPECT_FALSE(manager_->GetUsername().empty()); | 66 EXPECT_FALSE(manager_->GetUsername().empty()); |
66 | 67 |
67 SimulateValidResponse(); | 68 SimulateValidResponse(); |
68 | 69 |
69 // Should go into token service and stop. | 70 // Should go into token service and stop. |
70 EXPECT_EQ(1U, google_login_success_.size()); | 71 EXPECT_EQ(1U, google_login_success_.size()); |
71 EXPECT_EQ(0U, google_login_failure_.size()); | 72 EXPECT_EQ(0U, google_login_failure_.size()); |
72 | 73 |
73 // Should persist across resets. | 74 // Should persist across resets. |
74 manager_.reset(new SigninManager()); | 75 manager_.reset(SigninManager::CreateSigninManager()); |
75 manager_->Initialize(profile_.get()); | 76 manager_->Initialize(profile_.get()); |
76 EXPECT_EQ("user@gmail.com", manager_->GetUsername()); | 77 EXPECT_EQ("user@gmail.com", manager_->GetUsername()); |
77 } | 78 } |
78 | 79 |
79 TEST_F(SigninManagerTest, SignOut) { | 80 TEST_F(SigninManagerTest, SignOut) { |
80 manager_->Initialize(profile_.get()); | 81 manager_->Initialize(profile_.get()); |
81 manager_->StartSignIn("username", "password", "", ""); | 82 manager_->StartSignIn("username", "password", "", ""); |
82 SimulateValidResponse(); | 83 SimulateValidResponse(); |
83 manager_->OnClientLoginSuccess(credentials_); | 84 static_cast<SigninManagerClientLogin*>(manager_.get())-> |
| 85 OnClientLoginSuccess( |
| 86 static_cast<GaiaAuthConsumer::ClientLoginResult*>(&credentials_)); |
84 | 87 |
85 EXPECT_EQ("user@gmail.com", manager_->GetUsername()); | 88 EXPECT_EQ("user@gmail.com", manager_->GetUsername()); |
86 manager_->SignOut(); | 89 manager_->SignOut(); |
87 EXPECT_TRUE(manager_->GetUsername().empty()); | 90 EXPECT_TRUE(manager_->GetUsername().empty()); |
88 // Should not be persisted anymore | 91 // Should not be persisted anymore |
89 manager_.reset(new SigninManager()); | 92 manager_.reset(SigninManager::CreateSigninManager()); |
90 manager_->Initialize(profile_.get()); | 93 manager_->Initialize(profile_.get()); |
91 EXPECT_TRUE(manager_->GetUsername().empty()); | 94 EXPECT_TRUE(manager_->GetUsername().empty()); |
92 } | 95 } |
93 | 96 |
94 TEST_F(SigninManagerTest, SignInFailure) { | 97 TEST_F(SigninManagerTest, SignInFailure) { |
95 manager_->Initialize(profile_.get()); | 98 manager_->Initialize(profile_.get()); |
96 manager_->StartSignIn("username", "password", "", ""); | 99 manager_->StartSignIn("username", "password", "", ""); |
97 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); | 100 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); |
98 manager_->OnClientLoginFailure(error); | 101 static_cast<SigninManagerClientLogin*>(manager_.get())-> |
| 102 OnClientLoginFailure(error); |
99 | 103 |
100 EXPECT_EQ(0U, google_login_success_.size()); | 104 EXPECT_EQ(0U, google_login_success_.size()); |
101 EXPECT_EQ(1U, google_login_failure_.size()); | 105 EXPECT_EQ(1U, google_login_failure_.size()); |
102 | 106 |
103 EXPECT_TRUE(manager_->GetUsername().empty()); | 107 EXPECT_TRUE(manager_->GetUsername().empty()); |
104 | 108 |
105 // Should not be persisted | 109 // Should not be persisted |
106 manager_.reset(new SigninManager()); | 110 manager_.reset(SigninManager::CreateSigninManager()); |
107 manager_->Initialize(profile_.get()); | 111 manager_->Initialize(profile_.get()); |
108 EXPECT_TRUE(manager_->GetUsername().empty()); | 112 EXPECT_TRUE(manager_->GetUsername().empty()); |
109 } | 113 } |
110 | 114 |
111 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) { | 115 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) { |
112 manager_->Initialize(profile_.get()); | 116 manager_->Initialize(profile_.get()); |
113 manager_->StartSignIn("username", "password", "", ""); | 117 manager_->StartSignIn("username", "password", "", ""); |
114 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); | 118 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); |
115 manager_->OnClientLoginFailure(error); | 119 static_cast<SigninManagerClientLogin*>(manager_.get())-> |
| 120 OnClientLoginFailure(error); |
116 | 121 |
117 EXPECT_EQ(0U, google_login_success_.size()); | 122 EXPECT_EQ(0U, google_login_success_.size()); |
118 EXPECT_EQ(1U, google_login_failure_.size()); | 123 EXPECT_EQ(1U, google_login_failure_.size()); |
119 | 124 |
120 EXPECT_FALSE(manager_->GetUsername().empty()); | 125 EXPECT_FALSE(manager_->GetUsername().empty()); |
121 | 126 |
122 manager_->ProvideSecondFactorAccessCode("access"); | 127 manager_->ProvideSecondFactorAccessCode("access"); |
123 SimulateValidResponse(); | 128 SimulateValidResponse(); |
124 | 129 |
125 EXPECT_EQ(1U, google_login_success_.size()); | 130 EXPECT_EQ(1U, google_login_success_.size()); |
126 EXPECT_EQ(1U, google_login_failure_.size()); | 131 EXPECT_EQ(1U, google_login_failure_.size()); |
127 } | 132 } |
128 | 133 |
129 TEST_F(SigninManagerTest, ProvideSecondFactorFailure) { | 134 TEST_F(SigninManagerTest, ProvideSecondFactorFailure) { |
130 manager_->Initialize(profile_.get()); | 135 manager_->Initialize(profile_.get()); |
131 manager_->StartSignIn("username", "password", "", ""); | 136 manager_->StartSignIn("username", "password", "", ""); |
132 GoogleServiceAuthError error1(GoogleServiceAuthError::TWO_FACTOR); | 137 GoogleServiceAuthError error1(GoogleServiceAuthError::TWO_FACTOR); |
133 manager_->OnClientLoginFailure(error1); | 138 static_cast<SigninManagerClientLogin*>(manager_.get())-> |
| 139 OnClientLoginFailure(error1); |
134 | 140 |
135 EXPECT_EQ(0U, google_login_success_.size()); | 141 EXPECT_EQ(0U, google_login_success_.size()); |
136 EXPECT_EQ(1U, google_login_failure_.size()); | 142 EXPECT_EQ(1U, google_login_failure_.size()); |
137 | 143 |
138 EXPECT_FALSE(manager_->GetUsername().empty()); | 144 EXPECT_FALSE(manager_->GetUsername().empty()); |
139 | 145 |
140 manager_->ProvideSecondFactorAccessCode("badaccess"); | 146 manager_->ProvideSecondFactorAccessCode("badaccess"); |
141 GoogleServiceAuthError error2( | 147 GoogleServiceAuthError error2( |
142 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 148 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
143 manager_->OnClientLoginFailure(error2); | 149 static_cast<SigninManagerClientLogin*>(manager_.get())-> |
| 150 OnClientLoginFailure(error2); |
144 | 151 |
145 EXPECT_EQ(0U, google_login_success_.size()); | 152 EXPECT_EQ(0U, google_login_success_.size()); |
146 EXPECT_EQ(2U, google_login_failure_.size()); | 153 EXPECT_EQ(2U, google_login_failure_.size()); |
147 EXPECT_FALSE(manager_->GetUsername().empty()); | 154 EXPECT_FALSE(manager_->GetUsername().empty()); |
148 | 155 |
149 manager_->ProvideSecondFactorAccessCode("badaccess"); | 156 manager_->ProvideSecondFactorAccessCode("badaccess"); |
150 GoogleServiceAuthError error3(GoogleServiceAuthError::CONNECTION_FAILED); | 157 GoogleServiceAuthError error3(GoogleServiceAuthError::CONNECTION_FAILED); |
151 manager_->OnClientLoginFailure(error3); | 158 static_cast<SigninManagerClientLogin*>(manager_.get())-> |
| 159 OnClientLoginFailure(error3); |
152 | 160 |
153 EXPECT_EQ(0U, google_login_success_.size()); | 161 EXPECT_EQ(0U, google_login_success_.size()); |
154 EXPECT_EQ(3U, google_login_failure_.size()); | 162 EXPECT_EQ(3U, google_login_failure_.size()); |
155 EXPECT_TRUE(manager_->GetUsername().empty()); | 163 EXPECT_TRUE(manager_->GetUsername().empty()); |
156 } | 164 } |
157 | 165 |
158 TEST_F(SigninManagerTest, SignOutMidConnect) { | 166 TEST_F(SigninManagerTest, SignOutMidConnect) { |
159 manager_->Initialize(profile_.get()); | 167 manager_->Initialize(profile_.get()); |
160 manager_->StartSignIn("username", "password", "", ""); | 168 manager_->StartSignIn("username", "password", "", ""); |
161 manager_->SignOut(); | 169 manager_->SignOut(); |
162 EXPECT_EQ(0U, google_login_success_.size()); | 170 EXPECT_EQ(0U, google_login_success_.size()); |
163 EXPECT_EQ(0U, google_login_failure_.size()); | 171 EXPECT_EQ(0U, google_login_failure_.size()); |
164 | 172 |
165 EXPECT_TRUE(manager_->GetUsername().empty()); | 173 EXPECT_TRUE(manager_->GetUsername().empty()); |
166 } | 174 } |
OLD | NEW |