Index: components/policy/core/common/cloud/user_cloud_policy_store_unittest.cc |
diff --git a/components/policy/core/common/cloud/user_cloud_policy_store_unittest.cc b/components/policy/core/common/cloud/user_cloud_policy_store_unittest.cc |
index c1f7272479e0547bd874de262058386e2c1a35cb..b07c5d5b141aff623e7bcec86af6881fefe71b3e 100644 |
--- a/components/policy/core/common/cloud/user_cloud_policy_store_unittest.cc |
+++ b/components/policy/core/common/cloud/user_cloud_policy_store_unittest.cc |
@@ -8,6 +8,8 @@ |
#include "base/files/scoped_temp_dir.h" |
#include "base/macros.h" |
#include "base/run_loop.h" |
+#include "base/test/scoped_task_environment.h" |
+#include "base/threading/thread_task_runner_handle.h" |
#include "components/policy/core/common/cloud/cloud_policy_constants.h" |
#include "components/policy/core/common/cloud/mock_cloud_external_data_manager.h" |
#include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
@@ -52,12 +54,14 @@ bool WriteStringToFile(const base::FilePath path, const std::string& data) { |
class UserCloudPolicyStoreTest : public testing::Test { |
public: |
- UserCloudPolicyStoreTest() {} |
+ UserCloudPolicyStoreTest() |
+ : scoped_task_environment_( |
+ base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
void SetUp() override { |
ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); |
store_.reset(new UserCloudPolicyStore(policy_file(), key_file(), |
- loop_.task_runner())); |
+ base::ThreadTaskRunnerHandle::Get())); |
external_data_manager_.reset(new MockCloudExternalDataManager); |
external_data_manager_->SetPolicyStore(store_.get()); |
store_->SetSigninUsername(PolicyBuilder::kFakeUsername); |
@@ -130,10 +134,7 @@ class UserCloudPolicyStoreTest : public testing::Test { |
std::unique_ptr<UserCloudPolicyStore> store_; |
std::unique_ptr<MockCloudExternalDataManager> external_data_manager_; |
- // CloudPolicyValidator() requires a FILE thread so declare one here. Both |
- // |ui_thread_| and |file_thread_| share the same MessageLoop |loop_| so |
- // callers can use RunLoop to manage both virtual threads. |
- base::MessageLoopForUI loop_; |
+ base::test::ScopedTaskEnvironment scoped_task_environment_; |
base::ScopedTempDir tmp_dir_; |
@@ -353,8 +354,8 @@ TEST_F(UserCloudPolicyStoreTest, StoreThenLoad) { |
EXPECT_FALSE(store_->policy_signature_public_key().empty()); |
// Now, make sure the policy can be read back in from a second store. |
- std::unique_ptr<UserCloudPolicyStore> store2( |
- new UserCloudPolicyStore(policy_file(), key_file(), loop_.task_runner())); |
+ std::unique_ptr<UserCloudPolicyStore> store2(new UserCloudPolicyStore( |
+ policy_file(), key_file(), base::ThreadTaskRunnerHandle::Get())); |
store2->SetSigninUsername(PolicyBuilder::kFakeUsername); |
store2->AddObserver(&observer_); |
EXPECT_CALL(observer_, OnStoreLoaded(store2.get())); |
@@ -378,8 +379,8 @@ TEST_F(UserCloudPolicyStoreTest, StoreThenLoadImmediately) { |
StorePolicyAndEnsureLoaded(policy_.policy()); |
// Now, make sure the policy can be read back in from a second store. |
- std::unique_ptr<UserCloudPolicyStore> store2( |
- new UserCloudPolicyStore(policy_file(), key_file(), loop_.task_runner())); |
+ std::unique_ptr<UserCloudPolicyStore> store2(new UserCloudPolicyStore( |
+ policy_file(), key_file(), base::ThreadTaskRunnerHandle::Get())); |
store2->SetSigninUsername(PolicyBuilder::kFakeUsername); |
store2->AddObserver(&observer_); |
EXPECT_CALL(observer_, OnStoreLoaded(store2.get())); |
@@ -422,8 +423,8 @@ TEST_F(UserCloudPolicyStoreTest, LoadValidationError) { |
// Sign out, and sign back in as a different user, and try to load the profile |
// data (should fail due to mismatched username). |
- std::unique_ptr<UserCloudPolicyStore> store2( |
- new UserCloudPolicyStore(policy_file(), key_file(), loop_.task_runner())); |
+ std::unique_ptr<UserCloudPolicyStore> store2(new UserCloudPolicyStore( |
+ policy_file(), key_file(), base::ThreadTaskRunnerHandle::Get())); |
store2->SetSigninUsername("foobar@foobar.com"); |
store2->AddObserver(&observer_); |
ExpectError(store2.get(), CloudPolicyStore::STATUS_VALIDATION_ERROR); |
@@ -435,8 +436,8 @@ TEST_F(UserCloudPolicyStoreTest, LoadValidationError) { |
// Sign out - we should be able to load the policy (don't check usernames |
// when signed out). |
- std::unique_ptr<UserCloudPolicyStore> store3( |
- new UserCloudPolicyStore(policy_file(), key_file(), loop_.task_runner())); |
+ std::unique_ptr<UserCloudPolicyStore> store3(new UserCloudPolicyStore( |
+ policy_file(), key_file(), base::ThreadTaskRunnerHandle::Get())); |
store3->AddObserver(&observer_); |
EXPECT_CALL(observer_, OnStoreLoaded(store3.get())); |
store3->Load(); |
@@ -446,8 +447,8 @@ TEST_F(UserCloudPolicyStoreTest, LoadValidationError) { |
store3->RemoveObserver(&observer_); |
// Now start a signin as a different user - this should fail validation. |
- std::unique_ptr<UserCloudPolicyStore> store4( |
- new UserCloudPolicyStore(policy_file(), key_file(), loop_.task_runner())); |
+ std::unique_ptr<UserCloudPolicyStore> store4(new UserCloudPolicyStore( |
+ policy_file(), key_file(), base::ThreadTaskRunnerHandle::Get())); |
store4->SetSigninUsername("foobar@foobar.com"); |
store4->AddObserver(&observer_); |
ExpectError(store4.get(), CloudPolicyStore::STATUS_VALIDATION_ERROR); |
@@ -474,8 +475,8 @@ TEST_F(UserCloudPolicyStoreTest, KeyRotation) { |
// Now load this in a new store - this should trigger key rotation. The keys |
// will still verify using the existing verification key. |
- std::unique_ptr<UserCloudPolicyStore> store2( |
- new UserCloudPolicyStore(policy_file(), key_file(), loop_.task_runner())); |
+ std::unique_ptr<UserCloudPolicyStore> store2(new UserCloudPolicyStore( |
+ policy_file(), key_file(), base::ThreadTaskRunnerHandle::Get())); |
store2->SetSigninUsername(PolicyBuilder::kFakeUsername); |
store2->AddObserver(&observer_); |
EXPECT_CALL(observer_, OnStoreLoaded(store2.get())); |
@@ -500,8 +501,8 @@ TEST_F(UserCloudPolicyStoreTest, InvalidCachedVerificationSignature) { |
// Now load this in a new store - this should cause a validation error because |
// the key won't verify. |
- std::unique_ptr<UserCloudPolicyStore> store2( |
- new UserCloudPolicyStore(policy_file(), key_file(), loop_.task_runner())); |
+ std::unique_ptr<UserCloudPolicyStore> store2(new UserCloudPolicyStore( |
+ policy_file(), key_file(), base::ThreadTaskRunnerHandle::Get())); |
store2->SetSigninUsername(PolicyBuilder::kFakeUsername); |
store2->AddObserver(&observer_); |
ExpectError(store2.get(), CloudPolicyStore::STATUS_VALIDATION_ERROR); |