Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos_unittest.cc

Issue 2851593002: Use ScopedTaskEnvironment instead of MessageLoopForUI in chrome tests. (Closed)
Patch Set: fix-build-error Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/settings/install_attributes_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/message_loop/message_loop.h"
19 #include "base/run_loop.h" 18 #include "base/run_loop.h"
20 #include "base/single_thread_task_runner.h" 19 #include "base/single_thread_task_runner.h"
20 #include "base/test/scoped_task_environment.h"
21 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
22 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
23 #include "chromeos/dbus/mock_cryptohome_client.h" 23 #include "chromeos/dbus/mock_cryptohome_client.h"
24 #include "chromeos/dbus/mock_session_manager_client.h" 24 #include "chromeos/dbus/mock_session_manager_client.h"
25 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 25 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
26 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" 26 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
27 #include "components/policy/core/common/cloud/policy_builder.h" 27 #include "components/policy/core/common/cloud/policy_builder.h"
28 #include "components/policy/core/common/policy_types.h" 28 #include "components/policy/core/common/policy_types.h"
29 #include "components/policy/policy_constants.h" 29 #include "components/policy/policy_constants.h"
30 #include "components/policy/proto/cloud_policy.pb.h" 30 #include "components/policy/proto/cloud_policy.pb.h"
(...skipping 24 matching lines...) Expand all
55 "0123456789ABCDEF0123456789ABCDEF012345678@example.com"; 55 "0123456789ABCDEF0123456789ABCDEF012345678@example.com";
56 const char kDefaultHomepage[] = "http://chromium.org"; 56 const char kDefaultHomepage[] = "http://chromium.org";
57 57
58 ACTION_P2(SendSanitizedUsername, call_status, sanitized_username) { 58 ACTION_P2(SendSanitizedUsername, call_status, sanitized_username) {
59 base::ThreadTaskRunnerHandle::Get()->PostTask( 59 base::ThreadTaskRunnerHandle::Get()->PostTask(
60 FROM_HERE, base::Bind(arg1, call_status, sanitized_username)); 60 FROM_HERE, base::Bind(arg1, call_status, sanitized_username));
61 } 61 }
62 62
63 class UserCloudPolicyStoreChromeOSTest : public testing::Test { 63 class UserCloudPolicyStoreChromeOSTest : public testing::Test {
64 protected: 64 protected:
65 UserCloudPolicyStoreChromeOSTest() {} 65 UserCloudPolicyStoreChromeOSTest()
66 : scoped_task_environment_(
67 base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
66 68
67 void SetUp() override { 69 void SetUp() override {
68 EXPECT_CALL(cryptohome_client_, GetSanitizedUsername(cryptohome_id_, _)) 70 EXPECT_CALL(cryptohome_client_, GetSanitizedUsername(cryptohome_id_, _))
69 .Times(AnyNumber()) 71 .Times(AnyNumber())
70 .WillRepeatedly(SendSanitizedUsername( 72 .WillRepeatedly(SendSanitizedUsername(
71 chromeos::DBUS_METHOD_CALL_SUCCESS, kSanitizedUsername)); 73 chromeos::DBUS_METHOD_CALL_SUCCESS, kSanitizedUsername));
72 74
73 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); 75 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir());
74 store_.reset(new UserCloudPolicyStoreChromeOS( 76 store_.reset(new UserCloudPolicyStoreChromeOS(
75 &cryptohome_client_, &session_manager_client_, loop_.task_runner(), 77 &cryptohome_client_, &session_manager_client_,
76 account_id_, user_policy_dir(), false /* is_active_directory */)); 78 base::ThreadTaskRunnerHandle::Get(), account_id_, user_policy_dir(),
79 false /* is_active_directory */));
77 store_->AddObserver(&observer_); 80 store_->AddObserver(&observer_);
78 81
79 // Install the initial public key, so that by default the validation of 82 // Install the initial public key, so that by default the validation of
80 // the stored/loaded policy blob succeeds. 83 // the stored/loaded policy blob succeeds.
81 std::string public_key = policy_.GetPublicSigningKeyAsString(); 84 std::string public_key = policy_.GetPublicSigningKeyAsString();
82 ASSERT_FALSE(public_key.empty()); 85 ASSERT_FALSE(public_key.empty());
83 StoreUserPolicyKey(public_key); 86 StoreUserPolicyKey(public_key);
84 87
85 policy_.payload().mutable_homepagelocation()->set_value(kDefaultHomepage); 88 policy_.payload().mutable_homepagelocation()->set_value(kDefaultHomepage);
86 policy_.Build(); 89 policy_.Build();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 208
206 base::FilePath user_policy_dir() { 209 base::FilePath user_policy_dir() {
207 return tmp_dir_.GetPath().AppendASCII("var_run_user_policy"); 210 return tmp_dir_.GetPath().AppendASCII("var_run_user_policy");
208 } 211 }
209 212
210 base::FilePath user_policy_key_file() { 213 base::FilePath user_policy_key_file() {
211 return user_policy_dir().AppendASCII(kSanitizedUsername) 214 return user_policy_dir().AppendASCII(kSanitizedUsername)
212 .AppendASCII("policy.pub"); 215 .AppendASCII("policy.pub");
213 } 216 }
214 217
215 base::MessageLoopForUI loop_; 218 base::test::ScopedTaskEnvironment scoped_task_environment_;
216 chromeos::MockCryptohomeClient cryptohome_client_; 219 chromeos::MockCryptohomeClient cryptohome_client_;
217 chromeos::MockSessionManagerClient session_manager_client_; 220 chromeos::MockSessionManagerClient session_manager_client_;
218 UserPolicyBuilder policy_; 221 UserPolicyBuilder policy_;
219 MockCloudPolicyStoreObserver observer_; 222 MockCloudPolicyStoreObserver observer_;
220 std::unique_ptr<UserCloudPolicyStoreChromeOS> store_; 223 std::unique_ptr<UserCloudPolicyStoreChromeOS> store_;
221 const AccountId account_id_ = 224 const AccountId account_id_ =
222 AccountId::FromUserEmail(PolicyBuilder::kFakeUsername); 225 AccountId::FromUserEmail(PolicyBuilder::kFakeUsername);
223 const cryptohome::Identification cryptohome_id_ = 226 const cryptohome::Identification cryptohome_id_ =
224 cryptohome::Identification(account_id_); 227 cryptohome::Identification(account_id_);
225 228
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 599
597 EXPECT_FALSE(store_->policy()); 600 EXPECT_FALSE(store_->policy());
598 EXPECT_TRUE(store_->policy_map().empty()); 601 EXPECT_TRUE(store_->policy_map().empty());
599 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); 602 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status());
600 EXPECT_EQ(std::string(), store_->policy_signature_public_key()); 603 EXPECT_EQ(std::string(), store_->policy_signature_public_key());
601 } 604 }
602 605
603 } // namespace 606 } // namespace
604 607
605 } // namespace policy 608 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/settings/install_attributes_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698