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

Side by Side Diff: chrome/browser/sync/sync_setup_wizard_unittest.cc

Issue 389017: Implement the gaia captcha state and unlock capability in the sync setup wiza... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_list.h" 11 #include "chrome/browser/browser_list.h"
12 #include "chrome/browser/google_service_auth_error.h" 12 #include "chrome/browser/google_service_auth_error.h"
13 #include "chrome/browser/sync/profile_sync_service.h" 13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/browser/sync/sync_setup_flow.h" 14 #include "chrome/browser/sync/sync_setup_flow.h"
15 #include "chrome/browser/sync/sync_setup_wizard.h" 15 #include "chrome/browser/sync/sync_setup_wizard.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "chrome/common/pref_service.h" 17 #include "chrome/common/pref_service.h"
18 #include "chrome/test/browser_with_test_window_test.h" 18 #include "chrome/test/browser_with_test_window_test.h"
19 #include "chrome/test/testing_profile.h" 19 #include "chrome/test/testing_profile.h"
20 #include "chrome/test/test_browser_window.h" 20 #include "chrome/test/test_browser_window.h"
21 21
22 static const char* kTestUser = "chrome.p13n.test@gmail.com"; 22 static const char* kTestUser = "chrome.p13n.test@gmail.com";
23 static const char* kTestPassword = "passwd"; 23 static const char* kTestPassword = "passwd";
24 static const char* kTestCaptcha = "pizzamyheart";
25 static const char* kTestCaptchaUrl = "http://pizzamyheart/";
24 26
25 typedef GoogleServiceAuthError AuthError; 27 typedef GoogleServiceAuthError AuthError;
26 28
27 // A PSS subtype to inject. 29 // A PSS subtype to inject.
28 class ProfileSyncServiceForWizardTest : public ProfileSyncService { 30 class ProfileSyncServiceForWizardTest : public ProfileSyncService {
29 public: 31 public:
30 explicit ProfileSyncServiceForWizardTest(Profile* profile) 32 explicit ProfileSyncServiceForWizardTest(Profile* profile)
31 : ProfileSyncService(profile), user_accepted_merge_and_sync_(false), 33 : ProfileSyncService(profile), user_accepted_merge_and_sync_(false),
32 user_cancelled_dialog_(false) { 34 user_cancelled_dialog_(false) {
33 RegisterPreferences(); 35 RegisterPreferences();
34 } 36 }
35 37
36 virtual ~ProfileSyncServiceForWizardTest() { } 38 virtual ~ProfileSyncServiceForWizardTest() { }
37 39
38 virtual void OnUserSubmittedAuth(const std::string& username, 40 virtual void OnUserSubmittedAuth(const std::string& username,
39 const std::string& password) { 41 const std::string& password,
42 const std::string& captcha) {
40 username_ = username; 43 username_ = username;
41 password_ = password; 44 password_ = password;
45 captcha_ = captcha;
42 } 46 }
43 virtual void OnUserAcceptedMergeAndSync() { 47 virtual void OnUserAcceptedMergeAndSync() {
44 user_accepted_merge_and_sync_ = true; 48 user_accepted_merge_and_sync_ = true;
45 } 49 }
46 virtual void OnUserCancelledDialog() { 50 virtual void OnUserCancelledDialog() {
47 user_cancelled_dialog_ = true; 51 user_cancelled_dialog_ = true;
48 } 52 }
49 53
50 virtual string16 GetAuthenticatedUsername() const { 54 virtual string16 GetAuthenticatedUsername() const {
51 return UTF8ToUTF16(username_); 55 return UTF8ToUTF16(username_);
52 } 56 }
53 57
54 void set_auth_state(const std::string& last_email, 58 void set_auth_state(const std::string& last_email,
55 const AuthError::State& state) { 59 const AuthError& error) {
56 last_attempted_user_email_ = last_email; 60 last_attempted_user_email_ = last_email;
57 last_auth_error_ = AuthError(state); 61 last_auth_error_ = error;
58 } 62 }
59 63
60 void ResetTestStats() { 64 void ResetTestStats() {
61 username_.clear(); 65 username_.clear();
62 password_.clear(); 66 password_.clear();
67 captcha_.clear();
63 user_accepted_merge_and_sync_ = false; 68 user_accepted_merge_and_sync_ = false;
64 user_cancelled_dialog_ = false; 69 user_cancelled_dialog_ = false;
65 } 70 }
66 71
67 std::string username_; 72 std::string username_;
68 std::string password_; 73 std::string password_;
74 std::string captcha_;
69 bool user_accepted_merge_and_sync_; 75 bool user_accepted_merge_and_sync_;
70 bool user_cancelled_dialog_; 76 bool user_cancelled_dialog_;
71 77
72 private: 78 private:
73 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); 79 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest);
74 }; 80 };
75 81
76 class TestingProfileWithSyncService : public TestingProfile { 82 class TestingProfileWithSyncService : public TestingProfile {
77 public: 83 public:
78 TestingProfileWithSyncService() { 84 TestingProfileWithSyncService() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 }; 187 };
182 188
183 TEST_F(SyncSetupWizardTest, InitialStepLogin) { 189 TEST_F(SyncSetupWizardTest, InitialStepLogin) {
184 DictionaryValue dialog_args; 190 DictionaryValue dialog_args;
185 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); 191 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
186 std::string json_start_args; 192 std::string json_start_args;
187 base::JSONWriter::Write(&dialog_args, false, &json_start_args); 193 base::JSONWriter::Write(&dialog_args, false, &json_start_args);
188 ListValue credentials; 194 ListValue credentials;
189 std::string auth = "{\"user\":\""; 195 std::string auth = "{\"user\":\"";
190 auth += std::string(kTestUser) + "\",\"pass\":\""; 196 auth += std::string(kTestUser) + "\",\"pass\":\"";
191 auth += std::string(kTestPassword) + "\"}"; 197 auth += std::string(kTestPassword) + "\",\"captcha\":\"";
198 auth += std::string(kTestCaptcha) + "\"}";
192 credentials.Append(new StringValue(auth)); 199 credentials.Append(new StringValue(auth));
193 200
194 EXPECT_FALSE(wizard_->IsVisible()); 201 EXPECT_FALSE(wizard_->IsVisible());
195 EXPECT_FALSE(test_window_->flow()); 202 EXPECT_FALSE(test_window_->flow());
196 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 203 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
197 204
198 EXPECT_TRUE(wizard_->IsVisible()); 205 EXPECT_TRUE(wizard_->IsVisible());
199 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 206 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
200 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); 207 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
201 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_); 208 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_);
202 EXPECT_EQ(json_start_args, test_window_->flow()->dialog_start_args_); 209 EXPECT_EQ(json_start_args, test_window_->flow()->dialog_start_args_);
203 210
204 // Simulate the user submitting credentials. 211 // Simulate the user submitting credentials.
205 test_window_->flow()->flow_handler_->HandleSubmitAuth(&credentials); 212 test_window_->flow()->flow_handler_->HandleSubmitAuth(&credentials);
206 EXPECT_TRUE(wizard_->IsVisible()); 213 EXPECT_TRUE(wizard_->IsVisible());
207 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); 214 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
208 EXPECT_EQ(kTestUser, service_->username_); 215 EXPECT_EQ(kTestUser, service_->username_);
209 EXPECT_EQ(kTestPassword, service_->password_); 216 EXPECT_EQ(kTestPassword, service_->password_);
217 EXPECT_EQ(kTestCaptcha, service_->captcha_);
210 EXPECT_FALSE(service_->user_accepted_merge_and_sync_); 218 EXPECT_FALSE(service_->user_accepted_merge_and_sync_);
211 EXPECT_FALSE(service_->user_cancelled_dialog_); 219 EXPECT_FALSE(service_->user_cancelled_dialog_);
212 service_->ResetTestStats(); 220 service_->ResetTestStats();
213 221
214 // Simulate failed credentials. 222 // Simulate failed credentials.
215 service_->set_auth_state(kTestUser, AuthError::INVALID_GAIA_CREDENTIALS); 223 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS);
224 service_->set_auth_state(kTestUser, invalid_gaia);
216 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 225 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
217 EXPECT_TRUE(wizard_->IsVisible()); 226 EXPECT_TRUE(wizard_->IsVisible());
218 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 227 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
219 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); 228 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_);
220 dialog_args.Clear(); 229 dialog_args.Clear();
221 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); 230 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
222 EXPECT_TRUE(2 == dialog_args.GetSize()); 231 EXPECT_TRUE(3 == dialog_args.GetSize());
223 std::string actual_user; 232 std::string actual_user;
224 dialog_args.GetString(L"user", &actual_user); 233 dialog_args.GetString(L"user", &actual_user);
225 EXPECT_EQ(kTestUser, actual_user); 234 EXPECT_EQ(kTestUser, actual_user);
226 int error = -1; 235 int error = -1;
227 dialog_args.GetInteger(L"error", &error); 236 dialog_args.GetInteger(L"error", &error);
228 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); 237 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error);
229 service_->set_auth_state(kTestUser, AuthError::NONE); 238 service_->set_auth_state(kTestUser, AuthError::None());
239
240 // Simulate captcha.
241 AuthError captcha_error(AuthError::FromCaptchaChallenge(
242 std::string(), GURL(kTestCaptchaUrl), GURL()));
243 service_->set_auth_state(kTestUser, captcha_error);
244 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
245 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
246 EXPECT_TRUE(3 == dialog_args.GetSize());
247 std::string captcha_url;
248 dialog_args.GetString(L"captchaUrl", &captcha_url);
249 EXPECT_EQ(kTestCaptchaUrl, GURL(captcha_url).spec());
250 error = -1;
251 dialog_args.GetInteger(L"error", &error);
252 EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error);
253 service_->set_auth_state(kTestUser, AuthError::None());
230 254
231 // Simulate success. 255 // Simulate success.
232 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); 256 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
233 EXPECT_TRUE(wizard_->IsVisible()); 257 EXPECT_TRUE(wizard_->IsVisible());
234 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 258 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled());
235 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, 259 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS,
236 test_window_->flow()->current_state_); 260 test_window_->flow()->current_state_);
237 261
238 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync. 262 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync.
239 EXPECT_TRUE(wizard_->IsVisible()); 263 EXPECT_TRUE(wizard_->IsVisible());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 382 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
359 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); 383 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
360 wizard_->Step(SyncSetupWizard::MERGE_AND_SYNC); 384 wizard_->Step(SyncSetupWizard::MERGE_AND_SYNC);
361 wizard_->Step(SyncSetupWizard::DONE); 385 wizard_->Step(SyncSetupWizard::DONE);
362 test_window_->CloseDialog(); 386 test_window_->CloseDialog();
363 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 387 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
364 388
365 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 389 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
366 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_); 390 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_);
367 391
368 service_->set_auth_state(kTestUser, AuthError::INVALID_GAIA_CREDENTIALS); 392 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS);
393 service_->set_auth_state(kTestUser, invalid_gaia);
369 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); 394 wizard_->Step(SyncSetupWizard::GAIA_LOGIN);
370 EXPECT_TRUE(wizard_->IsVisible()); 395 EXPECT_TRUE(wizard_->IsVisible());
371 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); 396 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args);
372 EXPECT_TRUE(2 == dialog_args.GetSize()); 397 EXPECT_TRUE(3 == dialog_args.GetSize());
373 std::string actual_user; 398 std::string actual_user;
374 dialog_args.GetString(L"user", &actual_user); 399 dialog_args.GetString(L"user", &actual_user);
375 EXPECT_EQ(kTestUser, actual_user); 400 EXPECT_EQ(kTestUser, actual_user);
376 int error = -1; 401 int error = -1;
377 dialog_args.GetInteger(L"error", &error); 402 dialog_args.GetInteger(L"error", &error);
378 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); 403 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error);
379 service_->set_auth_state(kTestUser, AuthError::NONE); 404 service_->set_auth_state(kTestUser, AuthError::None());
380 405
381 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); 406 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS);
382 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); 407 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled());
383 } 408 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/sync_setup_wizard.cc ('k') | chrome/test/live_sync/profile_sync_service_test_harness.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698