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

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

Issue 2971353002: [sync] Prevent flash of error icon while loading syncSetup page (Closed)
Patch Set: rename MaybeAcquireSyncBlocker Created 3 years, 5 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
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/macros.h" 13 #include "base/macros.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 "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/signin/fake_signin_manager_builder.h" 17 #include "chrome/browser/signin/fake_signin_manager_builder.h"
18 #include "chrome/browser/signin/signin_error_controller_factory.h" 18 #include "chrome/browser/signin/signin_error_controller_factory.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 19 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/browser/sync/profile_sync_service_factory.h" 20 #include "chrome/browser/sync/profile_sync_service_factory.h"
21 #include "chrome/browser/sync/profile_sync_test_util.h" 21 #include "chrome/browser/sync/profile_sync_test_util.h"
22 #include "chrome/browser/ui/chrome_pages.h"
22 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 23 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 24 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "chrome/common/url_constants.h"
28 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
26 #include "chrome/test/base/scoped_testing_local_state.h" 29 #include "chrome/test/base/scoped_testing_local_state.h"
30 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
27 #include "chrome/test/base/testing_browser_process.h" 31 #include "chrome/test/base/testing_browser_process.h"
28 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
29 #include "chrome/test/base/testing_profile_manager.h"
30 #include "components/prefs/pref_service.h" 33 #include "components/prefs/pref_service.h"
31 #include "components/signin/core/browser/fake_auth_status_provider.h" 34 #include "components/signin/core/browser/fake_auth_status_provider.h"
32 #include "components/signin/core/browser/signin_manager.h" 35 #include "components/signin/core/browser/signin_manager.h"
33 #include "components/sync/base/sync_prefs.h" 36 #include "components/sync/base/sync_prefs.h"
34 #include "components/sync_preferences/pref_service_syncable.h" 37 #include "components/sync_preferences/pref_service_syncable.h"
38 #include "content/public/browser/web_contents.h"
35 #include "content/public/browser/web_ui.h" 39 #include "content/public/browser/web_ui.h"
40 #include "content/public/browser/web_ui_controller.h"
36 #include "content/public/test/test_browser_thread.h" 41 #include "content/public/test/test_browser_thread.h"
37 #include "content/public/test/test_browser_thread_bundle.h" 42 #include "content/public/test/test_browser_thread_bundle.h"
38 #include "content/public/test/test_web_ui.h" 43 #include "content/public/test/test_web_ui.h"
44 #include "content/public/test/web_contents_tester.h"
39 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/base/layout.h" 46 #include "ui/base/layout.h"
41 47
42 using ::testing::_; 48 using ::testing::_;
43 using ::testing::Mock; 49 using ::testing::Mock;
44 using ::testing::Return; 50 using ::testing::Return;
45 using ::testing::ReturnRef; 51 using ::testing::ReturnRef;
46 using ::testing::Values; 52 using ::testing::Values;
47 using browser_sync::ProfileSyncService; 53 using browser_sync::ProfileSyncService;
48 using browser_sync::ProfileSyncServiceMock; 54 using browser_sync::ProfileSyncServiceMock;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 168
163 private: 169 private:
164 #if !defined(OS_CHROMEOS) 170 #if !defined(OS_CHROMEOS)
165 void DisplayGaiaLoginInNewTabOrWindow( 171 void DisplayGaiaLoginInNewTabOrWindow(
166 signin_metrics::AccessPoint access_point) override {} 172 signin_metrics::AccessPoint access_point) override {}
167 #endif 173 #endif
168 174
169 DISALLOW_COPY_AND_ASSIGN(TestingPeopleHandler); 175 DISALLOW_COPY_AND_ASSIGN(TestingPeopleHandler);
170 }; 176 };
171 177
178 class TestWebUIProvider
179 : public TestChromeWebUIControllerFactory::WebUIProvider {
180 public:
181 content::WebUIController* NewWebUI(content::WebUI* web_ui,
182 const GURL& url) override {
183 content::WebUIController* controller = new content::WebUIController(web_ui);
184 return controller;
185 }
186 };
187
172 // The boolean parameter indicates whether the test is run with ClientOAuth 188 // The boolean parameter indicates whether the test is run with ClientOAuth
173 // or not. The test parameter is a bool: whether or not to test with/ 189 // or not. The test parameter is a bool: whether or not to test with/
174 // /ClientLogin enabled or not. 190 // /ClientLogin enabled or not.
175 class PeopleHandlerTest : public testing::Test { 191 class PeopleHandlerTest : public ChromeRenderViewHostTestHarness {
176 public: 192 public:
177 PeopleHandlerTest() : error_(GoogleServiceAuthError::NONE) {} 193 PeopleHandlerTest() : error_(GoogleServiceAuthError::NONE) {}
178 void SetUp() override { 194 void SetUp() override {
195 ChromeRenderViewHostTestHarness::SetUp();
179 error_ = GoogleServiceAuthError::AuthErrorNone(); 196 error_ = GoogleServiceAuthError::AuthErrorNone();
180 197
181 profile_manager_.reset(
182 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
183 ASSERT_TRUE(profile_manager_->SetUp());
184
185 TestingProfile::TestingFactories testing_factories;
186 testing_factories.push_back(std::make_pair(
187 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase));
188 profile_ = profile_manager_->CreateTestingProfile(
189 "Person 1", nullptr, base::UTF8ToUTF16("Person 1"), 0, std::string(),
190 testing_factories);
191
192 // Sign in the user. 198 // Sign in the user.
193 mock_signin_ = static_cast<SigninManagerBase*>( 199 mock_signin_ = static_cast<SigninManagerBase*>(
194 SigninManagerFactory::GetForProfile(profile_)); 200 SigninManagerFactory::GetForProfile(profile()));
195 std::string username = GetTestUser(); 201 std::string username = GetTestUser();
196 if (!username.empty()) 202 if (!username.empty())
197 mock_signin_->SetAuthenticatedAccountInfo(username, username); 203 mock_signin_->SetAuthenticatedAccountInfo(username, username);
198 204
199 mock_pss_ = static_cast<ProfileSyncServiceMock*>( 205 mock_pss_ = static_cast<ProfileSyncServiceMock*>(
200 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 206 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
201 profile_, BuildMockProfileSyncService)); 207 profile(), BuildMockProfileSyncService));
202 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 208 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
203 ON_CALL(*mock_pss_, GetPassphraseType()) 209 ON_CALL(*mock_pss_, GetPassphraseType())
204 .WillByDefault(Return(syncer::PassphraseType::IMPLICIT_PASSPHRASE)); 210 .WillByDefault(Return(syncer::PassphraseType::IMPLICIT_PASSPHRASE));
205 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault( 211 ON_CALL(*mock_pss_, GetExplicitPassphraseTime()).WillByDefault(
206 Return(base::Time())); 212 Return(base::Time()));
207 ON_CALL(*mock_pss_, GetRegisteredDataTypes()) 213 ON_CALL(*mock_pss_, GetRegisteredDataTypes())
208 .WillByDefault(Return(syncer::ModelTypeSet())); 214 .WillByDefault(Return(syncer::ModelTypeSet()));
209 215
210 mock_pss_->Initialize(); 216 mock_pss_->Initialize();
211 217
212 handler_.reset(new TestingPeopleHandler(&web_ui_, profile_)); 218 handler_.reset(new TestingPeopleHandler(&web_ui_, profile()));
213 handler_->AllowJavascript(); 219 handler_->AllowJavascript();
214 } 220 }
215 221
222 void TearDown() override {
223 handler_->set_web_ui(nullptr);
224 handler_->DisallowJavascript();
225 handler_->sync_startup_tracker_.reset();
226 ChromeRenderViewHostTestHarness::TearDown();
227 }
228
216 // Setup the expectations for calls made when displaying the config page. 229 // Setup the expectations for calls made when displaying the config page.
217 void SetDefaultExpectationsForConfigPage() { 230 void SetDefaultExpectationsForConfigPage() {
218 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 231 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
219 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes()) 232 EXPECT_CALL(*mock_pss_, GetRegisteredDataTypes())
220 .WillRepeatedly(Return(GetAllTypes())); 233 .WillRepeatedly(Return(GetAllTypes()));
221 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()) 234 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes())
222 .WillRepeatedly(Return(GetAllTypes())); 235 .WillRepeatedly(Return(GetAllTypes()));
223 EXPECT_CALL(*mock_pss_, GetActiveDataTypes()) 236 EXPECT_CALL(*mock_pss_, GetActiveDataTypes())
224 .WillRepeatedly(Return(GetAllTypes())); 237 .WillRepeatedly(Return(GetAllTypes()));
225 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 238 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 std::string status; 271 std::string status;
259 ASSERT_TRUE(data.arg2()->GetAsString(&status)); 272 ASSERT_TRUE(data.arg2()->GetAsString(&status));
260 EXPECT_EQ(expected_status, status); 273 EXPECT_EQ(expected_status, status);
261 } 274 }
262 275
263 void ExpectSpinnerAndClose() { 276 void ExpectSpinnerAndClose() {
264 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus); 277 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus);
265 278
266 // Cancelling the spinner dialog will cause CloseSyncSetup(). 279 // Cancelling the spinner dialog will cause CloseSyncSetup().
267 handler_->CloseSyncSetup(); 280 handler_->CloseSyncSetup();
268 EXPECT_EQ(NULL, 281 EXPECT_EQ(
269 LoginUIServiceFactory::GetForProfile( 282 NULL,
270 profile_)->current_login_ui()); 283 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
271 } 284 }
272 285
273 const base::DictionaryValue* ExpectSyncPrefsChanged() { 286 const base::DictionaryValue* ExpectSyncPrefsChanged() {
274 const content::TestWebUI::CallData& data1 = *web_ui_.call_data().back(); 287 const content::TestWebUI::CallData& data1 = *web_ui_.call_data().back();
275 EXPECT_EQ("cr.webUIListenerCallback", data1.function_name()); 288 EXPECT_EQ("cr.webUIListenerCallback", data1.function_name());
276 289
277 std::string event; 290 std::string event;
278 EXPECT_TRUE(data1.arg1()->GetAsString(&event)); 291 EXPECT_TRUE(data1.arg1()->GetAsString(&event));
279 EXPECT_EQ(event, "sync-prefs-changed"); 292 EXPECT_EQ(event, "sync-prefs-changed");
280 293
281 const base::DictionaryValue* dictionary = nullptr; 294 const base::DictionaryValue* dictionary = nullptr;
282 EXPECT_TRUE(data1.arg2()->GetAsDictionary(&dictionary)); 295 EXPECT_TRUE(data1.arg2()->GetAsDictionary(&dictionary));
283 return dictionary; 296 return dictionary;
284 } 297 }
285 298
286 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock 299 // It's difficult to notify sync listeners when using a ProfileSyncServiceMock
287 // so this helper routine dispatches an OnStateChanged() notification to the 300 // so this helper routine dispatches an OnStateChanged() notification to the
288 // SyncStartupTracker. 301 // SyncStartupTracker.
289 void NotifySyncListeners() { 302 void NotifySyncListeners() {
290 if (handler_->sync_startup_tracker_) 303 if (handler_->sync_startup_tracker_)
291 handler_->sync_startup_tracker_->OnStateChanged(mock_pss_); 304 handler_->sync_startup_tracker_->OnStateChanged(mock_pss_);
292 } 305 }
293 306
294 void NotifySyncStateChanged() { handler_->OnStateChanged(mock_pss_); } 307 void NotifySyncStateChanged() { handler_->OnStateChanged(mock_pss_); }
295 308
296 virtual std::string GetTestUser() { 309 virtual std::string GetTestUser() {
297 return std::string(kTestUser); 310 return std::string(kTestUser);
298 } 311 }
299 312
300 content::TestBrowserThreadBundle thread_bundle_;
301 std::unique_ptr<TestingProfileManager> profile_manager_;
302 Profile* profile_;
303 ProfileSyncServiceMock* mock_pss_; 313 ProfileSyncServiceMock* mock_pss_;
304 GoogleServiceAuthError error_; 314 GoogleServiceAuthError error_;
305 SigninManagerBase* mock_signin_; 315 SigninManagerBase* mock_signin_;
306 content::TestWebUI web_ui_; 316 content::TestWebUI web_ui_;
317 TestWebUIProvider test_provider_;
318 std::unique_ptr<TestChromeWebUIControllerFactory> test_factory_;
307 std::unique_ptr<TestingPeopleHandler> handler_; 319 std::unique_ptr<TestingPeopleHandler> handler_;
308 }; 320 };
309 321
310 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest { 322 class PeopleHandlerFirstSigninTest : public PeopleHandlerTest {
311 std::string GetTestUser() override { return std::string(); } 323 std::string GetTestUser() override { return std::string(); }
312 }; 324 };
313 325
314 #if !defined(OS_CHROMEOS) 326 #if !defined(OS_CHROMEOS)
315 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) { 327 TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) {
316 // Test that the HandleStartSignin call enables JavaScript. 328 // Test that the HandleStartSignin call enables JavaScript.
317 handler_->DisallowJavascript(); 329 handler_->DisallowJavascript();
318 330
319 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 331 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
320 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 332 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
321 // Ensure that the user is not signed in before calling |HandleStartSignin()|. 333 // Ensure that the user is not signed in before calling |HandleStartSignin()|.
322 SigninManager* manager = static_cast<SigninManager*>(mock_signin_); 334 SigninManager* manager = static_cast<SigninManager*>(mock_signin_);
323 manager->SignOut(signin_metrics::SIGNOUT_TEST, 335 manager->SignOut(signin_metrics::SIGNOUT_TEST,
324 signin_metrics::SignoutDelete::IGNORE_METRIC); 336 signin_metrics::SignoutDelete::IGNORE_METRIC);
325 base::ListValue list_args; 337 base::ListValue list_args;
326 handler_->HandleStartSignin(&list_args); 338 handler_->HandleStartSignin(&list_args);
327 339
328 // Sync setup hands off control to the gaia login tab. 340 // Sync setup hands off control to the gaia login tab.
329 EXPECT_EQ(NULL, 341 EXPECT_EQ(
330 LoginUIServiceFactory::GetForProfile( 342 NULL,
331 profile_)->current_login_ui()); 343 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
332 344
333 ASSERT_FALSE(handler_->is_configuring_sync()); 345 ASSERT_FALSE(handler_->is_configuring_sync());
334 346
335 handler_->CloseSyncSetup(); 347 handler_->CloseSyncSetup();
336 EXPECT_EQ(NULL, 348 EXPECT_EQ(
337 LoginUIServiceFactory::GetForProfile( 349 NULL,
338 profile_)->current_login_ui()); 350 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
339 } 351 }
340 352
341 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) { 353 TEST_F(PeopleHandlerTest, ShowSyncSetupWhenNotSignedIn) {
342 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 354 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
343 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 355 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
344 handler_->HandleShowSetupUI(NULL); 356 handler_->HandleShowSetupUI(NULL);
345 357
346 ExpectPageStatusChanged(PeopleHandler::kDonePageStatus); 358 ExpectPageStatusChanged(PeopleHandler::kDonePageStatus);
347 359
348 ASSERT_FALSE(handler_->is_configuring_sync()); 360 ASSERT_FALSE(handler_->is_configuring_sync());
349 EXPECT_EQ(NULL, 361 EXPECT_EQ(
350 LoginUIServiceFactory::GetForProfile( 362 NULL,
351 profile_)->current_login_ui()); 363 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
352 } 364 }
353 #endif // !defined(OS_CHROMEOS) 365 #endif // !defined(OS_CHROMEOS)
354 366
355 // Verifies that the sync setup is terminated correctly when the 367 // Verifies that the sync setup is terminated correctly when the
356 // sync is disabled. 368 // sync is disabled.
357 TEST_F(PeopleHandlerTest, HandleSetupUIWhenSyncDisabled) { 369 TEST_F(PeopleHandlerTest, HandleSetupUIWhenSyncDisabled) {
358 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true)); 370 EXPECT_CALL(*mock_pss_, IsManaged()).WillRepeatedly(Return(true));
359 handler_->HandleShowSetupUI(NULL); 371 handler_->HandleShowSetupUI(NULL);
360 372
361 // Sync setup is closed when sync is disabled. 373 // Sync setup is closed when sync is disabled.
362 EXPECT_EQ(NULL, 374 EXPECT_EQ(
363 LoginUIServiceFactory::GetForProfile( 375 NULL,
364 profile_)->current_login_ui()); 376 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
365 ASSERT_FALSE(handler_->is_configuring_sync()); 377 ASSERT_FALSE(handler_->is_configuring_sync());
366 } 378 }
367 379
368 // Verifies that the handler correctly handles a cancellation when 380 // Verifies that the handler correctly handles a cancellation when
369 // it is displaying the spinner to the user. 381 // it is displaying the spinner to the user.
370 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndCancel) { 382 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndCancel) {
371 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 383 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
372 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 384 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
373 error_ = GoogleServiceAuthError::AuthErrorNone(); 385 error_ = GoogleServiceAuthError::AuthErrorNone();
374 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); 386 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
375 EXPECT_CALL(*mock_pss_, RequestStart()); 387 EXPECT_CALL(*mock_pss_, RequestStart());
376 388
377 // We're simulating a user setting up sync, which would cause the engine to 389 // We're simulating a user setting up sync, which would cause the engine to
378 // kick off initialization, but not download user data types. The sync 390 // kick off initialization, but not download user data types. The sync
379 // engine will try to download control data types (e.g encryption info), but 391 // engine will try to download control data types (e.g encryption info), but
380 // that won't finish for this test as we're simulating cancelling while the 392 // that won't finish for this test as we're simulating cancelling while the
381 // spinner is showing. 393 // spinner is showing.
382 handler_->HandleShowSetupUI(NULL); 394 handler_->HandleShowSetupUI(NULL);
383 395
384 EXPECT_EQ(handler_.get(), 396 EXPECT_EQ(
385 LoginUIServiceFactory::GetForProfile( 397 handler_.get(),
386 profile_)->current_login_ui()); 398 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
387 399
388 ExpectSpinnerAndClose(); 400 ExpectSpinnerAndClose();
389 } 401 }
390 402
391 // Verifies that the handler correctly transitions from showing the spinner 403 // Verifies that the handler correctly transitions from showing the spinner
392 // to showing a configuration page when sync setup completes successfully. 404 // to showing a configuration page when sync setup completes successfully.
393 TEST_F(PeopleHandlerTest, 405 TEST_F(PeopleHandlerTest,
394 DisplayConfigureWithEngineDisabledAndSyncStartupCompleted) { 406 DisplayConfigureWithEngineDisabledAndSyncStartupCompleted) {
395 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 407 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
396 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 408 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 SetDefaultExpectationsForConfigPage(); 451 SetDefaultExpectationsForConfigPage();
440 handler_->OpenSyncSetup(); 452 handler_->OpenSyncSetup();
441 453
442 // It's important to tell sync the user cancelled the setup flow before we 454 // It's important to tell sync the user cancelled the setup flow before we
443 // tell it we're through with the setup progress. 455 // tell it we're through with the setup progress.
444 testing::InSequence seq; 456 testing::InSequence seq;
445 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA)); 457 EXPECT_CALL(*mock_pss_, RequestStop(ProfileSyncService::CLEAR_DATA));
446 EXPECT_CALL(*mock_pss_, OnSetupInProgressHandleDestroyed()); 458 EXPECT_CALL(*mock_pss_, OnSetupInProgressHandleDestroyed());
447 459
448 handler_->CloseSyncSetup(); 460 handler_->CloseSyncSetup();
449 EXPECT_EQ(NULL, 461 EXPECT_EQ(
450 LoginUIServiceFactory::GetForProfile( 462 NULL,
451 profile_)->current_login_ui()); 463 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
452 } 464 }
453 465
454 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndSigninFailed) { 466 TEST_F(PeopleHandlerTest, DisplayConfigureWithEngineDisabledAndSigninFailed) {
455 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 467 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
456 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false)); 468 EXPECT_CALL(*mock_pss_, IsFirstSetupComplete()).WillRepeatedly(Return(false));
457 error_ = GoogleServiceAuthError::AuthErrorNone(); 469 error_ = GoogleServiceAuthError::AuthErrorNone();
458 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); 470 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
459 EXPECT_CALL(*mock_pss_, RequestStart()); 471 EXPECT_CALL(*mock_pss_, RequestStart());
460 472
461 handler_->OpenSyncSetup(); 473 handler_->OpenSyncSetup();
462 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus); 474 ExpectPageStatusChanged(PeopleHandler::kSpinnerPageStatus);
463 Mock::VerifyAndClearExpectations(mock_pss_); 475 Mock::VerifyAndClearExpectations(mock_pss_);
464 error_ = GoogleServiceAuthError( 476 error_ = GoogleServiceAuthError(
465 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 477 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
466 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_)); 478 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error_));
467 NotifySyncListeners(); 479 NotifySyncListeners();
468 480
469 // On failure, the dialog will be closed. 481 // On failure, the dialog will be closed.
470 EXPECT_EQ(NULL, 482 EXPECT_EQ(
471 LoginUIServiceFactory::GetForProfile( 483 NULL,
472 profile_)->current_login_ui()); 484 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
473 } 485 }
474 486
475 // Tests that signals not related to user intention to configure sync don't 487 // Tests that signals not related to user intention to configure sync don't
476 // trigger sync engine start. 488 // trigger sync engine start.
477 TEST_F(PeopleHandlerTest, OnlyStartEngineWhenConfiguringSync) { 489 TEST_F(PeopleHandlerTest, OnlyStartEngineWhenConfiguringSync) {
478 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); 490 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
479 EXPECT_CALL(*mock_pss_, RequestStart()).Times(0); 491 EXPECT_CALL(*mock_pss_, RequestStart()).Times(0);
480 NotifySyncStateChanged(); 492 NotifySyncStateChanged();
481 } 493 }
482 494
495 TEST_F(PeopleHandlerTest, AcquireSyncBlockerWhenLoadingSyncSettingsSubpage) {
496 /// We set up a factory override here to prevent a new web ui from being
497 /// created when we navigate to a page that would normally create one.
498 web_ui_.set_web_contents(web_contents());
499 test_factory_ = base::MakeUnique<TestChromeWebUIControllerFactory>();
500 test_factory_->AddFactoryOverride(
501 chrome::GetSettingsUrl(chrome::kSyncSetupSubPage).host(),
502 &test_provider_);
503 content::WebUIControllerFactory::RegisterFactory(test_factory_.get());
504 content::WebUIControllerFactory::UnregisterFactoryForTesting(
505 ChromeWebUIControllerFactory::GetInstance());
506
507 EXPECT_FALSE(handler_->sync_blocker_);
508
509 content::WebContentsTester::For(web_contents())
510 ->StartNavigation(chrome::GetSettingsUrl(chrome::kSyncSetupSubPage));
511 handler_->InitializeSyncBlocker();
512
513 EXPECT_TRUE(handler_->sync_blocker_);
514 }
515
483 #if !defined(OS_CHROMEOS) 516 #if !defined(OS_CHROMEOS)
484 517
485 class PeopleHandlerNonCrosTest : public PeopleHandlerTest { 518 class PeopleHandlerNonCrosTest : public PeopleHandlerTest {
486 public: 519 public:
487 PeopleHandlerNonCrosTest() {} 520 PeopleHandlerNonCrosTest() {}
488 }; 521 };
489 522
490 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) { 523 TEST_F(PeopleHandlerNonCrosTest, HandleGaiaAuthFailure) {
491 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false)); 524 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(false));
492 EXPECT_CALL(*mock_pss_, HasUnrecoverableError()) 525 EXPECT_CALL(*mock_pss_, HasUnrecoverableError())
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 752
720 // We do not display signin on chromeos in the case of auth error. 753 // We do not display signin on chromeos in the case of auth error.
721 TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) { 754 TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) {
722 // Initialize the system to a signed in state, but with an auth error. 755 // Initialize the system to a signed in state, but with an auth error.
723 error_ = GoogleServiceAuthError( 756 error_ = GoogleServiceAuthError(
724 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 757 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
725 758
726 SetupInitializedProfileSyncService(); 759 SetupInitializedProfileSyncService();
727 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); 760 mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser);
728 FakeAuthStatusProvider provider( 761 FakeAuthStatusProvider provider(
729 SigninErrorControllerFactory::GetForProfile(profile_)); 762 SigninErrorControllerFactory::GetForProfile(profile()));
730 provider.SetAuthError(kTestUser, error_); 763 provider.SetAuthError(kTestUser, error_);
731 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true)); 764 EXPECT_CALL(*mock_pss_, CanSyncStart()).WillRepeatedly(Return(true));
732 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 765 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
733 .WillRepeatedly(Return(false)); 766 .WillRepeatedly(Return(false));
734 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 767 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
735 .WillRepeatedly(Return(false)); 768 .WillRepeatedly(Return(false));
736 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false)); 769 EXPECT_CALL(*mock_pss_, IsEngineInitialized()).WillRepeatedly(Return(false));
737 770
738 #if defined(OS_CHROMEOS) 771 #if defined(OS_CHROMEOS)
739 // On ChromeOS, auth errors are ignored - instead we just try to start the 772 // On ChromeOS, auth errors are ignored - instead we just try to start the
740 // sync engine (which will fail due to the auth error). This should only 773 // sync engine (which will fail due to the auth error). This should only
741 // happen if the user manually navigates to chrome://settings/syncSetup - 774 // happen if the user manually navigates to chrome://settings/syncSetup -
742 // clicking on the button in the UI will sign the user out rather than 775 // clicking on the button in the UI will sign the user out rather than
743 // displaying a spinner. Should be no visible UI on ChromeOS in this case. 776 // displaying a spinner. Should be no visible UI on ChromeOS in this case.
744 EXPECT_EQ(NULL, LoginUIServiceFactory::GetForProfile( 777 EXPECT_EQ(
745 profile_)->current_login_ui()); 778 NULL,
779 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
746 #else 780 #else
747 781
748 // On ChromeOS, this should display the spinner while we try to startup the 782 // On ChromeOS, this should display the spinner while we try to startup the
749 // sync engine, and on desktop this displays the login dialog. 783 // sync engine, and on desktop this displays the login dialog.
750 handler_->OpenSyncSetup(); 784 handler_->OpenSyncSetup();
751 785
752 // Sync setup is closed when re-auth is in progress. 786 // Sync setup is closed when re-auth is in progress.
753 EXPECT_EQ(NULL, 787 EXPECT_EQ(
754 LoginUIServiceFactory::GetForProfile( 788 NULL,
755 profile_)->current_login_ui()); 789 LoginUIServiceFactory::GetForProfile(profile())->current_login_ui());
756 790
757 ASSERT_FALSE(handler_->is_configuring_sync()); 791 ASSERT_FALSE(handler_->is_configuring_sync());
758 #endif 792 #endif
759 } 793 }
760 794
761 TEST_F(PeopleHandlerTest, ShowSetupSyncEverything) { 795 TEST_F(PeopleHandlerTest, ShowSetupSyncEverything) {
762 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 796 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
763 .WillRepeatedly(Return(false)); 797 .WillRepeatedly(Return(false));
764 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 798 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
765 .WillRepeatedly(Return(false)); 799 .WillRepeatedly(Return(false));
(...skipping 19 matching lines...) Expand all
785 CheckBool(dictionary, "encryptAllData", false); 819 CheckBool(dictionary, "encryptAllData", false);
786 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes()); 820 CheckConfigDataTypeArguments(dictionary, SYNC_ALL_DATA, GetAllTypes());
787 } 821 }
788 822
789 TEST_F(PeopleHandlerTest, ShowSetupManuallySyncAll) { 823 TEST_F(PeopleHandlerTest, ShowSetupManuallySyncAll) {
790 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 824 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
791 .WillRepeatedly(Return(false)); 825 .WillRepeatedly(Return(false));
792 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 826 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
793 .WillRepeatedly(Return(false)); 827 .WillRepeatedly(Return(false));
794 SetupInitializedProfileSyncService(); 828 SetupInitializedProfileSyncService();
795 syncer::SyncPrefs sync_prefs(profile_->GetPrefs()); 829 syncer::SyncPrefs sync_prefs(profile()->GetPrefs());
796 sync_prefs.SetKeepEverythingSynced(false); 830 sync_prefs.SetKeepEverythingSynced(false);
797 SetDefaultExpectationsForConfigPage(); 831 SetDefaultExpectationsForConfigPage();
798 // This should display the sync setup dialog (not login). 832 // This should display the sync setup dialog (not login).
799 handler_->OpenSyncSetup(); 833 handler_->OpenSyncSetup();
800 834
801 const base::DictionaryValue* dictionary = ExpectSyncPrefsChanged(); 835 const base::DictionaryValue* dictionary = ExpectSyncPrefsChanged();
802 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes()); 836 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, GetAllTypes());
803 } 837 }
804 838
805 TEST_F(PeopleHandlerTest, ShowSetupSyncForAllTypesIndividually) { 839 TEST_F(PeopleHandlerTest, ShowSetupSyncForAllTypesIndividually) {
806 syncer::ModelTypeSet user_selectable_types = GetAllTypes(); 840 syncer::ModelTypeSet user_selectable_types = GetAllTypes();
807 syncer::ModelTypeSet::Iterator it; 841 syncer::ModelTypeSet::Iterator it;
808 for (it = user_selectable_types.First(); it.Good(); it.Inc()) { 842 for (it = user_selectable_types.First(); it.Good(); it.Inc()) {
809 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 843 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
810 .WillRepeatedly(Return(false)); 844 .WillRepeatedly(Return(false));
811 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 845 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
812 .WillRepeatedly(Return(false)); 846 .WillRepeatedly(Return(false));
813 SetupInitializedProfileSyncService(); 847 SetupInitializedProfileSyncService();
814 syncer::SyncPrefs sync_prefs(profile_->GetPrefs()); 848 syncer::SyncPrefs sync_prefs(profile()->GetPrefs());
815 sync_prefs.SetKeepEverythingSynced(false); 849 sync_prefs.SetKeepEverythingSynced(false);
816 SetDefaultExpectationsForConfigPage(); 850 SetDefaultExpectationsForConfigPage();
817 syncer::ModelTypeSet types; 851 syncer::ModelTypeSet types;
818 types.Put(it.Get()); 852 types.Put(it.Get());
819 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). 853 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()).
820 WillRepeatedly(Return(types)); 854 WillRepeatedly(Return(types));
821 855
822 // This should display the sync setup dialog (not login). 856 // This should display the sync setup dialog (not login).
823 handler_->OpenSyncSetup(); 857 handler_->OpenSyncSetup();
824 858
825 // Close the config overlay. 859 // Close the config overlay.
826 LoginUIServiceFactory::GetForProfile(profile_)->LoginUIClosed( 860 LoginUIServiceFactory::GetForProfile(profile())->LoginUIClosed(
827 handler_.get()); 861 handler_.get());
828 862
829 const base::DictionaryValue* dictionary = ExpectSyncPrefsChanged(); 863 const base::DictionaryValue* dictionary = ExpectSyncPrefsChanged();
830 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types); 864 CheckConfigDataTypeArguments(dictionary, CHOOSE_WHAT_TO_SYNC, types);
831 Mock::VerifyAndClearExpectations(mock_pss_); 865 Mock::VerifyAndClearExpectations(mock_pss_);
832 // Clean up so we can loop back to display the dialog again. 866 // Clean up so we can loop back to display the dialog again.
833 web_ui_.ClearTrackedCalls(); 867 web_ui_.ClearTrackedCalls();
834 } 868 }
835 } 869 }
836 870
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 SetupInitializedProfileSyncService(); 949 SetupInitializedProfileSyncService();
916 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed()) 950 EXPECT_CALL(*mock_pss_, IsEncryptEverythingAllowed())
917 .WillRepeatedly(Return(false)); 951 .WillRepeatedly(Return(false));
918 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0); 952 EXPECT_CALL(*mock_pss_, EnableEncryptEverything()).Times(0);
919 handler_->HandleSetEncryption(&list_args); 953 handler_->HandleSetEncryption(&list_args);
920 954
921 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus); 955 ExpectPageStatusResponse(PeopleHandler::kConfigurePageStatus);
922 } 956 }
923 957
924 } // namespace settings 958 } // 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