blob: cc79833c5dd601d379ec472e128c1c4ff6307e60 [file] [log] [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/supervised_user/supervised_user_test_util.h"
#include <string>
#include "base/check.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/supervised_user/supervised_user_settings_service_factory.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/supervised_user/core/browser/supervised_user_settings_service.h"
#include "components/supervised_user/core/common/pref_names.h"
#include "components/supervised_user/core/common/supervised_user_constants.h"
namespace supervised_user_test_util {
void AddCustodians(Profile* profile) {
DCHECK(profile->IsChild());
PrefService* prefs = profile->GetPrefs();
prefs->SetString(prefs::kSupervisedUserCustodianEmail,
"test_parent_0@google.com");
prefs->SetString(prefs::kSupervisedUserCustodianObfuscatedGaiaId,
"239029320");
prefs->SetString(prefs::kSupervisedUserSecondCustodianEmail,
"test_parent_1@google.com");
prefs->SetString(prefs::kSupervisedUserSecondCustodianObfuscatedGaiaId,
"85948533");
}
void SetSupervisedUserExtensionsMayRequestPermissionsPref(Profile* profile,
bool enabled) {
// TODO(crbug/1024646): kSupervisedUserExtensionsMayRequestPermissions is
// currently set indirectly by setting geolocation requests. Update Kids
// Management server to set a new bit for extension permissions and update
// this setter function.
supervised_user::SupervisedUserSettingsService* settings_service =
SupervisedUserSettingsServiceFactory::GetInstance()->GetForKey(
profile->GetProfileKey());
settings_service->SetLocalSetting(supervised_user::kGeolocationDisabled,
base::Value(!enabled));
profile->GetPrefs()->SetBoolean(
prefs::kSupervisedUserExtensionsMayRequestPermissions, enabled);
}
void SetSkipParentApprovalToInstallExtensionsPref(Profile* profile,
bool enabled) {
// TODO(b/324898798): Once the new extension handling mode is releaded, this
// method replaces `SetSupervisedUserExtensionsMayRequestPermissionsPref` for
// handling the Extensions behaviour.
supervised_user::SupervisedUserSettingsService* settings_service =
SupervisedUserSettingsServiceFactory::GetInstance()->GetForKey(
profile->GetProfileKey());
settings_service->SetLocalSetting(
supervised_user::kSkipParentApprovalToInstallExtensions,
base::Value(enabled));
profile->GetPrefs()->SetBoolean(prefs::kSkipParentApprovalToInstallExtensions,
enabled);
}
void PopulateAccountInfoWithName(AccountInfo& info,
const std::string& given_name) {
info.given_name = given_name;
info.full_name = "fullname";
info.hosted_domain = "example.com";
info.locale = "en";
info.picture_url = "https://example.com";
CHECK(info.IsValid());
}
void SetManualFilterForHost(Profile* profile,
const std::string& host,
bool allowlist) {
supervised_user::SupervisedUserSettingsService* settings_service =
SupervisedUserSettingsServiceFactory::GetForKey(profile->GetProfileKey());
const base::Value::Dict& local_settings =
settings_service->LocalSettingsForTest();
base::Value::Dict dict_to_insert;
if (const base::Value::Dict* dict_value = local_settings.FindDict(
supervised_user::kContentPackManualBehaviorHosts)) {
dict_to_insert = dict_value->Clone();
}
dict_to_insert.Set(host, allowlist);
settings_service->SetLocalSetting(
supervised_user::kContentPackManualBehaviorHosts,
std::move(dict_to_insert));
}
} // namespace supervised_user_test_util