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 "chrome/browser/sync/sync_setup_wizard.h" | 5 #include "chrome/browser/sync/sync_setup_wizard.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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // A PSS subtype to inject. | 31 // A PSS subtype to inject. |
32 class ProfileSyncServiceForWizardTest : public ProfileSyncService { | 32 class ProfileSyncServiceForWizardTest : public ProfileSyncService { |
33 public: | 33 public: |
34 ProfileSyncServiceForWizardTest(ProfileSyncFactory* factory, Profile* profile) | 34 ProfileSyncServiceForWizardTest(ProfileSyncFactory* factory, Profile* profile) |
35 : ProfileSyncService(factory, profile, | 35 : ProfileSyncService(factory, profile, |
36 &fake_network_change_notifier_thread_, | 36 &fake_network_change_notifier_thread_, |
37 false), | 37 false), |
38 user_accepted_merge_and_sync_(false), | 38 user_accepted_merge_and_sync_(false), |
39 user_cancelled_dialog_(false) { | 39 user_cancelled_dialog_(false) { |
40 RegisterPreferences(); | 40 RegisterPreferences(); |
| 41 ResetTestStats(); |
41 } | 42 } |
42 | 43 |
43 virtual ~ProfileSyncServiceForWizardTest() { } | 44 virtual ~ProfileSyncServiceForWizardTest() { } |
44 | 45 |
45 virtual void OnUserSubmittedAuth(const std::string& username, | 46 virtual void OnUserSubmittedAuth(const std::string& username, |
46 const std::string& password, | 47 const std::string& password, |
47 const std::string& captcha) { | 48 const std::string& captcha) { |
48 username_ = username; | 49 username_ = username; |
49 password_ = password; | 50 password_ = password; |
50 captcha_ = captcha; | 51 captcha_ = captcha; |
51 } | 52 } |
| 53 |
| 54 virtual void OnUserChoseDatatypes(bool sync_everything, |
| 55 const syncable::ModelTypeSet& chosen_types) { |
| 56 user_chose_data_types_ = true; |
| 57 chosen_data_types_ = chosen_types; |
| 58 } |
| 59 |
52 virtual void OnUserAcceptedMergeAndSync() { | 60 virtual void OnUserAcceptedMergeAndSync() { |
53 user_accepted_merge_and_sync_ = true; | 61 user_accepted_merge_and_sync_ = true; |
54 } | 62 } |
55 virtual void OnUserCancelledDialog() { | 63 virtual void OnUserCancelledDialog() { |
56 user_cancelled_dialog_ = true; | 64 user_cancelled_dialog_ = true; |
57 } | 65 } |
58 | 66 |
59 virtual string16 GetAuthenticatedUsername() const { | 67 virtual string16 GetAuthenticatedUsername() const { |
60 return UTF8ToUTF16(username_); | 68 return UTF8ToUTF16(username_); |
61 } | 69 } |
62 | 70 |
63 void set_auth_state(const std::string& last_email, | 71 void set_auth_state(const std::string& last_email, |
64 const AuthError& error) { | 72 const AuthError& error) { |
65 last_attempted_user_email_ = last_email; | 73 last_attempted_user_email_ = last_email; |
66 last_auth_error_ = error; | 74 last_auth_error_ = error; |
67 } | 75 } |
68 | 76 |
69 void ResetTestStats() { | 77 void ResetTestStats() { |
70 username_.clear(); | 78 username_.clear(); |
71 password_.clear(); | 79 password_.clear(); |
72 captcha_.clear(); | 80 captcha_.clear(); |
73 user_accepted_merge_and_sync_ = false; | 81 user_accepted_merge_and_sync_ = false; |
74 user_cancelled_dialog_ = false; | 82 user_cancelled_dialog_ = false; |
| 83 user_chose_data_types_ = false; |
| 84 keep_everything_synced_ = false; |
| 85 chosen_data_types_.clear(); |
75 } | 86 } |
76 | 87 |
77 std::string username_; | 88 std::string username_; |
78 std::string password_; | 89 std::string password_; |
79 std::string captcha_; | 90 std::string captcha_; |
80 bool user_accepted_merge_and_sync_; | 91 bool user_accepted_merge_and_sync_; |
81 bool user_cancelled_dialog_; | 92 bool user_cancelled_dialog_; |
| 93 bool user_chose_data_types_; |
| 94 bool keep_everything_synced_; |
| 95 syncable::ModelTypeSet chosen_data_types_; |
82 | 96 |
83 private: | 97 private: |
84 chrome_common_net::FakeNetworkChangeNotifierThread | 98 chrome_common_net::FakeNetworkChangeNotifierThread |
85 fake_network_change_notifier_thread_; | 99 fake_network_change_notifier_thread_; |
86 | 100 |
87 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); | 101 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); |
88 }; | 102 }; |
89 | 103 |
90 class TestingProfileWithSyncService : public TestingProfile { | 104 class TestingProfileWithSyncService : public TestingProfile { |
91 public: | 105 public: |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 256 |
243 // Simulate failed credentials. | 257 // Simulate failed credentials. |
244 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS); | 258 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS); |
245 service_->set_auth_state(kTestUser, invalid_gaia); | 259 service_->set_auth_state(kTestUser, invalid_gaia); |
246 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 260 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
247 EXPECT_TRUE(wizard_->IsVisible()); | 261 EXPECT_TRUE(wizard_->IsVisible()); |
248 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 262 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
249 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); | 263 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); |
250 dialog_args.Clear(); | 264 dialog_args.Clear(); |
251 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); | 265 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); |
252 EXPECT_EQ(4U, dialog_args.size()); | 266 EXPECT_EQ(5U, dialog_args.size()); |
| 267 std::string iframe_to_show; |
| 268 dialog_args.GetString(L"iframeToShow", &iframe_to_show); |
| 269 EXPECT_EQ("login", iframe_to_show); |
253 std::string actual_user; | 270 std::string actual_user; |
254 dialog_args.GetString(L"user", &actual_user); | 271 dialog_args.GetString(L"user", &actual_user); |
255 EXPECT_EQ(kTestUser, actual_user); | 272 EXPECT_EQ(kTestUser, actual_user); |
256 int error = -1; | 273 int error = -1; |
257 dialog_args.GetInteger(L"error", &error); | 274 dialog_args.GetInteger(L"error", &error); |
258 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); | 275 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); |
259 service_->set_auth_state(kTestUser, AuthError::None()); | 276 service_->set_auth_state(kTestUser, AuthError::None()); |
260 | 277 |
261 // Simulate captcha. | 278 // Simulate captcha. |
262 AuthError captcha_error(AuthError::FromCaptchaChallenge( | 279 AuthError captcha_error(AuthError::FromCaptchaChallenge( |
263 std::string(), GURL(kTestCaptchaUrl), GURL())); | 280 std::string(), GURL(kTestCaptchaUrl), GURL())); |
264 service_->set_auth_state(kTestUser, captcha_error); | 281 service_->set_auth_state(kTestUser, captcha_error); |
265 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 282 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
266 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); | 283 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); |
267 EXPECT_EQ(4U, dialog_args.size()); | 284 EXPECT_EQ(5U, dialog_args.size()); |
| 285 dialog_args.GetString(L"iframeToShow", &iframe_to_show); |
| 286 EXPECT_EQ("login", iframe_to_show); |
268 std::string captcha_url; | 287 std::string captcha_url; |
269 dialog_args.GetString(L"captchaUrl", &captcha_url); | 288 dialog_args.GetString(L"captchaUrl", &captcha_url); |
270 EXPECT_EQ(kTestCaptchaUrl, GURL(captcha_url).spec()); | 289 EXPECT_EQ(kTestCaptchaUrl, GURL(captcha_url).spec()); |
271 error = -1; | 290 error = -1; |
272 dialog_args.GetInteger(L"error", &error); | 291 dialog_args.GetInteger(L"error", &error); |
273 EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error); | 292 EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error); |
274 service_->set_auth_state(kTestUser, AuthError::None()); | 293 service_->set_auth_state(kTestUser, AuthError::None()); |
275 | 294 |
276 // Simulate success. | 295 // Simulate success. |
277 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 296 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
278 EXPECT_TRUE(wizard_->IsVisible()); | 297 EXPECT_TRUE(wizard_->IsVisible()); |
279 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 298 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
280 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, | 299 // In a non-discrete run, GAIA_SUCCESS immediately transitions you to |
| 300 // CHOOSE_DATA_TYPES. |
| 301 EXPECT_EQ(SyncSetupWizard::CHOOSE_DATA_TYPES, |
281 test_window_->flow()->current_state_); | 302 test_window_->flow()->current_state_); |
282 | 303 |
| 304 // That's all we're testing here, just move on to DONE. We'll test the |
| 305 // "choose data types" scenarios elsewhere. |
283 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync. | 306 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync. |
284 EXPECT_TRUE(wizard_->IsVisible()); | 307 EXPECT_TRUE(wizard_->IsVisible()); |
285 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 308 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
286 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->current_state_); | 309 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->current_state_); |
287 } | 310 } |
288 | 311 |
| 312 TEST_F(SyncSetupWizardTest, ChooseDataTypesSetsPrefs) { |
| 313 SKIP_TEST_ON_MACOSX(); |
| 314 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
| 315 wizard_->Step(SyncSetupWizard::CHOOSE_DATA_TYPES); |
| 316 |
| 317 ListValue data_type_choices_value; |
| 318 std::string data_type_choices = "{\"keepEverythingSynced\":false,"; |
| 319 data_type_choices += "\"syncBookmarks\":true,\"syncPreferences\":true,"; |
| 320 data_type_choices += "\"syncThemes\":false,\"syncPasswords\":false,"; |
| 321 data_type_choices += "\"syncAutofill\":false,\"syncExtensions\":false,"; |
| 322 data_type_choices += "\"syncTypedUrls\":true}"; |
| 323 data_type_choices_value.Append(new StringValue(data_type_choices)); |
| 324 |
| 325 // Simulate the user choosing data types; bookmarks and prefs are on, the rest |
| 326 // are off. |
| 327 test_window_->flow()->flow_handler_->HandleChooseDataTypes( |
| 328 &data_type_choices_value); |
| 329 EXPECT_TRUE(wizard_->IsVisible()); |
| 330 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
| 331 EXPECT_FALSE(service_->keep_everything_synced_); |
| 332 EXPECT_EQ(service_->chosen_data_types_.count(syncable::BOOKMARKS), 1U); |
| 333 EXPECT_EQ(service_->chosen_data_types_.count(syncable::PREFERENCES), 1U); |
| 334 EXPECT_EQ(service_->chosen_data_types_.count(syncable::THEMES), 0U); |
| 335 EXPECT_EQ(service_->chosen_data_types_.count(syncable::PASSWORDS), 0U); |
| 336 EXPECT_EQ(service_->chosen_data_types_.count(syncable::AUTOFILL), 0U); |
| 337 EXPECT_EQ(service_->chosen_data_types_.count(syncable::EXTENSIONS), 0U); |
| 338 EXPECT_EQ(service_->chosen_data_types_.count(syncable::TYPED_URLS), 1U); |
| 339 |
| 340 test_window_->CloseDialog(); |
| 341 } |
| 342 |
289 TEST_F(SyncSetupWizardTest, DialogCancelled) { | 343 TEST_F(SyncSetupWizardTest, DialogCancelled) { |
290 SKIP_TEST_ON_MACOSX(); | 344 SKIP_TEST_ON_MACOSX(); |
291 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 345 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
292 // Simulate the user closing the dialog. | 346 // Simulate the user closing the dialog. |
293 test_window_->CloseDialog(); | 347 test_window_->CloseDialog(); |
294 EXPECT_FALSE(wizard_->IsVisible()); | 348 EXPECT_FALSE(wizard_->IsVisible()); |
295 EXPECT_TRUE(service_->user_cancelled_dialog_); | 349 EXPECT_TRUE(service_->user_cancelled_dialog_); |
296 EXPECT_EQ(std::string(), service_->username_); | 350 EXPECT_EQ(std::string(), service_->username_); |
297 EXPECT_EQ(std::string(), service_->password_); | 351 EXPECT_EQ(std::string(), service_->password_); |
298 EXPECT_FALSE(service_->user_accepted_merge_and_sync_); | 352 EXPECT_FALSE(service_->user_accepted_merge_and_sync_); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 425 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
372 | 426 |
373 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 427 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
374 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_); | 428 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_); |
375 | 429 |
376 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS); | 430 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS); |
377 service_->set_auth_state(kTestUser, invalid_gaia); | 431 service_->set_auth_state(kTestUser, invalid_gaia); |
378 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 432 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
379 EXPECT_TRUE(wizard_->IsVisible()); | 433 EXPECT_TRUE(wizard_->IsVisible()); |
380 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); | 434 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); |
381 EXPECT_EQ(4U, dialog_args.size()); | 435 EXPECT_EQ(5U, dialog_args.size()); |
| 436 std::string iframe_to_show; |
| 437 dialog_args.GetString(L"iframeToShow", &iframe_to_show); |
| 438 EXPECT_EQ("login", iframe_to_show); |
382 std::string actual_user; | 439 std::string actual_user; |
383 dialog_args.GetString(L"user", &actual_user); | 440 dialog_args.GetString(L"user", &actual_user); |
384 EXPECT_EQ(kTestUser, actual_user); | 441 EXPECT_EQ(kTestUser, actual_user); |
385 int error = -1; | 442 int error = -1; |
386 dialog_args.GetInteger(L"error", &error); | 443 dialog_args.GetInteger(L"error", &error); |
387 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); | 444 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); |
388 service_->set_auth_state(kTestUser, AuthError::None()); | 445 service_->set_auth_state(kTestUser, AuthError::None()); |
389 | 446 |
390 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 447 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
391 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 448 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
392 } | 449 } |
393 | 450 |
394 #undef SKIP_TEST_ON_MACOSX | 451 #undef SKIP_TEST_ON_MACOSX |
OLD | NEW |