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

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

Issue 1503333003: Settings People Rewrite: Make Sync/Sign-in naming consistent to People. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge upstream changes Created 5 years 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
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/sync_handler.h" 5 #include "chrome/browser/ui/webui/settings/people_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/values.h" 15 #include "base/values.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); 142 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES));
143 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); 143 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS));
144 CheckBool(dictionary, "wifiCredentialsSynced", 144 CheckBool(dictionary, "wifiCredentialsSynced",
145 types.Has(syncer::WIFI_CREDENTIALS)); 145 types.Has(syncer::WIFI_CREDENTIALS));
146 } 146 }
147 147
148 } // namespace 148 } // namespace
149 149
150 namespace settings { 150 namespace settings {
151 151
152 class TestingSyncHandler : public SyncHandler { 152 class TestingPeopleHandler : public PeopleHandler {
153 public: 153 public:
154 TestingSyncHandler(content::WebUI* web_ui, Profile* profile) 154 TestingPeopleHandler(content::WebUI* web_ui, Profile* profile)
155 : SyncHandler(profile) { 155 : PeopleHandler(profile) {
156 set_web_ui(web_ui); 156 set_web_ui(web_ui);
157 } 157 }
158 ~TestingSyncHandler() override { 158 ~TestingPeopleHandler() override {
159 // TODO(tommycli): SyncHandler needs this call to destruct properly in the 159 // TODO(tommycli): PeopleHandler needs this call to destruct properly in the
160 // unit testing context. See the destructor to SyncHandler. This is hacky. 160 // unit testing context. See the destructor to PeopleHandler. This is hacky.
161 set_web_ui(nullptr); 161 set_web_ui(nullptr);
162 } 162 }
163 163
164 void FocusUI() override {} 164 void FocusUI() override {}
165 165
166 using SyncHandler::is_configuring_sync; 166 using PeopleHandler::is_configuring_sync;
167 167
168 private: 168 private:
169 #if !defined(OS_CHROMEOS) 169 #if !defined(OS_CHROMEOS)
170 void DisplayGaiaLoginInNewTabOrWindow( 170 void DisplayGaiaLoginInNewTabOrWindow(
171 signin_metrics::AccessPoint access_point) override {} 171 signin_metrics::AccessPoint access_point) override {}
172 #endif 172 #endif
173 173
174 DISALLOW_COPY_AND_ASSIGN(TestingSyncHandler); 174 DISALLOW_COPY_AND_ASSIGN(TestingPeopleHandler);
175 }; 175 };
176 176
177 // The boolean parameter indicates whether the test is run with ClientOAuth 177 // The boolean parameter indicates whether the test is run with ClientOAuth
178 // or not. The test parameter is a bool: whether or not to test with/ 178 // or not. The test parameter is a bool: whether or not to test with/
179 // /ClientLogin enabled or not. 179 // /ClientLogin enabled or not.
180 class SyncHandlerTest : public testing::Test { 180 class PeopleHandlerTest : public testing::Test {
181 public: 181 public:
182 SyncHandlerTest() : error_(GoogleServiceAuthError::NONE) {} 182 PeopleHandlerTest() : error_(GoogleServiceAuthError::NONE) {}
183 void SetUp() override { 183 void SetUp() override {
184 error_ = GoogleServiceAuthError::AuthErrorNone(); 184 error_ = GoogleServiceAuthError::AuthErrorNone();
185 185
186 TestingProfile::Builder builder; 186 TestingProfile::Builder builder;
187 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), 187 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
188 BuildFakeSigninManagerBase); 188 BuildFakeSigninManagerBase);
189 profile_ = builder.Build(); 189 profile_ = builder.Build();
190 190
191 // Sign in the user. 191 // Sign in the user.
192 mock_signin_ = static_cast<SigninManagerBase*>( 192 mock_signin_ = static_cast<SigninManagerBase*>(
193 SigninManagerFactory::GetForProfile(profile_.get())); 193 SigninManagerFactory::GetForProfile(profile_.get()));
194 std::string username = GetTestUser(); 194 std::string username = GetTestUser();
195 if (!username.empty()) 195 if (!username.empty())
196 mock_signin_->SetAuthenticatedAccountInfo(username, username); 196 mock_signin_->SetAuthenticatedAccountInfo(username, username);
197 197
198 mock_pss_ = static_cast<ProfileSyncServiceMock*>( 198 mock_pss_ = static_cast<ProfileSyncServiceMock*>(
199 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 199 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
200 profile_.get(), BuildMockProfileSyncService)); 200 profile_.get(), BuildMockProfileSyncService));
201 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 201 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
202 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( 202 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault(
203 Return(syncer::IMPLICIT_PASSPHRASE)); 203 Return(syncer::IMPLICIT_PASSPHRASE));
204 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( 204 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault(
205 Return(base::Time())); 205 Return(base::Time()));
206 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) 206 ON_CALL(*mock_pss_, GetRegisteredDataTypes())
207 .WillByDefault(Return(syncer::ModelTypeSet())); 207 .WillByDefault(Return(syncer::ModelTypeSet()));
208 208
209 mock_pss_->Initialize(); 209 mock_pss_->Initialize();
210 210
211 handler_.reset(new TestingSyncHandler(&web_ui_, profile_.get())); 211 handler_.reset(new TestingPeopleHandler(&web_ui_, profile_.get()));
212 } 212 }
213 213
214 // Setup the expectations for calls made when displaying the config page. 214 // Setup the expectations for calls made when displaying the config page.
215 void SetDefaultExpectationsForConfigPage() { 215 void SetDefaultExpectationsForConfigPage() {
216 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 216 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
217 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()) 217 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes())
218 .WillRepeatedly(Return(GetAllTypes())); 218 .WillRepeatedly(Return(GetAllTypes()));
219 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()) 219 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes())
220 .WillRepeatedly(Return(GetAllTypes())); 220 .WillRepeatedly(Return(GetAllTypes()));
221 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()) 221 EXPECT_CALL(*mock_pss_, GetActiveDataTypes())
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 virtual std::string GetTestUser() { 282 virtual std::string GetTestUser() {
283 return std::string(kTestUser); 283 return std::string(kTestUser);
284 } 284 }
285 285
286 content::TestBrowserThreadBundle thread_bundle_; 286 content::TestBrowserThreadBundle thread_bundle_;
287 scoped_ptr<Profile> profile_; 287 scoped_ptr<Profile> profile_;
288 ProfileSyncServiceMock* mock_pss_; 288 ProfileSyncServiceMock* mock_pss_;
289 GoogleServiceAuthError error_; 289 GoogleServiceAuthError error_;
290 SigninManagerBase* mock_signin_; 290 SigninManagerBase* mock_signin_;
291 content::TestWebUI web_ui_; 291 content::TestWebUI web_ui_;
292 scoped_ptr<TestingSyncHandler> handler_; 292 scoped_ptr<TestingPeopleHandler> handler_;
293 }; 293 };
294 294
295 class SyncHandlerFirstSigninTest : public SyncHandlerTest { 295 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest {
296 std::string GetTestUser() override { return std::string(); } 296 std::string GetTestUser() override { return std::string(); }
297 }; 297 };
298 298
299 TEST_F(SyncHandlerTest, Basic) { 299 TEST_F(PeopleHandlerTest, Basic) {
300 } 300 }
301 301
302 #if !defined(OS_CHROMEOS) 302 #if !defined(OS_CHROMEOS)
303 TEST_F(SyncHandlerFirstSigninTest, DisplayBasicLogin) { 303 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) {
304 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 304 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
305 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 305 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
306 .WillRepeatedly(Return(false)); 306 .WillRepeatedly(Return(false));
307 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 307 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
308 .WillRepeatedly(Return(false)); 308 .WillRepeatedly(Return(false));
309 // Ensure that the user is not signed in before calling |HandleStartSignin()|. 309 // Ensure that the user is not signed in before calling |HandleStartSignin()|.
310 SigninManager* manager = static_cast<SigninManager*>(mock_signin_); 310 SigninManager* manager = static_cast<SigninManager*>(mock_signin_);
311 manager->SignOut(signin_metrics::SIGNOUT_TEST); 311 manager->SignOut(signin_metrics::SIGNOUT_TEST);
312 handler_->HandleStartSignin(NULL); 312 handler_->HandleStartSignin(NULL);
313 313
314 // Sync setup hands off control to the gaia login tab. 314 // Sync setup hands off control to the gaia login tab.
315 EXPECT_EQ(NULL, 315 EXPECT_EQ(NULL,
316 LoginUIServiceFactory::GetForProfile( 316 LoginUIServiceFactory::GetForProfile(
317 profile_.get())->current_login_ui()); 317 profile_.get())->current_login_ui());
318 318
319 ASSERT_FALSE(handler_->is_configuring_sync()); 319 ASSERT_FALSE(handler_->is_configuring_sync());
320 320
321 handler_->CloseSyncSetup(); 321 handler_->CloseSyncSetup();
322 EXPECT_EQ(NULL, 322 EXPECT_EQ(NULL,
323 LoginUIServiceFactory::GetForProfile( 323 LoginUIServiceFactory::GetForProfile(
324 profile_.get())->current_login_ui()); 324 profile_.get())->current_login_ui());
325 } 325 }
326 326
327 TEST_F(SyncHandlerTest, ShowSyncSetupWhenNotSignedIn) { 327 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) {
328 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 328 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
329 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 329 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
330 .WillRepeatedly(Return(false)); 330 .WillRepeatedly(Return(false));
331 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 331 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
332 .WillRepeatedly(Return(false)); 332 .WillRepeatedly(Return(false));
333 handler_->HandleShowSetupUI(NULL); 333 handler_->HandleShowSetupUI(NULL);
334 334
335 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. 335 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage.
336 ASSERT_EQ(1U, web_ui_.call_data().size()); 336 ASSERT_EQ(1U, web_ui_.call_data().size());
337 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 337 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
338 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 338 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
339 339
340 ASSERT_FALSE(handler_->is_configuring_sync()); 340 ASSERT_FALSE(handler_->is_configuring_sync());
341 EXPECT_EQ(NULL, 341 EXPECT_EQ(NULL,
342 LoginUIServiceFactory::GetForProfile( 342 LoginUIServiceFactory::GetForProfile(
343 profile_.get())->current_login_ui()); 343 profile_.get())->current_login_ui());
344 } 344 }
345 #endif // !defined(OS_CHROMEOS) 345 #endif // !defined(OS_CHROMEOS)
346 346
347 // Verifies that the sync setup is terminated correctly when the 347 // Verifies that the sync setup is terminated correctly when the
348 // sync is disabled. 348 // sync is disabled.
349 TEST_F(SyncHandlerTest, HandleSetupUIWhenSyncDisabled) { 349 TEST_F(PeopleHandlerTest, HandleSetupUIWhenSyncDisabled) {
350 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true)); 350 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true));
351 handler_->HandleShowSetupUI(NULL); 351 handler_->HandleShowSetupUI(NULL);
352 352
353 // Sync setup is closed when sync is disabled. 353 // Sync setup is closed when sync is disabled.
354 EXPECT_EQ(NULL, 354 EXPECT_EQ(NULL,
355 LoginUIServiceFactory::GetForProfile( 355 LoginUIServiceFactory::GetForProfile(
356 profile_.get())->current_login_ui()); 356 profile_.get())->current_login_ui());
357 ASSERT_FALSE(handler_->is_configuring_sync()); 357 ASSERT_FALSE(handler_->is_configuring_sync());
358 } 358 }
359 359
360 // Verifies that the handler correctly handles a cancellation when 360 // Verifies that the handler correctly handles a cancellation when
361 // it is displaying the spinner to the user. 361 // it is displaying the spinner to the user.
362 TEST_F(SyncHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { 362 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) {
363 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 363 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
364 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 364 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
365 .WillRepeatedly(Return(true)); 365 .WillRepeatedly(Return(true));
366 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 366 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
367 .WillRepeatedly(Return(false)); 367 .WillRepeatedly(Return(false));
368 error_ = GoogleServiceAuthError::AuthErrorNone(); 368 error_ = GoogleServiceAuthError::AuthErrorNone();
369 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 369 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
370 370
371 // We're simulating a user setting up sync, which would cause the backend to 371 // We're simulating a user setting up sync, which would cause the backend to
372 // kick off initialization, but not download user data types. The sync 372 // kick off initialization, but not download user data types. The sync
373 // backend will try to download control data types (e.g encryption info), but 373 // backend will try to download control data types (e.g encryption info), but
374 // that won't finish for this test as we're simulating cancelling while the 374 // that won't finish for this test as we're simulating cancelling while the
375 // spinner is showing. 375 // spinner is showing.
376 handler_->HandleShowSetupUI(NULL); 376 handler_->HandleShowSetupUI(NULL);
377 377
378 EXPECT_EQ(handler_.get(), 378 EXPECT_EQ(handler_.get(),
379 LoginUIServiceFactory::GetForProfile( 379 LoginUIServiceFactory::GetForProfile(
380 profile_.get())->current_login_ui()); 380 profile_.get())->current_login_ui());
381 381
382 ExpectSpinnerAndClose(); 382 ExpectSpinnerAndClose();
383 } 383 }
384 384
385 // Verifies that the handler correctly transitions from showing the spinner 385 // Verifies that the handler correctly transitions from showing the spinner
386 // to showing a configuration page when sync setup completes successfully. 386 // to showing a configuration page when sync setup completes successfully.
387 TEST_F(SyncHandlerTest, 387 TEST_F(PeopleHandlerTest,
388 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { 388 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) {
389 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 389 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
390 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 390 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
391 .WillRepeatedly(Return(true)); 391 .WillRepeatedly(Return(true));
392 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 392 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
393 .WillRepeatedly(Return(false)); 393 .WillRepeatedly(Return(false));
394 error_ = GoogleServiceAuthError::AuthErrorNone(); 394 error_ = GoogleServiceAuthError::AuthErrorNone();
395 // Sync backend is stopped initially, and will start up. 395 // Sync backend is stopped initially, and will start up.
396 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 396 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
397 SetDefaultExpectationsForConfigPage(); 397 SetDefaultExpectationsForConfigPage();
(...skipping 30 matching lines...) Expand all
428 CheckBool(dictionary, "encryptAllDataAllowed", true); 428 CheckBool(dictionary, "encryptAllDataAllowed", true);
429 CheckBool(dictionary, "encryptAllData", false); 429 CheckBool(dictionary, "encryptAllData", false);
430 CheckBool(dictionary, "usePassphrase", false); 430 CheckBool(dictionary, "usePassphrase", false);
431 } 431 }
432 432
433 // Verifies the case where the user cancels after the sync backend has 433 // Verifies the case where the user cancels after the sync backend has
434 // initialized (meaning it already transitioned from the spinner to a proper 434 // initialized (meaning it already transitioned from the spinner to a proper
435 // configuration page, tested by 435 // configuration page, tested by
436 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user 436 // DisplayConfigureWithBackendDisabledAndSigninSuccess), but before the user
437 // before the user has continued on. 437 // before the user has continued on.
438 TEST_F(SyncHandlerTest, 438 TEST_F(PeopleHandlerTest,
439 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) { 439 DisplayConfigureWithBackendDisabledAndCancelAfterSigninSuccess) {
440 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 440 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
441 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 441 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
442 .WillRepeatedly(Return(true)); 442 .WillRepeatedly(Return(true));
443 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 443 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
444 .WillRepeatedly(Return(false)); 444 .WillRepeatedly(Return(false));
445 error_ = GoogleServiceAuthError::AuthErrorNone(); 445 error_ = GoogleServiceAuthError::AuthErrorNone();
446 EXPECT_CALL(*mock_pss_, IsBackendInitialized()) 446 EXPECT_CALL(*mock_pss_, IsBackendInitialized())
447 .WillOnce(Return(false)) 447 .WillOnce(Return(false))
448 .WillRepeatedly(Return(true)); 448 .WillRepeatedly(Return(true));
449 SetDefaultExpectationsForConfigPage(); 449 SetDefaultExpectationsForConfigPage();
450 handler_->OpenSyncSetup(nullptr); 450 handler_->OpenSyncSetup(nullptr);
451 451
452 // It's important to tell sync the user cancelled the setup flow before we 452 // It's important to tell sync the user cancelled the setup flow before we
453 // tell it we're through with the setup progress. 453 // tell it we're through with the setup progress.
454 testing::InSequence seq; 454 testing::InSequence seq;
455 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 455 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
456 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); 456 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false));
457 457
458 handler_->CloseSyncSetup(); 458 handler_->CloseSyncSetup();
459 EXPECT_EQ(NULL, 459 EXPECT_EQ(NULL,
460 LoginUIServiceFactory::GetForProfile( 460 LoginUIServiceFactory::GetForProfile(
461 profile_.get())->current_login_ui()); 461 profile_.get())->current_login_ui());
462 } 462 }
463 463
464 TEST_F(SyncHandlerTest, 464 TEST_F(PeopleHandlerTest,
465 DisplayConfigureWithBackendDisabledAndSigninFailed) { 465 DisplayConfigureWithBackendDisabledAndSigninFailed) {
466 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 466 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
467 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 467 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
468 .WillRepeatedly(Return(true)); 468 .WillRepeatedly(Return(true));
469 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 469 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
470 .WillRepeatedly(Return(false)); 470 .WillRepeatedly(Return(false));
471 error_ = GoogleServiceAuthError::AuthErrorNone(); 471 error_ = GoogleServiceAuthError::AuthErrorNone();
472 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 472 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
473 473
474 handler_->OpenSyncSetup(nullptr); 474 handler_->OpenSyncSetup(nullptr);
475 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 475 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
476 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 476 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
477 std::string page; 477 std::string page;
478 ASSERT_TRUE(data.arg1()->GetAsString(&page)); 478 ASSERT_TRUE(data.arg1()->GetAsString(&page));
479 EXPECT_EQ(page, "spinner"); 479 EXPECT_EQ(page, "spinner");
480 Mock::VerifyAndClearExpectations(mock_pss_); 480 Mock::VerifyAndClearExpectations(mock_pss_);
481 error_ = GoogleServiceAuthError( 481 error_ = GoogleServiceAuthError(
482 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 482 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
483 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 483 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
484 NotifySyncListeners(); 484 NotifySyncListeners();
485 485
486 // On failure, the dialog will be closed. 486 // On failure, the dialog will be closed.
487 EXPECT_EQ(NULL, 487 EXPECT_EQ(NULL,
488 LoginUIServiceFactory::GetForProfile( 488 LoginUIServiceFactory::GetForProfile(
489 profile_.get())->current_login_ui()); 489 profile_.get())->current_login_ui());
490 } 490 }
491 491
492 #if !defined(OS_CHROMEOS) 492 #if !defined(OS_CHROMEOS)
493 493
494 class SyncHandlerNonCrosTest : public SyncHandlerTest { 494 class PeopleHandlerNonCrosTest : public PeopleHandlerTest {
495 public: 495 public:
496 SyncHandlerNonCrosTest() {} 496 PeopleHandlerNonCrosTest() {}
497 }; 497 };
498 498
499 TEST_F(SyncHandlerNonCrosTest, HandleGaiaAuthFailure) { 499 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) {
500 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 500 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
501 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 501 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
502 .WillRepeatedly(Return(false)); 502 .WillRepeatedly(Return(false));
503 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) 503 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
504 .WillRepeatedly(Return(false)); 504 .WillRepeatedly(Return(false));
505 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 505 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
506 .WillRepeatedly(Return(false)); 506 .WillRepeatedly(Return(false));
507 // Open the web UI. 507 // Open the web UI.
508 handler_->OpenSyncSetup(nullptr); 508 handler_->OpenSyncSetup(nullptr);
509 509
510 ASSERT_FALSE(handler_->is_configuring_sync()); 510 ASSERT_FALSE(handler_->is_configuring_sync());
511 } 511 }
512 512
513 // TODO(kochi): We need equivalent tests for ChromeOS. 513 // TODO(kochi): We need equivalent tests for ChromeOS.
514 TEST_F(SyncHandlerNonCrosTest, UnrecoverableErrorInitializingSync) { 514 TEST_F(PeopleHandlerNonCrosTest, UnrecoverableErrorInitializingSync) {
515 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 515 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
516 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 516 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
517 .WillRepeatedly(Return(false)); 517 .WillRepeatedly(Return(false));
518 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 518 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
519 .WillRepeatedly(Return(false)); 519 .WillRepeatedly(Return(false));
520 // Open the web UI. 520 // Open the web UI.
521 handler_->OpenSyncSetup(nullptr); 521 handler_->OpenSyncSetup(nullptr);
522 522
523 ASSERT_FALSE(handler_->is_configuring_sync()); 523 ASSERT_FALSE(handler_->is_configuring_sync());
524 } 524 }
525 525
526 TEST_F(SyncHandlerNonCrosTest, GaiaErrorInitializingSync) { 526 TEST_F(PeopleHandlerNonCrosTest, GaiaErrorInitializingSync) {
527 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 527 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
528 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 528 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
529 .WillRepeatedly(Return(false)); 529 .WillRepeatedly(Return(false));
530 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 530 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
531 .WillRepeatedly(Return(false)); 531 .WillRepeatedly(Return(false));
532 // Open the web UI. 532 // Open the web UI.
533 handler_->OpenSyncSetup(nullptr); 533 handler_->OpenSyncSetup(nullptr);
534 534
535 ASSERT_FALSE(handler_->is_configuring_sync()); 535 ASSERT_FALSE(handler_->is_configuring_sync());
536 } 536 }
537 537
538 #endif // #if !defined(OS_CHROMEOS) 538 #endif // #if !defined(OS_CHROMEOS)
539 539
540 TEST_F(SyncHandlerTest, TestSyncEverything) { 540 TEST_F(PeopleHandlerTest, TestSyncEverything) {
541 std::string args = GetConfiguration( 541 std::string args = GetConfiguration(
542 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 542 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
543 base::ListValue list_args; 543 base::ListValue list_args;
544 list_args.Append(new base::StringValue(args)); 544 list_args.Append(new base::StringValue(args));
545 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 545 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
546 .WillRepeatedly(Return(false)); 546 .WillRepeatedly(Return(false));
547 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 547 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
548 .WillRepeatedly(Return(false)); 548 .WillRepeatedly(Return(false));
549 SetupInitializedProfileSyncService(); 549 SetupInitializedProfileSyncService();
550 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 550 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
551 handler_->HandleConfigure(&list_args); 551 handler_->HandleConfigure(&list_args);
552 552
553 // Ensure that we navigated to the "done" state since we don't need a 553 // Ensure that we navigated to the "done" state since we don't need a
554 // passphrase. 554 // passphrase.
555 ExpectDone(); 555 ExpectDone();
556 } 556 }
557 557
558 TEST_F(SyncHandlerTest, TestSyncNothing) { 558 TEST_F(PeopleHandlerTest, TestSyncNothing) {
559 std::string args = GetConfiguration( 559 std::string args = GetConfiguration(
560 NULL, SYNC_NOTHING, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 560 NULL, SYNC_NOTHING, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
561 base::ListValue list_args; 561 base::ListValue list_args;
562 list_args.Append(new base::StringValue(args)); 562 list_args.Append(new base::StringValue(args));
563 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 563 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
564 SetupInitializedProfileSyncService(); 564 SetupInitializedProfileSyncService();
565 handler_->HandleConfigure(&list_args); 565 handler_->HandleConfigure(&list_args);
566 566
567 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. 567 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage.
568 ASSERT_EQ(1U, web_ui_.call_data().size()); 568 ASSERT_EQ(1U, web_ui_.call_data().size());
569 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 569 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
570 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 570 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
571 } 571 }
572 572
573 TEST_F(SyncHandlerTest, TurnOnEncryptAll) { 573 TEST_F(PeopleHandlerTest, TurnOnEncryptAll) {
574 std::string args = GetConfiguration( 574 std::string args = GetConfiguration(
575 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); 575 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA);
576 base::ListValue list_args; 576 base::ListValue list_args;
577 list_args.Append(new base::StringValue(args)); 577 list_args.Append(new base::StringValue(args));
578 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 578 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
579 .WillRepeatedly(Return(false)); 579 .WillRepeatedly(Return(false));
580 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 580 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
581 .WillRepeatedly(Return(false)); 581 .WillRepeatedly(Return(false));
582 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 582 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
583 .WillRepeatedly(Return(true)); 583 .WillRepeatedly(Return(true));
584 SetupInitializedProfileSyncService(); 584 SetupInitializedProfileSyncService();
585 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()); 585 EXPECT_CALL(*mock_pss_, EnableEncryptEverything());
586 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 586 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
587 handler_->HandleConfigure(&list_args); 587 handler_->HandleConfigure(&list_args);
588 588
589 // Ensure that we navigated to the "done" state since we don't need a 589 // Ensure that we navigated to the "done" state since we don't need a
590 // passphrase. 590 // passphrase.
591 ExpectDone(); 591 ExpectDone();
592 } 592 }
593 593
594 TEST_F(SyncHandlerTest, TestPassphraseStillRequired) { 594 TEST_F(PeopleHandlerTest, TestPassphraseStillRequired) {
595 std::string args = GetConfiguration( 595 std::string args = GetConfiguration(
596 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS); 596 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
597 base::ListValue list_args; 597 base::ListValue list_args;
598 list_args.Append(new base::StringValue(args)); 598 list_args.Append(new base::StringValue(args));
599 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 599 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
600 .WillRepeatedly(Return(true)); 600 .WillRepeatedly(Return(true));
601 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 601 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
602 .WillRepeatedly(Return(true)); 602 .WillRepeatedly(Return(true));
603 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 603 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
604 .WillRepeatedly(Return(false)); 604 .WillRepeatedly(Return(false));
605 SetupInitializedProfileSyncService(); 605 SetupInitializedProfileSyncService();
606 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); 606 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
607 SetDefaultExpectationsForConfigPage(); 607 SetDefaultExpectationsForConfigPage();
608 608
609 // We should navigate back to the configure page since we need a passphrase. 609 // We should navigate back to the configure page since we need a passphrase.
610 handler_->HandleConfigure(&list_args); 610 handler_->HandleConfigure(&list_args);
611 611
612 ExpectConfig(); 612 ExpectConfig();
613 } 613 }
614 614
615 TEST_F(SyncHandlerTest, SuccessfullySetPassphrase) { 615 TEST_F(PeopleHandlerTest, SuccessfullySetPassphrase) {
616 base::DictionaryValue dict; 616 base::DictionaryValue dict;
617 dict.SetBoolean("isGooglePassphrase", true); 617 dict.SetBoolean("isGooglePassphrase", true);
618 std::string args = GetConfiguration(&dict, 618 std::string args = GetConfiguration(&dict,
619 SYNC_ALL_DATA, 619 SYNC_ALL_DATA,
620 GetAllTypes(), 620 GetAllTypes(),
621 "gaiaPassphrase", 621 "gaiaPassphrase",
622 ENCRYPT_PASSWORDS); 622 ENCRYPT_PASSWORDS);
623 base::ListValue list_args; 623 base::ListValue list_args;
624 list_args.Append(new base::StringValue(args)); 624 list_args.Append(new base::StringValue(args));
625 // Act as if an encryption passphrase is required the first time, then never 625 // Act as if an encryption passphrase is required the first time, then never
626 // again after that. 626 // again after that.
627 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true)); 627 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()).WillOnce(Return(true));
628 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 628 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
629 .WillRepeatedly(Return(false)); 629 .WillRepeatedly(Return(false));
630 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 630 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
631 .WillRepeatedly(Return(false)); 631 .WillRepeatedly(Return(false));
632 SetupInitializedProfileSyncService(); 632 SetupInitializedProfileSyncService();
633 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); 633 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
634 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase")). 634 EXPECT_CALL(*mock_pss_, SetDecryptionPassphrase("gaiaPassphrase")).
635 WillOnce(Return(true)); 635 WillOnce(Return(true));
636 636
637 handler_->HandleConfigure(&list_args); 637 handler_->HandleConfigure(&list_args);
638 // We should navigate to "done" page since we finished configuring. 638 // We should navigate to "done" page since we finished configuring.
639 ExpectDone(); 639 ExpectDone();
640 } 640 }
641 641
642 TEST_F(SyncHandlerTest, SelectCustomEncryption) { 642 TEST_F(PeopleHandlerTest, SelectCustomEncryption) {
643 base::DictionaryValue dict; 643 base::DictionaryValue dict;
644 dict.SetBoolean("isGooglePassphrase", false); 644 dict.SetBoolean("isGooglePassphrase", false);
645 std::string args = GetConfiguration(&dict, 645 std::string args = GetConfiguration(&dict,
646 SYNC_ALL_DATA, 646 SYNC_ALL_DATA,
647 GetAllTypes(), 647 GetAllTypes(),
648 "custom_passphrase", 648 "custom_passphrase",
649 ENCRYPT_PASSWORDS); 649 ENCRYPT_PASSWORDS);
650 base::ListValue list_args; 650 base::ListValue list_args;
651 list_args.Append(new base::StringValue(args)); 651 list_args.Append(new base::StringValue(args));
652 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 652 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
653 .WillRepeatedly(Return(false)); 653 .WillRepeatedly(Return(false));
654 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 654 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
655 .WillRepeatedly(Return(false)); 655 .WillRepeatedly(Return(false));
656 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 656 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
657 .WillRepeatedly(Return(false)); 657 .WillRepeatedly(Return(false));
658 SetupInitializedProfileSyncService(); 658 SetupInitializedProfileSyncService();
659 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _)); 659 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(_, _));
660 EXPECT_CALL(*mock_pss_, 660 EXPECT_CALL(*mock_pss_,
661 SetEncryptionPassphrase("custom_passphrase", 661 SetEncryptionPassphrase("custom_passphrase",
662 ProfileSyncService::EXPLICIT)); 662 ProfileSyncService::EXPLICIT));
663 663
664 handler_->HandleConfigure(&list_args); 664 handler_->HandleConfigure(&list_args);
665 // We should navigate to "done" page since we finished configuring. 665 // We should navigate to "done" page since we finished configuring.
666 ExpectDone(); 666 ExpectDone();
667 } 667 }
668 668
669 TEST_F(SyncHandlerTest, UnsuccessfullySetPassphrase) { 669 TEST_F(PeopleHandlerTest, UnsuccessfullySetPassphrase) {
670 base::DictionaryValue dict; 670 base::DictionaryValue dict;
671 dict.SetBoolean("isGooglePassphrase", true); 671 dict.SetBoolean("isGooglePassphrase", true);
672 std::string args = GetConfiguration(&dict, 672 std::string args = GetConfiguration(&dict,
673 SYNC_ALL_DATA, 673 SYNC_ALL_DATA,
674 GetAllTypes(), 674 GetAllTypes(),
675 "invalid_passphrase", 675 "invalid_passphrase",
676 ENCRYPT_PASSWORDS); 676 ENCRYPT_PASSWORDS);
677 base::ListValue list_args; 677 base::ListValue list_args;
678 list_args.Append(new base::StringValue(args)); 678 list_args.Append(new base::StringValue(args));
679 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 679 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
(...skipping 16 matching lines...) Expand all
696 // Make sure we display an error message to the user due to the failed 696 // Make sure we display an error message to the user due to the failed
697 // passphrase. 697 // passphrase.
698 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 698 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
699 const base::DictionaryValue* dictionary = nullptr; 699 const base::DictionaryValue* dictionary = nullptr;
700 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 700 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
701 CheckBool(dictionary, "passphraseFailed", true); 701 CheckBool(dictionary, "passphraseFailed", true);
702 } 702 }
703 703
704 // Walks through each user selectable type, and tries to sync just that single 704 // Walks through each user selectable type, and tries to sync just that single
705 // data type. 705 // data type.
706 TEST_F(SyncHandlerTest, TestSyncIndividualTypes) { 706 TEST_F(PeopleHandlerTest, TestSyncIndividualTypes) {
707 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); 707 syncer::ModelTypeSet user_selectable_types = GetAllTypes();
708 syncer::ModelTypeSet::Iterator it; 708 syncer::ModelTypeSet::Iterator it;
709 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { 709 for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
710 syncer::ModelTypeSet type_to_set; 710 syncer::ModelTypeSet type_to_set;
711 type_to_set.Put(it.Get()); 711 type_to_set.Put(it.Get());
712 std::string args = GetConfiguration(NULL, 712 std::string args = GetConfiguration(NULL,
713 CHOOSE_WHAT_TO_SYNC, 713 CHOOSE_WHAT_TO_SYNC,
714 type_to_set, 714 type_to_set,
715 std::string(), 715 std::string(),
716 ENCRYPT_PASSWORDS); 716 ENCRYPT_PASSWORDS);
717 base::ListValue list_args; 717 base::ListValue list_args;
718 list_args.Append(new base::StringValue(args)); 718 list_args.Append(new base::StringValue(args));
719 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 719 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
720 .WillRepeatedly(Return(false)); 720 .WillRepeatedly(Return(false));
721 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 721 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
722 .WillRepeatedly(Return(false)); 722 .WillRepeatedly(Return(false));
723 SetupInitializedProfileSyncService(); 723 SetupInitializedProfileSyncService();
724 EXPECT_CALL(*mock_pss_, 724 EXPECT_CALL(*mock_pss_,
725 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set))); 725 OnUserChoseDatatypes(false, ModelTypeSetMatches(type_to_set)));
726 handler_->HandleConfigure(&list_args); 726 handler_->HandleConfigure(&list_args);
727 727
728 ExpectDone(); 728 ExpectDone();
729 Mock::VerifyAndClearExpectations(mock_pss_); 729 Mock::VerifyAndClearExpectations(mock_pss_);
730 web_ui_.ClearTrackedCalls(); 730 web_ui_.ClearTrackedCalls();
731 } 731 }
732 } 732 }
733 733
734 TEST_F(SyncHandlerTest, TestSyncAllManually) { 734 TEST_F(PeopleHandlerTest, TestSyncAllManually) {
735 std::string args = GetConfiguration(NULL, 735 std::string args = GetConfiguration(NULL,
736 CHOOSE_WHAT_TO_SYNC, 736 CHOOSE_WHAT_TO_SYNC,
737 GetAllTypes(), 737 GetAllTypes(),
738 std::string(), 738 std::string(),
739 ENCRYPT_PASSWORDS); 739 ENCRYPT_PASSWORDS);
740 base::ListValue list_args; 740 base::ListValue list_args;
741 list_args.Append(new base::StringValue(args)); 741 list_args.Append(new base::StringValue(args));
742 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 742 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
743 .WillRepeatedly(Return(false)); 743 .WillRepeatedly(Return(false));
744 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 744 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
745 .WillRepeatedly(Return(false)); 745 .WillRepeatedly(Return(false));
746 SetupInitializedProfileSyncService(); 746 SetupInitializedProfileSyncService();
747 EXPECT_CALL(*mock_pss_, 747 EXPECT_CALL(*mock_pss_,
748 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes()))); 748 OnUserChoseDatatypes(false, ModelTypeSetMatches(GetAllTypes())));
749 handler_->HandleConfigure(&list_args); 749 handler_->HandleConfigure(&list_args);
750 750
751 ExpectDone(); 751 ExpectDone();
752 } 752 }
753 753
754 TEST_F(SyncHandlerTest, ShowSyncSetup) { 754 TEST_F(PeopleHandlerTest, ShowSyncSetup) {
755 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 755 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
756 .WillRepeatedly(Return(false)); 756 .WillRepeatedly(Return(false));
757 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 757 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
758 .WillRepeatedly(Return(false)); 758 .WillRepeatedly(Return(false));
759 SetupInitializedProfileSyncService(); 759 SetupInitializedProfileSyncService();
760 // This should display the sync setup dialog (not login). 760 // This should display the sync setup dialog (not login).
761 SetDefaultExpectationsForConfigPage(); 761 SetDefaultExpectationsForConfigPage();
762 handler_->OpenSyncSetup(nullptr); 762 handler_->OpenSyncSetup(nullptr);
763 763
764 ExpectConfig(); 764 ExpectConfig();
765 } 765 }
766 766
767 // We do not display signin on chromeos in the case of auth error. 767 // We do not display signin on chromeos in the case of auth error.
768 TEST_F(SyncHandlerTest, ShowSigninOnAuthError) { 768 TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) {
769 // Initialize the system to a signed in state, but with an auth error. 769 // Initialize the system to a signed in state, but with an auth error.
770 error_ = GoogleServiceAuthError( 770 error_ = GoogleServiceAuthError(
771 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 771 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
772 772
773 SetupInitializedProfileSyncService(); 773 SetupInitializedProfileSyncService();
774 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); 774 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
775 FakeAuthStatusProvider provider( 775 FakeAuthStatusProvider provider(
776 SigninErrorControllerFactory::GetForProfile(profile_.get())); 776 SigninErrorControllerFactory::GetForProfile(profile_.get()));
777 provider.SetAuthError(kTestUser, error_); 777 provider.SetAuthError(kTestUser, error_);
778 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 778 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
(...skipping 21 matching lines...) Expand all
800 800
801 // Sync setup is closed when re-auth is in progress. 801 // Sync setup is closed when re-auth is in progress.
802 EXPECT_EQ(NULL, 802 EXPECT_EQ(NULL,
803 LoginUIServiceFactory::GetForProfile( 803 LoginUIServiceFactory::GetForProfile(
804 profile_.get())->current_login_ui()); 804 profile_.get())->current_login_ui());
805 805
806 ASSERT_FALSE(handler_->is_configuring_sync()); 806 ASSERT_FALSE(handler_->is_configuring_sync());
807 #endif 807 #endif
808 } 808 }
809 809
810 TEST_F(SyncHandlerTest, ShowSetupSyncEverything) { 810 TEST_F(PeopleHandlerTest, ShowSetupSyncEverything) {
811 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 811 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
812 .WillRepeatedly(Return(false)); 812 .WillRepeatedly(Return(false));
813 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 813 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
814 .WillRepeatedly(Return(false)); 814 .WillRepeatedly(Return(false));
815 SetupInitializedProfileSyncService(); 815 SetupInitializedProfileSyncService();
816 SetDefaultExpectationsForConfigPage(); 816 SetDefaultExpectationsForConfigPage();
817 // This should display the sync setup dialog (not login). 817 // This should display the sync setup dialog (not login).
818 handler_->OpenSyncSetup(nullptr); 818 handler_->OpenSyncSetup(nullptr);
819 819
820 ExpectConfig(); 820 ExpectConfig();
(...skipping 11 matching lines...) Expand all
832 CheckBool(dictionary, "tabsRegistered", true); 832 CheckBool(dictionary, "tabsRegistered", true);
833 CheckBool(dictionary, "themesRegistered", true); 833 CheckBool(dictionary, "themesRegistered", true);
834 CheckBool(dictionary, "typedUrlsRegistered", true); 834 CheckBool(dictionary, "typedUrlsRegistered", true);
835 CheckBool(dictionary, "showPassphrase", false); 835 CheckBool(dictionary, "showPassphrase", false);
836 CheckBool(dictionary, "usePassphrase", false); 836 CheckBool(dictionary, "usePassphrase", false);
837 CheckBool(dictionary, "passphraseFailed", false); 837 CheckBool(dictionary, "passphraseFailed", false);
838 CheckBool(dictionary, "encryptAllData", false); 838 CheckBool(dictionary, "encryptAllData", false);
839 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); 839 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes());
840 } 840 }
841 841
842 TEST_F(SyncHandlerTest, ShowSetupManuallySyncAll) { 842 TEST_F(PeopleHandlerTest, ShowSetupManuallySyncAll) {
843 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 843 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
844 .WillRepeatedly(Return(false)); 844 .WillRepeatedly(Return(false));
845 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 845 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
846 .WillRepeatedly(Return(false)); 846 .WillRepeatedly(Return(false));
847 SetupInitializedProfileSyncService(); 847 SetupInitializedProfileSyncService();
848 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); 848 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
849 sync_prefs.SetKeepEverythingSynced(false); 849 sync_prefs.SetKeepEverythingSynced(false);
850 SetDefaultExpectationsForConfigPage(); 850 SetDefaultExpectationsForConfigPage();
851 // This should display the sync setup dialog (not login). 851 // This should display the sync setup dialog (not login).
852 handler_->OpenSyncSetup(nullptr); 852 handler_->OpenSyncSetup(nullptr);
853 853
854 ExpectConfig(); 854 ExpectConfig();
855 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 855 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
856 const base::DictionaryValue* dictionary = nullptr; 856 const base::DictionaryValue* dictionary = nullptr;
857 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 857 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
858 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes()); 858 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes());
859 } 859 }
860 860
861 TEST_F(SyncHandlerTest, ShowSetupSyncForAllTypesIndividually) { 861 TEST_F(PeopleHandlerTest, ShowSetupSyncForAllTypesIndividually) {
862 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); 862 syncer::ModelTypeSet user_selectable_types = GetAllTypes();
863 syncer::ModelTypeSet::Iterator it; 863 syncer::ModelTypeSet::Iterator it;
864 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { 864 for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
865 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 865 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
866 .WillRepeatedly(Return(false)); 866 .WillRepeatedly(Return(false));
867 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 867 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
868 .WillRepeatedly(Return(false)); 868 .WillRepeatedly(Return(false));
869 SetupInitializedProfileSyncService(); 869 SetupInitializedProfileSyncService();
870 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs()); 870 sync_driver::SyncPrefs sync_prefs(profile_->GetPrefs());
871 sync_prefs.SetKeepEverythingSynced(false); 871 sync_prefs.SetKeepEverythingSynced(false);
(...skipping 13 matching lines...) Expand all
885 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 885 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
886 const base::DictionaryValue* dictionary = nullptr; 886 const base::DictionaryValue* dictionary = nullptr;
887 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 887 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
888 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types); 888 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types);
889 Mock::VerifyAndClearExpectations(mock_pss_); 889 Mock::VerifyAndClearExpectations(mock_pss_);
890 // Clean up so we can loop back to display the dialog again. 890 // Clean up so we can loop back to display the dialog again.
891 web_ui_.ClearTrackedCalls(); 891 web_ui_.ClearTrackedCalls();
892 } 892 }
893 } 893 }
894 894
895 TEST_F(SyncHandlerTest, ShowSetupGaiaPassphraseRequired) { 895 TEST_F(PeopleHandlerTest, ShowSetupGaiaPassphraseRequired) {
896 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 896 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
897 .WillRepeatedly(Return(true)); 897 .WillRepeatedly(Return(true));
898 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 898 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
899 .WillRepeatedly(Return(false)); 899 .WillRepeatedly(Return(false));
900 SetupInitializedProfileSyncService(); 900 SetupInitializedProfileSyncService();
901 SetDefaultExpectationsForConfigPage(); 901 SetDefaultExpectationsForConfigPage();
902 902
903 // This should display the sync setup dialog (not login). 903 // This should display the sync setup dialog (not login).
904 handler_->OpenSyncSetup(nullptr); 904 handler_->OpenSyncSetup(nullptr);
905 905
906 ExpectConfig(); 906 ExpectConfig();
907 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 907 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
908 const base::DictionaryValue* dictionary = nullptr; 908 const base::DictionaryValue* dictionary = nullptr;
909 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 909 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
910 CheckBool(dictionary, "showPassphrase", true); 910 CheckBool(dictionary, "showPassphrase", true);
911 CheckBool(dictionary, "usePassphrase", false); 911 CheckBool(dictionary, "usePassphrase", false);
912 CheckBool(dictionary, "passphraseFailed", false); 912 CheckBool(dictionary, "passphraseFailed", false);
913 } 913 }
914 914
915 TEST_F(SyncHandlerTest, ShowSetupCustomPassphraseRequired) { 915 TEST_F(PeopleHandlerTest, ShowSetupCustomPassphraseRequired) {
916 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 916 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
917 .WillRepeatedly(Return(true)); 917 .WillRepeatedly(Return(true));
918 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 918 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
919 .WillRepeatedly(Return(true)); 919 .WillRepeatedly(Return(true));
920 EXPECT_CALL(*mock_pss_, GetPassphraseType()) 920 EXPECT_CALL(*mock_pss_, GetPassphraseType())
921 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE)); 921 .WillRepeatedly(Return(syncer::CUSTOM_PASSPHRASE));
922 SetupInitializedProfileSyncService(); 922 SetupInitializedProfileSyncService();
923 SetDefaultExpectationsForConfigPage(); 923 SetDefaultExpectationsForConfigPage();
924 924
925 // This should display the sync setup dialog (not login). 925 // This should display the sync setup dialog (not login).
926 handler_->OpenSyncSetup(nullptr); 926 handler_->OpenSyncSetup(nullptr);
927 927
928 ExpectConfig(); 928 ExpectConfig();
929 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 929 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
930 const base::DictionaryValue* dictionary = nullptr; 930 const base::DictionaryValue* dictionary = nullptr;
931 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 931 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
932 CheckBool(dictionary, "showPassphrase", true); 932 CheckBool(dictionary, "showPassphrase", true);
933 CheckBool(dictionary, "usePassphrase", true); 933 CheckBool(dictionary, "usePassphrase", true);
934 CheckBool(dictionary, "passphraseFailed", false); 934 CheckBool(dictionary, "passphraseFailed", false);
935 } 935 }
936 936
937 TEST_F(SyncHandlerTest, ShowSetupEncryptAll) { 937 TEST_F(PeopleHandlerTest, ShowSetupEncryptAll) {
938 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 938 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
939 .WillRepeatedly(Return(false)); 939 .WillRepeatedly(Return(false));
940 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 940 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
941 .WillRepeatedly(Return(false)); 941 .WillRepeatedly(Return(false));
942 SetupInitializedProfileSyncService(); 942 SetupInitializedProfileSyncService();
943 SetDefaultExpectationsForConfigPage(); 943 SetDefaultExpectationsForConfigPage();
944 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled()) 944 EXPECT_CALL(*mock_pss_, IsEncryptEverythingEnabled())
945 .WillRepeatedly(Return(true)); 945 .WillRepeatedly(Return(true));
946 946
947 // This should display the sync setup dialog (not login). 947 // This should display the sync setup dialog (not login).
948 handler_->OpenSyncSetup(nullptr); 948 handler_->OpenSyncSetup(nullptr);
949 949
950 ExpectConfig(); 950 ExpectConfig();
951 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 951 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
952 const base::DictionaryValue* dictionary = nullptr; 952 const base::DictionaryValue* dictionary = nullptr;
953 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 953 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
954 CheckBool(dictionary, "encryptAllData", true); 954 CheckBool(dictionary, "encryptAllData", true);
955 } 955 }
956 956
957 TEST_F(SyncHandlerTest, ShowSetupEncryptAllDisallowed) { 957 TEST_F(PeopleHandlerTest, ShowSetupEncryptAllDisallowed) {
958 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 958 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
959 .WillRepeatedly(Return(false)); 959 .WillRepeatedly(Return(false));
960 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 960 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
961 .WillRepeatedly(Return(false)); 961 .WillRepeatedly(Return(false));
962 SetupInitializedProfileSyncService(); 962 SetupInitializedProfileSyncService();
963 SetDefaultExpectationsForConfigPage(); 963 SetDefaultExpectationsForConfigPage();
964 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 964 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
965 .WillRepeatedly(Return(false)); 965 .WillRepeatedly(Return(false));
966 966
967 // This should display the sync setup dialog (not login). 967 // This should display the sync setup dialog (not login).
968 handler_->OpenSyncSetup(nullptr); 968 handler_->OpenSyncSetup(nullptr);
969 969
970 ExpectConfig(); 970 ExpectConfig();
971 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 971 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
972 const base::DictionaryValue* dictionary = nullptr; 972 const base::DictionaryValue* dictionary = nullptr;
973 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 973 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
974 CheckBool(dictionary, "encryptAllData", false); 974 CheckBool(dictionary, "encryptAllData", false);
975 CheckBool(dictionary, "encryptAllDataAllowed", false); 975 CheckBool(dictionary, "encryptAllDataAllowed", false);
976 } 976 }
977 977
978 TEST_F(SyncHandlerTest, TurnOnEncryptAllDisallowed) { 978 TEST_F(PeopleHandlerTest, TurnOnEncryptAllDisallowed) {
979 std::string args = GetConfiguration( 979 std::string args = GetConfiguration(
980 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); 980 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA);
981 base::ListValue list_args; 981 base::ListValue list_args;
982 list_args.Append(new base::StringValue(args)); 982 list_args.Append(new base::StringValue(args));
983 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 983 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
984 .WillRepeatedly(Return(false)); 984 .WillRepeatedly(Return(false));
985 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 985 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
986 .WillRepeatedly(Return(false)); 986 .WillRepeatedly(Return(false));
987 SetupInitializedProfileSyncService(); 987 SetupInitializedProfileSyncService();
988 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 988 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
989 .WillRepeatedly(Return(false)); 989 .WillRepeatedly(Return(false));
990 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 990 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
991 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 991 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
992 handler_->HandleConfigure(&list_args); 992 handler_->HandleConfigure(&list_args);
993 993
994 // Ensure that we navigated to the "done" state since we don't need a 994 // Ensure that we navigated to the "done" state since we don't need a
995 // passphrase. 995 // passphrase.
996 ExpectDone(); 996 ExpectDone();
997 } 997 }
998 998
999 } // namespace settings 999 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/people_handler.cc ('k') | chrome/browser/ui/webui/settings/sync_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698