| 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/browser/ui/webui/signin/signin_utils.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 19 #include "chrome/test/base/browser_with_test_window_test.h" | 19 #include "chrome/test/base/browser_with_test_window_test.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chrome/test/base/testing_profile_manager.h" | 21 #include "chrome/test/base/testing_profile_manager.h" |
| 22 #include "components/signin/core/browser/fake_auth_status_provider.h" | 22 #include "components/signin/core/browser/fake_auth_status_provider.h" |
| 23 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" | 23 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" |
| 24 #include "components/sync/model/fake_sync_change_processor.h" | 24 #include "components/sync/model/fake_sync_change_processor.h" |
| 25 #include "components/sync/model/sync_data.h" | 25 #include "components/sync/model/sync_data.h" |
| 26 #include "components/sync/model/sync_error_factory_mock.h" | 26 #include "components/sync/model/sync_error_factory_mock.h" |
| 27 #include "components/sync/protocol/sync.pb.h" | 27 #include "components/sync/protocol/sync.pb.h" |
| 28 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 28 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 29 #include "content/public/test/test_web_ui.h" | 29 #include "content/public/test/test_web_ui.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 33 | 33 |
| 34 #if defined(ENABLE_SUPERVISED_USERS) | 34 #if defined(ENABLE_SUPERVISED_USERS) |
| 35 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" | 35 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" |
| 36 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac
tory.h" | 36 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac
tory.h" |
| 37 #endif | 37 #endif |
| 38 | 38 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Creates the profile synchronously, sets the appropriate flag and calls the | 103 // Creates the profile synchronously, sets the appropriate flag and calls the |
| 104 // callback method to resume profile creation flow. | 104 // callback method to resume profile creation flow. |
| 105 void RealDoCreateProfile(const base::string16& name, | 105 void RealDoCreateProfile(const base::string16& name, |
| 106 const std::string& icon_url, | 106 const std::string& icon_url, |
| 107 bool create_shortcut, | 107 bool create_shortcut, |
| 108 const std::string& supervised_user_id, | 108 const std::string& supervised_user_id, |
| 109 Profile* custodian_profile) { | 109 Profile* custodian_profile) { |
| 110 // Create the profile synchronously. | 110 // Create the profile synchronously. |
| 111 Profile* profile = profile_manager_->CreateTestingProfile( | 111 Profile* profile = profile_manager_->CreateTestingProfile( |
| 112 kTestProfileName, | 112 kTestProfileName, |
| 113 std::unique_ptr<syncable_prefs::TestingPrefServiceSyncable>(), | 113 std::unique_ptr<sync_preferences::TestingPrefServiceSyncable>(), name, |
| 114 name, | 114 0, supervised_user_id, TestingProfile::TestingFactories()); |
| 115 0, | |
| 116 supervised_user_id, | |
| 117 TestingProfile::TestingFactories()); | |
| 118 | 115 |
| 119 // Set the flag used to track the state of the creation flow. | 116 // Set the flag used to track the state of the creation flow. |
| 120 profile_path_being_created_ = profile->GetPath(); | 117 profile_path_being_created_ = profile->GetPath(); |
| 121 | 118 |
| 122 // Call the callback method to resume profile creation flow. | 119 // Call the callback method to resume profile creation flow. |
| 123 SigninCreateProfileHandler::OnProfileCreated( | 120 SigninCreateProfileHandler::OnProfileCreated( |
| 124 create_shortcut, | 121 create_shortcut, |
| 125 supervised_user_id, | 122 supervised_user_id, |
| 126 custodian_profile, | 123 custodian_profile, |
| 127 profile, | 124 profile, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 ASSERT_TRUE(profile_manager_->SetUp()); | 175 ASSERT_TRUE(profile_manager_->SetUp()); |
| 179 | 176 |
| 180 handler_.reset(new TestSigninCreateProfileHandler(web_ui(), | 177 handler_.reset(new TestSigninCreateProfileHandler(web_ui(), |
| 181 profile_manager())); | 178 profile_manager())); |
| 182 | 179 |
| 183 TestingProfile::TestingFactories factories; | 180 TestingProfile::TestingFactories factories; |
| 184 factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(), | 181 factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(), |
| 185 BuildFakeSigninManagerBase)); | 182 BuildFakeSigninManagerBase)); |
| 186 custodian_ = profile_manager_.get()->CreateTestingProfile( | 183 custodian_ = profile_manager_.get()->CreateTestingProfile( |
| 187 "custodian-profile", | 184 "custodian-profile", |
| 188 std::unique_ptr<syncable_prefs::TestingPrefServiceSyncable>(), | 185 std::unique_ptr<sync_preferences::TestingPrefServiceSyncable>(), |
| 189 base::UTF8ToUTF16("custodian-profile"), | 186 base::UTF8ToUTF16("custodian-profile"), 0, std::string(), factories); |
| 190 0, | |
| 191 std::string(), | |
| 192 factories); | |
| 193 | 187 |
| 194 // Authenticate the custodian profile. | 188 // Authenticate the custodian profile. |
| 195 fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>( | 189 fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>( |
| 196 SigninManagerFactory::GetForProfile(custodian_)); | 190 SigninManagerFactory::GetForProfile(custodian_)); |
| 197 fake_signin_manager_->SetAuthenticatedAccountInfo(kTestGaiaId1, | 191 fake_signin_manager_->SetAuthenticatedAccountInfo(kTestGaiaId1, |
| 198 kTestEmail1); | 192 kTestEmail1); |
| 199 | 193 |
| 200 #if defined(ENABLE_SUPERVISED_USERS) | 194 #if defined(ENABLE_SUPERVISED_USERS) |
| 201 // Add supervised users to the custodian profile. | 195 // Add supervised users to the custodian profile. |
| 202 SupervisedUserSyncService* sync_service_ = | 196 SupervisedUserSyncService* sync_service_ = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 214 std::unique_ptr<syncer::SyncChangeProcessor>( | 208 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 215 new syncer::FakeSyncChangeProcessor()), | 209 new syncer::FakeSyncChangeProcessor()), |
| 216 std::unique_ptr<syncer::SyncErrorFactory>( | 210 std::unique_ptr<syncer::SyncErrorFactory>( |
| 217 new syncer::SyncErrorFactoryMock())); | 211 new syncer::SyncErrorFactoryMock())); |
| 218 EXPECT_FALSE(result.error().IsSet()); | 212 EXPECT_FALSE(result.error().IsSet()); |
| 219 EXPECT_EQ(2u, sync_service_->GetSupervisedUsers()->size()); | 213 EXPECT_EQ(2u, sync_service_->GetSupervisedUsers()->size()); |
| 220 | 214 |
| 221 // The second supervised user exists on the device. | 215 // The second supervised user exists on the device. |
| 222 profile_manager()->CreateTestingProfile( | 216 profile_manager()->CreateTestingProfile( |
| 223 kSupervisedUsername2, | 217 kSupervisedUsername2, |
| 224 std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), | 218 std::unique_ptr<sync_preferences::PrefServiceSyncable>(), |
| 225 base::UTF8ToUTF16(kSupervisedUsername2), | 219 base::UTF8ToUTF16(kSupervisedUsername2), 0, |
| 226 0, | |
| 227 kSupervisedUserId2, // supervised_user_id | 220 kSupervisedUserId2, // supervised_user_id |
| 228 TestingProfile::TestingFactories()); | 221 TestingProfile::TestingFactories()); |
| 229 | 222 |
| 230 EXPECT_EQ(2u, | 223 EXPECT_EQ(2u, |
| 231 profile_manager()->profile_attributes_storage()->GetNumberOfProfiles()); | 224 profile_manager()->profile_attributes_storage()->GetNumberOfProfiles()); |
| 232 #endif | 225 #endif |
| 233 } | 226 } |
| 234 | 227 |
| 235 void TearDown() override { | 228 void TearDown() override { |
| 236 handler_.reset(); | 229 handler_.reset(); |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 EXPECT_EQ("create-profile-error", callback_name); | 649 EXPECT_EQ("create-profile-error", callback_name); |
| 657 | 650 |
| 658 base::string16 expected_error_message = l10n_util::GetStringUTF16( | 651 base::string16 expected_error_message = l10n_util::GetStringUTF16( |
| 659 IDS_PROFILES_CREATE_SUPERVISED_NOT_ALLOWED_BY_POLICY); | 652 IDS_PROFILES_CREATE_SUPERVISED_NOT_ALLOWED_BY_POLICY); |
| 660 base::string16 error_message; | 653 base::string16 error_message; |
| 661 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message)); | 654 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message)); |
| 662 EXPECT_EQ(expected_error_message, error_message); | 655 EXPECT_EQ(expected_error_message, error_message); |
| 663 } | 656 } |
| 664 | 657 |
| 665 #endif | 658 #endif |
| OLD | NEW |