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

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

Issue 1536593004: Settings People Revamp: Implement Chrome Profile name/icon selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/people_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"
16 #include "chrome/browser/signin/fake_signin_manager_builder.h" 16 #include "chrome/browser/signin/fake_signin_manager_builder.h"
17 #include "chrome/browser/signin/signin_error_controller_factory.h" 17 #include "chrome/browser/signin/signin_error_controller_factory.h"
18 #include "chrome/browser/signin/signin_manager_factory.h" 18 #include "chrome/browser/signin/signin_manager_factory.h"
19 #include "chrome/browser/sync/profile_sync_service_factory.h" 19 #include "chrome/browser/sync/profile_sync_service_factory.h"
20 #include "chrome/browser/sync/profile_sync_test_util.h" 20 #include "chrome/browser/sync/profile_sync_test_util.h"
21 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 21 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
22 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 22 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
25 #include "chrome/test/base/scoped_testing_local_state.h" 25 #include "chrome/test/base/scoped_testing_local_state.h"
26 #include "chrome/test/base/testing_browser_process.h" 26 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "chrome/test/base/testing_profile_manager.h"
28 #include "components/signin/core/browser/fake_auth_status_provider.h" 29 #include "components/signin/core/browser/fake_auth_status_provider.h"
29 #include "components/signin/core/browser/signin_manager.h" 30 #include "components/signin/core/browser/signin_manager.h"
30 #include "components/sync_driver/sync_prefs.h" 31 #include "components/sync_driver/sync_prefs.h"
32 #include "components/syncable_prefs/pref_service_syncable.h"
31 #include "content/public/browser/web_ui.h" 33 #include "content/public/browser/web_ui.h"
32 #include "content/public/test/test_browser_thread.h" 34 #include "content/public/test/test_browser_thread.h"
33 #include "content/public/test/test_browser_thread_bundle.h" 35 #include "content/public/test/test_browser_thread_bundle.h"
34 #include "content/public/test/test_web_ui.h" 36 #include "content/public/test/test_web_ui.h"
35 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
36 #include "ui/base/layout.h" 38 #include "ui/base/layout.h"
37 39
38 using ::testing::_; 40 using ::testing::_;
39 using ::testing::Mock; 41 using ::testing::Mock;
40 using ::testing::Return; 42 using ::testing::Return;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 178
177 // The boolean parameter indicates whether the test is run with ClientOAuth 179 // 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/ 180 // or not. The test parameter is a bool: whether or not to test with/
179 // /ClientLogin enabled or not. 181 // /ClientLogin enabled or not.
180 class PeopleHandlerTest : public testing::Test { 182 class PeopleHandlerTest : public testing::Test {
181 public: 183 public:
182 PeopleHandlerTest() : error_(GoogleServiceAuthError::NONE) {} 184 PeopleHandlerTest() : error_(GoogleServiceAuthError::NONE) {}
183 void SetUp() override { 185 void SetUp() override {
184 error_ = GoogleServiceAuthError::AuthErrorNone(); 186 error_ = GoogleServiceAuthError::AuthErrorNone();
185 187
186 TestingProfile::Builder builder; 188 profile_manager_.reset(
187 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), 189 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
188 BuildFakeSigninManagerBase); 190 ASSERT_TRUE(profile_manager_->SetUp());
189 profile_ = builder.Build(); 191
192 TestingProfile::TestingFactories testing_factories;
193 testing_factories.push_back(std::make_pair(
194 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase));
195 profile_ = profile_manager_->CreateTestingProfile(
196 "Person 1", nullptr, base::UTF8ToUTF16("Person 1"), 0, std::string(),
197 testing_factories);
190 198
191 // Sign in the user. 199 // Sign in the user.
192 mock_signin_ = static_cast<SigninManagerBase*>( 200 mock_signin_ = static_cast<SigninManagerBase*>(
193 SigninManagerFactory::GetForProfile(profile_.get())); 201 SigninManagerFactory::GetForProfile(profile_));
194 std::string username = GetTestUser(); 202 std::string username = GetTestUser();
195 if (!username.empty()) 203 if (!username.empty())
196 mock_signin_->SetAuthenticatedAccountInfo(username, username); 204 mock_signin_->SetAuthenticatedAccountInfo(username, username);
197 205
198 mock_pss_ = static_cast<ProfileSyncServiceMock*>( 206 mock_pss_ = static_cast<ProfileSyncServiceMock*>(
199 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 207 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
200 profile_.get(), BuildMockProfileSyncService)); 208 profile_, BuildMockProfileSyncService));
201 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 209 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
202 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault( 210 ON_CALL(*mock_pss_, GetPassphraseType()).WillByDefault(
203 Return(syncer::IMPLICIT_PASSPHRASE)); 211 Return(syncer::IMPLICIT_PASSPHRASE));
204 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( 212 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault(
205 Return(base::Time())); 213 Return(base::Time()));
206 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) 214 ON_CALL(*mock_pss_, GetRegisteredDataTypes())
207 .WillByDefault(Return(syncer::ModelTypeSet())); 215 .WillByDefault(Return(syncer::ModelTypeSet()));
208 216
209 mock_pss_->Initialize(); 217 mock_pss_->Initialize();
210 218
211 handler_.reset(new TestingPeopleHandler(&web_ui_, profile_.get())); 219 handler_.reset(new TestingPeopleHandler(&web_ui_, profile_));
212 } 220 }
213 221
214 // Setup the expectations for calls made when displaying the config page. 222 // Setup the expectations for calls made when displaying the config page.
215 void SetDefaultExpectationsForConfigPage() { 223 void SetDefaultExpectationsForConfigPage() {
216 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 224 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
217 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()) 225 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes())
218 .WillRepeatedly(Return(GetAllTypes())); 226 .WillRepeatedly(Return(GetAllTypes()));
219 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()) 227 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes())
220 .WillRepeatedly(Return(GetAllTypes())); 228 .WillRepeatedly(Return(GetAllTypes()));
221 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()) 229 EXPECT_CALL(*mock_pss_, GetActiveDataTypes())
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", 269 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage",
262 data.function_name()); 270 data.function_name());
263 271
264 std::string page; 272 std::string page;
265 ASSERT_TRUE(data.arg1()->GetAsString(&page)); 273 ASSERT_TRUE(data.arg1()->GetAsString(&page));
266 EXPECT_EQ(page, "spinner"); 274 EXPECT_EQ(page, "spinner");
267 // Cancelling the spinner dialog will cause CloseSyncSetup(). 275 // Cancelling the spinner dialog will cause CloseSyncSetup().
268 handler_->CloseSyncSetup(); 276 handler_->CloseSyncSetup();
269 EXPECT_EQ(NULL, 277 EXPECT_EQ(NULL,
270 LoginUIServiceFactory::GetForProfile( 278 LoginUIServiceFactory::GetForProfile(
271 profile_.get())->current_login_ui()); 279 profile_)->current_login_ui());
272 } 280 }
273 281
274 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock 282 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock
275 // so this helper routine dispatches an OnStateChanged() notification to the 283 // so this helper routine dispatches an OnStateChanged() notification to the
276 // SyncStartupTracker. 284 // SyncStartupTracker.
277 void NotifySyncListeners() { 285 void NotifySyncListeners() {
278 if (handler_->sync_startup_tracker_) 286 if (handler_->sync_startup_tracker_)
279 handler_->sync_startup_tracker_->OnStateChanged(); 287 handler_->sync_startup_tracker_->OnStateChanged();
280 } 288 }
281 289
282 virtual std::string GetTestUser() { 290 virtual std::string GetTestUser() {
283 return std::string(kTestUser); 291 return std::string(kTestUser);
284 } 292 }
285 293
286 content::TestBrowserThreadBundle thread_bundle_; 294 content::TestBrowserThreadBundle thread_bundle_;
287 scoped_ptr<Profile> profile_; 295 scoped_ptr<TestingProfileManager> profile_manager_;
296 Profile* profile_;
288 ProfileSyncServiceMock* mock_pss_; 297 ProfileSyncServiceMock* mock_pss_;
289 GoogleServiceAuthError error_; 298 GoogleServiceAuthError error_;
290 SigninManagerBase* mock_signin_; 299 SigninManagerBase* mock_signin_;
291 content::TestWebUI web_ui_; 300 content::TestWebUI web_ui_;
292 scoped_ptr<TestingPeopleHandler> handler_; 301 scoped_ptr<TestingPeopleHandler> handler_;
293 }; 302 };
294 303
295 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest { 304 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest {
296 std::string GetTestUser() override { return std::string(); } 305 std::string GetTestUser() override { return std::string(); }
297 }; 306 };
298 307
299 TEST_F(PeopleHandlerTest, Basic) { 308 TEST_F(PeopleHandlerTest, Basic) {
300 } 309 }
301 310
302 #if !defined(OS_CHROMEOS) 311 #if !defined(OS_CHROMEOS)
303 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) { 312 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) {
304 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 313 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
305 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 314 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
306 .WillRepeatedly(Return(false)); 315 .WillRepeatedly(Return(false));
307 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 316 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
308 .WillRepeatedly(Return(false)); 317 .WillRepeatedly(Return(false));
309 // Ensure that the user is not signed in before calling |HandleStartSignin()|. 318 // Ensure that the user is not signed in before calling |HandleStartSignin()|.
310 SigninManager* manager = static_cast<SigninManager*>(mock_signin_); 319 SigninManager* manager = static_cast<SigninManager*>(mock_signin_);
311 manager->SignOut(signin_metrics::SIGNOUT_TEST); 320 manager->SignOut(signin_metrics::SIGNOUT_TEST);
312 handler_->HandleStartSignin(NULL); 321 handler_->HandleStartSignin(NULL);
313 322
314 // Sync setup hands off control to the gaia login tab. 323 // Sync setup hands off control to the gaia login tab.
315 EXPECT_EQ(NULL, 324 EXPECT_EQ(NULL,
316 LoginUIServiceFactory::GetForProfile( 325 LoginUIServiceFactory::GetForProfile(
317 profile_.get())->current_login_ui()); 326 profile_)->current_login_ui());
318 327
319 ASSERT_FALSE(handler_->is_configuring_sync()); 328 ASSERT_FALSE(handler_->is_configuring_sync());
320 329
321 handler_->CloseSyncSetup(); 330 handler_->CloseSyncSetup();
322 EXPECT_EQ(NULL, 331 EXPECT_EQ(NULL,
323 LoginUIServiceFactory::GetForProfile( 332 LoginUIServiceFactory::GetForProfile(
324 profile_.get())->current_login_ui()); 333 profile_)->current_login_ui());
325 } 334 }
326 335
327 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) { 336 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) {
328 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 337 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
329 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 338 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
330 .WillRepeatedly(Return(false)); 339 .WillRepeatedly(Return(false));
331 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 340 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
332 .WillRepeatedly(Return(false)); 341 .WillRepeatedly(Return(false));
333 handler_->HandleShowSetupUI(NULL); 342 handler_->HandleShowSetupUI(NULL);
334 343
335 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage. 344 // We expect a call to settings.SyncPrivateApi.showSyncSetupPage.
336 ASSERT_EQ(1U, web_ui_.call_data().size()); 345 ASSERT_EQ(1U, web_ui_.call_data().size());
337 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 346 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
338 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 347 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
339 348
340 ASSERT_FALSE(handler_->is_configuring_sync()); 349 ASSERT_FALSE(handler_->is_configuring_sync());
341 EXPECT_EQ(NULL, 350 EXPECT_EQ(NULL,
342 LoginUIServiceFactory::GetForProfile( 351 LoginUIServiceFactory::GetForProfile(
343 profile_.get())->current_login_ui()); 352 profile_)->current_login_ui());
344 } 353 }
345 #endif // !defined(OS_CHROMEOS) 354 #endif // !defined(OS_CHROMEOS)
346 355
347 // Verifies that the sync setup is terminated correctly when the 356 // Verifies that the sync setup is terminated correctly when the
348 // sync is disabled. 357 // sync is disabled.
349 TEST_F(PeopleHandlerTest, HandleSetupUIWhenSyncDisabled) { 358 TEST_F(PeopleHandlerTest, HandleSetupUIWhenSyncDisabled) {
350 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true)); 359 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true));
351 handler_->HandleShowSetupUI(NULL); 360 handler_->HandleShowSetupUI(NULL);
352 361
353 // Sync setup is closed when sync is disabled. 362 // Sync setup is closed when sync is disabled.
354 EXPECT_EQ(NULL, 363 EXPECT_EQ(NULL,
355 LoginUIServiceFactory::GetForProfile( 364 LoginUIServiceFactory::GetForProfile(
356 profile_.get())->current_login_ui()); 365 profile_)->current_login_ui());
357 ASSERT_FALSE(handler_->is_configuring_sync()); 366 ASSERT_FALSE(handler_->is_configuring_sync());
358 } 367 }
359 368
360 // Verifies that the handler correctly handles a cancellation when 369 // Verifies that the handler correctly handles a cancellation when
361 // it is displaying the spinner to the user. 370 // it is displaying the spinner to the user.
362 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) { 371 TEST_F(PeopleHandlerTest, DisplayConfigureWithBackendDisabledAndCancel) {
363 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 372 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
364 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 373 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
365 .WillRepeatedly(Return(true)); 374 .WillRepeatedly(Return(true));
366 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 375 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
367 .WillRepeatedly(Return(false)); 376 .WillRepeatedly(Return(false));
368 error_ = GoogleServiceAuthError::AuthErrorNone(); 377 error_ = GoogleServiceAuthError::AuthErrorNone();
369 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 378 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
370 379
371 // We're simulating a user setting up sync, which would cause the backend to 380 // 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 381 // 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 382 // 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 383 // that won't finish for this test as we're simulating cancelling while the
375 // spinner is showing. 384 // spinner is showing.
376 handler_->HandleShowSetupUI(NULL); 385 handler_->HandleShowSetupUI(NULL);
377 386
378 EXPECT_EQ(handler_.get(), 387 EXPECT_EQ(handler_.get(),
379 LoginUIServiceFactory::GetForProfile( 388 LoginUIServiceFactory::GetForProfile(
380 profile_.get())->current_login_ui()); 389 profile_)->current_login_ui());
381 390
382 ExpectSpinnerAndClose(); 391 ExpectSpinnerAndClose();
383 } 392 }
384 393
385 // Verifies that the handler correctly transitions from showing the spinner 394 // Verifies that the handler correctly transitions from showing the spinner
386 // to showing a configuration page when sync setup completes successfully. 395 // to showing a configuration page when sync setup completes successfully.
387 TEST_F(PeopleHandlerTest, 396 TEST_F(PeopleHandlerTest,
388 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) { 397 DisplayConfigureWithBackendDisabledAndSyncStartupCompleted) {
389 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 398 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
390 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 399 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 460
452 // It's important to tell sync the user cancelled the setup flow before we 461 // It's important to tell sync the user cancelled the setup flow before we
453 // tell it we're through with the setup progress. 462 // tell it we're through with the setup progress.
454 testing::InSequence seq; 463 testing::InSequence seq;
455 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 464 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
456 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false)); 465 EXPECT_CALL(*mock_pss_, SetSetupInProgress(false));
457 466
458 handler_->CloseSyncSetup(); 467 handler_->CloseSyncSetup();
459 EXPECT_EQ(NULL, 468 EXPECT_EQ(NULL,
460 LoginUIServiceFactory::GetForProfile( 469 LoginUIServiceFactory::GetForProfile(
461 profile_.get())->current_login_ui()); 470 profile_)->current_login_ui());
462 } 471 }
463 472
464 TEST_F(PeopleHandlerTest, 473 TEST_F(PeopleHandlerTest,
465 DisplayConfigureWithBackendDisabledAndSigninFailed) { 474 DisplayConfigureWithBackendDisabledAndSigninFailed) {
466 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 475 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
467 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 476 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
468 .WillRepeatedly(Return(true)); 477 .WillRepeatedly(Return(true));
469 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) 478 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted())
470 .WillRepeatedly(Return(false)); 479 .WillRepeatedly(Return(false));
471 error_ = GoogleServiceAuthError::AuthErrorNone(); 480 error_ = GoogleServiceAuthError::AuthErrorNone();
472 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 481 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
473 482
474 handler_->OpenSyncSetup(nullptr); 483 handler_->OpenSyncSetup(nullptr);
475 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 484 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
476 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name()); 485 EXPECT_EQ("settings.SyncPrivateApi.showSyncSetupPage", data.function_name());
477 std::string page; 486 std::string page;
478 ASSERT_TRUE(data.arg1()->GetAsString(&page)); 487 ASSERT_TRUE(data.arg1()->GetAsString(&page));
479 EXPECT_EQ(page, "spinner"); 488 EXPECT_EQ(page, "spinner");
480 Mock::VerifyAndClearExpectations(mock_pss_); 489 Mock::VerifyAndClearExpectations(mock_pss_);
481 error_ = GoogleServiceAuthError( 490 error_ = GoogleServiceAuthError(
482 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 491 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
483 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 492 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
484 NotifySyncListeners(); 493 NotifySyncListeners();
485 494
486 // On failure, the dialog will be closed. 495 // On failure, the dialog will be closed.
487 EXPECT_EQ(NULL, 496 EXPECT_EQ(NULL,
488 LoginUIServiceFactory::GetForProfile( 497 LoginUIServiceFactory::GetForProfile(
489 profile_.get())->current_login_ui()); 498 profile_)->current_login_ui());
490 } 499 }
491 500
492 #if !defined(OS_CHROMEOS) 501 #if !defined(OS_CHROMEOS)
493 502
494 class PeopleHandlerNonCrosTest : public PeopleHandlerTest { 503 class PeopleHandlerNonCrosTest : public PeopleHandlerTest {
495 public: 504 public:
496 PeopleHandlerNonCrosTest() {} 505 PeopleHandlerNonCrosTest() {}
497 }; 506 };
498 507
499 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) { 508 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 775
767 // We do not display signin on chromeos in the case of auth error. 776 // We do not display signin on chromeos in the case of auth error.
768 TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) { 777 TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) {
769 // Initialize the system to a signed in state, but with an auth error. 778 // Initialize the system to a signed in state, but with an auth error.
770 error_ = GoogleServiceAuthError( 779 error_ = GoogleServiceAuthError(
771 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 780 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
772 781
773 SetupInitializedProfileSyncService(); 782 SetupInitializedProfileSyncService();
774 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); 783 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
775 FakeAuthStatusProvider provider( 784 FakeAuthStatusProvider provider(
776 SigninErrorControllerFactory::GetForProfile(profile_.get())); 785 SigninErrorControllerFactory::GetForProfile(profile_));
777 provider.SetAuthError(kTestUser, error_); 786 provider.SetAuthError(kTestUser, error_);
778 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 787 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
779 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable()) 788 EXPECT_CALL(*mock_pss_, IsOAuthRefreshTokenAvailable())
780 .WillRepeatedly(Return(true)); 789 .WillRepeatedly(Return(true));
781 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 790 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
782 .WillRepeatedly(Return(false)); 791 .WillRepeatedly(Return(false));
783 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 792 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
784 .WillRepeatedly(Return(false)); 793 .WillRepeatedly(Return(false));
785 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false)); 794 EXPECT_CALL(*mock_pss_, IsBackendInitialized()).WillRepeatedly(Return(false));
786 795
787 #if defined(OS_CHROMEOS) 796 #if defined(OS_CHROMEOS)
788 // On ChromeOS, auth errors are ignored - instead we just try to start the 797 // On ChromeOS, auth errors are ignored - instead we just try to start the
789 // sync backend (which will fail due to the auth error). This should only 798 // sync backend (which will fail due to the auth error). This should only
790 // happen if the user manually navigates to chrome://settings/syncSetup - 799 // happen if the user manually navigates to chrome://settings/syncSetup -
791 // clicking on the button in the UI will sign the user out rather than 800 // clicking on the button in the UI will sign the user out rather than
792 // displaying a spinner. Should be no visible UI on ChromeOS in this case. 801 // displaying a spinner. Should be no visible UI on ChromeOS in this case.
793 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile( 802 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile(
794 profile_.get())->current_login_ui()); 803 profile_)->current_login_ui());
795 #else 804 #else
796 805
797 // On ChromeOS, this should display the spinner while we try to startup the 806 // On ChromeOS, this should display the spinner while we try to startup the
798 // sync backend, and on desktop this displays the login dialog. 807 // sync backend, and on desktop this displays the login dialog.
799 handler_->OpenSyncSetup(nullptr); 808 handler_->OpenSyncSetup(nullptr);
800 809
801 // Sync setup is closed when re-auth is in progress. 810 // Sync setup is closed when re-auth is in progress.
802 EXPECT_EQ(NULL, 811 EXPECT_EQ(NULL,
803 LoginUIServiceFactory::GetForProfile( 812 LoginUIServiceFactory::GetForProfile(
804 profile_.get())->current_login_ui()); 813 profile_)->current_login_ui());
805 814
806 ASSERT_FALSE(handler_->is_configuring_sync()); 815 ASSERT_FALSE(handler_->is_configuring_sync());
807 #endif 816 #endif
808 } 817 }
809 818
810 TEST_F(PeopleHandlerTest, ShowSetupSyncEverything) { 819 TEST_F(PeopleHandlerTest, ShowSetupSyncEverything) {
811 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 820 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
812 .WillRepeatedly(Return(false)); 821 .WillRepeatedly(Return(false));
813 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 822 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
814 .WillRepeatedly(Return(false)); 823 .WillRepeatedly(Return(false));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 syncer::ModelTypeSet types; 882 syncer::ModelTypeSet types;
874 types.Put(it.Get()); 883 types.Put(it.Get());
875 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). 884 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()).
876 WillRepeatedly(Return(types)); 885 WillRepeatedly(Return(types));
877 886
878 // This should display the sync setup dialog (not login). 887 // This should display the sync setup dialog (not login).
879 handler_->OpenSyncSetup(nullptr); 888 handler_->OpenSyncSetup(nullptr);
880 889
881 ExpectConfig(); 890 ExpectConfig();
882 // Close the config overlay. 891 // Close the config overlay.
883 LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed( 892 LoginUIServiceFactory::GetForProfile(profile_)->LoginUIClosed(
884 handler_.get()); 893 handler_.get());
885 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0]; 894 const content::TestWebUI::CallData& data = *web_ui_.call_data()[0];
886 const base::DictionaryValue* dictionary = nullptr; 895 const base::DictionaryValue* dictionary = nullptr;
887 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary)); 896 ASSERT_TRUE(data.arg2()->GetAsDictionary(&dictionary));
888 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types); 897 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types);
889 Mock::VerifyAndClearExpectations(mock_pss_); 898 Mock::VerifyAndClearExpectations(mock_pss_);
890 // Clean up so we can loop back to display the dialog again. 899 // Clean up so we can loop back to display the dialog again.
891 web_ui_.ClearTrackedCalls(); 900 web_ui_.ClearTrackedCalls();
892 } 901 }
893 } 902 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 999 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
991 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 1000 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
992 handler_->HandleConfigure(&list_args); 1001 handler_->HandleConfigure(&list_args);
993 1002
994 // Ensure that we navigated to the "done" state since we don't need a 1003 // Ensure that we navigated to the "done" state since we don't need a
995 // passphrase. 1004 // passphrase.
996 ExpectDone(); 1005 ExpectDone();
997 } 1006 }
998 1007
999 } // namespace settings 1008 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698