OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 error = -1; | 278 error = -1; |
279 dialog_args.GetInteger("error", &error); | 279 dialog_args.GetInteger("error", &error); |
280 EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error); | 280 EXPECT_EQ(static_cast<int>(AuthError::CAPTCHA_REQUIRED), error); |
281 service_->set_auth_state(kTestUser, AuthError::None()); | 281 service_->set_auth_state(kTestUser, AuthError::None()); |
282 | 282 |
283 // Simulate success. | 283 // Simulate success. |
284 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 284 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
285 EXPECT_TRUE(wizard_->IsVisible()); | 285 EXPECT_TRUE(wizard_->IsVisible()); |
286 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 286 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
287 // In a non-discrete run, GAIA_SUCCESS immediately transitions you to | 287 // In a non-discrete run, GAIA_SUCCESS immediately transitions you to |
288 // CHOOSE_DATA_TYPES. | 288 // CONFIGURE. |
289 EXPECT_EQ(SyncSetupWizard::CHOOSE_DATA_TYPES, | 289 EXPECT_EQ(SyncSetupWizard::CONFIGURE, |
290 test_window_->flow()->current_state_); | 290 test_window_->flow()->current_state_); |
291 | 291 |
292 // That's all we're testing here, just move on to DONE. We'll test the | 292 // That's all we're testing here, just move on to DONE. We'll test the |
293 // "choose data types" scenarios elsewhere. | 293 // "choose data types" scenarios elsewhere. |
| 294 wizard_->Step(SyncSetupWizard::SETTING_UP); // No merge and sync. |
294 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync. | 295 wizard_->Step(SyncSetupWizard::DONE); // No merge and sync. |
295 EXPECT_TRUE(wizard_->IsVisible()); | 296 EXPECT_TRUE(wizard_->IsVisible()); |
296 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 297 EXPECT_FALSE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
297 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->current_state_); | 298 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->current_state_); |
298 } | 299 } |
299 | 300 |
300 TEST_F(SyncSetupWizardTest, ChooseDataTypesSetsPrefs) { | 301 TEST_F(SyncSetupWizardTest, ChooseDataTypesSetsPrefs) { |
301 SKIP_TEST_ON_MACOSX(); | 302 SKIP_TEST_ON_MACOSX(); |
302 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 303 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
303 wizard_->Step(SyncSetupWizard::CHOOSE_DATA_TYPES); | 304 wizard_->Step(SyncSetupWizard::CONFIGURE); |
304 | 305 |
305 ListValue data_type_choices_value; | 306 ListValue data_type_choices_value; |
306 std::string data_type_choices = "{\"keepEverythingSynced\":false,"; | 307 std::string data_type_choices = "{\"keepEverythingSynced\":false,"; |
307 data_type_choices += "\"syncBookmarks\":true,\"syncPreferences\":true,"; | 308 data_type_choices += "\"syncBookmarks\":true,\"syncPreferences\":true,"; |
308 data_type_choices += "\"syncThemes\":false,\"syncPasswords\":false,"; | 309 data_type_choices += "\"syncThemes\":false,\"syncPasswords\":false,"; |
309 data_type_choices += "\"syncAutofill\":false,\"syncExtensions\":false,"; | 310 data_type_choices += "\"syncAutofill\":false,\"syncExtensions\":false,"; |
310 data_type_choices += "\"syncTypedUrls\":true,\"syncApps\":true,"; | 311 data_type_choices += "\"syncTypedUrls\":true,\"syncApps\":true,"; |
311 data_type_choices += "\"syncSessions\":false}"; | 312 data_type_choices += "\"syncSessions\":false,\"usePassphrase\":false}"; |
312 data_type_choices_value.Append(new StringValue(data_type_choices)); | 313 data_type_choices_value.Append(new StringValue(data_type_choices)); |
313 | 314 |
314 // Simulate the user choosing data types; bookmarks, prefs, typed | 315 // Simulate the user choosing data types; bookmarks, prefs, typed |
315 // URLS, and apps are on, the rest are off. | 316 // URLS, and apps are on, the rest are off. |
316 test_window_->flow()->flow_handler_->HandleChooseDataTypes( | 317 test_window_->flow()->flow_handler_->HandleConfigure( |
317 &data_type_choices_value); | 318 &data_type_choices_value); |
318 EXPECT_TRUE(wizard_->IsVisible()); | 319 EXPECT_TRUE(wizard_->IsVisible()); |
319 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 320 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
320 EXPECT_FALSE(service_->keep_everything_synced_); | 321 EXPECT_FALSE(service_->keep_everything_synced_); |
321 EXPECT_EQ(service_->chosen_data_types_.count(syncable::BOOKMARKS), 1U); | 322 EXPECT_EQ(service_->chosen_data_types_.count(syncable::BOOKMARKS), 1U); |
322 EXPECT_EQ(service_->chosen_data_types_.count(syncable::PREFERENCES), 1U); | 323 EXPECT_EQ(service_->chosen_data_types_.count(syncable::PREFERENCES), 1U); |
323 EXPECT_EQ(service_->chosen_data_types_.count(syncable::THEMES), 0U); | 324 EXPECT_EQ(service_->chosen_data_types_.count(syncable::THEMES), 0U); |
324 EXPECT_EQ(service_->chosen_data_types_.count(syncable::PASSWORDS), 0U); | 325 EXPECT_EQ(service_->chosen_data_types_.count(syncable::PASSWORDS), 0U); |
325 EXPECT_EQ(service_->chosen_data_types_.count(syncable::AUTOFILL), 0U); | 326 EXPECT_EQ(service_->chosen_data_types_.count(syncable::AUTOFILL), 0U); |
326 EXPECT_EQ(service_->chosen_data_types_.count(syncable::EXTENSIONS), 0U); | 327 EXPECT_EQ(service_->chosen_data_types_.count(syncable::EXTENSIONS), 0U); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 wizard_->Step(SyncSetupWizard::DONE); | 373 wizard_->Step(SyncSetupWizard::DONE); |
373 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); | 374 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); |
374 wizard_->Step(SyncSetupWizard::DONE_FIRST_TIME); | 375 wizard_->Step(SyncSetupWizard::DONE_FIRST_TIME); |
375 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); | 376 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, test_window_->flow()->current_state_); |
376 | 377 |
377 wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); | 378 wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); |
378 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, | 379 EXPECT_EQ(SyncSetupWizard::GAIA_LOGIN, |
379 test_window_->flow()->current_state_); | 380 test_window_->flow()->current_state_); |
380 | 381 |
381 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 382 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
382 EXPECT_EQ(SyncSetupWizard::CHOOSE_DATA_TYPES, | 383 EXPECT_EQ(SyncSetupWizard::CONFIGURE, |
383 test_window_->flow()->current_state_); | 384 test_window_->flow()->current_state_); |
384 | 385 |
385 wizard_->Step(SyncSetupWizard::FATAL_ERROR); | 386 wizard_->Step(SyncSetupWizard::FATAL_ERROR); |
386 EXPECT_EQ(SyncSetupWizard::FATAL_ERROR, test_window_->flow()->current_state_); | 387 EXPECT_EQ(SyncSetupWizard::FATAL_ERROR, test_window_->flow()->current_state_); |
387 } | 388 } |
388 | 389 |
389 TEST_F(SyncSetupWizardTest, FullSuccessfulRunSetsPref) { | 390 TEST_F(SyncSetupWizardTest, FullSuccessfulRunSetsPref) { |
390 SKIP_TEST_ON_MACOSX(); | 391 SKIP_TEST_ON_MACOSX(); |
391 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 392 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
392 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 393 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
| 394 wizard_->Step(SyncSetupWizard::SETTING_UP); |
393 wizard_->Step(SyncSetupWizard::DONE); | 395 wizard_->Step(SyncSetupWizard::DONE); |
394 test_window_->CloseDialog(); | 396 test_window_->CloseDialog(); |
395 EXPECT_FALSE(wizard_->IsVisible()); | 397 EXPECT_FALSE(wizard_->IsVisible()); |
396 EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean( | 398 EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean( |
397 prefs::kSyncHasSetupCompleted)); | 399 prefs::kSyncHasSetupCompleted)); |
398 } | 400 } |
399 | 401 |
400 TEST_F(SyncSetupWizardTest, FirstFullSuccessfulRunSetsPref) { | 402 TEST_F(SyncSetupWizardTest, FirstFullSuccessfulRunSetsPref) { |
401 SKIP_TEST_ON_MACOSX(); | 403 SKIP_TEST_ON_MACOSX(); |
402 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 404 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
403 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 405 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
| 406 wizard_->Step(SyncSetupWizard::SETTING_UP); |
404 wizard_->Step(SyncSetupWizard::DONE_FIRST_TIME); | 407 wizard_->Step(SyncSetupWizard::DONE_FIRST_TIME); |
405 test_window_->CloseDialog(); | 408 test_window_->CloseDialog(); |
406 EXPECT_FALSE(wizard_->IsVisible()); | 409 EXPECT_FALSE(wizard_->IsVisible()); |
407 EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean( | 410 EXPECT_TRUE(service_->profile()->GetPrefs()->GetBoolean( |
408 prefs::kSyncHasSetupCompleted)); | 411 prefs::kSyncHasSetupCompleted)); |
409 } | 412 } |
410 | 413 |
411 TEST_F(SyncSetupWizardTest, AbortedByPendingClear) { | 414 TEST_F(SyncSetupWizardTest, AbortedByPendingClear) { |
412 SKIP_TEST_ON_MACOSX(); | 415 SKIP_TEST_ON_MACOSX(); |
413 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 416 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
414 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 417 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
415 wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); | 418 wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); |
416 EXPECT_EQ(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR, | 419 EXPECT_EQ(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR, |
417 test_window_->flow()->current_state_); | 420 test_window_->flow()->current_state_); |
418 test_window_->CloseDialog(); | 421 test_window_->CloseDialog(); |
419 EXPECT_FALSE(wizard_->IsVisible()); | 422 EXPECT_FALSE(wizard_->IsVisible()); |
420 } | 423 } |
421 | 424 |
422 TEST_F(SyncSetupWizardTest, DiscreteRunChooseDataTypes) { | 425 TEST_F(SyncSetupWizardTest, DiscreteRunChooseDataTypes) { |
423 SKIP_TEST_ON_MACOSX(); | 426 SKIP_TEST_ON_MACOSX(); |
424 // For a discrete run, we need to have ran through setup once. | 427 // For a discrete run, we need to have ran through setup once. |
425 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 428 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
426 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 429 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
427 wizard_->Step(SyncSetupWizard::DONE); | 430 wizard_->Step(SyncSetupWizard::DONE); |
428 test_window_->CloseDialog(); | 431 test_window_->CloseDialog(); |
429 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 432 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
430 | 433 |
431 wizard_->Step(SyncSetupWizard::CHOOSE_DATA_TYPES); | 434 wizard_->Step(SyncSetupWizard::CONFIGURE); |
432 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 435 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
433 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_); | 436 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_); |
434 | 437 |
435 wizard_->Step(SyncSetupWizard::DONE); | 438 wizard_->Step(SyncSetupWizard::DONE); |
436 test_window_->CloseDialog(); | 439 test_window_->CloseDialog(); |
437 EXPECT_FALSE(wizard_->IsVisible()); | 440 EXPECT_FALSE(wizard_->IsVisible()); |
438 } | 441 } |
439 | 442 |
440 TEST_F(SyncSetupWizardTest, DiscreteRunChooseDataTypesAbortedByPendingClear) { | 443 TEST_F(SyncSetupWizardTest, DiscreteRunChooseDataTypesAbortedByPendingClear) { |
441 SKIP_TEST_ON_MACOSX(); | 444 SKIP_TEST_ON_MACOSX(); |
442 // For a discrete run, we need to have ran through setup once. | 445 // For a discrete run, we need to have ran through setup once. |
443 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 446 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
444 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 447 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
445 wizard_->Step(SyncSetupWizard::DONE); | 448 wizard_->Step(SyncSetupWizard::DONE); |
446 test_window_->CloseDialog(); | 449 test_window_->CloseDialog(); |
447 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 450 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
448 | 451 |
449 wizard_->Step(SyncSetupWizard::CHOOSE_DATA_TYPES); | 452 wizard_->Step(SyncSetupWizard::CONFIGURE); |
450 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 453 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
451 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_); | 454 EXPECT_EQ(SyncSetupWizard::DONE, test_window_->flow()->end_state_); |
452 wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); | 455 wizard_->Step(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR); |
453 EXPECT_EQ(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR, | 456 EXPECT_EQ(SyncSetupWizard::SETUP_ABORTED_BY_PENDING_CLEAR, |
454 test_window_->flow()->current_state_); | 457 test_window_->flow()->current_state_); |
455 | 458 |
456 test_window_->CloseDialog(); | 459 test_window_->CloseDialog(); |
457 EXPECT_FALSE(wizard_->IsVisible()); | 460 EXPECT_FALSE(wizard_->IsVisible()); |
458 } | 461 } |
459 | 462 |
460 TEST_F(SyncSetupWizardTest, DiscreteRunGaiaLogin) { | 463 TEST_F(SyncSetupWizardTest, DiscreteRunGaiaLogin) { |
461 SKIP_TEST_ON_MACOSX(); | 464 SKIP_TEST_ON_MACOSX(); |
462 DictionaryValue dialog_args; | 465 DictionaryValue dialog_args; |
463 // For a discrete run, we need to have ran through setup once. | 466 // For a discrete run, we need to have ran through setup once. |
464 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 467 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
465 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 468 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
| 469 wizard_->Step(SyncSetupWizard::SETTING_UP); |
466 wizard_->Step(SyncSetupWizard::DONE); | 470 wizard_->Step(SyncSetupWizard::DONE); |
467 test_window_->CloseDialog(); | 471 test_window_->CloseDialog(); |
468 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 472 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
469 | 473 |
470 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 474 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
471 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_); | 475 EXPECT_EQ(SyncSetupWizard::GAIA_SUCCESS, test_window_->flow()->end_state_); |
472 | 476 |
473 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS); | 477 AuthError invalid_gaia(AuthError::INVALID_GAIA_CREDENTIALS); |
474 service_->set_auth_state(kTestUser, invalid_gaia); | 478 service_->set_auth_state(kTestUser, invalid_gaia); |
475 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); | 479 wizard_->Step(SyncSetupWizard::GAIA_LOGIN); |
476 EXPECT_TRUE(wizard_->IsVisible()); | 480 EXPECT_TRUE(wizard_->IsVisible()); |
477 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); | 481 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); |
478 EXPECT_EQ(5U, dialog_args.size()); | 482 EXPECT_EQ(5U, dialog_args.size()); |
479 std::string iframe_to_show; | 483 std::string iframe_to_show; |
480 dialog_args.GetString("iframeToShow", &iframe_to_show); | 484 dialog_args.GetString("iframeToShow", &iframe_to_show); |
481 EXPECT_EQ("login", iframe_to_show); | 485 EXPECT_EQ("login", iframe_to_show); |
482 std::string actual_user; | 486 std::string actual_user; |
483 dialog_args.GetString("user", &actual_user); | 487 dialog_args.GetString("user", &actual_user); |
484 EXPECT_EQ(kTestUser, actual_user); | 488 EXPECT_EQ(kTestUser, actual_user); |
485 int error = -1; | 489 int error = -1; |
486 dialog_args.GetInteger("error", &error); | 490 dialog_args.GetInteger("error", &error); |
487 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); | 491 EXPECT_EQ(static_cast<int>(AuthError::INVALID_GAIA_CREDENTIALS), error); |
488 service_->set_auth_state(kTestUser, AuthError::None()); | 492 service_->set_auth_state(kTestUser, AuthError::None()); |
489 | 493 |
490 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 494 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
491 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 495 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
492 } | 496 } |
493 | 497 |
494 #undef SKIP_TEST_ON_MACOSX | 498 #undef SKIP_TEST_ON_MACOSX |
OLD | NEW |