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

Side by Side Diff: chrome/browser/ui/webui/signin/signin_create_profile_handler_unittest.cc

Issue 2468723003: Move session service and supervised users to buildflags. (Closed)
Patch Set: Created 4 years, 1 month 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/signin/signin_create_profile_handler.cc ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/features.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
19 #include "chrome/test/base/browser_with_test_window_test.h" 20 #include "chrome/test/base/browser_with_test_window_test.h"
20 #include "chrome/test/base/testing_browser_process.h" 21 #include "chrome/test/base/testing_browser_process.h"
21 #include "chrome/test/base/testing_profile_manager.h" 22 #include "chrome/test/base/testing_profile_manager.h"
22 #include "components/signin/core/browser/fake_auth_status_provider.h" 23 #include "components/signin/core/browser/fake_auth_status_provider.h"
23 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" 24 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h"
24 #include "components/sync/model/fake_sync_change_processor.h" 25 #include "components/sync/model/fake_sync_change_processor.h"
25 #include "components/sync/model/sync_data.h" 26 #include "components/sync/model/sync_data.h"
26 #include "components/sync/model/sync_error_factory_mock.h" 27 #include "components/sync/model/sync_error_factory_mock.h"
27 #include "components/sync/protocol/sync.pb.h" 28 #include "components/sync/protocol/sync.pb.h"
28 #include "components/sync_preferences/testing_pref_service_syncable.h" 29 #include "components/sync_preferences/testing_pref_service_syncable.h"
29 #include "content/public/test/test_web_ui.h" 30 #include "content/public/test/test_web_ui.h"
30 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
33 34
34 #if defined(ENABLE_SUPERVISED_USERS) 35 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
35 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service.h" 36 #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" 37 #include "chrome/browser/supervised_user/legacy/supervised_user_sync_service_fac tory.h"
37 #endif 38 #endif
38 39
39 // Gmock matchers and actions. 40 // Gmock matchers and actions.
40 using testing::_; 41 using testing::_;
41 using testing::Invoke; 42 using testing::Invoke;
42 43
43 namespace { 44 namespace {
44 45
45 const char kTestProfileName[] = "test-profile-name"; 46 const char kTestProfileName[] = "test-profile-name";
46 47
47 const char kTestGaiaId1[] = "test-gaia-id-1"; 48 const char kTestGaiaId1[] = "test-gaia-id-1";
48 const char kTestEmail1[] = "foo1@bar.com"; 49 const char kTestEmail1[] = "foo1@bar.com";
49 50
50 const char kTestGaiaId2[] = "test-gaia-id-2"; 51 const char kTestGaiaId2[] = "test-gaia-id-2";
51 const char kTestEmail2[] = "foo2@bar.com"; 52 const char kTestEmail2[] = "foo2@bar.com";
52 53
53 const char kTestWebUIResponse[] = "cr.webUIListenerCallback"; 54 const char kTestWebUIResponse[] = "cr.webUIListenerCallback";
54 55
55 #if defined(ENABLE_SUPERVISED_USERS) 56 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
56 const char kSupervisedUserId1[] = "test-supervised-id-1"; 57 const char kSupervisedUserId1[] = "test-supervised-id-1";
57 const char kSupervisedUserId2[] = "test-supervised-id-2"; 58 const char kSupervisedUserId2[] = "test-supervised-id-2";
58 59
59 const char kSupervisedUsername1[] = "test-supervised-username-1"; 60 const char kSupervisedUsername1[] = "test-supervised-username-1";
60 const char kSupervisedUsername2[] = "test-supervised-username-2"; 61 const char kSupervisedUsername2[] = "test-supervised-username-2";
61 62
62 const char kSupervisedUserAvatarName1[] = "chrome-avatar-index:0"; 63 const char kSupervisedUserAvatarName1[] = "chrome-avatar-index:0";
63 const char kSupervisedUserAvatarName2[] = "chrome-avatar-index:1"; 64 const char kSupervisedUserAvatarName2[] = "chrome-avatar-index:1";
64 65
65 syncer::SyncData CreateSyncData(const std::string& id, 66 syncer::SyncData CreateSyncData(const std::string& id,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 MOCK_METHOD1(OpenSigninDialogForProfile, void(Profile* profile)); 136 MOCK_METHOD1(OpenSigninDialogForProfile, void(Profile* profile));
136 137
137 // We don't actually need to register supervised users in the test. Mock this 138 // We don't actually need to register supervised users in the test. Mock this
138 // method to fake the registration part. 139 // method to fake the registration part.
139 MOCK_METHOD4(RegisterSupervisedUser, 140 MOCK_METHOD4(RegisterSupervisedUser,
140 void(bool create_shortcut, 141 void(bool create_shortcut,
141 const std::string& supervised_user_id, 142 const std::string& supervised_user_id,
142 Profile* custodian_profile, 143 Profile* custodian_profile,
143 Profile* new_profile)); 144 Profile* new_profile));
144 145
145 #if defined(ENABLE_SUPERVISED_USERS) 146 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
146 // Calls the callback method to resume profile creation flow. 147 // Calls the callback method to resume profile creation flow.
147 void RealRegisterSupervisedUser(bool create_shortcut, 148 void RealRegisterSupervisedUser(bool create_shortcut,
148 const std::string& supervised_user_id, 149 const std::string& supervised_user_id,
149 Profile* custodian_profile, 150 Profile* custodian_profile,
150 Profile* new_profile) { 151 Profile* new_profile) {
151 // Call the callback method to resume profile creation flow. 152 // Call the callback method to resume profile creation flow.
152 SigninCreateProfileHandler::OnSupervisedUserRegistered( 153 SigninCreateProfileHandler::OnSupervisedUserRegistered(
153 create_shortcut, 154 create_shortcut,
154 custodian_profile, 155 custodian_profile,
155 new_profile, 156 new_profile,
(...skipping 28 matching lines...) Expand all
184 "custodian-profile", 185 "custodian-profile",
185 std::unique_ptr<sync_preferences::TestingPrefServiceSyncable>(), 186 std::unique_ptr<sync_preferences::TestingPrefServiceSyncable>(),
186 base::UTF8ToUTF16("custodian-profile"), 0, std::string(), factories); 187 base::UTF8ToUTF16("custodian-profile"), 0, std::string(), factories);
187 188
188 // Authenticate the custodian profile. 189 // Authenticate the custodian profile.
189 fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>( 190 fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>(
190 SigninManagerFactory::GetForProfile(custodian_)); 191 SigninManagerFactory::GetForProfile(custodian_));
191 fake_signin_manager_->SetAuthenticatedAccountInfo(kTestGaiaId1, 192 fake_signin_manager_->SetAuthenticatedAccountInfo(kTestGaiaId1,
192 kTestEmail1); 193 kTestEmail1);
193 194
194 #if defined(ENABLE_SUPERVISED_USERS) 195 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
195 // Add supervised users to the custodian profile. 196 // Add supervised users to the custodian profile.
196 SupervisedUserSyncService* sync_service_ = 197 SupervisedUserSyncService* sync_service_ =
197 SupervisedUserSyncServiceFactory::GetForProfile(custodian_); 198 SupervisedUserSyncServiceFactory::GetForProfile(custodian_);
198 syncer::SyncDataList sync_data; 199 syncer::SyncDataList sync_data;
199 sync_data.push_back(CreateSyncData(kSupervisedUserId1, 200 sync_data.push_back(CreateSyncData(kSupervisedUserId1,
200 kSupervisedUsername1, 201 kSupervisedUsername1,
201 kSupervisedUserAvatarName1)); 202 kSupervisedUserAvatarName1));
202 sync_data.push_back(CreateSyncData(kSupervisedUserId2, 203 sync_data.push_back(CreateSyncData(kSupervisedUserId2,
203 kSupervisedUsername2, 204 kSupervisedUsername2,
204 kSupervisedUserAvatarName2)); 205 kSupervisedUserAvatarName2));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 ASSERT_TRUE(profile->GetString("filePath", &profile_path)); 417 ASSERT_TRUE(profile->GetString("filePath", &profile_path));
417 EXPECT_NE("", profile_path); 418 EXPECT_NE("", profile_path);
418 bool is_supervised; 419 bool is_supervised;
419 ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised)); 420 ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised));
420 ASSERT_FALSE(is_supervised); 421 ASSERT_FALSE(is_supervised);
421 bool show_confirmation; 422 bool show_confirmation;
422 ASSERT_TRUE(profile->GetBoolean("showConfirmation", &show_confirmation)); 423 ASSERT_TRUE(profile->GetBoolean("showConfirmation", &show_confirmation));
423 ASSERT_FALSE(show_confirmation); 424 ASSERT_FALSE(show_confirmation);
424 } 425 }
425 426
426 #if defined(ENABLE_SUPERVISED_USERS) 427 #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
427 428
428 TEST_F(SigninCreateProfileHandlerTest, CreateSupervisedUser) { 429 TEST_F(SigninCreateProfileHandlerTest, CreateSupervisedUser) {
429 // Expect the call to create the profile. 430 // Expect the call to create the profile.
430 EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _)) 431 EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _))
431 .WillOnce(Invoke(handler(), 432 .WillOnce(Invoke(handler(),
432 &TestSigninCreateProfileHandler::RealDoCreateProfile)); 433 &TestSigninCreateProfileHandler::RealDoCreateProfile));
433 434
434 // Expect the call to register the supervised user. 435 // Expect the call to register the supervised user.
435 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)) 436 EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _))
436 .WillOnce(Invoke( 437 .WillOnce(Invoke(
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 EXPECT_EQ("create-profile-error", callback_name); 650 EXPECT_EQ("create-profile-error", callback_name);
650 651
651 base::string16 expected_error_message = l10n_util::GetStringUTF16( 652 base::string16 expected_error_message = l10n_util::GetStringUTF16(
652 IDS_PROFILES_CREATE_SUPERVISED_NOT_ALLOWED_BY_POLICY); 653 IDS_PROFILES_CREATE_SUPERVISED_NOT_ALLOWED_BY_POLICY);
653 base::string16 error_message; 654 base::string16 error_message;
654 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message)); 655 ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsString(&error_message));
655 EXPECT_EQ(expected_error_message, error_message); 656 EXPECT_EQ(expected_error_message, error_message);
656 } 657 }
657 658
658 #endif 659 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/signin_create_profile_handler.cc ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698