Use a TestBrowserThreadBundle in the DeviceSettingsTestBase.

Lots of policy tests inherit from that class to reuse common setup code.
The recent work on cloud policy for extensions wired a new class to some
of the existing ones that posts a cleanup task to the IO thread, and
DeviceSettingsTestBase wasn't mocking that thread; so these tests started
leaking at shutdown.

The TestBrowserThreadBundle sets up the UI and FILE threads that the tests
were expecting as well as the other common threads, which makes these tests
more robust.

TBR=pastarmovj@chromium.org
BUG=None

Review URL: https://codereview.chromium.org/348713004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278648 0039d316-1c4b-4281-b951-d872f2087c98
parent 1b5cd520
...@@ -177,10 +177,10 @@ void CloudExternalDataPolicyObserverTest::SetUp() { ...@@ -177,10 +177,10 @@ void CloudExternalDataPolicyObserverTest::SetUp() {
new DeviceLocalAccountPolicyService(&device_settings_test_helper_, new DeviceLocalAccountPolicyService(&device_settings_test_helper_,
&device_settings_service_, &device_settings_service_,
&cros_settings_, &cros_settings_,
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
NULL)); NULL));
url_fetcher_factory_.set_remove_fetcher_on_delete(true); url_fetcher_factory_.set_remove_fetcher_on_delete(true);
......
...@@ -69,7 +69,7 @@ class DeviceCloudPolicyManagerChromeOSTest ...@@ -69,7 +69,7 @@ class DeviceCloudPolicyManagerChromeOSTest
protected: protected:
DeviceCloudPolicyManagerChromeOSTest() DeviceCloudPolicyManagerChromeOSTest()
: state_keys_broker_(&fake_session_manager_client_, : state_keys_broker_(&fake_session_manager_client_,
loop_.message_loop_proxy()), base::MessageLoopProxy::current()),
store_(NULL) { store_(NULL) {
EXPECT_CALL(mock_statistics_provider_, EXPECT_CALL(mock_statistics_provider_,
GetMachineStatistic(_, _)) GetMachineStatistic(_, _))
...@@ -97,13 +97,14 @@ class DeviceCloudPolicyManagerChromeOSTest ...@@ -97,13 +97,14 @@ class DeviceCloudPolicyManagerChromeOSTest
// DBusThreadManager is set up in DeviceSettingsTestBase::SetUp(). // DBusThreadManager is set up in DeviceSettingsTestBase::SetUp().
install_attributes_.reset(new EnterpriseInstallAttributes( install_attributes_.reset(new EnterpriseInstallAttributes(
chromeos::DBusThreadManager::Get()->GetCryptohomeClient())); chromeos::DBusThreadManager::Get()->GetCryptohomeClient()));
store_ = new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, store_ =
new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
install_attributes_.get(), install_attributes_.get(),
loop_.message_loop_proxy()); base::MessageLoopProxy::current());
manager_.reset(new DeviceCloudPolicyManagerChromeOS( manager_.reset(new DeviceCloudPolicyManagerChromeOS(
make_scoped_ptr(store_), make_scoped_ptr(store_),
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
install_attributes_.get(), install_attributes_.get(),
&state_keys_broker_)); &state_keys_broker_));
...@@ -114,7 +115,7 @@ class DeviceCloudPolicyManagerChromeOSTest ...@@ -114,7 +115,7 @@ class DeviceCloudPolicyManagerChromeOSTest
// OAuth tokens, then writes the token to local state, encrypting it // OAuth tokens, then writes the token to local state, encrypting it
// first with methods in CryptohomeTokenEncryptor. // first with methods in CryptohomeTokenEncryptor.
request_context_getter_ = new net::TestURLRequestContextGetter( request_context_getter_ = new net::TestURLRequestContextGetter(
loop_.message_loop_proxy()); base::MessageLoopProxy::current());
TestingBrowserProcess::GetGlobal()->SetSystemRequestContext( TestingBrowserProcess::GetGlobal()->SetSystemRequestContext(
request_context_getter_.get()); request_context_getter_.get());
TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
...@@ -36,11 +37,12 @@ class DeviceCloudPolicyStoreChromeOSTest ...@@ -36,11 +37,12 @@ class DeviceCloudPolicyStoreChromeOSTest
protected: protected:
DeviceCloudPolicyStoreChromeOSTest() DeviceCloudPolicyStoreChromeOSTest()
: fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), : fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()),
install_attributes_(new EnterpriseInstallAttributes( install_attributes_(
fake_cryptohome_client_.get())), new EnterpriseInstallAttributes(fake_cryptohome_client_.get())),
store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, store_(new DeviceCloudPolicyStoreChromeOS(
&device_settings_service_,
install_attributes_.get(), install_attributes_.get(),
loop_.message_loop_proxy())) { base::MessageLoopProxy::current())) {
fake_cryptohome_client_->Init(NULL /* no dbus::Bus */); fake_cryptohome_client_->Init(NULL /* no dbus::Bus */);
} }
...@@ -103,7 +105,7 @@ class DeviceCloudPolicyStoreChromeOSTest ...@@ -103,7 +105,7 @@ class DeviceCloudPolicyStoreChromeOSTest
store_.reset( store_.reset(
new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, new DeviceCloudPolicyStoreChromeOS(&device_settings_service_,
install_attributes_.get(), install_attributes_.get(),
loop_.message_loop_proxy())); base::MessageLoopProxy::current()));
} }
scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_; scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_;
......
...@@ -159,12 +159,11 @@ void DeviceLocalAccountPolicyServiceTestBase::CreatePolicyService() { ...@@ -159,12 +159,11 @@ void DeviceLocalAccountPolicyServiceTestBase::CreatePolicyService() {
&device_settings_test_helper_, &device_settings_test_helper_,
&device_settings_service_, &device_settings_service_,
&cros_settings_, &cros_settings_,
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
extension_cache_task_runner_, extension_cache_task_runner_,
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
loop_.message_loop_proxy(), base::MessageLoopProxy::current(),
new net::TestURLRequestContextGetter( new net::TestURLRequestContextGetter(base::MessageLoopProxy::current())));
base::MessageLoop::current()->message_loop_proxy())));
} }
void DeviceLocalAccountPolicyServiceTestBase:: void DeviceLocalAccountPolicyServiceTestBase::
......
...@@ -203,9 +203,7 @@ ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() { ...@@ -203,9 +203,7 @@ ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() {
} }
DeviceSettingsTestBase::DeviceSettingsTestBase() DeviceSettingsTestBase::DeviceSettingsTestBase()
: ui_thread_(content::BrowserThread::UI, &loop_), : user_manager_(new FakeUserManager()),
file_thread_(content::BrowserThread::FILE, &loop_),
user_manager_(new FakeUserManager()),
user_manager_enabler_(user_manager_), user_manager_enabler_(user_manager_),
owner_key_util_(new MockOwnerKeyUtil()), owner_key_util_(new MockOwnerKeyUtil()),
fake_dbus_thread_manager_(new FakeDBusThreadManager()) { fake_dbus_thread_manager_(new FakeDBusThreadManager()) {
...@@ -221,7 +219,7 @@ void DeviceSettingsTestBase::SetUp() { ...@@ -221,7 +219,7 @@ void DeviceSettingsTestBase::SetUp() {
chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager_); chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager_);
NetworkHandler::Initialize(); NetworkHandler::Initialize();
loop_.RunUntilIdle(); base::RunLoop().RunUntilIdle();
device_policy_.payload().mutable_metrics_enabled()->set_metrics_enabled( device_policy_.payload().mutable_metrics_enabled()->set_metrics_enabled(
false); false);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "chrome/browser/chromeos/settings/device_settings_test_helper.h" #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
#include "chrome/browser/chromeos/settings/mock_owner_key_util.h" #include "chrome/browser/chromeos/settings/mock_owner_key_util.h"
#include "chromeos/dbus/session_manager_client.h" #include "chromeos/dbus/session_manager_client.h"
#include "content/public/test/test_browser_thread.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
class TestingProfile; class TestingProfile;
...@@ -179,9 +179,7 @@ class DeviceSettingsTestBase : public testing::Test { ...@@ -179,9 +179,7 @@ class DeviceSettingsTestBase : public testing::Test {
void InitOwner(const std::string& user_id, bool tpm_is_ready); void InitOwner(const std::string& user_id, bool tpm_is_ready);
base::MessageLoopForUI loop_; content::TestBrowserThreadBundle thread_bundle_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
policy::DevicePolicyBuilder device_policy_; policy::DevicePolicyBuilder device_policy_;
......
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