Commit 7d5271d9 authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

Migrate moar tests to LoginManagerMixin

Bug: 1067260
Change-Id: Ic86579fd50c5815c9adadbd3feade22cbd1c37a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144146Reviewed-by: default avatarRoman Aleksandrov <raleksandrov@google.com>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760159}
parent dd0dcf3a
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/login_wizard.h" #include "chrome/browser/chromeos/login/login_wizard.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"
...@@ -44,10 +45,6 @@ using ::testing::Return; ...@@ -44,10 +45,6 @@ using ::testing::Return;
namespace chromeos { namespace chromeos {
namespace { namespace {
const char kGaiaId[] = "12345";
const char kTestUser[] = "test-user@gmail.com";
const char kPassword[] = "password";
class LoginUserTest : public InProcessBrowserTest { class LoginUserTest : public InProcessBrowserTest {
protected: protected:
void SetUpCommandLine(base::CommandLine* command_line) override { void SetUpCommandLine(base::CommandLine* command_line) override {
...@@ -67,37 +64,20 @@ class LoginCursorTest : public OobeBaseTest { ...@@ -67,37 +64,20 @@ class LoginCursorTest : public OobeBaseTest {
~LoginCursorTest() override = default; ~LoginCursorTest() override = default;
}; };
class LoginSigninTest : public InProcessBrowserTest { using LoginSigninTest = LoginManagerTest;
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kLoginManager);
command_line->AppendSwitch(switches::kForceLoginManagerInTests);
}
void SetUpOnMainThread() override { class LoginOfflineTest : public LoginManagerTest {
LoginDisplayHostWebUI::DisableRestrictiveProxyCheckForTest();
}
};
class LoginTest : public MixinBasedInProcessBrowserTest {
public: public:
LoginTest() = default; LoginOfflineTest() {
~LoginTest() override {} login_manager_.AppendRegularUsers(1);
test_account_id_ = login_manager_.users()[0].account_id;
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
MixinBasedInProcessBrowserTest::SetUpOnMainThread();
} }
~LoginOfflineTest() override {}
protected: protected:
const LoginManagerMixin::TestUserInfo test_user_{ AccountId test_account_id_;
AccountId::FromUserEmailGaiaId(kTestUser, kGaiaId), LoginManagerMixin login_manager_{&mixin_host_};
user_manager::USER_TYPE_REGULAR};
LoginManagerMixin login_manager_{&mixin_host_, {test_user_}};
OfflineGaiaTestMixin offline_gaia_test_mixin_{&mixin_host_}; OfflineGaiaTestMixin offline_gaia_test_mixin_{&mixin_host_};
EmbeddedTestServerSetupMixin embedded_test_server_{&mixin_host_,
embedded_test_server()};
// We need Fake gaia to avoid network errors that can be caused by // We need Fake gaia to avoid network errors that can be caused by
// attempts to load real GAIA. // attempts to load real GAIA.
FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()}; FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
...@@ -182,16 +162,17 @@ IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) { ...@@ -182,16 +162,17 @@ IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) {
.Wait(); .Wait();
} }
IN_PROC_BROWSER_TEST_F(LoginTest, PRE_GaiaAuthOffline) { IN_PROC_BROWSER_TEST_F(LoginOfflineTest, PRE_GaiaAuthOffline) {
offline_gaia_test_mixin_.PrepareOfflineGaiaLogin(); offline_gaia_test_mixin_.PrepareOfflineGaiaLogin();
} }
IN_PROC_BROWSER_TEST_F(LoginTest, GaiaAuthOffline) { IN_PROC_BROWSER_TEST_F(LoginOfflineTest, GaiaAuthOffline) {
offline_gaia_test_mixin_.GoOffline(); offline_gaia_test_mixin_.GoOffline();
offline_gaia_test_mixin_.InitOfflineLogin(test_user_.account_id, kPassword); offline_gaia_test_mixin_.InitOfflineLogin(test_account_id_,
LoginManagerTest::kPassword);
offline_gaia_test_mixin_.CheckManagedStatus(false); offline_gaia_test_mixin_.CheckManagedStatus(false);
offline_gaia_test_mixin_.SubmitGaiaAuthOfflineForm( offline_gaia_test_mixin_.SubmitGaiaAuthOfflineForm(
test_user_.account_id.GetUserEmail(), kPassword, test_account_id_.GetUserEmail(), LoginManagerTest::kPassword,
true /* wait for sign-in */); true /* wait for sign-in */);
TestSystemTrayIsVisible(false); TestSystemTrayIsVisible(false);
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/startup_utils.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/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/test/oobe_base_test.h" #include "chrome/browser/chromeos/login/test/oobe_base_test.h"
#include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
#include "chrome/browser/chromeos/login/test/session_manager_state_waiter.h" #include "chrome/browser/chromeos/login/test/session_manager_state_waiter.h"
...@@ -35,13 +36,6 @@ namespace chromeos { ...@@ -35,13 +36,6 @@ namespace chromeos {
namespace { namespace {
struct {
const char* email;
const char* gaia_id;
} const kTestUsers[] = {{"test-user1@consumer.example.com", "1111111111"},
{"test-user2@consumer.example.com", "2222222222"},
{"test-user3@consumer.example.com", "3333333333"}};
// Helper class to wait for user adding screen to finish. // Helper class to wait for user adding screen to finish.
class UserAddingScreenWaiter : public UserAddingScreen::Observer { class UserAddingScreenWaiter : public UserAddingScreen::Observer {
public: public:
...@@ -108,14 +102,15 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, OobeNewUser) { ...@@ -108,14 +102,15 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, OobeNewUser) {
// Login via fake gaia to add a new user. // Login via fake gaia to add a new user.
fake_gaia_.SetupFakeGaiaForLoginManager(); fake_gaia_.SetupFakeGaiaForLoginManager();
fake_gaia_.fake_gaia()->SetFakeMergeSessionParams(kTestUsers[0].email, fake_gaia_.fake_gaia()->SetFakeMergeSessionParams(
"fake_sid", "fake_lsid"); FakeGaiaMixin::kFakeUserEmail, "fake_sid", "fake_lsid");
StartSignInScreen(); StartSignInScreen();
LoginDisplayHost::default_host() LoginDisplayHost::default_host()
->GetOobeUI() ->GetOobeUI()
->GetView<GaiaScreenHandler>() ->GetView<GaiaScreenHandler>()
->ShowSigninScreenForTest(kTestUsers[0].email, "fake_password", "[]"); ->ShowSigninScreenForTest(FakeGaiaMixin::kFakeUserEmail, "fake_password",
"[]");
test::WaitForPrimaryUserSessionStart(); test::WaitForPrimaryUserSessionStart();
...@@ -124,14 +119,17 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, OobeNewUser) { ...@@ -124,14 +119,17 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, OobeNewUser) {
EXPECT_EQ(1u, manager->sessions().size()); EXPECT_EQ(1u, manager->sessions().size());
} }
IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, PRE_LoginExistingUsers) { class ChromeSessionManagerExistingUsersTest : public ChromeSessionManagerTest {
for (const auto& user : kTestUsers) { public:
RegisterUser(AccountId::FromUserEmailGaiaId(user.email, user.gaia_id)); ChromeSessionManagerExistingUsersTest() {
login_manager_.AppendRegularUsers(3);
} }
StartupUtils::MarkOobeCompleted();
}
IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) { LoginManagerMixin login_manager_{&mixin_host_};
};
IN_PROC_BROWSER_TEST_F(ChromeSessionManagerExistingUsersTest,
LoginExistingUsers) {
// Verify that session state is LOGIN_PRIMARY with existing user data dir. // Verify that session state is LOGIN_PRIMARY with existing user data dir.
session_manager::SessionManager* manager = session_manager::SessionManager* manager =
session_manager::SessionManager::Get(); session_manager::SessionManager::Get();
...@@ -139,16 +137,14 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) { ...@@ -139,16 +137,14 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) {
manager->session_state()); manager->session_state());
EXPECT_EQ(0u, manager->sessions().size()); EXPECT_EQ(0u, manager->sessions().size());
std::vector<AccountId> test_users; const auto& users = login_manager_.users();
test_users.push_back(AccountId::FromUserEmailGaiaId(kTestUsers[0].email,
kTestUsers[0].gaia_id));
// Verify that session state is ACTIVE with one user session after signing // Verify that session state is ACTIVE with one user session after signing
// in a user. // in a user.
LoginUser(test_users[0]); LoginUser(users[0].account_id);
EXPECT_EQ(session_manager::SessionState::ACTIVE, manager->session_state()); EXPECT_EQ(session_manager::SessionState::ACTIVE, manager->session_state());
EXPECT_EQ(1u, manager->sessions().size()); EXPECT_EQ(1u, manager->sessions().size());
for (size_t i = 1; i < base::size(kTestUsers); ++i) { for (size_t i = 1; i < users.size(); ++i) {
// Verify that session state is LOGIN_SECONDARY during user adding. // Verify that session state is LOGIN_SECONDARY during user adding.
UserAddingScreen::Get()->Start(); UserAddingScreen::Get()->Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -158,9 +154,7 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) { ...@@ -158,9 +154,7 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) {
// Verify that session state is ACTIVE with 1+i user sessions after user // Verify that session state is ACTIVE with 1+i user sessions after user
// is added and new user session is started.. // is added and new user session is started..
UserAddingScreenWaiter waiter; UserAddingScreenWaiter waiter;
test_users.push_back(AccountId::FromUserEmailGaiaId(kTestUsers[i].email, AddUser(users[i].account_id);
kTestUsers[i].gaia_id));
AddUser(test_users.back());
waiter.Wait(); waiter.Wait();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -169,9 +163,9 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) { ...@@ -169,9 +163,9 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) {
} }
// Verify that session manager has the correct user session info. // Verify that session manager has the correct user session info.
ASSERT_EQ(test_users.size(), manager->sessions().size()); ASSERT_EQ(users.size(), manager->sessions().size());
for (size_t i = 0; i < test_users.size(); ++i) { for (size_t i = 0; i < users.size(); ++i) {
EXPECT_EQ(test_users[i], manager->sessions()[i].user_account_id); EXPECT_EQ(users[i].account_id, manager->sessions()[i].user_account_id);
} }
} }
...@@ -192,14 +186,15 @@ class ChromeSessionManagerRlzTest : public ChromeSessionManagerTest { ...@@ -192,14 +186,15 @@ class ChromeSessionManagerRlzTest : public ChromeSessionManagerTest {
// Login via fake gaia to add a new user. // Login via fake gaia to add a new user.
fake_gaia_.SetupFakeGaiaForLoginManager(); fake_gaia_.SetupFakeGaiaForLoginManager();
fake_gaia_.fake_gaia()->SetFakeMergeSessionParams(kTestUsers[0].email, fake_gaia_.fake_gaia()->SetFakeMergeSessionParams(
"fake_sid", "fake_lsid"); FakeGaiaMixin::kFakeUserEmail "fake_sid", "fake_lsid");
StartSignInScreen(); StartSignInScreen();
LoginDisplayHost::default_host() LoginDisplayHost::default_host()
->GetOobeUI() ->GetOobeUI()
->GetView<GaiaScreenHandler>() ->GetView<GaiaScreenHandler>()
->ShowSigninScreenForTest(kTestUsers[0].email, "fake_password", "[]"); ->ShowSigninScreenForTest(FakeGaiaMixin::kFakeUserEmail,
"fake_password", "[]");
test::WaitForPrimaryUserSessionStart(); test::WaitForPrimaryUserSessionStart();
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/device_state_mixin.h" #include "chrome/browser/chromeos/login/test/device_state_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/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h"
#include "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_util.h" #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_util.h"
#include "chrome/browser/chromeos/login/users/chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
...@@ -84,12 +85,6 @@ namespace chromeos { ...@@ -84,12 +85,6 @@ namespace chromeos {
namespace { namespace {
// Because policy is not needed in some tests it is better to use e-mails that
// are definitely not enterprise. This lets us to avoid faking of policy fetch
// procedure.
constexpr char kTestUserEmail1[] = "test-user@gmail.com";
constexpr char kTestUserEmail2[] = "test-user2@gmail.com";
constexpr char kRandomTokenStrForTesting[] = "random-token-str-for-testing"; constexpr char kRandomTokenStrForTesting[] = "random-token-str-for-testing";
policy::CloudPolicyStore* GetStoreForUser(const user_manager::User* user) { policy::CloudPolicyStore* GetStoreForUser(const user_manager::User* user) {
...@@ -133,8 +128,8 @@ class UserImageChangeWaiter : public user_manager::UserManager::Observer { ...@@ -133,8 +128,8 @@ class UserImageChangeWaiter : public user_manager::UserManager::Observer {
} // namespace } // namespace
class UserImageManagerTest : public LoginManagerTest, class UserImageManagerTestBase : public LoginManagerTest,
public user_manager::UserManager::Observer { public user_manager::UserManager::Observer {
public: public:
std::unique_ptr<net::test_server::BasicHttpResponse> HandleRequest( std::unique_ptr<net::test_server::BasicHttpResponse> HandleRequest(
const net::test_server::HttpRequest& request) { const net::test_server::HttpRequest& request) {
...@@ -169,7 +164,7 @@ class UserImageManagerTest : public LoginManagerTest, ...@@ -169,7 +164,7 @@ class UserImageManagerTest : public LoginManagerTest,
} }
protected: protected:
UserImageManagerTest() = default; UserImageManagerTestBase() = default;
// LoginManagerTest overrides: // LoginManagerTest overrides:
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
...@@ -200,17 +195,6 @@ class UserImageManagerTest : public LoginManagerTest, ...@@ -200,17 +195,6 @@ class UserImageManagerTest : public LoginManagerTest,
LoginManagerTest::SetUpOnMainThread(); LoginManagerTest::SetUpOnMainThread();
local_state_ = g_browser_process->local_state(); local_state_ = g_browser_process->local_state();
user_manager::UserManager::Get()->AddObserver(this); user_manager::UserManager::Get()->AddObserver(this);
// FakeGaia authorizes requests for profile info.
FakeGaia::AccessTokenInfo token_info;
token_info.any_scope = true;
token_info.audience = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
token_info.token = kRandomTokenStrForTesting;
token_info.email = test_account_id1_.GetUserEmail();
fake_gaia_.fake_gaia()->IssueOAuthToken(kRandomTokenStrForTesting,
token_info);
fake_gaia_.fake_gaia()->MapEmailToGaiaId(
kTestUserEmail1, signin::GetTestGaiaIdForEmail(kTestUserEmail1));
} }
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
...@@ -331,27 +315,38 @@ class UserImageManagerTest : public LoginManagerTest, ...@@ -331,27 +315,38 @@ class UserImageManagerTest : public LoginManagerTest,
std::unique_ptr<net::test_server::ControllableHttpResponse> std::unique_ptr<net::test_server::ControllableHttpResponse>
controllable_http_response_; controllable_http_response_;
const AccountId test_account_id1_ = AccountId::FromUserEmailGaiaId( FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
kTestUserEmail1,
signin::GetTestGaiaIdForEmail(kTestUserEmail1));
const AccountId test_account_id2_ = AccountId::FromUserEmailGaiaId(
kTestUserEmail2,
signin::GetTestGaiaIdForEmail(kTestUserEmail2));
const AccountId enterprise_account_id_ = AccountId::FromUserEmailGaiaId(
FakeGaiaMixin::kEnterpriseUser1,
signin::GetTestGaiaIdForEmail(FakeGaiaMixin::kEnterpriseUser1));
const cryptohome::AccountIdentifier cryptohome_id_ =
cryptohome::CreateAccountIdentifierFromAccountId(enterprise_account_id_);
private: private:
FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()}; DISALLOW_COPY_AND_ASSIGN(UserImageManagerTestBase);
};
DISALLOW_COPY_AND_ASSIGN(UserImageManagerTest); class UserImageManagerTest : public UserImageManagerTestBase {
public:
UserImageManagerTest() {
login_manager_mixin_.AppendRegularUsers(1);
test_account_id1_ = login_manager_mixin_.users()[0].account_id;
}
void SetUpOnMainThread() override {
UserImageManagerTestBase::SetUpOnMainThread();
// FakeGaia authorizes requests for profile info.
FakeGaia::AccessTokenInfo token_info;
token_info.any_scope = true;
token_info.audience = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
token_info.token = kRandomTokenStrForTesting;
token_info.email = test_account_id1_.GetUserEmail();
fake_gaia_.fake_gaia()->IssueOAuthToken(kRandomTokenStrForTesting,
token_info);
fake_gaia_.fake_gaia()->MapEmailToGaiaId(test_account_id1_.GetUserEmail(),
test_account_id1_.GetGaiaId());
}
protected:
AccountId test_account_id1_;
LoginManagerMixin login_manager_mixin_{&mixin_host_};
}; };
IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_SaveAndLoadUserImage) { IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_SaveAndLoadUserImage) {
RegisterUser(test_account_id1_);
// Setup a user with JPEG image. // Setup a user with JPEG image.
run_loop_.reset(new base::RunLoop); run_loop_.reset(new base::RunLoop);
const gfx::ImageSkia& image = default_user_image::GetDefaultImage( const gfx::ImageSkia& image = default_user_image::GetDefaultImage(
...@@ -379,10 +374,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveAndLoadUserImage) { ...@@ -379,10 +374,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveAndLoadUserImage) {
EXPECT_EQ(saved_image.height(), user->GetImage().height()); EXPECT_EQ(saved_image.height(), user->GetImage().height());
} }
IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_SaveUserDefaultImageIndex) {
RegisterUser(test_account_id1_);
}
// Verifies that SaveUserDefaultImageIndex() correctly sets and persists the // Verifies that SaveUserDefaultImageIndex() correctly sets and persists the
// chosen user image. // chosen user image.
IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserDefaultImageIndex) { IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserDefaultImageIndex) {
...@@ -406,10 +397,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserDefaultImageIndex) { ...@@ -406,10 +397,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserDefaultImageIndex) {
base::FilePath()); base::FilePath());
} }
IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_SaveUserImage) {
RegisterUser(test_account_id1_);
}
// Verifies that SaveUserImage() correctly sets and persists the chosen user // Verifies that SaveUserImage() correctly sets and persists the chosen user
// image. // image.
IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImage) { IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImage) {
...@@ -447,10 +434,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImage) { ...@@ -447,10 +434,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImage) {
EXPECT_EQ(custom_image.height(), saved_image.height()); EXPECT_EQ(custom_image.height(), saved_image.height());
} }
IN_PROC_BROWSER_TEST_F(UserImageManagerTest, PRE_SaveUserImageFromFile) {
RegisterUser(test_account_id1_);
}
// Verifies that SaveUserImageFromFile() correctly sets and persists the chosen // Verifies that SaveUserImageFromFile() correctly sets and persists the chosen
// user image. // user image.
IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImageFromFile) { IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImageFromFile) {
...@@ -517,12 +500,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImageFromFile) { ...@@ -517,12 +500,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImageFromFile) {
EXPECT_TRUE(base::PathExists(GetUserImagePath(test_account_id1_, "png"))); EXPECT_TRUE(base::PathExists(GetUserImagePath(test_account_id1_, "png")));
} }
IN_PROC_BROWSER_TEST_F(UserImageManagerTest,
PRE_SaveUserImageFromProfileImage) {
RegisterUser(test_account_id1_);
chromeos::StartupUtils::MarkOobeCompleted();
}
// Verifies that SaveUserImageFromProfileImage() correctly downloads, sets and // Verifies that SaveUserImageFromProfileImage() correctly downloads, sets and
// persists the chosen user image. // persists the chosen user image.
// TODO(crbug.com/998369): Flaky on Linux TSAN and ASAN. // TODO(crbug.com/998369): Flaky on Linux TSAN and ASAN.
...@@ -568,11 +545,16 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, ...@@ -568,11 +545,16 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest,
EXPECT_EQ(profile_image.height(), saved_image.height()); EXPECT_EQ(profile_image.height(), saved_image.height());
} }
class UserImageManagerPolicyTest : public UserImageManagerTest, class UserImageManagerPolicyTest : public UserImageManagerTestBase,
public policy::CloudPolicyStore::Observer { public policy::CloudPolicyStore::Observer {
protected: protected:
UserImageManagerPolicyTest() UserImageManagerPolicyTest()
: owner_key_util_(new ownership::MockOwnerKeyUtil()) {} : owner_key_util_(new ownership::MockOwnerKeyUtil()) {
login_manager_.AppendManagedUsers(1);
enterprise_account_id_ = login_manager_.users()[0].account_id;
cryptohome_id_ = cryptohome::CreateAccountIdentifierFromAccountId(
enterprise_account_id_);
}
// UserImageManagerTest overrides: // UserImageManagerTest overrides:
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
...@@ -586,11 +568,11 @@ class UserImageManagerPolicyTest : public UserImageManagerTest, ...@@ -586,11 +568,11 @@ class UserImageManagerPolicyTest : public UserImageManagerTest,
FakeSessionManagerClient::Get()->set_device_policy( FakeSessionManagerClient::Get()->set_device_policy(
device_policy_.GetBlob()); device_policy_.GetBlob());
UserImageManagerTest::SetUpInProcessBrowserTestFixture(); UserImageManagerTestBase::SetUpInProcessBrowserTestFixture();
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
UserImageManagerTest::SetUpOnMainThread(); UserImageManagerTestBase::SetUpOnMainThread();
base::FilePath user_keys_dir; base::FilePath user_keys_dir;
ASSERT_TRUE(base::PathService::Get( ASSERT_TRUE(base::PathService::Get(
...@@ -653,15 +635,15 @@ class UserImageManagerPolicyTest : public UserImageManagerTest, ...@@ -653,15 +635,15 @@ class UserImageManagerPolicyTest : public UserImageManagerTest,
gfx::ImageSkia policy_image_; gfx::ImageSkia policy_image_;
AccountId enterprise_account_id_;
cryptohome::AccountIdentifier cryptohome_id_ =
cryptohome::CreateAccountIdentifierFromAccountId(enterprise_account_id_);
LoginManagerMixin login_manager_{&mixin_host_};
private: private:
DISALLOW_COPY_AND_ASSIGN(UserImageManagerPolicyTest); DISALLOW_COPY_AND_ASSIGN(UserImageManagerPolicyTest);
}; };
IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest, PRE_SetAndClear) {
RegisterUser(enterprise_account_id_);
chromeos::StartupUtils::MarkOobeCompleted();
}
// Verifies that the user image can be set through policy. Also verifies that // Verifies that the user image can be set through policy. Also verifies that
// after the policy has been cleared, the user is able to choose a different // after the policy has been cleared, the user is able to choose a different
// image. // image.
...@@ -747,11 +729,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest, SetAndClear) { ...@@ -747,11 +729,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest, SetAndClear) {
base::FilePath()); base::FilePath());
} }
IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest, PRE_PolicyOverridesUser) {
RegisterUser(enterprise_account_id_);
chromeos::StartupUtils::MarkOobeCompleted();
}
// Verifies that when the user chooses a user image and a different image is // Verifies that when the user chooses a user image and a different image is
// then set through policy, the policy takes precedence, overriding the // then set through policy, the policy takes precedence, overriding the
// previously chosen image. // previously chosen image.
...@@ -810,12 +787,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest, PolicyOverridesUser) { ...@@ -810,12 +787,6 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest, PolicyOverridesUser) {
EXPECT_EQ(policy_image_.height(), saved_image.height()); EXPECT_EQ(policy_image_.height(), saved_image.height());
} }
IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest,
PRE_UserDoesNotOverridePolicy) {
RegisterUser(enterprise_account_id_);
chromeos::StartupUtils::MarkOobeCompleted();
}
// Verifies that when the user image has been set through policy and the user // Verifies that when the user image has been set through policy and the user
// chooses a different image, the policy takes precedence, preventing the user // chooses a different image, the policy takes precedence, preventing the user
// from overriding the previously chosen image. // from overriding the previously chosen image.
......
...@@ -76,7 +76,7 @@ class UserImageManagerImpl : public UserImageManager, ...@@ -76,7 +76,7 @@ class UserImageManagerImpl : public UserImageManager,
static const char kImageURLNodeName[]; static const char kImageURLNodeName[];
private: private:
friend class UserImageManagerTest; friend class UserImageManagerTestBase;
// Every image load or update is encapsulated by a Job. Whenever an image load // Every image load or update is encapsulated by a Job. Whenever an image load
// or update is requested for a user, the Job currently running for that user // or update is requested for a user, the Job currently running for that user
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/test/device_state_mixin.h" #include "chrome/browser/chromeos/login/test/device_state_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/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h" #include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h" #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_factory.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
...@@ -133,12 +134,7 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -133,12 +134,7 @@ class WallpaperPolicyTest : public LoginManagerTest,
protected: protected:
WallpaperPolicyTest() WallpaperPolicyTest()
: LoginManagerTest(), owner_key_util_(new ownership::MockOwnerKeyUtil()) { : LoginManagerTest(), owner_key_util_(new ownership::MockOwnerKeyUtil()) {
testUsers_.push_back( login_manager_.AppendManagedUsers(2);
AccountId::FromUserEmailGaiaId(FakeGaiaMixin::kEnterpriseUser1,
FakeGaiaMixin::kEnterpriseUser1GaiaId));
testUsers_.push_back(
AccountId::FromUserEmailGaiaId(FakeGaiaMixin::kEnterpriseUser2,
FakeGaiaMixin::kEnterpriseUser2GaiaId));
} }
std::unique_ptr<policy::UserPolicyBuilder> GetUserPolicyBuilder( std::unique_ptr<policy::UserPolicyBuilder> GetUserPolicyBuilder(
...@@ -186,13 +182,6 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -186,13 +182,6 @@ class WallpaperPolicyTest : public LoginManagerTest,
} }
void SetUpCommandLine(base::CommandLine* command_line) override { void SetUpCommandLine(base::CommandLine* command_line) override {
// Set the same switches as LoginManagerTest, except that kMultiProfiles is
// only set when GetParam() is true and except that kLoginProfile is set
// when GetParam() is false. The latter seems to be required for the sane
// start-up of user profiles.
command_line->AppendSwitch(switches::kLoginManager);
command_line->AppendSwitch(switches::kForceLoginManagerInTests);
// Allow policy fetches to fail - these tests instead invoke InjectPolicy() // Allow policy fetches to fail - these tests instead invoke InjectPolicy()
// to directly inject and modify policy dynamically. // to directly inject and modify policy dynamically.
command_line->AppendSwitch(switches::kAllowFailedPolicyFetchForTest); command_line->AppendSwitch(switches::kAllowFailedPolicyFetchForTest);
...@@ -205,8 +194,10 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -205,8 +194,10 @@ class WallpaperPolicyTest : public LoginManagerTest,
WallpaperControllerClient::Get()->AddObserver(this); WallpaperControllerClient::Get()->AddObserver(this);
// Set up policy signing. // Set up policy signing.
user_policy_builders_[0] = GetUserPolicyBuilder(testUsers_[0]); user_policy_builders_[0] =
user_policy_builders_[1] = GetUserPolicyBuilder(testUsers_[1]); GetUserPolicyBuilder(login_manager_.users()[0].account_id);
user_policy_builders_[1] =
GetUserPolicyBuilder(login_manager_.users()[1].account_id);
} }
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
...@@ -263,7 +254,8 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -263,7 +254,8 @@ class WallpaperPolicyTest : public LoginManagerTest,
// empty |filename| to clear policy. // empty |filename| to clear policy.
void InjectPolicy(int user_number, const std::string& filename) { void InjectPolicy(int user_number, const std::string& filename) {
ASSERT_TRUE(user_number == 0 || user_number == 1); ASSERT_TRUE(user_number == 0 || user_number == 1);
const AccountId& account_id = testUsers_[user_number]; const AccountId& account_id =
login_manager_.users()[user_number].account_id;
policy::UserPolicyBuilder* builder = policy::UserPolicyBuilder* builder =
user_policy_builders_[user_number].get(); user_policy_builders_[user_number].get();
if (!filename.empty()) { if (!filename.empty()) {
...@@ -310,10 +302,10 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -310,10 +302,10 @@ class WallpaperPolicyTest : public LoginManagerTest,
std::unique_ptr<policy::UserPolicyBuilder> user_policy_builders_[2]; std::unique_ptr<policy::UserPolicyBuilder> user_policy_builders_[2];
policy::DevicePolicyBuilder device_policy_; policy::DevicePolicyBuilder device_policy_;
scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_;
std::vector<AccountId> testUsers_;
FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()}; FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
DeviceStateMixin device_state_{ DeviceStateMixin device_state_{
&mixin_host_, DeviceStateMixin::State::OOBE_COMPLETED_CLOUD_ENROLLED}; &mixin_host_, DeviceStateMixin::State::OOBE_COMPLETED_CLOUD_ENROLLED};
LoginManagerMixin login_manager_{&mixin_host_};
private: private:
// The average ARGB color of the current wallpaper. // The average ARGB color of the current wallpaper.
...@@ -324,12 +316,6 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -324,12 +316,6 @@ class WallpaperPolicyTest : public LoginManagerTest,
DISALLOW_COPY_AND_ASSIGN(WallpaperPolicyTest); DISALLOW_COPY_AND_ASSIGN(WallpaperPolicyTest);
}; };
IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, PRE_SetResetClear) {
RegisterUser(testUsers_[0]);
RegisterUser(testUsers_[1]);
StartupUtils::MarkOobeCompleted();
}
// Verifies that the wallpaper can be set and re-set through policy and that // Verifies that the wallpaper can be set and re-set through policy and that
// setting policy for a user that is not logged in doesn't affect the current // setting policy for a user that is not logged in doesn't affect the current
// user. Also verifies that after the policy has been cleared, the wallpaper // user. Also verifies that after the policy has been cleared, the wallpaper
...@@ -338,7 +324,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, PRE_SetResetClear) { ...@@ -338,7 +324,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, PRE_SetResetClear) {
// Disabled due to flakiness: https://crbug.com/873908. // Disabled due to flakiness: https://crbug.com/873908.
IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, DISABLED_SetResetClear) { IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, DISABLED_SetResetClear) {
SetSystemSalt(); SetSystemSalt();
LoginUser(testUsers_[0]); LoginUser(login_manager_.users()[0].account_id);
// First user: Stores the average color of the default wallpaper (set // First user: Stores the average color of the default wallpaper (set
// automatically) to be compared against later. // automatically) to be compared against later.
...@@ -366,12 +352,6 @@ IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, DISABLED_SetResetClear) { ...@@ -366,12 +352,6 @@ IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, DISABLED_SetResetClear) {
ASSERT_EQ(3, wallpaper_change_count_); ASSERT_EQ(3, wallpaper_change_count_);
} }
IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, PRE_DevicePolicyTest) {
SetSystemSalt();
RegisterUser(testUsers_[0]);
StartupUtils::MarkOobeCompleted();
}
// Test that if device policy wallpaper and user policy wallpaper are both // Test that if device policy wallpaper and user policy wallpaper are both
// specified, the device policy wallpaper is used in the login screen and the // specified, the device policy wallpaper is used in the login screen and the
// user policy wallpaper is used inside of a user session. // user policy wallpaper is used inside of a user session.
...@@ -386,7 +366,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, DevicePolicyTest) { ...@@ -386,7 +366,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, DevicePolicyTest) {
// Log in a test user. The default wallpaper should be shown to replace the // Log in a test user. The default wallpaper should be shown to replace the
// device policy wallpaper. // device policy wallpaper.
LoginUser(testUsers_[0]); LoginUser(login_manager_.users()[0].account_id);
RunUntilWallpaperChangeToColor(original_wallpaper_color); RunUntilWallpaperChangeToColor(original_wallpaper_color);
// Now set the user wallpaper policy. The user policy controlled wallpaper // Now set the user wallpaper policy. The user policy controlled wallpaper
......
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