Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
James Cook | 3bd49ab | 2020-04-02 23:47:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/supervised_user/supervised_user_test_util.h" |
| 6 | |
Aga Wronska | e482265 | 2023-05-22 16:45:23 | [diff] [blame] | 7 | #include <string> |
| 8 | |
| 9 | #include "base/check.h" |
James Cook | 3bd49ab | 2020-04-02 23:47:55 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile.h" |
Nohemi Fernandez | dfc72df6 | 2023-03-22 13:08:19 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile_key.h" |
| 12 | #include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h" |
James Cook | 3bd49ab | 2020-04-02 23:47:55 | [diff] [blame] | 13 | #include "components/prefs/pref_service.h" |
Aga Wronska | e482265 | 2023-05-22 16:45:23 | [diff] [blame] | 14 | #include "components/signin/public/identity_manager/account_info.h" |
Nohemi Fernandez | dfc72df6 | 2023-03-22 13:08:19 | [diff] [blame] | 15 | #include "components/supervised_user/core/browser/supervised_user_settings_service.h" |
[email protected] | f1a9899c | 2023-01-26 16:48:24 | [diff] [blame] | 16 | #include "components/supervised_user/core/common/pref_names.h" |
Nohemi Fernandez | dfc72df6 | 2023-03-22 13:08:19 | [diff] [blame] | 17 | #include "components/supervised_user/core/common/supervised_user_constants.h" |
James Cook | 3bd49ab | 2020-04-02 23:47:55 | [diff] [blame] | 18 | |
| 19 | namespace supervised_user_test_util { |
| 20 | |
| 21 | void AddCustodians(Profile* profile) { |
Nohemi Fernandez | 1ee7df1 | 2021-12-06 10:34:05 | [diff] [blame] | 22 | DCHECK(profile->IsChild()); |
James Cook | 3bd49ab | 2020-04-02 23:47:55 | [diff] [blame] | 23 | PrefService* prefs = profile->GetPrefs(); |
| 24 | prefs->SetString(prefs::kSupervisedUserCustodianEmail, |
| 25 | "[email protected]"); |
| 26 | prefs->SetString(prefs::kSupervisedUserCustodianObfuscatedGaiaId, |
| 27 | "239029320"); |
| 28 | |
| 29 | prefs->SetString(prefs::kSupervisedUserSecondCustodianEmail, |
| 30 | "[email protected]"); |
| 31 | prefs->SetString(prefs::kSupervisedUserSecondCustodianObfuscatedGaiaId, |
| 32 | "85948533"); |
| 33 | } |
| 34 | |
Nohemi Fernandez | dfc72df6 | 2023-03-22 13:08:19 | [diff] [blame] | 35 | void SetSupervisedUserExtensionsMayRequestPermissionsPref(Profile* profile, |
| 36 | bool enabled) { |
| 37 | // TODO(crbug/1024646): kSupervisedUserExtensionsMayRequestPermissions is |
| 38 | // currently set indirectly by setting geolocation requests. Update Kids |
| 39 | // Management server to set a new bit for extension permissions and update |
| 40 | // this setter function. |
| 41 | supervised_user::SupervisedUserSettingsService* settings_service = |
| 42 | SupervisedUserSettingsServiceFactory::GetInstance()->GetForKey( |
| 43 | profile->GetProfileKey()); |
| 44 | settings_service->SetLocalSetting(supervised_user::kGeolocationDisabled, |
| 45 | base::Value(!enabled)); |
| 46 | profile->GetPrefs()->SetBoolean( |
| 47 | prefs::kSupervisedUserExtensionsMayRequestPermissions, enabled); |
| 48 | } |
| 49 | |
Aga Wronska | e482265 | 2023-05-22 16:45:23 | [diff] [blame] | 50 | void PopulateAccountInfoWithName(AccountInfo& info, |
| 51 | const std::string& given_name) { |
| 52 | info.given_name = given_name; |
| 53 | info.full_name = "fullname"; |
| 54 | info.hosted_domain = "example.com"; |
| 55 | info.locale = "en"; |
| 56 | info.picture_url = "https://example.com"; |
| 57 | |
| 58 | CHECK(info.IsValid()); |
| 59 | } |
| 60 | |
James Cook | 3bd49ab | 2020-04-02 23:47:55 | [
|