blob: 548912bc29ba7a5970ae24e45d594467e32e1b01 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
James Cook3bd49ab2020-04-02 23:47:552// 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 Wronskae4822652023-05-22 16:45:237#include <string>
8
9#include "base/check.h"
James Cook3bd49ab2020-04-02 23:47:5510#include "chrome/browser/profiles/profile.h"
Nohemi Fernandezdfc72df62023-03-22 13:08:1911#include "chrome/browser/profiles/profile_key.h"
12#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
James Cook3bd49ab2020-04-02 23:47:5513#include "components/prefs/pref_service.h"
Aga Wronskae4822652023-05-22 16:45:2314#include "components/signin/public/identity_manager/account_info.h"
Nohemi Fernandezdfc72df62023-03-22 13:08:1915#include "components/supervised_user/core/browser/supervised_user_settings_service.h"
[email protected]f1a9899c2023-01-26 16:48:2416#include "components/supervised_user/core/common/pref_names.h"
Nohemi Fernandezdfc72df62023-03-22 13:08:1917#include "components/supervised_user/core/common/supervised_user_constants.h"
James Cook3bd49ab2020-04-02 23:47:5518
19namespace supervised_user_test_util {
20
21void AddCustodians(Profile* profile) {
Nohemi Fernandez1ee7df12021-12-06 10:34:0522 DCHECK(profile->IsChild());
James Cook3bd49ab2020-04-02 23:47:5523 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 Fernandezdfc72df62023-03-22 13:08:1935void 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 Wronskae4822652023-05-22 16:45:2350void 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
Liza Bipin1302f072023-09-19 11:37:5061void SetManualFilterForHost(Profile* profile,
62 const std::string& host,
63 bool allowlist) {
64 supervised_user::SupervisedUserSettingsService* settings_service =
65 SupervisedUserSettingsServiceFactory::GetForKey(profile->GetProfileKey());
66
67 const base::Value::Dict& local_settings =
68 settings_service->LocalSettingsForTest();
69 base::Value::Dict dict_to_insert;
70
71 if (const base::Value::Dict* dict_value = local_settings.FindDict(
72 supervised_user::kContentPackManualBehaviorHosts)) {
73 dict_to_insert = dict_value->Clone();
74 }
75
76 dict_to_insert.Set(host, allowlist);
77 settings_service->SetLocalSetting(
78 supervised_user::kContentPackManualBehaviorHosts,
79 std::move(dict_to_insert));
80}
81
James Cook3bd49ab2020-04-02 23:47:5582} // namespace supervised_user_test_util