OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
7 #include "base/test/test_file_util.h" | 7 #include "base/test/test_file_util.h" |
8 #include "base/waitable_event.h" | 8 #include "base/waitable_event.h" |
9 #include "chrome/browser/sync/engine/all_status.h" | 9 #include "chrome/browser/sync/engine/all_status.h" |
10 #include "chrome/browser/sync/engine/auth_watcher.h" | 10 #include "chrome/browser/sync/engine/auth_watcher.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 results->lsid = kValidLSID; | 64 results->lsid = kValidLSID; |
65 results->auth_token = kValidAuthToken; | 65 results->auth_token = kValidAuthToken; |
66 } | 66 } |
67 if (use_bad_auth_token_) { | 67 if (use_bad_auth_token_) { |
68 results->auth_token = kInvalidAuthToken; | 68 results->auth_token = kInvalidAuthToken; |
69 use_bad_auth_token_ = false; | 69 use_bad_auth_token_ = false; |
70 } | 70 } |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 bool LookupEmail(AuthResults* results) { | |
75 results->signin = gaia::GMAIL_SIGNIN; | |
76 return true; | |
77 } | |
78 | |
79 void RenewAuthToken(const std::string& auth_token) { | 74 void RenewAuthToken(const std::string& auth_token) { |
80 renewed_token_ = auth_token; | 75 renewed_token_ = auth_token; |
81 } | 76 } |
82 | 77 |
83 private: | 78 private: |
84 // Whether we should send an invalid auth token on the next request. | 79 // Whether we should send an invalid auth token on the next request. |
85 bool use_bad_auth_token_; | 80 bool use_bad_auth_token_; |
86 std::string renewed_token_; | 81 std::string renewed_token_; |
87 }; | 82 }; |
88 | 83 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 EXPECT_TRUE(auth_watcher()->message_loop()); | 182 EXPECT_TRUE(auth_watcher()->message_loop()); |
188 EXPECT_EQ("SyncEngine_AuthWatcherThread", | 183 EXPECT_EQ("SyncEngine_AuthWatcherThread", |
189 auth_watcher()->message_loop()->thread_name()); | 184 auth_watcher()->message_loop()->thread_name()); |
190 EXPECT_TRUE(auth_watcher()->auth_backend_thread_.IsRunning()); | 185 EXPECT_TRUE(auth_watcher()->auth_backend_thread_.IsRunning()); |
191 EXPECT_EQ(AuthWatcher::NOT_AUTHENTICATED, auth_watcher()->status()); | 186 EXPECT_EQ(AuthWatcher::NOT_AUTHENTICATED, auth_watcher()->status()); |
192 } | 187 } |
193 | 188 |
194 TEST_F(AuthWatcherTest, AuthenticateGaiaAuthFailure) { | 189 TEST_F(AuthWatcherTest, AuthenticateGaiaAuthFailure) { |
195 auth_watcher()->Authenticate(kTestEmail, kWrongPassword, | 190 auth_watcher()->Authenticate(kTestEmail, kWrongPassword, |
196 std::string(), // captcha_token | 191 std::string(), // captcha_token |
197 std::string(), // captcha_value | 192 std::string()); // captcha_value |
198 false); // persist_creds_to_disk | 193 |
199 EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); | 194 EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); |
200 EXPECT_EQ(AuthWatcherEvent::GAIA_AUTH_FAILED, ConsumeNextEvent()); | 195 EXPECT_EQ(AuthWatcherEvent::GAIA_AUTH_FAILED, ConsumeNextEvent()); |
201 } | 196 } |
202 | 197 |
203 TEST_F(AuthWatcherTest, AuthenticateBadAuthToken) { | 198 TEST_F(AuthWatcherTest, AuthenticateBadAuthToken) { |
204 gaia_auth()->SendBadAuthTokenForNextRequest(); | 199 gaia_auth()->SendBadAuthTokenForNextRequest(); |
205 auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), | 200 auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), |
206 std::string(), false); | 201 std::string()); |
207 EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); | 202 EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); |
208 EXPECT_EQ(AuthWatcherEvent::SERVICE_AUTH_FAILED, ConsumeNextEvent()); | 203 EXPECT_EQ(AuthWatcherEvent::SERVICE_AUTH_FAILED, ConsumeNextEvent()); |
209 } | 204 } |
210 | 205 |
211 TEST_F(AuthWatcherTest, AuthenticateSuccess) { | 206 TEST_F(AuthWatcherTest, AuthenticateSuccess) { |
212 auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), | 207 auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), |
213 std::string(), false); | 208 std::string()); |
214 EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); | 209 EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); |
215 EXPECT_EQ(AuthWatcherEvent::AUTH_SUCCEEDED, ConsumeNextEvent()); | 210 EXPECT_EQ(AuthWatcherEvent::AUTH_SUCCEEDED, ConsumeNextEvent()); |
216 | 211 |
217 // The server responds with a different email than what we used in the call | 212 // The server responds with a different email than what we used in the call |
218 // to Authenticate, and the AuthWatcher should have told us about. | 213 // to Authenticate, and the AuthWatcher should have told us about. |
219 EXPECT_EQ(kUserDisplayEmail, user_email()); | 214 EXPECT_EQ(kUserDisplayEmail, user_email()); |
220 } | 215 } |
221 | 216 |
222 TEST_F(AuthWatcherTest, AuthenticateWithTokenBadAuthToken) { | 217 TEST_F(AuthWatcherTest, AuthenticateWithTokenBadAuthToken) { |
223 auth_watcher()->AuthenticateWithToken(kTestEmail, kInvalidAuthToken); | 218 auth_watcher()->AuthenticateWithToken(kTestEmail, kInvalidAuthToken); |
224 EXPECT_EQ(AuthWatcherEvent::SERVICE_AUTH_FAILED, ConsumeNextEvent()); | 219 EXPECT_EQ(AuthWatcherEvent::SERVICE_AUTH_FAILED, ConsumeNextEvent()); |
225 } | 220 } |
226 | 221 |
227 TEST_F(AuthWatcherTest, AuthenticateWithTokenSuccess) { | 222 TEST_F(AuthWatcherTest, AuthenticateWithTokenSuccess) { |
228 auth_watcher()->AuthenticateWithToken(kTestEmail, kValidAuthToken); | 223 auth_watcher()->AuthenticateWithToken(kTestEmail, kValidAuthToken); |
229 EXPECT_EQ(AuthWatcherEvent::AUTH_SUCCEEDED, ConsumeNextEvent()); | 224 EXPECT_EQ(AuthWatcherEvent::AUTH_SUCCEEDED, ConsumeNextEvent()); |
230 EXPECT_EQ(kUserDisplayEmail, user_email()); | 225 EXPECT_EQ(kUserDisplayEmail, user_email()); |
231 } | 226 } |
232 | 227 |
233 // Just check that the thread task was properly issued. | 228 // Just check that the thread task was properly issued. |
234 TEST_F(AuthWatcherTest, RenewAuthToken) { | 229 TEST_F(AuthWatcherTest, RenewAuthToken) { |
235 auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), | 230 auth_watcher()->Authenticate(kTestEmail, kCorrectPassword, std::string(), |
236 std::string(), false); | 231 std::string()); |
237 EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); | 232 EXPECT_EQ(AuthWatcherEvent::AUTHENTICATION_ATTEMPT_START, ConsumeNextEvent()); |
238 EXPECT_EQ(AuthWatcherEvent::AUTH_SUCCEEDED, ConsumeNextEvent()); | 233 EXPECT_EQ(AuthWatcherEvent::AUTH_SUCCEEDED, ConsumeNextEvent()); |
239 | 234 |
240 auth_watcher()->RenewAuthToken("updated_token"); | 235 auth_watcher()->RenewAuthToken("updated_token"); |
241 EXPECT_EQ(AuthWatcherEvent::AUTH_RENEWED, ConsumeNextEvent()); | 236 EXPECT_EQ(AuthWatcherEvent::AUTH_RENEWED, ConsumeNextEvent()); |
242 EXPECT_EQ(gaia_auth()->renewed_token(), "updated_token"); | 237 EXPECT_EQ(gaia_auth()->renewed_token(), "updated_token"); |
243 EXPECT_EQ(connection()->auth_token(), "updated_token"); | 238 EXPECT_EQ(connection()->auth_token(), "updated_token"); |
244 } | 239 } |
245 | 240 |
246 } // namespace browser_sync | 241 } // namespace browser_sync |
OLD | NEW |