Commit 846d6841 authored by Toby Huang's avatar Toby Huang Committed by Commit Bot

Refactor UserCloudPolicyManagerTest to use LoggedInUserMixin.

UserCloudPolicyManagerTest uses a lot of login functionality that's
centralized within LoggedInUserMixin. Avoid code duplication by
refactoring UserCloudPolicyManagerTest to use LoggedInUserMixin for
logging in.

Bug: 990909
Change-Id: I929c7182e8fc178191b8cc722ea6bbd6987b3411
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1796562Reviewed-by: default avatarDenis Kuznetsov <antrim@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Commit-Queue: Toby Huang <tobyhuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698550}
parent cae14279
......@@ -47,7 +47,7 @@ class SupervisionTransitionScreenTest
}
void SetUpOnMainThread() override {
ASSERT_TRUE(logged_in_user_mixin_.RequestPolicyUpdate());
CHECK(logged_in_user_mixin_.GetUserPolicyMixin()->RequestPolicyUpdate());
arc::ArcServiceLauncher::Get()->ResetForTesting();
arc::ArcSessionManager::Get()->SetArcSessionRunnerForTesting(
......@@ -108,7 +108,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, SuccessfulTransition) {
EXPECT_FALSE(ProfileManager::GetPrimaryUserProfile()->GetPrefs()->GetBoolean(
arc::prefs::kArcDataRemoveRequested));
logged_in_user_mixin().WaitForActiveSession();
logged_in_user_mixin().GetLoginManagerMixin()->WaitForActiveSession();
}
IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, PRE_TransitionTimeout) {
......@@ -151,7 +151,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, TransitionTimeout) {
test::OobeJS().TapOnPath({"supervision-transition-md", "accept-button"});
logged_in_user_mixin().WaitForActiveSession();
logged_in_user_mixin().GetLoginManagerMixin()->WaitForActiveSession();
}
IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest,
......@@ -161,7 +161,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest,
IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest,
SkipTransitionIfArcNeverStarted) {
// Login should go through without being interrupted.
logged_in_user_mixin().WaitForActiveSession();
logged_in_user_mixin().GetLoginManagerMixin()->WaitForActiveSession();
}
INSTANTIATE_TEST_SUITE_P(/* no prefix */,
......
......@@ -10,21 +10,14 @@
#include "base/stl_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "chrome/browser/chromeos/child_accounts/child_account_test_utils.h"
#include "chrome/browser/chromeos/login/test/embedded_test_server_mixin.h"
#include "chrome/browser/chromeos/login/test/fake_gaia_mixin.h"
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/supervised_user/logged_in_user_mixin.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "components/arc/arc_features.h"
......@@ -38,32 +31,23 @@
#include "components/user_manager/user_manager.h"
#include "net/dns/mock_host_resolver.h"
namespace {
// The information supplied by FakeGaia for our mocked-out signin.
constexpr char kTestGaiaId[] = "12345";
constexpr char kAccountPassword[] = "fake-password";
constexpr char kTestRefreshToken[] = "fake-refresh-token";
} // namespace
namespace policy {
class UserCloudPolicyManagerTest
: public MixinBasedInProcessBrowserTest,
public testing::WithParamInterface<std::vector<base::Feature>> {
public testing::WithParamInterface<
std::tuple<std::vector<base::Feature>,
chromeos::LoggedInUserMixin::LogInType>> {
protected:
UserCloudPolicyManagerTest() {
// Override default tests configuration that prevents effective testing of
// whether start-up URL policy is properly applied:
// * LoginManagerMixin skips browser launch after log-in by default.
// * InProcessBrowserTest force about://blank start-up URL via command
// line (which trumps policy values).
login_manager_.set_should_launch_browser(true);
set_open_about_blank_on_browser_launch(false);
scoped_feature_list_.InitWithFeatures(
GetParam() /* enabled_features */,
std::get<0>(GetParam()) /* enabled_features */,
std::vector<base::Feature>() /* disabled_features */);
}
......@@ -83,52 +67,23 @@ class UserCloudPolicyManagerTest
MixinBasedInProcessBrowserTest::TearDown();
}
void SetMandatoryUserPolicy(const AccountId& account_id,
base::Value mandatory_policy) {
ASSERT_TRUE(policy_server_.UpdateUserPolicy(
std::move(mandatory_policy),
base::Value(base::Value::Type::DICTIONARY) /* recommended policy */,
account_id.GetUserEmail()));
}
// Sets up fake GAIA for specified user login, and requests login for the user
// (using GaiaScreenHandler test API).
void StartUserLogIn(const AccountId& account_id,
const std::string& password,
bool child_user) {
fake_gaia_.SetupFakeGaiaForLogin(account_id.GetUserEmail(),
account_id.GetGaiaId(), kTestRefreshToken);
fake_gaia_.fake_gaia()->SetFakeMergeSessionParams(
account_id.GetUserEmail(), "fake-SID-cookie", "fake-LSID-cookie");
FakeGaia::MergeSessionParams merge_session_update;
merge_session_update.id_token =
child_user ? chromeos::test::GetChildAccountOAuthIdToken() : "";
fake_gaia_.fake_gaia()->UpdateMergeSessionParams(merge_session_update);
const std::string services =
child_user ? chromeos::test::kChildAccountServiceFlags : "[]";
chromeos::LoginDisplayHost::default_host()
->GetOobeUI()
->GetView<chromeos::GaiaScreenHandler>()
->ShowSigninScreenForTest(account_id.GetUserEmail(), password,
services);
// (using LoggedInUserMixin).
void StartUserLogIn(bool wait_for_active_session) {
logged_in_user_mixin_.LogInUser(false /*issue_any_scope_token*/,
wait_for_active_session);
}
protected:
AccountId test_account_id_ =
AccountId::FromUserEmailGaiaId(chromeos::FakeGaiaMixin::kEnterpriseUser1,
kTestGaiaId);
// Initializing the login manager with no user will cause GAIA screen to be
// shown on start-up.
chromeos::LoginManagerMixin login_manager_{&mixin_host_, {}};
chromeos::EmbeddedTestServerSetupMixin embedded_test_server_setup_{
&mixin_host_, embedded_test_server()};
chromeos::FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
chromeos::LocalPolicyTestServerMixin policy_server_{&mixin_host_};
chromeos::LoggedInUserMixin logged_in_user_mixin_{
&mixin_host_, std::get<1>(GetParam()) /*type*/, embedded_test_server(),
true /*should_launch_browser*/,
AccountId::FromUserEmailGaiaId(
chromeos::FakeGaiaMixin::kEnterpriseUser1,
chromeos::FakeGaiaMixin::kEnterpriseUser1GaiaId),
// Initializing the login manager with no user will cause GAIA screen to
// be shown on start-up.
false /*include_initial_user*/};
private:
base::test::ScopedFeatureList scoped_feature_list_;
......@@ -136,36 +91,30 @@ class UserCloudPolicyManagerTest
DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyManagerTest);
};
// TODO(agawronska): Remove test instantiation with kDMServerOAuthForChildUser
// once it is enabled by default.
INSTANTIATE_TEST_SUITE_P(
/* no prefix */,
UserCloudPolicyManagerTest,
testing::Values(std::vector<base::Feature>(),
std::vector<base::Feature>{
features::kDMServerOAuthForChildUser}));
// Flaky: crbug.com/1005697, crbug.com/1005450
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) {
// User hasn't signed in yet, so shouldn't know if the user requires policy.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
// Set up start-up URLs through a mandatory user policy.
const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"};
base::Value mandatory_policy(base::Value::Type::DICTIONARY);
base::Value startup_urls(base::Value::Type::LIST);
enterprise_management::StringList* startup_urls_proto =
logged_in_user_mixin_.GetUserPolicyMixin()
->RequestPolicyUpdate()
->policy_payload()
->mutable_restoreonstartupurls()
->mutable_value();
for (auto* const url : kStartupURLs)
startup_urls.Append(base::Value(url));
mandatory_policy.SetKey(key::kRestoreOnStartupURLs, std::move(startup_urls));
mandatory_policy.SetKey(key::kRestoreOnStartup,
base::Value(SessionStartupPref::kPrefValueURLs));
startup_urls_proto->add_entries(url);
logged_in_user_mixin_.GetUserPolicyMixin()
->RequestPolicyUpdate()
->policy_payload()
->mutable_restoreonstartup()
->set_value(SessionStartupPref::kPrefValueURLs);
SetMandatoryUserPolicy(test_account_id_, std::move(mandatory_policy));
StartUserLogIn(test_account_id_, kAccountPassword, false /*child_user*/);
login_manager_.WaitForActiveSession();
StartUserLogIn(true /*wait_for_active_session*/);
// User should be marked as having a valid OAuth token.
const user_manager::UserManager* const user_manager =
......@@ -189,9 +138,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) {
}
// User should be marked as requiring policy.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
// It is expected that if ArcEnabled policy is not set then it is managed
// by default and user is not able manually set it.
......@@ -203,18 +152,19 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) {
// Flaky: crbug.com/1005697, crbug.com/1005452
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
DISABLED_ErrorLoadingPolicy) {
policy_server_.SetExpectedPolicyFetchError(500);
logged_in_user_mixin_.GetLocalPolicyTestServerMixin()
->SetExpectedPolicyFetchError(500);
StartUserLogIn(test_account_id_, kAccountPassword, false /*child_user*/);
StartUserLogIn(false /*wait_for_active_session*/);
RunUntilBrowserProcessQuits();
// Session should not have been started.
EXPECT_FALSE(session_manager::SessionManager::Get()->IsSessionStarted());
// User should be marked as not knowing if policy is required yet.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
}
// Flaky: crbug.com/1005697, crbug.com/1005455
......@@ -223,13 +173,13 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
// Mark user as not needing policy - errors loading policy should be
// ignored (unlike previous ErrorLoadingPolicy test).
user_manager::known_user::SetProfileRequiresPolicy(
test_account_id_,
logged_in_user_mixin_.GetAccountId(),
user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired);
policy_server_.SetExpectedPolicyFetchError(500);
logged_in_user_mixin_.GetLocalPolicyTestServerMixin()
->SetExpectedPolicyFetchError(500);
StartUserLogIn(test_account_id_, kAccountPassword, false /*child_user*/);
login_manager_.WaitForActiveSession();
StartUserLogIn(true /*wait_for_active_session*/);
// User should be marked as having a valid OAuth token.
const user_manager::UserManager* const user_manager =
......@@ -238,9 +188,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
user_manager->GetActiveUser()->oauth_token_status());
// User should still be marked as not needing policy
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
}
// Flaky: crbug.com/1005697, crbug.com/1005451
......@@ -252,15 +202,14 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting(
"example.com");
EXPECT_TRUE(policy::BrowserPolicyConnector::IsNonEnterpriseUser(
test_account_id_.GetUserEmail()));
logged_in_user_mixin_.GetAccountId().GetUserEmail()));
// If a user signs in with a known non-enterprise account there should be no
// policy.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
StartUserLogIn(test_account_id_, kAccountPassword, false /*child_user*/);
login_manager_.WaitForActiveSession();
StartUserLogIn(true /*wait_for_active_session*/);
// User should be marked as having a valid OAuth token.
const user_manager::UserManager* const user_manager =
......@@ -269,29 +218,32 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
user_manager->GetActiveUser()->oauth_token_status());
// User should be marked as not requiring policy.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
}
using UserCloudPolicyManagerChildTest = UserCloudPolicyManagerTest;
// Flaky: crbug.com/1005697, crbug.com/1005454
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerChildTest,
DISABLED_PolicyForChildUser) {
policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting(
"example.com");
EXPECT_TRUE(policy::BrowserPolicyConnector::IsNonEnterpriseUser(
test_account_id_.GetUserEmail()));
logged_in_user_mixin_.GetAccountId().GetUserEmail()));
// If a user signs in with a known non-enterprise account there should be no
// policy in case user type is child.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
SetMandatoryUserPolicy(test_account_id_,
base::Value(base::Value::Type::DICTIONARY));
StartUserLogIn(test_account_id_, kAccountPassword, true /*child_user*/);
login_manager_.WaitForActiveSession();
logged_in_user_mixin_.GetUserPolicyMixin()
->RequestPolicyUpdate()
->policy_payload()
->Clear();
StartUserLogIn(true /*wait_for_active_session*/);
// User should be marked as having a valid OAuth token.
const user_manager::UserManager* const user_manager =
......@@ -300,9 +252,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
user_manager->GetActiveUser()->oauth_token_status());
// User of CHILD type should be marked as requiring policy.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
// It is expected that if ArcEnabled policy is not set then it is not managed
// by default and user is able manually set it.
......@@ -312,29 +264,49 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
}
// Flaky: crbug.com/1005697, crbug.com/1005453
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerChildTest,
DISABLED_PolicyForChildUserMissing) {
policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting(
"example.com");
EXPECT_TRUE(policy::BrowserPolicyConnector::IsNonEnterpriseUser(
test_account_id_.GetUserEmail()));
logged_in_user_mixin_.GetAccountId().GetUserEmail()));
// If a user signs in with a known non-enterprise account there should be no
// policy in case user type is child.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
StartUserLogIn(test_account_id_, kAccountPassword, true /*child_user*/);
StartUserLogIn(false /*wait_for_active_session*/);
RunUntilBrowserProcessQuits();
// Session should not have been started.
EXPECT_FALSE(session_manager::SessionManager::Get()->IsSessionStarted());
// User should be marked as not knowing if policy is required yet.
EXPECT_EQ(
user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_));
EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::GetProfileRequiresPolicy(
logged_in_user_mixin_.GetAccountId()));
}
const std::vector<base::Feature> feature_lists[] = {
{},
{features::kDMServerOAuthForChildUser}};
// TODO(agawronska): Remove test instantiation with kDMServerOAuthForChildUser
// once it is enabled by default.
INSTANTIATE_TEST_SUITE_P(
/* no prefix */,
UserCloudPolicyManagerTest,
testing::Combine(
testing::ValuesIn(feature_lists),
testing::Values(chromeos::LoggedInUserMixin::LogInType::kRegular)));
INSTANTIATE_TEST_SUITE_P(
/* no prefix */,
UserCloudPolicyManagerChildTest,
testing::Combine(
testing::ValuesIn(feature_lists),
testing::Values(chromeos::LoggedInUserMixin::LogInType::kChild)));
} // namespace policy
......@@ -4,17 +4,17 @@
#include "chrome/browser/supervised_user/logged_in_user_mixin.h"
#include <vector>
#include "chromeos/login/auth/stub_authenticator_builder.h"
#include "chromeos/login/auth/user_context.h"
#include "components/account_id/account_id.h"
#include "net/dns/mock_host_resolver.h"
namespace chromeos {
namespace {
constexpr char kTestUserName[] = "user@gmail.com";
constexpr char kTestUserGaiaId[] = "user";
user_manager::UserType ConvertUserType(LoggedInUserMixin::LogInType type) {
switch (type) {
case LoggedInUserMixin::LogInType::kChild:
......@@ -24,16 +24,28 @@ user_manager::UserType ConvertUserType(LoggedInUserMixin::LogInType type) {
}
}
std::vector<LoginManagerMixin::TestUserInfo> GetInitialUsers(
const LoginManagerMixin::TestUserInfo& user,
bool include_initial_user) {
if (include_initial_user)
return {user};
return {};
}
} // namespace
LoggedInUserMixin::LoggedInUserMixin(
InProcessBrowserTestMixinHost* mixin_host,
LogInType type,
net::EmbeddedTestServer* embedded_test_server,
bool should_launch_browser)
: user_(AccountId::FromUserEmailGaiaId(kTestUserName, kTestUserGaiaId),
bool should_launch_browser,
base::Optional<AccountId> account_id,
bool include_initial_user)
: user_(account_id.value_or(
AccountId::FromUserEmailGaiaId(FakeGaiaMixin::kFakeUserEmail,
FakeGaiaMixin::kFakeUserGaiaId)),
ConvertUserType(type)),
login_manager_(mixin_host, {user_}),
login_manager_(mixin_host, GetInitialUsers(user_, include_initial_user)),
policy_server_(mixin_host),
user_policy_(mixin_host, user_.account_id, &policy_server_),
embedded_test_server_setup_(mixin_host, embedded_test_server),
......@@ -67,6 +79,7 @@ void LoggedInUserMixin::SetUpOnMainThreadHelper(
void LoggedInUserMixin::LogInUser(bool issue_any_scope_token,
bool wait_for_active_session) {
UserContext user_context = LoginManagerMixin::CreateDefaultUserContext(user_);
user_context.SetRefreshToken(FakeGaiaMixin::kFakeRefreshToken);
if (user_.user_type == user_manager::USER_TYPE_CHILD) {
fake_gaia_.SetupFakeGaiaForChildUser(
user_.account_id.GetUserEmail(), user_.account_id.GetGaiaId(),
......@@ -76,7 +89,6 @@ void LoggedInUserMixin::LogInUser(bool issue_any_scope_token,
user_.account_id.GetGaiaId(),
FakeGaiaMixin::kFakeRefreshToken);
}
user_context.SetRefreshToken(FakeGaiaMixin::kFakeRefreshToken);
if (wait_for_active_session) {
login_manager_.LoginAndWaitForActiveSession(user_context);
} else {
......
......@@ -6,26 +6,46 @@
#define CHROME_BROWSER_SUPERVISED_USER_LOGGED_IN_USER_MIXIN_H_
#include "base/macros.h"
#include "base/optional.h"
#include "chrome/browser/chromeos/login/test/embedded_test_server_mixin.h"
#include "chrome/browser/chromeos/login/test/fake_gaia_mixin.h"
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/test/user_policy_mixin.h"
class AccountId;
namespace chromeos {
// Compound mixin class for child user browser tests.
// Supports logging in as regular or child accounts.
// Initiates other mixins required to log in users, sets up their user policies
// and gaia auth.
// Compound mixin class for easily logging in as regular or child accounts for
// browser tests. Initiates other mixins required to log in users, sets up their
// user policies and gaia auth.
class LoggedInUserMixin {
public:
enum class LogInType { kRegular, kChild };
// |mixin_host| coordinates the other mixins and usually gets passed in from a
// descendant of MixinBasedInProcessBrowserTest.
// |type| specifies the desired user log in type, currently either regular or
// child.
// |embedded_test_server| usually gets passed in from a descendant of
// BrowserTestBase.
// |should_launch_browser| determines whether a browser instance is launched
// after successful login. Call SelectFirstBrowser() afterwards to ensure
// calls to browser() don't return nullptr. SetUpOnMainThreadHelper() already
// packages the calls to LoginUser() and SelectFirstBrowser() together for
// convenience.
// |account_id| is the desired test account id for logging in. The default
// test account already works for the majority of test cases, unless an
// enterprise account is needed for setting up policy.
// |include_initial_user| determines whether the TestUserInfo should be passed
// to the initial users list of the LoginManagerMixin.
LoggedInUserMixin(InProcessBrowserTestMixinHost* mixin_host,
LogInType type,
net::EmbeddedTestServer* embedded_test_server,
bool should_launch_browser = true);
bool should_launch_browser = true,
base::Optional<AccountId> account_id = base::nullopt,
bool include_initial_user = true);
~LoggedInUserMixin();
// Helper function for refactoring common setup code.
......@@ -52,16 +72,16 @@ class LoggedInUserMixin {
void LogInUser(bool issue_any_scope_token = false,
bool wait_for_active_session = true);
// Waits for the session state to change to ACTIVE. Returns immediately if the
// session is already active.
void WaitForActiveSession() { login_manager_.WaitForActiveSession(); }
LoginManagerMixin* GetLoginManagerMixin() { return &login_manager_; }
// Creates scoped user policy update from UserPolicyMixin.
// See UserPolicyMixin::RequestPolicyUpdate() for more info.
std::unique_ptr<ScopedUserPolicyUpdate> RequestPolicyUpdate() {
return user_policy_.RequestPolicyUpdate();
LocalPolicyTestServerMixin* GetLocalPolicyTestServerMixin() {
return &policy_server_;
}
UserPolicyMixin* GetUserPolicyMixin() { return &user_policy_; }
const AccountId& GetAccountId() { return user_.account_id; }
private:
LoginManagerMixin::TestUserInfo user_;
LoginManagerMixin login_manager_;
......
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