| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/signin/signin_create_profile_handler.h" | 5 #include "chrome/browser/ui/webui/signin/signin_create_profile_handler.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/prefs/browser_prefs.h" | 8 #include "chrome/browser/prefs/browser_prefs.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/profiles/profile_attributes_entry.h" | 10 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 11 #include "chrome/browser/profiles/profile_attributes_storage.h" | 11 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 12 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 13 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 13 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 14 #include "chrome/browser/signin/signin_error_controller_factory.h" | 14 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "chrome/browser/ui/webui/signin/signin_utils.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 18 #include "chrome/test/base/browser_with_test_window_test.h" | 19 #include "chrome/test/base/browser_with_test_window_test.h" |
| 19 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
| 20 #include "chrome/test/base/testing_profile_manager.h" | 21 #include "chrome/test/base/testing_profile_manager.h" |
| 21 #include "components/signin/core/browser/fake_auth_status_provider.h" | 22 #include "components/signin/core/browser/fake_auth_status_provider.h" |
| 22 #include "components/sync/api/fake_sync_change_processor.h" | 23 #include "components/sync/api/fake_sync_change_processor.h" |
| 23 #include "components/sync/api/sync_data.h" | 24 #include "components/sync/api/sync_data.h" |
| 24 #include "components/sync/api/sync_error_factory_mock.h" | 25 #include "components/sync/api/sync_error_factory_mock.h" |
| 25 #include "components/sync/core/attachments/attachment_service_proxy_for_test.h" | 26 #include "components/sync/core/attachments/attachment_service_proxy_for_test.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 custodian_profile, | 126 custodian_profile, |
| 126 profile, | 127 profile, |
| 127 Profile::CREATE_STATUS_INITIALIZED); | 128 Profile::CREATE_STATUS_INITIALIZED); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // Mock this method to track when an attempt to open a new browser window for | 131 // Mock this method to track when an attempt to open a new browser window for |
| 131 // the newly created/imported profile is made. | 132 // the newly created/imported profile is made. |
| 132 MOCK_METHOD2(OpenNewWindowForProfile, | 133 MOCK_METHOD2(OpenNewWindowForProfile, |
| 133 void(Profile* profile, Profile::CreateStatus status)); | 134 void(Profile* profile, Profile::CreateStatus status)); |
| 134 | 135 |
| 136 // Mock this method so that we don't actually open the signin dialog during |
| 137 // the test. |
| 138 MOCK_METHOD1(OpenSigninDialogForProfile, void(Profile* profile)); |
| 139 |
| 135 // We don't actually need to register supervised users in the test. Mock this | 140 // We don't actually need to register supervised users in the test. Mock this |
| 136 // method to fake the registration part. | 141 // method to fake the registration part. |
| 137 MOCK_METHOD4(RegisterSupervisedUser, | 142 MOCK_METHOD4(RegisterSupervisedUser, |
| 138 void(bool create_shortcut, | 143 void(bool create_shortcut, |
| 139 const std::string& supervised_user_id, | 144 const std::string& supervised_user_id, |
| 140 Profile* custodian_profile, | 145 Profile* custodian_profile, |
| 141 Profile* new_profile)); | 146 Profile* new_profile)); |
| 142 | 147 |
| 143 #if defined(ENABLE_SUPERVISED_USERS) | 148 #if defined(ENABLE_SUPERVISED_USERS) |
| 144 // Calls the callback method to resume profile creation flow. | 149 // Calls the callback method to resume profile creation flow. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _)) | 339 EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _)) |
| 335 .WillOnce(Invoke(handler(), | 340 .WillOnce(Invoke(handler(), |
| 336 &TestSigninCreateProfileHandler::RealDoCreateProfile)); | 341 &TestSigninCreateProfileHandler::RealDoCreateProfile)); |
| 337 | 342 |
| 338 // Expect no calls to register a supervised user. | 343 // Expect no calls to register a supervised user. |
| 339 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)).Times(0); | 344 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)).Times(0); |
| 340 | 345 |
| 341 // Expect a new browser window for the new profile to be opened. | 346 // Expect a new browser window for the new profile to be opened. |
| 342 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _)); | 347 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _)); |
| 343 | 348 |
| 349 // Expect no signin dialog opened for the new profile. |
| 350 EXPECT_CALL(*handler(), OpenSigninDialogForProfile(_)).Times(0); |
| 351 |
| 344 // Create a non-supervised profile. | 352 // Create a non-supervised profile. |
| 345 base::ListValue list_args; | 353 base::ListValue list_args; |
| 346 list_args.AppendString(kTestProfileName); | 354 list_args.AppendString(kTestProfileName); |
| 347 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0)); | 355 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0)); |
| 348 list_args.AppendBoolean(false); // create_shortcut | 356 list_args.AppendBoolean(false); // create_shortcut |
| 349 list_args.AppendBoolean(false); // is_supervised | 357 list_args.AppendBoolean(false); // is_supervised |
| 350 handler()->CreateProfile(&list_args); | 358 handler()->CreateProfile(&list_args); |
| 351 | 359 |
| 352 // Expect a JS callbacks with the new profile information. | 360 // Expect a JS callbacks with the new profile information. |
| 353 EXPECT_EQ(1U, web_ui()->call_data().size()); | 361 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 364 ASSERT_TRUE(profile->GetString("name", &profile_name)); | 372 ASSERT_TRUE(profile->GetString("name", &profile_name)); |
| 365 EXPECT_NE("", profile_name); | 373 EXPECT_NE("", profile_name); |
| 366 std::string profile_path; | 374 std::string profile_path; |
| 367 ASSERT_TRUE(profile->GetString("filePath", &profile_path)); | 375 ASSERT_TRUE(profile->GetString("filePath", &profile_path)); |
| 368 EXPECT_NE("", profile_path); | 376 EXPECT_NE("", profile_path); |
| 369 bool is_supervised; | 377 bool is_supervised; |
| 370 ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised)); | 378 ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised)); |
| 371 ASSERT_FALSE(is_supervised); | 379 ASSERT_FALSE(is_supervised); |
| 372 } | 380 } |
| 373 | 381 |
| 382 TEST_F(SigninCreateProfileHandlerTest, CreateProfileWithForceSignin) { |
| 383 g_browser_process->local_state()->SetBoolean(prefs::kForceBrowserSignin, |
| 384 true); |
| 385 ASSERT_TRUE(signin::IsForceSigninEnabled()); |
| 386 |
| 387 // Expect the call to create the profile. |
| 388 EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _)) |
| 389 .WillOnce(Invoke(handler(), |
| 390 &TestSigninCreateProfileHandler::RealDoCreateProfile)); |
| 391 |
| 392 // Expect no calls to register a supervised user. |
| 393 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)).Times(0); |
| 394 |
| 395 // Expect no new browser window for the new profile. |
| 396 EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _)).Times(0); |
| 397 |
| 398 // Expect a signin dialog opened for the new profile. |
| 399 EXPECT_CALL(*handler(), OpenSigninDialogForProfile(_)).Times(1); |
| 400 |
| 401 base::ListValue list_args; |
| 402 list_args.AppendString(kTestProfileName); |
| 403 list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0)); |
| 404 list_args.AppendBoolean(false); // create_shortcut |
| 405 list_args.AppendBoolean(false); // is_supervised |
| 406 handler()->CreateProfile(&list_args); |
| 407 |
| 408 // Expect a JS callbacks with the new profile information. |
| 409 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 410 |
| 411 EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name()); |
| 412 |
| 413 std::string callback_name; |
| 414 ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name)); |
| 415 EXPECT_EQ("create-profile-success", callback_name); |
| 416 |
| 417 const base::DictionaryValue* profile; |
| 418 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsDictionary(&profile)); |
| 419 std::string profile_name; |
| 420 ASSERT_TRUE(profile->GetString("name", &profile_name)); |
| 421 EXPECT_NE("", profile_name); |
| 422 std::string profile_path; |
| 423 ASSERT_TRUE(profile->GetString("filePath", &profile_path)); |
| 424 EXPECT_NE("", profile_path); |
| 425 bool is_supervised; |
| 426 ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised)); |
| 427 ASSERT_FALSE(is_supervised); |
| 428 bool show_confirmation; |
| 429 ASSERT_TRUE(profile->GetBoolean("showConfirmation", &show_confirmation)); |
| 430 ASSERT_FALSE(show_confirmation); |
| 431 } |
| 432 |
| 374 #if defined(ENABLE_SUPERVISED_USERS) | 433 #if defined(ENABLE_SUPERVISED_USERS) |
| 375 | 434 |
| 376 TEST_F(SigninCreateProfileHandlerTest, CreateSupervisedUser) { | 435 TEST_F(SigninCreateProfileHandlerTest, CreateSupervisedUser) { |
| 377 // Expect the call to create the profile. | 436 // Expect the call to create the profile. |
| 378 EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _)) | 437 EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _)) |
| 379 .WillOnce(Invoke(handler(), | 438 .WillOnce(Invoke(handler(), |
| 380 &TestSigninCreateProfileHandler::RealDoCreateProfile)); | 439 &TestSigninCreateProfileHandler::RealDoCreateProfile)); |
| 381 | 440 |
| 382 // Expect the call to register the supervised user. | 441 // Expect the call to register the supervised user. |
| 383 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)) | 442 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)) |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 EXPECT_EQ("create-profile-error", callback_name); | 656 EXPECT_EQ("create-profile-error", callback_name); |
| 598 | 657 |
| 599 base::string16 expected_error_message = l10n_util::GetStringUTF16( | 658 base::string16 expected_error_message = l10n_util::GetStringUTF16( |
| 600 IDS_PROFILES_CREATE_SUPERVISED_NOT_ALLOWED_BY_POLICY); | 659 IDS_PROFILES_CREATE_SUPERVISED_NOT_ALLOWED_BY_POLICY); |
| 601 base::string16 error_message; | 660 base::string16 error_message; |
| 602 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message)); | 661 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message)); |
| 603 EXPECT_EQ(expected_error_message, error_message); | 662 EXPECT_EQ(expected_error_message, error_message); |
| 604 } | 663 } |
| 605 | 664 |
| 606 #endif | 665 #endif |
| OLD | NEW |