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

Side by Side Diff: chrome/browser/ui/webui/settings/people_handler_unittest.cc

Issue 2711993002: Ensure PeopleHandler only calls PSS::RequestStart in response to intention to configure sync (Closed)
Patch Set: Address comment Created 3 years, 9 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
« no previous file with comments | « chrome/browser/ui/webui/settings/people_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/settings/people_handler.h" 5 #include "chrome/browser/ui/webui/settings/people_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 } 284 }
285 285
286 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock 286 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock
287 // so this helper routine dispatches an OnStateChanged() notification to the 287 // so this helper routine dispatches an OnStateChanged() notification to the
288 // SyncStartupTracker. 288 // SyncStartupTracker.
289 void NotifySyncListeners() { 289 void NotifySyncListeners() {
290 if (handler_->sync_startup_tracker_) 290 if (handler_->sync_startup_tracker_)
291 handler_->sync_startup_tracker_->OnStateChanged(mock_pss_); 291 handler_->sync_startup_tracker_->OnStateChanged(mock_pss_);
292 } 292 }
293 293
294 void NotifySyncStateChanged() { handler_->OnStateChanged(mock_pss_); }
295
294 virtual std::string GetTestUser() { 296 virtual std::string GetTestUser() {
295 return std::string(kTestUser); 297 return std::string(kTestUser);
296 } 298 }
297 299
298 content::TestBrowserThreadBundle thread_bundle_; 300 content::TestBrowserThreadBundle thread_bundle_;
299 std::unique_ptr<TestingProfileManager> profile_manager_; 301 std::unique_ptr<TestingProfileManager> profile_manager_;
300 Profile* profile_; 302 Profile* profile_;
301 ProfileSyncServiceMock* mock_pss_; 303 ProfileSyncServiceMock* mock_pss_;
302 GoogleServiceAuthError error_; 304 GoogleServiceAuthError error_;
303 SigninManagerBase* mock_signin_; 305 SigninManagerBase* mock_signin_;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 ASSERT_FALSE(handler_->is_configuring_sync()); 365 ASSERT_FALSE(handler_->is_configuring_sync());
364 } 366 }
365 367
366 // Verifies that the handler correctly handles a cancellation when 368 // Verifies that the handler correctly handles a cancellation when
367 // it is displaying the spinner to the user. 369 // it is displaying the spinner to the user.
368 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndCancel) { 370 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndCancel) {
369 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 371 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
370 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 372 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
371 error_ = GoogleServiceAuthError::AuthErrorNone(); 373 error_ = GoogleServiceAuthError::AuthErrorNone();
372 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); 374 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
375 EXPECT_CALL(*mock_pss_, RequestStart());
373 376
374 // We're simulating a user setting up sync, which would cause the engine to 377 // We're simulating a user setting up sync, which would cause the engine to
375 // kick off initialization, but not download user data types. The sync 378 // kick off initialization, but not download user data types. The sync
376 // engine will try to download control data types (e.g encryption info), but 379 // engine will try to download control data types (e.g encryption info), but
377 // that won't finish for this test as we're simulating cancelling while the 380 // that won't finish for this test as we're simulating cancelling while the
378 // spinner is showing. 381 // spinner is showing.
379 handler_->HandleShowSetupUI(NULL); 382 handler_->HandleShowSetupUI(NULL);
380 383
381 EXPECT_EQ(handler_.get(), 384 EXPECT_EQ(handler_.get(),
382 LoginUIServiceFactory::GetForProfile( 385 LoginUIServiceFactory::GetForProfile(
383 profile_)->current_login_ui()); 386 profile_)->current_login_ui());
384 387
385 ExpectSpinnerAndClose(); 388 ExpectSpinnerAndClose();
386 } 389 }
387 390
388 // Verifies that the handler correctly transitions from showing the spinner 391 // Verifies that the handler correctly transitions from showing the spinner
389 // to showing a configuration page when sync setup completes successfully. 392 // to showing a configuration page when sync setup completes successfully.
390 TEST_F(PeopleHandlerTest, 393 TEST_F(PeopleHandlerTest,
391 DisplayConfigureWithEngineDisabledAndSyncStartupCompleted) { 394 DisplayConfigureWithEngineDisabledAndSyncStartupCompleted) {
392 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 395 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
393 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 396 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
394 error_ = GoogleServiceAuthError::AuthErrorNone(); 397 error_ = GoogleServiceAuthError::AuthErrorNone();
395 // Sync engine is stopped initially, and will start up. 398 // Sync engine is stopped initially, and will start up.
396 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); 399 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
400 EXPECT_CALL(*mock_pss_, RequestStart());
397 SetDefaultExpectationsForConfigPage(); 401 SetDefaultExpectationsForConfigPage();
398 402
399 handler_->OpenSyncSetup(); 403 handler_->OpenSyncSetup();
400 404
401 EXPECT_EQ(1U, web_ui_.call_data().size()); 405 EXPECT_EQ(1U, web_ui_.call_data().size());
402 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus); 406 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus);
403 407
404 Mock::VerifyAndClearExpectations(mock_pss_); 408 Mock::VerifyAndClearExpectations(mock_pss_);
405 // Now, act as if the ProfileSyncService has started up. 409 // Now, act as if the ProfileSyncService has started up.
406 SetDefaultExpectationsForConfigPage(); 410 SetDefaultExpectationsForConfigPage();
(...skipping 17 matching lines...) Expand all
424 // DisplayConfigureWithEngineDisabledAndSyncStartupCompleted), but before the 428 // DisplayConfigureWithEngineDisabledAndSyncStartupCompleted), but before the
425 // user has continued on. 429 // user has continued on.
426 TEST_F(PeopleHandlerTest, 430 TEST_F(PeopleHandlerTest,
427 DisplayConfigureWithEngineDisabledAndCancelAfterSigninSuccess) { 431 DisplayConfigureWithEngineDisabledAndCancelAfterSigninSuccess) {
428 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 432 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
429 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 433 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
430 error_ = GoogleServiceAuthError::AuthErrorNone(); 434 error_ = GoogleServiceAuthError::AuthErrorNone();
431 EXPECT_CALL(*mock_pss_, IsEngineInitialized()) 435 EXPECT_CALL(*mock_pss_, IsEngineInitialized())
432 .WillOnce(Return(false)) 436 .WillOnce(Return(false))
433 .WillRepeatedly(Return(true)); 437 .WillRepeatedly(Return(true));
438 EXPECT_CALL(*mock_pss_, RequestStart());
434 SetDefaultExpectationsForConfigPage(); 439 SetDefaultExpectationsForConfigPage();
435 handler_->OpenSyncSetup(); 440 handler_->OpenSyncSetup();
436 441
437 // It's important to tell sync the user cancelled the setup flow before we 442 // It's important to tell sync the user cancelled the setup flow before we
438 // tell it we're through with the setup progress. 443 // tell it we're through with the setup progress.
439 testing::InSequence seq; 444 testing::InSequence seq;
440 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 445 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
441 EXPECT_CALL(*mock_pss_, OnSetupInProgressHandleDestroyed()); 446 EXPECT_CALL(*mock_pss_, OnSetupInProgressHandleDestroyed());
442 447
443 handler_->CloseSyncSetup(); 448 handler_->CloseSyncSetup();
444 EXPECT_EQ(NULL, 449 EXPECT_EQ(NULL,
445 LoginUIServiceFactory::GetForProfile( 450 LoginUIServiceFactory::GetForProfile(
446 profile_)->current_login_ui()); 451 profile_)->current_login_ui());
447 } 452 }
448 453
449 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndSigninFailed) { 454 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndSigninFailed) {
450 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 455 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
451 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 456 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
452 error_ = GoogleServiceAuthError::AuthErrorNone(); 457 error_ = GoogleServiceAuthError::AuthErrorNone();
453 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); 458 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
459 EXPECT_CALL(*mock_pss_, RequestStart());
454 460
455 handler_->OpenSyncSetup(); 461 handler_->OpenSyncSetup();
456 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus); 462 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus);
457 Mock::VerifyAndClearExpectations(mock_pss_); 463 Mock::VerifyAndClearExpectations(mock_pss_);
458 error_ = GoogleServiceAuthError( 464 error_ = GoogleServiceAuthError(
459 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 465 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
460 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 466 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
461 NotifySyncListeners(); 467 NotifySyncListeners();
462 468
463 // On failure, the dialog will be closed. 469 // On failure, the dialog will be closed.
464 EXPECT_EQ(NULL, 470 EXPECT_EQ(NULL,
465 LoginUIServiceFactory::GetForProfile( 471 LoginUIServiceFactory::GetForProfile(
466 profile_)->current_login_ui()); 472 profile_)->current_login_ui());
467 } 473 }
468 474
475 // Tests that signals not related to user intention to configure sync don't
476 // trigger sync engine start.
477 TEST_F(PeopleHandlerTest, OnlyStartEngineWhenConfiguringSync) {
478 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
479 EXPECT_CALL(*mock_pss_, RequestStart()).Times(0);
480 NotifySyncStateChanged();
481 }
482
469 #if !defined(OS_CHROMEOS) 483 #if !defined(OS_CHROMEOS)
470 484
471 class PeopleHandlerNonCrosTest : public PeopleHandlerTest { 485 class PeopleHandlerNonCrosTest : public PeopleHandlerTest {
472 public: 486 public:
473 PeopleHandlerNonCrosTest() {} 487 PeopleHandlerNonCrosTest() {}
474 }; 488 };
475 489
476 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) { 490 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) {
477 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 491 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
478 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) 492 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 SetupInitializedProfileSyncService(); 915 SetupInitializedProfileSyncService();
902 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 916 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
903 .WillRepeatedly(Return(false)); 917 .WillRepeatedly(Return(false));
904 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 918 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
905 handler_->HandleSetEncryption(&list_args); 919 handler_->HandleSetEncryption(&list_args);
906 920
907 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 921 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
908 } 922 }
909 923
910 } // namespace settings 924 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/people_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698