Commit 3bd49ab9 authored by James Cook's avatar James Cook Committed by Commit Bot

Add test helper for supervised user custodian setup

This logic was duplicated in 3 places, so consolidate in a new helper
function.

Bug: 1059085
Test: browser_tests, unit_tests
Change-Id: I5101d19f195f7ee9c1157330fa634a5f14b47cc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132332
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarDan S <danan@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756071}
parent 0382541b
......@@ -38,7 +38,7 @@
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/browser/supervised_user/supervised_user_test_util.h"
#include "extensions/browser/disable_reason.h"
#endif
......@@ -860,12 +860,8 @@ class ManagementApiSupervisedUserTest : public ManagementApiUnitTest {
void SetUp() override {
ManagementApiUnitTest::SetUp();
// Ensure the child has a custodian.
PrefService* prefs = browser()->profile()->GetPrefs();
prefs->SetString(prefs::kSupervisedUserCustodianEmail,
"test_parent_0@google.com");
prefs->SetString(prefs::kSupervisedUserCustodianObfuscatedGaiaId,
"239029320");
// Set up custodians (parents) for the child.
supervised_user_test_util::AddCustodians(browser()->profile());
// Set the pref to allow the child to request extension install.
SupervisedUserServiceFactory::GetForProfile(profile())
......
......@@ -51,9 +51,9 @@
#include "chrome/browser/supervised_user/supervised_user_features.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/supervised_user/supervised_user_test_util.h"
#include "chrome/browser/ui/supervised_user/parent_permission_dialog.h"
#include "chrome/browser/ui/views/parent_permission_dialog_view.h"
#include "chrome/common/pref_names.h"
#include "components/account_id/account_id.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "extensions/common/extension_builder.h"
......@@ -450,16 +450,7 @@ class ExtensionWebstorePrivateApiTestChild
void InitializeFamilyData() {
// Set up the child user's custodians (i.e. parents).
ASSERT_TRUE(browser());
PrefService* prefs = browser()->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");
supervised_user_test_util::AddCustodians(browser()->profile());
// Set up the identity test environment, which provides fake
// OAuth refresh tokens.
......
......@@ -17,3 +17,16 @@ grit("supervised_user_unscaled_resources") {
"root_gen_dir=" + rebase_path(root_gen_dir, root_build_dir),
]
}
static_library("test_support") {
testonly = true
sources = [
"supervised_user_test_util.cc",
"supervised_user_test_util.h",
]
deps = [
"//chrome/browser",
"//chrome/common:constants",
"//components/prefs",
]
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// 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 "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
namespace supervised_user_test_util {
void AddCustodians(Profile* profile) {
DCHECK(profile->IsSupervised());
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");
}
} // namespace supervised_user_test_util
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_TEST_UTIL_H_
#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_TEST_UTIL_H_
class Profile;
namespace supervised_user_test_util {
// Add custodians (e.g. parents) to |profile|, which must be a supervised user.
void AddCustodians(Profile* profile);
} // namespace supervised_user_test_util
#endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_TEST_UTIL_H_
......@@ -15,11 +15,11 @@
#include "chrome/browser/supervised_user/supervised_user_features.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/supervised_user/supervised_user_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/parent_permission_dialog_view.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "content/public/test/test_utils.h"
......@@ -112,16 +112,7 @@ class ParentPermissionDialogBrowserTest
void InitializeFamilyData() {
// Set up the child user's custodians (AKA parents).
ASSERT_TRUE(browser());
PrefService* prefs = browser()->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");
supervised_user_test_util::AddCustodians(browser()->profile());
// Set up the identity test environment, which provides fake
// OAuth refresh tokens.
......
......@@ -2679,6 +2679,7 @@ if (!is_android) {
if (enable_supervised_users) {
sources += [
# TODO(jamescook): Move to chrome/browser/supervised_users:test_support
"../browser/supervised_user/logged_in_user_mixin.cc",
"../browser/supervised_user/logged_in_user_mixin.h",
"../browser/supervised_user/navigation_finished_waiter.cc",
......@@ -2689,6 +2690,7 @@ if (!is_android) {
"../browser/supervised_user/supervised_user_service_browsertest.cc",
"../browser/supervised_user/supervised_user_url_filter_browsertest.cc",
]
deps += [ "//chrome/browser/supervised_user:test_support" ]
if (enable_extensions) {
sources += [
"../browser/supervised_user/supervised_user_extension_browsertest.cc",
......@@ -5426,6 +5428,7 @@ test("unit_tests") {
"../browser/supervised_user/supervised_user_whitelist_service_unittest.cc",
]
deps += [
"//chrome/browser/supervised_user:test_support",
"//chrome/browser/supervised_user/supervised_user_error_page:unit_tests",
]
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment