Commit 05ab390a authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros: Introduce LocalPolicyTestServerMixin

Used to setup and work with LocalPolicyTestServer.
Chrome OS tests are migrated.

TBD:
Enable disabled migrated tests
Migrate Chrome tests when mixins are Chrome-wide

Bug: 934224, 912704
Change-Id: I5fef3d20e3ec8dd23f6307139fab1fbc1517d3d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1495532
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarPavol Marko <pmarko@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638536}
parent ce9a71e2
......@@ -20,6 +20,7 @@
#include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/arc/test/arc_data_removed_waiter.h"
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
......@@ -28,7 +29,6 @@
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/test/base/in_process_browser_test.h"
......@@ -100,31 +100,20 @@ class ArcPlayStoreDisabledWaiter : public ArcSessionManager::Observer {
DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreDisabledWaiter);
};
class ArcSessionManagerTest : public InProcessBrowserTest {
class ArcSessionManagerTest : public chromeos::MixinBasedInProcessBrowserTest {
protected:
ArcSessionManagerTest() {}
// InProcessBrowserTest:
// MixinBasedInProcessBrowserTest:
~ArcSessionManagerTest() override {}
void SetUpCommandLine(base::CommandLine* command_line) override {
chromeos::MixinBasedInProcessBrowserTest::SetUpCommandLine(command_line);
arc::SetArcAvailableCommandLineForTesting(command_line);
}
void SetUpInProcessBrowserTestFixture() override {
// Start test device management server.
test_server_.reset(new policy::LocalPolicyTestServer());
ASSERT_TRUE(test_server_->Start());
// Specify device management server URL.
std::string url = test_server_->GetServiceURL().spec();
base::CommandLine* const command_line =
base::CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
url);
}
void SetUpOnMainThread() override {
chromeos::MixinBasedInProcessBrowserTest::SetUpOnMainThread();
user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>(
std::make_unique<chromeos::FakeChromeUserManager>());
// Init ArcSessionManager for testing.
......@@ -188,8 +177,8 @@ class ArcSessionManagerTest : public InProcessBrowserTest {
profile_.reset();
base::RunLoop().RunUntilIdle();
user_manager_enabler_.reset();
test_server_.reset();
chromeos::ProfileHelper::SetAlwaysReturnPrimaryUserForTesting(false);
chromeos::MixinBasedInProcessBrowserTest::TearDownOnMainThread();
}
chromeos::FakeChromeUserManager* GetFakeUserManager() const {
......@@ -214,7 +203,7 @@ class ArcSessionManagerTest : public InProcessBrowserTest {
}
private:
std::unique_ptr<policy::LocalPolicyTestServer> test_server_;
chromeos::LocalPolicyTestServerMixin local_policy_mixin_{&mixin_host_};
std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_environment_adaptor_;
......
......@@ -35,6 +35,7 @@
#include "chrome/browser/chromeos/login/test/fake_gaia_mixin.h"
#include "chrome/browser/chromeos/login/test/https_forwarder.h"
#include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.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/ui/login_display_host.h"
......@@ -47,7 +48,6 @@
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/signin/signin_utils.h"
#include "chrome/common/chrome_constants.h"
......@@ -157,7 +157,6 @@ constexpr char kRelayState[] = "RelayState";
constexpr char kTestUserinfoToken[] = "fake-userinfo-token";
constexpr char kTestRefreshToken[] = "fake-refresh-token";
constexpr char kPolicy[] = "{\"managed_users\": [\"*\"]}";
constexpr char kAffiliationID[] = "some-affiliation-id";
......@@ -855,8 +854,6 @@ class SAMLEnrollmentTest : public SamlTest,
~SAMLEnrollmentTest() override;
// SamlTest:
void SetUp() override;
void SetUpCommandLine(base::CommandLine* command_line) override;
void SetUpOnMainThread() override;
void StartSamlAndWaitForIdpPageLoad(const std::string& gaia_email) override;
......@@ -869,7 +866,7 @@ class SAMLEnrollmentTest : public SamlTest,
content::WebContents* GetEnrollmentContents();
private:
std::unique_ptr<policy::LocalPolicyTestServer> test_server_;
LocalPolicyTestServerMixin local_policy_mixin_{&mixin_host_};
base::ScopedTempDir temp_dir_;
std::unique_ptr<base::RunLoop> run_loop_;
......@@ -887,26 +884,6 @@ SAMLEnrollmentTest::SAMLEnrollmentTest() {
SAMLEnrollmentTest::~SAMLEnrollmentTest() {}
void SAMLEnrollmentTest::SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
const base::FilePath policy_file =
temp_dir_.GetPath().AppendASCII("policy.json");
ASSERT_EQ(static_cast<int>(strlen(kPolicy)),
base::WriteFile(policy_file, kPolicy, strlen(kPolicy)));
test_server_.reset(new policy::LocalPolicyTestServer(policy_file));
ASSERT_TRUE(test_server_->Start());
SamlTest::SetUp();
}
void SAMLEnrollmentTest::SetUpCommandLine(base::CommandLine* command_line) {
command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
test_server_->GetServiceURL().spec());
SamlTest::SetUpCommandLine(command_line);
}
void SAMLEnrollmentTest::SetUpOnMainThread() {
FakeGaia::AccessTokenInfo token_info;
token_info.token = kTestUserinfoToken;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.h"
#include <utility>
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/cloud/policy_builder.h"
#include "components/policy/core/common/policy_switches.h"
namespace chromeos {
namespace {
base::Value GetDefaultConfig() {
base::Value config(base::Value::Type::DICTIONARY);
base::Value managed_users(base::Value::Type::LIST);
managed_users.GetList().emplace_back("*");
config.SetKey("managed_users", std::move(managed_users));
return config;
}
} // namespace
LocalPolicyTestServerMixin::LocalPolicyTestServerMixin(
InProcessBrowserTestMixinHost* host)
: InProcessBrowserTestMixin(host) {
server_config_ = GetDefaultConfig();
}
void LocalPolicyTestServerMixin::SetUp() {
policy_test_server_ = std::make_unique<policy::LocalPolicyTestServer>();
policy_test_server_->SetConfig(server_config_);
policy_test_server_->RegisterClient(policy::PolicyBuilder::kFakeToken,
policy::PolicyBuilder::kFakeDeviceId,
{} /* state_keys */);
ASSERT_TRUE(policy_test_server_->SetSigningKeyAndSignature(
policy::PolicyBuilder::CreateTestSigningKey().get(),
policy::PolicyBuilder::GetTestSigningKeySignature()));
ASSERT_TRUE(policy_test_server_->Start());
}
void LocalPolicyTestServerMixin::SetUpCommandLine(
base::CommandLine* command_line) {
// Specify device management server URL.
command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
policy_test_server_->GetServiceURL().spec());
}
bool LocalPolicyTestServerMixin::UpdateDevicePolicy(
const enterprise_management::ChromeDeviceSettingsProto& policy) {
DCHECK(policy_test_server_);
return policy_test_server_->UpdatePolicy(
policy::dm_protocol::kChromeDevicePolicyType,
std::string() /* entity_id */, policy.SerializeAsString());
}
LocalPolicyTestServerMixin::~LocalPolicyTestServerMixin() = default;
} // namespace chromeos
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_TEST_LOCAL_POLICY_TEST_SERVER_MIXIN_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_TEST_LOCAL_POLICY_TEST_SERVER_MIXIN_H_
#include <memory>
#include "base/macros.h"
#include "base/values.h"
#include "chrome/browser/chromeos/login/mixin_based_in_process_browser_test.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "components/policy/proto/chrome_device_policy.pb.h"
namespace chromeos {
// This test mixin covers setting up LocalPolicyTestServer and adding a
// command-line flag to use it. Please see SetUp function for default settings.
// Server is started after SetUp execution.
class LocalPolicyTestServerMixin : public InProcessBrowserTestMixin {
public:
explicit LocalPolicyTestServerMixin(InProcessBrowserTestMixinHost* host);
~LocalPolicyTestServerMixin() override;
policy::LocalPolicyTestServer* server() { return policy_test_server_.get(); }
// InProcessBrowserTestMixin:
void SetUp() override;
void SetUpCommandLine(base::CommandLine* command_line) override;
bool UpdateDevicePolicy(
const enterprise_management::ChromeDeviceSettingsProto& policy);
private:
std::unique_ptr<policy::LocalPolicyTestServer> policy_test_server_;
base::Value server_config_;
DISALLOW_COPY_AND_ASSIGN(LocalPolicyTestServerMixin);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_TEST_LOCAL_POLICY_TEST_SERVER_MIXIN_H_
......@@ -21,6 +21,7 @@
#include "chrome/browser/chromeos/login/signin_partition_manager.h"
#include "chrome/browser/chromeos/login/test/fake_gaia_mixin.h"
#include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.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/ui/login_display_host.h"
......@@ -30,7 +31,6 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/scoped_testing_cros_settings.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/ui/login/login_handler.h"
#include "chrome/browser/ui/webui/signin/signin_utils.h"
#include "chromeos/constants/chromeos_switches.h"
......@@ -842,16 +842,7 @@ class WebviewProxyAuthLoginTest : public WebviewLoginTest {
.set_public_key_version(1);
device_policy_test_helper_.device_policy()->Build();
// Start policy server. Use the DMToken and DeviceId from PolicyBuilder.
// These also used in |device_policy_test_helper_| and was passed to
// |fake_session_manager_client_| above, so the device will request policy
// with these identifiers.
policy_test_server_.RegisterClient(policy::PolicyBuilder::kFakeToken,
policy::PolicyBuilder::kFakeDeviceId,
{} /* state_keys */);
UpdateServedPolicyFromDevicePolicyTestHelper();
ASSERT_TRUE(policy_test_server_.Start());
WebviewLoginTest::SetUp();
}
......@@ -859,8 +850,6 @@ class WebviewProxyAuthLoginTest : public WebviewLoginTest {
command_line->AppendSwitchASCII(
::switches::kProxyServer,
auth_proxy_server_->host_port_pair().ToString());
command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
policy_test_server_.GetServiceURL().spec());
WebviewLoginTest::SetUpCommandLine(command_line);
}
......@@ -933,10 +922,7 @@ class WebviewProxyAuthLoginTest : public WebviewLoginTest {
}
void UpdateServedPolicyFromDevicePolicyTestHelper() {
policy_test_server_.UpdatePolicy(
policy::dm_protocol::kChromeDevicePolicyType,
std::string() /* entity_id */,
device_policy_builder()->payload().SerializeAsString());
local_policy_mixin_.UpdateDevicePolicy(device_policy_builder()->payload());
}
policy::DevicePolicyBuilder* device_policy_builder() {
......@@ -956,7 +942,7 @@ class WebviewProxyAuthLoginTest : public WebviewLoginTest {
// A proxy server which requires authentication using the 'Basic'
// authentication method.
std::unique_ptr<net::SpawnedTestServer> auth_proxy_server_;
policy::LocalPolicyTestServer policy_test_server_;
LocalPolicyTestServerMixin local_policy_mixin_{&mixin_host_};
policy::DevicePolicyCrosTestHelper device_policy_test_helper_;
// FakeDBusThreadManager uses FakeSessionManagerClient.
......
......@@ -17,6 +17,7 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/policy/device_policy_builder.h"
......@@ -25,7 +26,6 @@
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_constants.h"
......@@ -109,14 +109,9 @@ class KeyRotationDeviceCloudPolicyTest : public DevicePolicyCrosBrowserTest {
void SetUp() override {
UpdateBuiltTestPolicyValue(kTestPolicyValue);
StartPolicyTestServer();
DevicePolicyCrosBrowserTest::SetUp();
}
void SetUpCommandLine(base::CommandLine* command_line) override {
DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
policy_test_server_.GetServiceURL().spec());
local_policy_mixin_.server()->EnableAutomaticRotationOfSigningKeys();
UpdateServedTestPolicy();
}
void SetUpInProcessBrowserTestFixture() override {
......@@ -149,9 +144,8 @@ class KeyRotationDeviceCloudPolicyTest : public DevicePolicyCrosBrowserTest {
}
void UpdateServedTestPolicy() {
EXPECT_TRUE(policy_test_server_.UpdatePolicy(
dm_protocol::kChromeDevicePolicyType, std::string() /* entity_id */,
device_policy()->payload().SerializeAsString()));
EXPECT_TRUE(
local_policy_mixin_.UpdateDevicePolicy(device_policy()->payload()));
}
int GetTestPolicyValue() {
......@@ -182,15 +176,6 @@ class KeyRotationDeviceCloudPolicyTest : public DevicePolicyCrosBrowserTest {
}
private:
void StartPolicyTestServer() {
policy_test_server_.RegisterClient(PolicyBuilder::kFakeToken,
PolicyBuilder::kFakeDeviceId,
{} /* state_keys */);
UpdateServedTestPolicy();
policy_test_server_.EnableAutomaticRotationOfSigningKeys();
EXPECT_TRUE(policy_test_server_.Start());
}
void SetFakeDevicePolicy() {
device_policy()
->payload()
......@@ -222,7 +207,7 @@ class KeyRotationDeviceCloudPolicyTest : public DevicePolicyCrosBrowserTest {
}
}
LocalPolicyTestServer policy_test_server_;
chromeos::LocalPolicyTestServerMixin local_policy_mixin_{&mixin_host_};
std::unique_ptr<PolicyChangeRegistrar> policy_change_registrar_;
int awaited_policy_value_ = -1;
std::unique_ptr<base::RunLoop> policy_change_waiting_run_loop_;
......@@ -286,7 +271,6 @@ class SigninExtensionsDeviceCloudPolicyBrowserTest
~SigninExtensionsDeviceCloudPolicyBrowserTest() override = default;
void SetUp() override {
StartPolicyTestServer();
ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
DevicePolicyCrosBrowserTest::SetUp();
}
......@@ -295,8 +279,6 @@ class SigninExtensionsDeviceCloudPolicyBrowserTest
DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
policy_test_server_.GetServiceURL().spec());
// The test app has to be whitelisted for sign-in screen.
command_line->AppendSwitchASCII(
extensions::switches::kWhitelistedExtensionID, kTestExtensionId);
......@@ -308,10 +290,9 @@ class SigninExtensionsDeviceCloudPolicyBrowserTest
MarkAsEnterpriseOwned();
SetFakeDevicePolicy();
EXPECT_TRUE(policy_test_server_.UpdatePolicy(
dm_protocol::kChromeDevicePolicyType, std::string() /* entity_id */,
device_policy()->payload().SerializeAsString()));
EXPECT_TRUE(policy_test_server_.UpdatePolicy(
EXPECT_TRUE(
local_policy_mixin_.UpdateDevicePolicy(device_policy()->payload()));
EXPECT_TRUE(local_policy_mixin_.server()->UpdatePolicy(
dm_protocol::kChromeSigninExtensionPolicyType, kTestExtensionId,
BuildTestComponentPolicyPayload().SerializeAsString()));
}
......@@ -375,17 +356,6 @@ class SigninExtensionsDeviceCloudPolicyBrowserTest
return response;
}
void StartPolicyTestServer() {
std::unique_ptr<crypto::RSAPrivateKey> signing_key(
PolicyBuilder::CreateTestSigningKey());
EXPECT_TRUE(policy_test_server_.SetSigningKeyAndSignature(
signing_key.get(), PolicyBuilder::GetTestSigningKeySignature()));
policy_test_server_.RegisterClient(PolicyBuilder::kFakeToken,
PolicyBuilder::kFakeDeviceId,
{} /* state_keys */);
EXPECT_TRUE(policy_test_server_.Start());
}
void SetFakeDevicePolicy() {
device_policy()->policy_data().set_public_key_version(
kFakePolicyPublicKeyVersion);
......@@ -421,7 +391,7 @@ class SigninExtensionsDeviceCloudPolicyBrowserTest
builder->Build();
}
LocalPolicyTestServer policy_test_server_;
chromeos::LocalPolicyTestServerMixin local_policy_mixin_{&mixin_host_};
DISALLOW_COPY_AND_ASSIGN(SigninExtensionsDeviceCloudPolicyBrowserTest);
};
......
......@@ -48,6 +48,7 @@
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h"
#include "chrome/browser/chromeos/login/signin_specifics.h"
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/ui/webui_login_view.h"
#include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h"
......@@ -71,7 +72,6 @@
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -456,17 +456,6 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
~DeviceLocalAccountTest() override {}
void SetUp() override {
// Configure and start the test server.
std::unique_ptr<crypto::RSAPrivateKey> signing_key(
PolicyBuilder::CreateTestSigningKey());
ASSERT_TRUE(test_server_.SetSigningKeyAndSignature(
signing_key.get(), PolicyBuilder::GetTestSigningKeySignature()));
signing_key.reset();
test_server_.RegisterClient(PolicyBuilder::kFakeToken,
PolicyBuilder::kFakeDeviceId,
{} /* state_keys */);
ASSERT_TRUE(test_server_.Start());
BrowserList::AddObserver(this);
DevicePolicyCrosBrowserTest::SetUp();
......@@ -477,8 +466,6 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl,
test_server_.GetServiceURL().spec());
}
void SetUpInProcessBrowserTestFixture() override {
......@@ -539,6 +526,7 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&chrome::AttemptExit));
base::RunLoop().RunUntilIdle();
DevicePolicyCrosBrowserTest::TearDownOnMainThread();
}
void LocalStateChanged(user_manager::UserManager* user_manager) override {
......@@ -586,7 +574,7 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
void UploadDeviceLocalAccountPolicy() {
BuildDeviceLocalAccountPolicy();
ASSERT_TRUE(test_server_.UpdatePolicy(
ASSERT_TRUE(local_policy_mixin_.server()->UpdatePolicy(
dm_protocol::kChromePublicAccountPolicyType, kAccountId1,
device_local_account_policy_.payload().SerializeAsString()));
}
......@@ -618,9 +606,7 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
account->set_type(
em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
RefreshDevicePolicy();
ASSERT_TRUE(test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType,
std::string(),
proto.SerializeAsString()));
ASSERT_TRUE(local_policy_mixin_.UpdateDevicePolicy(proto));
}
void SetManagedSessionsEnabled(bool managed_sessions_enabled) {
......@@ -637,9 +623,7 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
device_local_accounts->set_auto_login_id(kAccountId1);
device_local_accounts->set_auto_login_delay(0);
RefreshDevicePolicy();
ASSERT_TRUE(test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType,
std::string(),
proto.SerializeAsString()));
ASSERT_TRUE(local_policy_mixin_.UpdateDevicePolicy(proto));
}
void CheckPublicSessionPresent(const AccountId& account_id) {
......@@ -801,7 +785,7 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
std::unique_ptr<base::RunLoop> run_loop_;
UserPolicyBuilder device_local_account_policy_;
LocalPolicyTestServer test_server_;
chromeos::LocalPolicyTestServerMixin local_policy_mixin_{&mixin_host_};
content::WebContents* contents_;
......@@ -1023,8 +1007,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, AccountListChange) {
account1->set_type(
em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType, std::string(),
policy.SerializeAsString());
local_policy_mixin_.UpdateDevicePolicy(policy);
g_browser_process->policy_service()->RefreshPolicies(base::Closure());
// Make sure the second device-local account disappears.
......@@ -2295,7 +2278,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyForExtensions) {
// Note that the policy for the device-local account will be fetched before
// the session is started, so the policy for the app must be installed before
// the first device policy fetch.
ASSERT_TRUE(test_server_.UpdatePolicyData(
ASSERT_TRUE(local_policy_mixin_.server()->UpdatePolicyData(
dm_protocol::kChromeExtensionPolicyType, kShowManagedStorageID,
"{"
" \"string\": {"
......@@ -2343,7 +2326,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyForExtensions) {
*policy_service->GetPolicies(ns).GetValue("string"));
// Now update the policy at the server.
ASSERT_TRUE(test_server_.UpdatePolicyData(
ASSERT_TRUE(local_policy_mixin_.server()->UpdatePolicyData(
dm_protocol::kChromeExtensionPolicyType, kShowManagedStorageID,
"{"
" \"string\": {"
......
......@@ -96,7 +96,7 @@ void DevicePolicyCrosBrowserTest::SetUp() {
std::vector<std::string> state_keys;
state_keys.push_back("1");
fake_session_manager_client_->set_server_backed_state_keys(state_keys);
InProcessBrowserTest::SetUp();
chromeos::MixinBasedInProcessBrowserTest::SetUp();
}
void DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture() {
......@@ -106,6 +106,7 @@ void DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture() {
dbus_setter_->SetSessionManagerClient(
std::unique_ptr<chromeos::SessionManagerClient>(
fake_session_manager_client_));
chromeos::MixinBasedInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
}
void DevicePolicyCrosBrowserTest::MarkOwnership() {
......
......@@ -9,8 +9,8 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/chromeos/login/mixin_based_in_process_browser_test.h"
#include "chrome/browser/chromeos/policy/device_policy_builder.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/dbus/dbus_thread_manager.h"
namespace chromeos {
......@@ -47,11 +47,13 @@ class DevicePolicyCrosTestHelper {
};
// Used to test Device policy changes in Chrome OS.
class DevicePolicyCrosBrowserTest : public InProcessBrowserTest {
class DevicePolicyCrosBrowserTest
: public chromeos::MixinBasedInProcessBrowserTest {
protected:
DevicePolicyCrosBrowserTest();
~DevicePolicyCrosBrowserTest() override;
// MixinBasedInProcessBrowserTest:
void SetUp() override;
void SetUpInProcessBrowserTestFixture() override;
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/screens/gaia_view.h"
#include "chrome/browser/chromeos/login/test/local_policy_test_server_mixin.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
......@@ -23,7 +24,6 @@
#include "chrome/browser/chromeos/policy/user_network_configuration_updater_factory.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/net/nss_context.h"
#include "chrome/browser/policy/test/local_policy_test_server.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
......@@ -437,21 +437,6 @@ class PolicyProvidedTrustAnchorsDeviceLocalAccountTest
}
protected:
void SetUp() override {
// Configure and start the test server.
std::unique_ptr<crypto::RSAPrivateKey> signing_key(
PolicyBuilder::CreateTestSigningKey());
ASSERT_TRUE(policy_server_.SetSigningKeyAndSignature(
signing_key.get(), PolicyBuilder::GetTestSigningKeySignature()));
signing_key.reset();
policy_server_.RegisterClient(PolicyBuilder::kFakeToken,
PolicyBuilder::kFakeDeviceId,
{} /* state_keys */);
ASSERT_TRUE(policy_server_.Start());
DevicePolicyCrosBrowserTest::SetUp();
}
virtual void SetupDevicePolicy() = 0;
void SetUpInProcessBrowserTestFixture() override {
......@@ -475,8 +460,6 @@ class PolicyProvidedTrustAnchorsDeviceLocalAccountTest
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
command_line->AppendSwitch(chromeos::switches::kOobeSkipPostLogin);
command_line->AppendSwitchASCII(switches::kDeviceManagementUrl,
policy_server_.GetServiceURL().spec());
}
void WaitForSessionStart() {
......@@ -487,7 +470,7 @@ class PolicyProvidedTrustAnchorsDeviceLocalAccountTest
.Wait();
}
LocalPolicyTestServer policy_server_;
chromeos::LocalPolicyTestServerMixin local_policy_mixin_{&mixin_host_};
const AccountId device_local_account_id_ =
AccountId::FromUserEmail(GenerateDeviceLocalAccountUserId(
......@@ -514,9 +497,7 @@ class PolicyProvidedTrustAnchorsPublicSessionTest
account->set_type(
em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
RefreshDevicePolicy();
ASSERT_TRUE(
policy_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType,
std::string(), proto.SerializeAsString()));
ASSERT_TRUE(local_policy_mixin_.UpdateDevicePolicy(proto));
}
void StartLogin() {
......
......@@ -1879,6 +1879,8 @@ test("browser_tests") {
"../browser/chromeos/login/test/hid_controller_mixin.h",
"../browser/chromeos/login/test/https_forwarder.cc",
"../browser/chromeos/login/test/https_forwarder.h",
"../browser/chromeos/login/test/local_policy_test_server_mixin.cc",
"../browser/chromeos/login/test/local_policy_test_server_mixin.h",
"../browser/chromeos/login/test/oobe_base_test.cc",
"../browser/chromeos/login/test/oobe_base_test.h",
"../browser/chromeos/login/ui/captive_portal_window_browsertest.cc",
......
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