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 ...@@ -47,7 +47,7 @@ class SupervisionTransitionScreenTest
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
ASSERT_TRUE(logged_in_user_mixin_.RequestPolicyUpdate()); CHECK(logged_in_user_mixin_.GetUserPolicyMixin()->RequestPolicyUpdate());
arc::ArcServiceLauncher::Get()->ResetForTesting(); arc::ArcServiceLauncher::Get()->ResetForTesting();
arc::ArcSessionManager::Get()->SetArcSessionRunnerForTesting( arc::ArcSessionManager::Get()->SetArcSessionRunnerForTesting(
...@@ -108,7 +108,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, SuccessfulTransition) { ...@@ -108,7 +108,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, SuccessfulTransition) {
EXPECT_FALSE(ProfileManager::GetPrimaryUserProfile()->GetPrefs()->GetBoolean( EXPECT_FALSE(ProfileManager::GetPrimaryUserProfile()->GetPrefs()->GetBoolean(
arc::prefs::kArcDataRemoveRequested)); arc::prefs::kArcDataRemoveRequested));
logged_in_user_mixin().WaitForActiveSession(); logged_in_user_mixin().GetLoginManagerMixin()->WaitForActiveSession();
} }
IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, PRE_TransitionTimeout) { IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, PRE_TransitionTimeout) {
...@@ -151,7 +151,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, TransitionTimeout) { ...@@ -151,7 +151,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, TransitionTimeout) {
test::OobeJS().TapOnPath({"supervision-transition-md", "accept-button"}); 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, IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest,
...@@ -161,7 +161,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, ...@@ -161,7 +161,7 @@ IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest,
IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest, IN_PROC_BROWSER_TEST_P(SupervisionTransitionScreenTest,
SkipTransitionIfArcNeverStarted) { SkipTransitionIfArcNeverStarted) {
// Login should go through without being interrupted. // Login should go through without being interrupted.
logged_in_user_mixin().WaitForActiveSession(); logged_in_user_mixin().GetLoginManagerMixin()->WaitForActiveSession();
} }
INSTANTIATE_TEST_SUITE_P(/* no prefix */, INSTANTIATE_TEST_SUITE_P(/* no prefix */,
......
...@@ -10,21 +10,14 @@ ...@@ -10,21 +10,14 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/values.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/chromeos/login/users/chrome_user_manager.h"
#include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.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.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.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/common/chrome_features.h"
#include "chrome/test/base/mixin_based_in_process_browser_test.h" #include "chrome/test/base/mixin_based_in_process_browser_test.h"
#include "components/arc/arc_features.h" #include "components/arc/arc_features.h"
...@@ -38,32 +31,23 @@ ...@@ -38,32 +31,23 @@
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "net/dns/mock_host_resolver.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 { namespace policy {
class UserCloudPolicyManagerTest class UserCloudPolicyManagerTest
: public MixinBasedInProcessBrowserTest, : public MixinBasedInProcessBrowserTest,
public testing::WithParamInterface<std::vector<base::Feature>> { public testing::WithParamInterface<
std::tuple<std::vector<base::Feature>,
chromeos::LoggedInUserMixin::LogInType>> {
protected: protected:
UserCloudPolicyManagerTest() { UserCloudPolicyManagerTest() {
// Override default tests configuration that prevents effective testing of // Override default tests configuration that prevents effective testing of
// whether start-up URL policy is properly applied: // 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 // * InProcessBrowserTest force about://blank start-up URL via command
// line (which trumps policy values). // line (which trumps policy values).
login_manager_.set_should_launch_browser(true);
set_open_about_blank_on_browser_launch(false); set_open_about_blank_on_browser_launch(false);
scoped_feature_list_.InitWithFeatures( scoped_feature_list_.InitWithFeatures(
GetParam() /* enabled_features */, std::get<0>(GetParam()) /* enabled_features */,
std::vector<base::Feature>() /* disabled_features */); std::vector<base::Feature>() /* disabled_features */);
} }
...@@ -83,52 +67,23 @@ class UserCloudPolicyManagerTest ...@@ -83,52 +67,23 @@ class UserCloudPolicyManagerTest
MixinBasedInProcessBrowserTest::TearDown(); 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 // Sets up fake GAIA for specified user login, and requests login for the user
// (using GaiaScreenHandler test API). // (using LoggedInUserMixin).
void StartUserLogIn(const AccountId& account_id, void StartUserLogIn(bool wait_for_active_session) {
const std::string& password, logged_in_user_mixin_.LogInUser(false /*issue_any_scope_token*/,
bool child_user) { wait_for_active_session);
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);
} }
protected: protected:
AccountId test_account_id_ = chromeos::LoggedInUserMixin logged_in_user_mixin_{
AccountId::FromUserEmailGaiaId(chromeos::FakeGaiaMixin::kEnterpriseUser1, &mixin_host_, std::get<1>(GetParam()) /*type*/, embedded_test_server(),
kTestGaiaId); true /*should_launch_browser*/,
AccountId::FromUserEmailGaiaId(
// Initializing the login manager with no user will cause GAIA screen to be chromeos::FakeGaiaMixin::kEnterpriseUser1,
// shown on start-up. chromeos::FakeGaiaMixin::kEnterpriseUser1GaiaId),
chromeos::LoginManagerMixin login_manager_{&mixin_host_, {}}; // Initializing the login manager with no user will cause GAIA screen to
// be shown on start-up.
chromeos::EmbeddedTestServerSetupMixin embedded_test_server_setup_{ false /*include_initial_user*/};
&mixin_host_, embedded_test_server()};
chromeos::FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
chromeos::LocalPolicyTestServerMixin policy_server_{&mixin_host_};
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
...@@ -136,36 +91,30 @@ class UserCloudPolicyManagerTest ...@@ -136,36 +91,30 @@ class UserCloudPolicyManagerTest
DISALLOW_COPY_AND_ASSIGN(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 // Flaky: crbug.com/1005697, crbug.com/1005450
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) { IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) {
// User hasn't signed in yet, so shouldn't know if the user requires policy. // User hasn't signed in yet, so shouldn't know if the user requires policy.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::ProfileRequiresPolicy::kUnknown, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
// Set up start-up URLs through a mandatory user policy. // Set up start-up URLs through a mandatory user policy.
const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"}; const char* const kStartupURLs[] = {"chrome://policy", "chrome://about"};
base::Value mandatory_policy(base::Value::Type::DICTIONARY); enterprise_management::StringList* startup_urls_proto =
base::Value startup_urls(base::Value::Type::LIST); logged_in_user_mixin_.GetUserPolicyMixin()
->RequestPolicyUpdate()
->policy_payload()
->mutable_restoreonstartupurls()
->mutable_value();
for (auto* const url : kStartupURLs) for (auto* const url : kStartupURLs)
startup_urls.Append(base::Value(url)); startup_urls_proto->add_entries(url);
mandatory_policy.SetKey(key::kRestoreOnStartupURLs, std::move(startup_urls)); logged_in_user_mixin_.GetUserPolicyMixin()
mandatory_policy.SetKey(key::kRestoreOnStartup, ->RequestPolicyUpdate()
base::Value(SessionStartupPref::kPrefValueURLs)); ->policy_payload()
->mutable_restoreonstartup()
->set_value(SessionStartupPref::kPrefValueURLs);
SetMandatoryUserPolicy(test_account_id_, std::move(mandatory_policy)); StartUserLogIn(true /*wait_for_active_session*/);
StartUserLogIn(test_account_id_, kAccountPassword, false /*child_user*/);
login_manager_.WaitForActiveSession();
// User should be marked as having a valid OAuth token. // User should be marked as having a valid OAuth token.
const user_manager::UserManager* const user_manager = const user_manager::UserManager* const user_manager =
...@@ -189,9 +138,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) { ...@@ -189,9 +138,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) {
} }
// User should be marked as requiring policy. // User should be marked as requiring policy.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired,
user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
// It is expected that if ArcEnabled policy is not set then it is managed // It is expected that if ArcEnabled policy is not set then it is managed
// by default and user is not able manually set it. // by default and user is not able manually set it.
...@@ -203,18 +152,19 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) { ...@@ -203,18 +152,19 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, DISABLED_StartSession) {
// Flaky: crbug.com/1005697, crbug.com/1005452 // Flaky: crbug.com/1005697, crbug.com/1005452
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
DISABLED_ErrorLoadingPolicy) { 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(); RunUntilBrowserProcessQuits();
// Session should not have been started. // Session should not have been started.
EXPECT_FALSE(session_manager::SessionManager::Get()->IsSessionStarted()); EXPECT_FALSE(session_manager::SessionManager::Get()->IsSessionStarted());
// User should be marked as not knowing if policy is required yet. // User should be marked as not knowing if policy is required yet.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::ProfileRequiresPolicy::kUnknown, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
} }
// Flaky: crbug.com/1005697, crbug.com/1005455 // Flaky: crbug.com/1005697, crbug.com/1005455
...@@ -223,13 +173,13 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, ...@@ -223,13 +173,13 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
// Mark user as not needing policy - errors loading policy should be // Mark user as not needing policy - errors loading policy should be
// ignored (unlike previous ErrorLoadingPolicy test). // ignored (unlike previous ErrorLoadingPolicy test).
user_manager::known_user::SetProfileRequiresPolicy( user_manager::known_user::SetProfileRequiresPolicy(
test_account_id_, logged_in_user_mixin_.GetAccountId(),
user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired); 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*/); StartUserLogIn(true /*wait_for_active_session*/);
login_manager_.WaitForActiveSession();
// User should be marked as having a valid OAuth token. // User should be marked as having a valid OAuth token.
const user_manager::UserManager* const user_manager = const user_manager::UserManager* const user_manager =
...@@ -238,9 +188,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, ...@@ -238,9 +188,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
user_manager->GetActiveUser()->oauth_token_status()); user_manager->GetActiveUser()->oauth_token_status());
// User should still be marked as not needing policy // User should still be marked as not needing policy
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired,
user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
} }
// Flaky: crbug.com/1005697, crbug.com/1005451 // Flaky: crbug.com/1005697, crbug.com/1005451
...@@ -252,15 +202,14 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, ...@@ -252,15 +202,14 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting( policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting(
"example.com"); "example.com");
EXPECT_TRUE(policy::BrowserPolicyConnector::IsNonEnterpriseUser( 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 // If a user signs in with a known non-enterprise account there should be no
// policy. // policy.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::ProfileRequiresPolicy::kUnknown, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
StartUserLogIn(test_account_id_, kAccountPassword, false /*child_user*/); StartUserLogIn(true /*wait_for_active_session*/);
login_manager_.WaitForActiveSession();
// User should be marked as having a valid OAuth token. // User should be marked as having a valid OAuth token.
const user_manager::UserManager* const user_manager = const user_manager::UserManager* const user_manager =
...@@ -269,29 +218,32 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, ...@@ -269,29 +218,32 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
user_manager->GetActiveUser()->oauth_token_status()); user_manager->GetActiveUser()->oauth_token_status());
// User should be marked as not requiring policy. // User should be marked as not requiring policy.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired,
user_manager::known_user::ProfileRequiresPolicy::kNoPolicyRequired, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
} }
using UserCloudPolicyManagerChildTest = UserCloudPolicyManagerTest;
// Flaky: crbug.com/1005697, crbug.com/1005454 // Flaky: crbug.com/1005697, crbug.com/1005454
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerChildTest,
DISABLED_PolicyForChildUser) { DISABLED_PolicyForChildUser) {
policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting( policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting(
"example.com"); "example.com");
EXPECT_TRUE(policy::BrowserPolicyConnector::IsNonEnterpriseUser( 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 // If a user signs in with a known non-enterprise account there should be no
// policy in case user type is child. // policy in case user type is child.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::ProfileRequiresPolicy::kUnknown, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
SetMandatoryUserPolicy(test_account_id_, logged_in_user_mixin_.GetUserPolicyMixin()
base::Value(base::Value::Type::DICTIONARY)); ->RequestPolicyUpdate()
StartUserLogIn(test_account_id_, kAccountPassword, true /*child_user*/); ->policy_payload()
login_manager_.WaitForActiveSession(); ->Clear();
StartUserLogIn(true /*wait_for_active_session*/);
// User should be marked as having a valid OAuth token. // User should be marked as having a valid OAuth token.
const user_manager::UserManager* const user_manager = const user_manager::UserManager* const user_manager =
...@@ -300,9 +252,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, ...@@ -300,9 +252,9 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
user_manager->GetActiveUser()->oauth_token_status()); user_manager->GetActiveUser()->oauth_token_status());
// User of CHILD type should be marked as requiring policy. // User of CHILD type should be marked as requiring policy.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired,
user_manager::known_user::ProfileRequiresPolicy::kPolicyRequired, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
// It is expected that if ArcEnabled policy is not set then it is not managed // It is expected that if ArcEnabled policy is not set then it is not managed
// by default and user is able manually set it. // by default and user is able manually set it.
...@@ -312,29 +264,49 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, ...@@ -312,29 +264,49 @@ IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest,
} }
// Flaky: crbug.com/1005697, crbug.com/1005453 // Flaky: crbug.com/1005697, crbug.com/1005453
IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerTest, IN_PROC_BROWSER_TEST_P(UserCloudPolicyManagerChildTest,
DISABLED_PolicyForChildUserMissing) { DISABLED_PolicyForChildUserMissing) {
policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting( policy::BrowserPolicyConnector::SetNonEnterpriseDomainForTesting(
"example.com"); "example.com");
EXPECT_TRUE(policy::BrowserPolicyConnector::IsNonEnterpriseUser( 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 // If a user signs in with a known non-enterprise account there should be no
// policy in case user type is child. // policy in case user type is child.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::ProfileRequiresPolicy::kUnknown, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); logged_in_user_mixin_.GetAccountId()));
StartUserLogIn(test_account_id_, kAccountPassword, true /*child_user*/); StartUserLogIn(false /*wait_for_active_session*/);
RunUntilBrowserProcessQuits(); RunUntilBrowserProcessQuits();
// Session should not have been started. // Session should not have been started.
EXPECT_FALSE(session_manager::SessionManager::Get()->IsSessionStarted()); EXPECT_FALSE(session_manager::SessionManager::Get()->IsSessionStarted());
// User should be marked as not knowing if policy is required yet. // User should be marked as not knowing if policy is required yet.
EXPECT_EQ( EXPECT_EQ(user_manager::known_user::ProfileRequiresPolicy::kUnknown,
user_manager::known_user::ProfileRequiresPolicy::kUnknown, user_manager::known_user::GetProfileRequiresPolicy(
user_manager::known_user::GetProfileRequiresPolicy(test_account_id_)); 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 } // namespace policy
...@@ -4,17 +4,17 @@ ...@@ -4,17 +4,17 @@
#include "chrome/browser/supervised_user/logged_in_user_mixin.h" #include "chrome/browser/supervised_user/logged_in_user_mixin.h"
#include <vector>
#include "chromeos/login/auth/stub_authenticator_builder.h" #include "chromeos/login/auth/stub_authenticator_builder.h"
#include "chromeos/login/auth/user_context.h" #include "chromeos/login/auth/user_context.h"
#include "components/account_id/account_id.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
namespace chromeos { namespace chromeos {
namespace { namespace {
constexpr char kTestUserName[] = "user@gmail.com";
constexpr char kTestUserGaiaId[] = "user";
user_manager::UserType ConvertUserType(LoggedInUserMixin::LogInType type) { user_manager::UserType ConvertUserType(LoggedInUserMixin::LogInType type) {
switch (type) { switch (type) {
case LoggedInUserMixin::LogInType::kChild: case LoggedInUserMixin::LogInType::kChild:
...@@ -24,16 +24,28 @@ user_manager::UserType ConvertUserType(LoggedInUserMixin::LogInType type) { ...@@ -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 } // namespace
LoggedInUserMixin::LoggedInUserMixin( LoggedInUserMixin::LoggedInUserMixin(
InProcessBrowserTestMixinHost* mixin_host, InProcessBrowserTestMixinHost* mixin_host,
LogInType type, LogInType type,
net::EmbeddedTestServer* embedded_test_server, net::EmbeddedTestServer* embedded_test_server,
bool should_launch_browser) bool should_launch_browser,
: user_(AccountId::FromUserEmailGaiaId(kTestUserName, kTestUserGaiaId), base::Optional<AccountId> account_id,
bool include_initial_user)
: user_(account_id.value_or(
AccountId::FromUserEmailGaiaId(FakeGaiaMixin::kFakeUserEmail,
FakeGaiaMixin::kFakeUserGaiaId)),
ConvertUserType(type)), ConvertUserType(type)),
login_manager_(mixin_host, {user_}), login_manager_(mixin_host, GetInitialUsers(user_, include_initial_user)),
policy_server_(mixin_host), policy_server_(mixin_host),
user_policy_(mixin_host, user_.account_id, &policy_server_), user_policy_(mixin_host, user_.account_id, &policy_server_),
embedded_test_server_setup_(mixin_host, embedded_test_server), embedded_test_server_setup_(mixin_host, embedded_test_server),
...@@ -67,6 +79,7 @@ void LoggedInUserMixin::SetUpOnMainThreadHelper( ...@@ -67,6 +79,7 @@ void LoggedInUserMixin::SetUpOnMainThreadHelper(
void LoggedInUserMixin::LogInUser(bool issue_any_scope_token, void LoggedInUserMixin::LogInUser(bool issue_any_scope_token,
bool wait_for_active_session) { bool wait_for_active_session) {
UserContext user_context = LoginManagerMixin::CreateDefaultUserContext(user_); UserContext user_context = LoginManagerMixin::CreateDefaultUserContext(user_);
user_context.SetRefreshToken(FakeGaiaMixin::kFakeRefreshToken);
if (user_.user_type == user_manager::USER_TYPE_CHILD) { if (user_.user_type == user_manager::USER_TYPE_CHILD) {
fake_gaia_.SetupFakeGaiaForChildUser( fake_gaia_.SetupFakeGaiaForChildUser(
user_.account_id.GetUserEmail(), user_.account_id.GetGaiaId(), user_.account_id.GetUserEmail(), user_.account_id.GetGaiaId(),
...@@ -76,7 +89,6 @@ void LoggedInUserMixin::LogInUser(bool issue_any_scope_token, ...@@ -76,7 +89,6 @@ void LoggedInUserMixin::LogInUser(bool issue_any_scope_token,
user_.account_id.GetGaiaId(), user_.account_id.GetGaiaId(),
FakeGaiaMixin::kFakeRefreshToken); FakeGaiaMixin::kFakeRefreshToken);
} }
user_context.SetRefreshToken(FakeGaiaMixin::kFakeRefreshToken);
if (wait_for_active_session) { if (wait_for_active_session) {
login_manager_.LoginAndWaitForActiveSession(user_context); login_manager_.LoginAndWaitForActiveSession(user_context);
} else { } else {
......
...@@ -6,26 +6,46 @@ ...@@ -6,26 +6,46 @@
#define CHROME_BROWSER_SUPERVISED_USER_LOGGED_IN_USER_MIXIN_H_ #define CHROME_BROWSER_SUPERVISED_USER_LOGGED_IN_USER_MIXIN_H_
#include "base/macros.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/embedded_test_server_mixin.h"
#include "chrome/browser/chromeos/login/test/fake_gaia_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/local_policy_test_server_mixin.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h" #include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/test/user_policy_mixin.h" #include "chrome/browser/chromeos/login/test/user_policy_mixin.h"
class AccountId;
namespace chromeos { namespace chromeos {
// Compound mixin class for child user browser tests. // Compound mixin class for easily logging in as regular or child accounts for
// Supports logging in as regular or child accounts. // browser tests. Initiates other mixins required to log in users, sets up their
// Initiates other mixins required to log in users, sets up their user policies // user policies and gaia auth.
// and gaia auth.
class LoggedInUserMixin { class LoggedInUserMixin {
public: public:
enum class LogInType { kRegular, kChild }; 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, LoggedInUserMixin(InProcessBrowserTestMixinHost* mixin_host,
LogInType type, LogInType type,
net::EmbeddedTestServer* embedded_test_server, 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(); ~LoggedInUserMixin();
// Helper function for refactoring common setup code. // Helper function for refactoring common setup code.
...@@ -52,16 +72,16 @@ class LoggedInUserMixin { ...@@ -52,16 +72,16 @@ class LoggedInUserMixin {
void LogInUser(bool issue_any_scope_token = false, void LogInUser(bool issue_any_scope_token = false,
bool wait_for_active_session = true); bool wait_for_active_session = true);
// Waits for the session state to change to ACTIVE. Returns immediately if the LoginManagerMixin* GetLoginManagerMixin() { return &login_manager_; }
// session is already active.
void WaitForActiveSession() { login_manager_.WaitForActiveSession(); }
// Creates scoped user policy update from UserPolicyMixin. LocalPolicyTestServerMixin* GetLocalPolicyTestServerMixin() {
// See UserPolicyMixin::RequestPolicyUpdate() for more info. return &policy_server_;
std::unique_ptr<ScopedUserPolicyUpdate> RequestPolicyUpdate() {
return user_policy_.RequestPolicyUpdate();
} }
UserPolicyMixin* GetUserPolicyMixin() { return &user_policy_; }
const AccountId& GetAccountId() { return user_.account_id; }
private: private:
LoginManagerMixin::TestUserInfo user_; LoginManagerMixin::TestUserInfo user_;
LoginManagerMixin login_manager_; 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