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

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler_unittest.cc

Issue 162443004: sync: final pieces to sync deferred initialization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 6 years, 10 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/sync_setup_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // The boolean parameter indicates whether the test is run with ClientOAuth 273 // The boolean parameter indicates whether the test is run with ClientOAuth
274 // or not. The test parameter is a bool: whether or not to test with/ 274 // or not. The test parameter is a bool: whether or not to test with/
275 // /ClientLogin enabled or not. 275 // /ClientLogin enabled or not.
276 class SyncSetupHandlerTest : public testing::Test { 276 class SyncSetupHandlerTest : public testing::Test {
277 public: 277 public:
278 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {} 278 SyncSetupHandlerTest() : error_(GoogleServiceAuthError::NONE) {}
279 virtual void SetUp() OVERRIDE { 279 virtual void SetUp() OVERRIDE {
280 error_ = GoogleServiceAuthError::AuthErrorNone(); 280 error_ = GoogleServiceAuthError::AuthErrorNone();
281 profile_.reset(ProfileSyncServiceMock::MakeSignedInTestingProfile()); 281 profile_.reset(ProfileSyncServiceMock::MakeSignedInTestingProfile());
282 282
283 profile_->GetPrefs()->SetString(
284 prefs::kGoogleServicesUsername, GetTestUser());
283 mock_signin_ = static_cast<SigninManagerBase*>( 285 mock_signin_ = static_cast<SigninManagerBase*>(
284 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 286 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
285 profile_.get(), FakeSigninManagerBase::Build)); 287 profile_.get(), FakeSigninManagerBase::Build));
286
287 mock_pss_ = static_cast<ProfileSyncServiceMock*>( 288 mock_pss_ = static_cast<ProfileSyncServiceMock*>(
288 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 289 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
289 profile_.get(), 290 profile_.get(),
290 ProfileSyncServiceMock::BuildMockProfileSyncService)); 291 ProfileSyncServiceMock::BuildMockProfileSyncService));
291 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 292 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
292 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( 293 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault(
293 Return(syncer::IMPLICIT_PASSPHRASE)); 294 Return(syncer::IMPLICIT_PASSPHRASE));
294 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault( 295 ON_CALL(*mock_pss_, GetPassphraseTime()).WillByDefault(
295 Return(base::Time())); 296 Return(base::Time()));
296 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( 297 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault(
(...skipping 15 matching lines...) Expand all
312 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()). 313 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()).
313 WillRepeatedly(Return(GetAllTypes())); 314 WillRepeatedly(Return(GetAllTypes()));
314 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()). 315 EXPECT_CALL(*mock_pss_, EncryptEverythingEnabled()).
315 WillRepeatedly(Return(false)); 316 WillRepeatedly(Return(false));
316 } 317 }
317 318
318 void SetupInitializedProfileSyncService() { 319 void SetupInitializedProfileSyncService() {
319 // An initialized ProfileSyncService will have already completed sync setup 320 // An initialized ProfileSyncService will have already completed sync setup
320 // and will have an initialized sync backend. 321 // and will have an initialized sync backend.
321 ASSERT_TRUE(mock_signin_->IsInitialized()); 322 ASSERT_TRUE(mock_signin_->IsInitialized());
322 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
323 .WillRepeatedly(Return(true));
324 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
325 .WillRepeatedly(Return(true));
326 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
327 .WillRepeatedly(Return(true));
328 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true)); 323 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(true));
329 } 324 }
330 325
331 void ExpectConfig() { 326 void ExpectConfig() {
332 ASSERT_EQ(1U, web_ui_.call_data().size()); 327 ASSERT_EQ(1U, web_ui_.call_data().size());
333 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 328 const TestWebUI::CallData& data = web_ui_.call_data()[0];
334 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); 329 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
335 std::string page; 330 std::string page;
336 ASSERT_TRUE(data.arg1->GetAsString(&page)); 331 ASSERT_TRUE(data.arg1->GetAsString(&page));
337 EXPECT_EQ(page, "configure"); 332 EXPECT_EQ(page, "configure");
(...skipping 25 matching lines...) Expand all
363 } 358 }
364 359
365 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock 360 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock
366 // so this helper routine dispatches an OnStateChanged() notification to the 361 // so this helper routine dispatches an OnStateChanged() notification to the
367 // SyncStartupTracker. 362 // SyncStartupTracker.
368 void NotifySyncListeners() { 363 void NotifySyncListeners() {
369 if (handler_->sync_startup_tracker_) 364 if (handler_->sync_startup_tracker_)
370 handler_->sync_startup_tracker_->OnStateChanged(); 365 handler_->sync_startup_tracker_->OnStateChanged();
371 } 366 }
372 367
368 virtual std::string GetTestUser() {
369 return std::string(kTestUser);
370 }
371
373 content::TestBrowserThreadBundle thread_bundle_; 372 content::TestBrowserThreadBundle thread_bundle_;
374 scoped_ptr<Profile> profile_; 373 scoped_ptr<Profile> profile_;
375 ProfileSyncServiceMock* mock_pss_; 374 ProfileSyncServiceMock* mock_pss_;
376 GoogleServiceAuthError error_; 375 GoogleServiceAuthError error_;
377 SigninManagerBase* mock_signin_; 376 SigninManagerBase* mock_signin_;
378 TestWebUI web_ui_; 377 TestWebUI web_ui_;
379 scoped_ptr<TestingSyncSetupHandler> handler_; 378 scoped_ptr<TestingSyncSetupHandler> handler_;
380 }; 379 };
381 380
381 class SyncSetupHandlerFirstSigninTest : public SyncSetupHandlerTest {
382 virtual std::string GetTestUser() OVERRIDE { return std::string(); }
383 };
384
382 TEST_F(SyncSetupHandlerTest, Basic) { 385 TEST_F(SyncSetupHandlerTest, Basic) {
383 } 386 }
384 387
385 #if !defined(OS_CHROMEOS) 388 #if !defined(OS_CHROMEOS)
386 TEST_F(SyncSetupHandlerTest, DisplayBasicLogin) { 389 TEST_F(SyncSetupHandlerFirstSigninTest, DisplayBasicLogin) {
387 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 390 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
388 .WillRepeatedly(Return(false)); 391 .WillRepeatedly(Return(false));
389 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 392 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
390 .WillRepeatedly(Return(false)); 393 .WillRepeatedly(Return(false));
391 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 394 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
392 .WillRepeatedly(Return(false)); 395 .WillRepeatedly(Return(false));
393 // Ensure that the user is not signed in before calling |HandleStartSignin()|. 396 // Ensure that the user is not signed in before calling |HandleStartSignin()|.
394 SigninManager* manager = static_cast<SigninManager*>(mock_signin_); 397 SigninManager* manager = static_cast<SigninManager*>(mock_signin_);
395 manager->SignOut(); 398 manager->SignOut();
396 handler_->HandleStartSignin(NULL); 399 handler_->HandleStartSignin(NULL);
(...skipping 23 matching lines...) Expand all
420 // We expect a call to SyncSetupOverlay.showSyncSetupPage. 423 // We expect a call to SyncSetupOverlay.showSyncSetupPage.
421 ASSERT_EQ(1U, web_ui_.call_data().size()); 424 ASSERT_EQ(1U, web_ui_.call_data().size());
422 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 425 const TestWebUI::CallData& data = web_ui_.call_data()[0];
423 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); 426 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
424 427
425 ASSERT_FALSE(handler_->is_configuring_sync()); 428 ASSERT_FALSE(handler_->is_configuring_sync());
426 EXPECT_EQ(NULL, 429 EXPECT_EQ(NULL,
427 LoginUIServiceFactory::GetForProfile( 430 LoginUIServiceFactory::GetForProfile(
428 profile_.get())->current_login_ui()); 431 profile_.get())->current_login_ui());
429 } 432 }
430 #endif 433 #endif // !defined(OS_CHROMEOS)
431 434
432 // Verifies that the handler correctly handles a cancellation when 435 // Verifies that the handler correctly handles a cancellation when
433 // it is displaying the spinner to the user. 436 // it is displaying the spinner to the user.
434 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { 437 TEST_F(SyncSetupHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) {
435 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 438 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
436 .WillRepeatedly(Return(true)); 439 .WillRepeatedly(Return(true));
437 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser);
438 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 440 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
439 .WillRepeatedly(Return(true)); 441 .WillRepeatedly(Return(true));
440 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 442 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
441 .WillRepeatedly(Return(false)); 443 .WillRepeatedly(Return(false));
442 error_ = GoogleServiceAuthError::AuthErrorNone(); 444 error_ = GoogleServiceAuthError::AuthErrorNone();
443 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); 445 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false));
444 446
445 // We're simulating a user setting up sync, which would cause the backend to 447 // We're simulating a user setting up sync, which would cause the backend to
446 // kick off initialization, but not download user data types. The sync 448 // kick off initialization, but not download user data types. The sync
447 // backend will try to download control data types (e.g encryption info), but 449 // backend will try to download control data types (e.g encryption info), but
448 // that won't finish for this test as we're simulating cancelling while the 450 // that won't finish for this test as we're simulating cancelling while the
449 // spinner is showing. 451 // spinner is showing.
450 handler_->HandleShowSetupUI(NULL); 452 handler_->HandleShowSetupUI(NULL);
451 453
452 EXPECT_EQ(handler_.get(), 454 EXPECT_EQ(handler_.get(),
453 LoginUIServiceFactory::GetForProfile( 455 LoginUIServiceFactory::GetForProfile(
454 profile_.get())->current_login_ui()); 456 profile_.get())->current_login_ui());
455 457
456 ExpectSpinnerAndClose(); 458 ExpectSpinnerAndClose();
457 } 459 }
458 460
459 // Verifies that the handler correctly transitions from showing the spinner 461 // Verifies that the handler correctly transitions from showing the spinner
460 // to showing a configuration page when sync setup completes successfully. 462 // to showing a configuration page when sync setup completes successfully.
461 TEST_F(SyncSetupHandlerTest, 463 TEST_F(SyncSetupHandlerTest,
462 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { 464 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) {
463 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 465 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
464 .WillRepeatedly(Return(true)); 466 .WillRepeatedly(Return(true));
465 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser);
466 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 467 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
467 .WillRepeatedly(Return(true)); 468 .WillRepeatedly(Return(true));
468 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 469 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
469 .WillRepeatedly(Return(false)); 470 .WillRepeatedly(Return(false));
470 error_ = GoogleServiceAuthError::AuthErrorNone(); 471 error_ = GoogleServiceAuthError::AuthErrorNone();
471 // Sync backend is stopped initially, and will start up. 472 // Sync backend is stopped initially, and will start up.
472 EXPECT_CALL(*mock_pss_, sync_initialized()) 473 EXPECT_CALL(*mock_pss_, sync_initialized())
473 .WillRepeatedly(Return(false)); 474 .WillRepeatedly(Return(false));
474 SetDefaultExpectationsForConfigPage(); 475 SetDefaultExpectationsForConfigPage();
475 476
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 511
511 // Verifies the case where the user cancels after the sync backend has 512 // Verifies the case where the user cancels after the sync backend has
512 // initialized (meaning it already transitioned from the spinner to a proper 513 // initialized (meaning it already transitioned from the spinner to a proper
513 // configuration page, tested by 514 // configuration page, tested by
514 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user 515 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user
515 // before the user has continued on. 516 // before the user has continued on.
516 TEST_F(SyncSetupHandlerTest, 517 TEST_F(SyncSetupHandlerTest,
517 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { 518 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) {
518 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 519 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
519 .WillRepeatedly(Return(true)); 520 .WillRepeatedly(Return(true));
520 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser);
521 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 521 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
522 .WillRepeatedly(Return(true)); 522 .WillRepeatedly(Return(true));
523 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 523 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
524 .WillRepeatedly(Return(false)); 524 .WillRepeatedly(Return(false));
525 error_ = GoogleServiceAuthError::AuthErrorNone(); 525 error_ = GoogleServiceAuthError::AuthErrorNone();
526 EXPECT_CALL(*mock_pss_, sync_initialized()) 526 EXPECT_CALL(*mock_pss_, sync_initialized())
527 .WillOnce(Return(false)) 527 .WillOnce(Return(false))
528 .WillRepeatedly(Return(true)); 528 .WillRepeatedly(Return(true));
529 SetDefaultExpectationsForConfigPage(); 529 SetDefaultExpectationsForConfigPage();
530 handler_->OpenSyncSetup(); 530 handler_->OpenSyncSetup();
531 531
532 // It's important to tell sync the user cancelled the setup flow before we 532 // It's important to tell sync the user cancelled the setup flow before we
533 // tell it we're through with the setup progress. 533 // tell it we're through with the setup progress.
534 testing::InSequence seq; 534 testing::InSequence seq;
535 EXPECT_CALL(*mock_pss_, DisableForUser()); 535 EXPECT_CALL(*mock_pss_, DisableForUser());
536 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); 536 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false));
537 537
538 handler_->CloseSyncSetup(); 538 handler_->CloseSyncSetup();
539 EXPECT_EQ(NULL, 539 EXPECT_EQ(NULL,
540 LoginUIServiceFactory::GetForProfile( 540 LoginUIServiceFactory::GetForProfile(
541 profile_.get())->current_login_ui()); 541 profile_.get())->current_login_ui());
542 } 542 }
543 543
544 TEST_F(SyncSetupHandlerTest, 544 TEST_F(SyncSetupHandlerTest,
545 DisplayConfigureWithBackendDisabledAndSigninFailed) { 545 DisplayConfigureWithBackendDisabledAndSigninFailed) {
546 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 546 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
547 .WillRepeatedly(Return(true)); 547 .WillRepeatedly(Return(true));
548 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, kTestUser);
549 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 548 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
550 .WillRepeatedly(Return(true)); 549 .WillRepeatedly(Return(true));
551 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 550 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
552 .WillRepeatedly(Return(false)); 551 .WillRepeatedly(Return(false));
553 error_ = GoogleServiceAuthError::AuthErrorNone(); 552 error_ = GoogleServiceAuthError::AuthErrorNone();
554 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false)); 553 EXPECT_CALL(*mock_pss_, sync_initialized()).WillRepeatedly(Return(false));
555 554
556 handler_->OpenSyncSetup(); 555 handler_->OpenSyncSetup();
557 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 556 const TestWebUI::CallData& data = web_ui_.call_data()[0];
558 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); 557 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 1029
1031 // This should display the sync setup dialog (not login). 1030 // This should display the sync setup dialog (not login).
1032 handler_->OpenSyncSetup(); 1031 handler_->OpenSyncSetup();
1033 1032
1034 ExpectConfig(); 1033 ExpectConfig();
1035 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 1034 const TestWebUI::CallData& data = web_ui_.call_data()[0];
1036 base::DictionaryValue* dictionary; 1035 base::DictionaryValue* dictionary;
1037 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); 1036 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
1038 CheckBool(dictionary, "encryptAllData", true); 1037 CheckBool(dictionary, "encryptAllData", true);
1039 } 1038 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698