Commit 748b6ba4 authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

Revert "Migrate moar tests to LoginManagerMixin"

This reverts commit 7d5271d9.

Reason for revert: Compile error:
https://ci.chromium.org/p/chrome/builders/ci/linux-chromeos-chrome/4945

Original change's description:
> Migrate moar tests to LoginManagerMixin
> 
> Bug: 1067260
> Change-Id: Ic86579fd50c5815c9adadbd3feade22cbd1c37a7
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144146
> Reviewed-by: Roman Aleksandrov <raleksandrov@google.com>
> Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#760159}

TBR=rsorokin@chromium.org,raleksandrov@google.com

Change-Id: Icbd2a6a47c85fe307b93efd769ef4a85800759d5
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1067260
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2155019Reviewed-by: default avatarSahel Sharify <sahel@chromium.org>
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760202}
parent 33e69a7c
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#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"
...@@ -45,6 +44,10 @@ using ::testing::Return; ...@@ -45,6 +44,10 @@ 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 {
...@@ -64,20 +67,37 @@ class LoginCursorTest : public OobeBaseTest { ...@@ -64,20 +67,37 @@ class LoginCursorTest : public OobeBaseTest {
~LoginCursorTest() override = default; ~LoginCursorTest() override = default;
}; };
using LoginSigninTest = LoginManagerTest; class LoginSigninTest : public InProcessBrowserTest {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(switches::kLoginManager);
command_line->AppendSwitch(switches::kForceLoginManagerInTests);
}
class LoginOfflineTest : public LoginManagerTest { void SetUpOnMainThread() override {
LoginDisplayHostWebUI::DisableRestrictiveProxyCheckForTest();
}
};
class LoginTest : public MixinBasedInProcessBrowserTest {
public: public:
LoginOfflineTest() { LoginTest() = default;
login_manager_.AppendRegularUsers(1); ~LoginTest() override {}
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:
AccountId test_account_id_; const LoginManagerMixin::TestUserInfo test_user_{
LoginManagerMixin login_manager_{&mixin_host_}; AccountId::FromUserEmailGaiaId(kTestUser, kGaiaId),
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()};
...@@ -162,17 +182,16 @@ IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) { ...@@ -162,17 +182,16 @@ IN_PROC_BROWSER_TEST_F(LoginSigninTest, WebUIVisible) {
.Wait(); .Wait();
} }
IN_PROC_BROWSER_TEST_F(LoginOfflineTest, PRE_GaiaAuthOffline) { IN_PROC_BROWSER_TEST_F(LoginTest, PRE_GaiaAuthOffline) {
offline_gaia_test_mixin_.PrepareOfflineGaiaLogin(); offline_gaia_test_mixin_.PrepareOfflineGaiaLogin();
} }
IN_PROC_BROWSER_TEST_F(LoginOfflineTest, GaiaAuthOffline) { IN_PROC_BROWSER_TEST_F(LoginTest, GaiaAuthOffline) {
offline_gaia_test_mixin_.GoOffline(); offline_gaia_test_mixin_.GoOffline();
offline_gaia_test_mixin_.InitOfflineLogin(test_account_id_, offline_gaia_test_mixin_.InitOfflineLogin(test_user_.account_id, kPassword);
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_account_id_.GetUserEmail(), LoginManagerTest::kPassword, test_user_.account_id.GetUserEmail(), kPassword,
true /* wait for sign-in */); true /* wait for sign-in */);
TestSystemTrayIsVisible(false); TestSystemTrayIsVisible(false);
} }
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#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"
...@@ -36,6 +35,13 @@ namespace chromeos { ...@@ -36,6 +35,13 @@ 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:
...@@ -102,15 +108,14 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, OobeNewUser) { ...@@ -102,15 +108,14 @@ 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( fake_gaia_.fake_gaia()->SetFakeMergeSessionParams(kTestUsers[0].email,
FakeGaiaMixin::kFakeUserEmail, "fake_sid", "fake_lsid"); "fake_sid", "fake_lsid");
StartSignInScreen(); StartSignInScreen();
LoginDisplayHost::default_host() LoginDisplayHost::default_host()
->GetOobeUI() ->GetOobeUI()
->GetView<GaiaScreenHandler>() ->GetView<GaiaScreenHandler>()
->ShowSigninScreenForTest(FakeGaiaMixin::kFakeUserEmail, "fake_password", ->ShowSigninScreenForTest(kTestUsers[0].email, "fake_password", "[]");
"[]");
test::WaitForPrimaryUserSessionStart(); test::WaitForPrimaryUserSessionStart();
...@@ -119,17 +124,14 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, OobeNewUser) { ...@@ -119,17 +124,14 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, OobeNewUser) {
EXPECT_EQ(1u, manager->sessions().size()); EXPECT_EQ(1u, manager->sessions().size());
} }
class ChromeSessionManagerExistingUsersTest : public ChromeSessionManagerTest { IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, PRE_LoginExistingUsers) {
public: for (const auto& user : kTestUsers) {
ChromeSessionManagerExistingUsersTest() { RegisterUser(AccountId::FromUserEmailGaiaId(user.email, user.gaia_id));
login_manager_.AppendRegularUsers(3);
} }
StartupUtils::MarkOobeCompleted();
}
LoginManagerMixin login_manager_{&mixin_host_}; IN_PROC_BROWSER_TEST_F(ChromeSessionManagerTest, LoginExistingUsers) {
};
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();
...@@ -137,14 +139,16 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerExistingUsersTest, ...@@ -137,14 +139,16 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerExistingUsersTest,
manager->session_state()); manager->session_state());
EXPECT_EQ(0u, manager->sessions().size()); EXPECT_EQ(0u, manager->sessions().size());
const auto& users = login_manager_.users(); std::vector<AccountId> test_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(users[0].account_id); LoginUser(test_users[0]);
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 < users.size(); ++i) { for (size_t i = 1; i < base::size(kTestUsers); ++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();
...@@ -154,7 +158,9 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerExistingUsersTest, ...@@ -154,7 +158,9 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerExistingUsersTest,
// 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;
AddUser(users[i].account_id); test_users.push_back(AccountId::FromUserEmailGaiaId(kTestUsers[i].email,
kTestUsers[i].gaia_id));
AddUser(test_users.back());
waiter.Wait(); waiter.Wait();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -163,9 +169,9 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerExistingUsersTest, ...@@ -163,9 +169,9 @@ IN_PROC_BROWSER_TEST_F(ChromeSessionManagerExistingUsersTest,
} }
// Verify that session manager has the correct user session info. // Verify that session manager has the correct user session info.
ASSERT_EQ(users.size(), manager->sessions().size()); ASSERT_EQ(test_users.size(), manager->sessions().size());
for (size_t i = 0; i < users.size(); ++i) { for (size_t i = 0; i < test_users.size(); ++i) {
EXPECT_EQ(users[i].account_id, manager->sessions()[i].user_account_id); EXPECT_EQ(test_users[i], manager->sessions()[i].user_account_id);
} }
} }
...@@ -186,15 +192,14 @@ class ChromeSessionManagerRlzTest : public ChromeSessionManagerTest { ...@@ -186,15 +192,14 @@ 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( fake_gaia_.fake_gaia()->SetFakeMergeSessionParams(kTestUsers[0].email,
FakeGaiaMixin::kFakeUserEmail "fake_sid", "fake_lsid"); "fake_sid", "fake_lsid");
StartSignInScreen(); StartSignInScreen();
LoginDisplayHost::default_host() LoginDisplayHost::default_host()
->GetOobeUI() ->GetOobeUI()
->GetView<GaiaScreenHandler>() ->GetView<GaiaScreenHandler>()
->ShowSigninScreenForTest(FakeGaiaMixin::kFakeUserEmail, ->ShowSigninScreenForTest(kTestUsers[0].email, "fake_password", "[]");
"fake_password", "[]");
test::WaitForPrimaryUserSessionStart(); test::WaitForPrimaryUserSessionStart();
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#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"
...@@ -85,6 +84,12 @@ namespace chromeos { ...@@ -85,6 +84,12 @@ 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) {
...@@ -128,8 +133,8 @@ class UserImageChangeWaiter : public user_manager::UserManager::Observer { ...@@ -128,8 +133,8 @@ class UserImageChangeWaiter : public user_manager::UserManager::Observer {
} // namespace } // namespace
class UserImageManagerTestBase : public LoginManagerTest, class UserImageManagerTest : 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) {
...@@ -164,7 +169,7 @@ class UserImageManagerTestBase : public LoginManagerTest, ...@@ -164,7 +169,7 @@ class UserImageManagerTestBase : public LoginManagerTest,
} }
protected: protected:
UserImageManagerTestBase() = default; UserImageManagerTest() = default;
// LoginManagerTest overrides: // LoginManagerTest overrides:
void SetUpInProcessBrowserTestFixture() override { void SetUpInProcessBrowserTestFixture() override {
...@@ -195,6 +200,17 @@ class UserImageManagerTestBase : public LoginManagerTest, ...@@ -195,6 +200,17 @@ class UserImageManagerTestBase : 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 {
...@@ -315,38 +331,27 @@ class UserImageManagerTestBase : public LoginManagerTest, ...@@ -315,38 +331,27 @@ class UserImageManagerTestBase : public LoginManagerTest,
std::unique_ptr<net::test_server::ControllableHttpResponse> std::unique_ptr<net::test_server::ControllableHttpResponse>
controllable_http_response_; controllable_http_response_;
FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()}; const AccountId test_account_id1_ = AccountId::FromUserEmailGaiaId(
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:
DISALLOW_COPY_AND_ASSIGN(UserImageManagerTestBase); FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
};
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: DISALLOW_COPY_AND_ASSIGN(UserImageManagerTest);
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(
...@@ -374,6 +379,10 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveAndLoadUserImage) { ...@@ -374,6 +379,10 @@ 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) {
...@@ -397,6 +406,10 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserDefaultImageIndex) { ...@@ -397,6 +406,10 @@ 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) {
...@@ -434,6 +447,10 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImage) { ...@@ -434,6 +447,10 @@ 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) {
...@@ -500,6 +517,12 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, SaveUserImageFromFile) { ...@@ -500,6 +517,12 @@ 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.
...@@ -545,16 +568,11 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerTest, ...@@ -545,16 +568,11 @@ 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 UserImageManagerTestBase, class UserImageManagerPolicyTest : public UserImageManagerTest,
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 {
...@@ -568,11 +586,11 @@ class UserImageManagerPolicyTest : public UserImageManagerTestBase, ...@@ -568,11 +586,11 @@ class UserImageManagerPolicyTest : public UserImageManagerTestBase,
FakeSessionManagerClient::Get()->set_device_policy( FakeSessionManagerClient::Get()->set_device_policy(
device_policy_.GetBlob()); device_policy_.GetBlob());
UserImageManagerTestBase::SetUpInProcessBrowserTestFixture(); UserImageManagerTest::SetUpInProcessBrowserTestFixture();
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
UserImageManagerTestBase::SetUpOnMainThread(); UserImageManagerTest::SetUpOnMainThread();
base::FilePath user_keys_dir; base::FilePath user_keys_dir;
ASSERT_TRUE(base::PathService::Get( ASSERT_TRUE(base::PathService::Get(
...@@ -635,15 +653,15 @@ class UserImageManagerPolicyTest : public UserImageManagerTestBase, ...@@ -635,15 +653,15 @@ class UserImageManagerPolicyTest : public UserImageManagerTestBase,
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.
...@@ -729,6 +747,11 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest, SetAndClear) { ...@@ -729,6 +747,11 @@ 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.
...@@ -787,6 +810,12 @@ IN_PROC_BROWSER_TEST_F(UserImageManagerPolicyTest, PolicyOverridesUser) { ...@@ -787,6 +810,12 @@ 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 UserImageManagerTestBase; friend class UserImageManagerTest;
// 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,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#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"
...@@ -134,7 +133,12 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -134,7 +133,12 @@ class WallpaperPolicyTest : public LoginManagerTest,
protected: protected:
WallpaperPolicyTest() WallpaperPolicyTest()
: LoginManagerTest(), owner_key_util_(new ownership::MockOwnerKeyUtil()) { : LoginManagerTest(), owner_key_util_(new ownership::MockOwnerKeyUtil()) {
login_manager_.AppendManagedUsers(2); testUsers_.push_back(
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(
...@@ -182,6 +186,13 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -182,6 +186,13 @@ 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);
...@@ -194,10 +205,8 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -194,10 +205,8 @@ class WallpaperPolicyTest : public LoginManagerTest,
WallpaperControllerClient::Get()->AddObserver(this); WallpaperControllerClient::Get()->AddObserver(this);
// Set up policy signing. // Set up policy signing.
user_policy_builders_[0] = user_policy_builders_[0] = GetUserPolicyBuilder(testUsers_[0]);
GetUserPolicyBuilder(login_manager_.users()[0].account_id); user_policy_builders_[1] = GetUserPolicyBuilder(testUsers_[1]);
user_policy_builders_[1] =
GetUserPolicyBuilder(login_manager_.users()[1].account_id);
} }
void TearDownOnMainThread() override { void TearDownOnMainThread() override {
...@@ -254,8 +263,7 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -254,8 +263,7 @@ 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 = const AccountId& account_id = testUsers_[user_number];
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()) {
...@@ -302,10 +310,10 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -302,10 +310,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.
...@@ -316,6 +324,12 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -316,6 +324,12 @@ 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
...@@ -324,7 +338,7 @@ class WallpaperPolicyTest : public LoginManagerTest, ...@@ -324,7 +338,7 @@ class WallpaperPolicyTest : public LoginManagerTest,
// 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(login_manager_.users()[0].account_id); LoginUser(testUsers_[0]);
// 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.
...@@ -352,6 +366,12 @@ IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, DISABLED_SetResetClear) { ...@@ -352,6 +366,12 @@ 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.
...@@ -366,7 +386,7 @@ IN_PROC_BROWSER_TEST_F(WallpaperPolicyTest, DevicePolicyTest) { ...@@ -366,7 +386,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(login_manager_.users()[0].account_id); LoginUser(testUsers_[0]);
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