OLD | NEW |
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 20 matching lines...) Expand all Loading... |
51 "0123456789ABCDEF0123456789ABCDEF012345678@example.com"; | 51 "0123456789ABCDEF0123456789ABCDEF012345678@example.com"; |
52 const char kDefaultHomepage[] = "http://chromium.org"; | 52 const char kDefaultHomepage[] = "http://chromium.org"; |
53 | 53 |
54 ACTION_P2(SendSanitizedUsername, call_status, sanitized_username) { | 54 ACTION_P2(SendSanitizedUsername, call_status, sanitized_username) { |
55 base::ThreadTaskRunnerHandle::Get()->PostTask( | 55 base::ThreadTaskRunnerHandle::Get()->PostTask( |
56 FROM_HERE, base::Bind(arg1, call_status, sanitized_username)); | 56 FROM_HERE, base::Bind(arg1, call_status, sanitized_username)); |
57 } | 57 } |
58 | 58 |
59 class UserCloudPolicyStoreChromeOSTest : public testing::Test { | 59 class UserCloudPolicyStoreChromeOSTest : public testing::Test { |
60 protected: | 60 protected: |
61 UserCloudPolicyStoreChromeOSTest() {} | 61 UserCloudPolicyStoreChromeOSTest() |
| 62 : scoped_task_environment_( |
| 63 base::test::ScopedTaskEnvironment::MainThreadType::UI) {} |
62 | 64 |
63 void SetUp() override { | 65 void SetUp() override { |
64 EXPECT_CALL(cryptohome_client_, GetSanitizedUsername(cryptohome_id_, _)) | 66 EXPECT_CALL(cryptohome_client_, GetSanitizedUsername(cryptohome_id_, _)) |
65 .Times(AnyNumber()) | 67 .Times(AnyNumber()) |
66 .WillRepeatedly(SendSanitizedUsername( | 68 .WillRepeatedly(SendSanitizedUsername( |
67 chromeos::DBUS_METHOD_CALL_SUCCESS, kSanitizedUsername)); | 69 chromeos::DBUS_METHOD_CALL_SUCCESS, kSanitizedUsername)); |
68 | 70 |
69 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); | 71 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); |
70 store_.reset(new UserCloudPolicyStoreChromeOS( | 72 store_.reset(new UserCloudPolicyStoreChromeOS( |
71 &cryptohome_client_, &session_manager_client_, loop_.task_runner(), | 73 &cryptohome_client_, &session_manager_client_, loop_.task_runner(), |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 202 |
201 base::FilePath user_policy_dir() { | 203 base::FilePath user_policy_dir() { |
202 return tmp_dir_.GetPath().AppendASCII("var_run_user_policy"); | 204 return tmp_dir_.GetPath().AppendASCII("var_run_user_policy"); |
203 } | 205 } |
204 | 206 |
205 base::FilePath user_policy_key_file() { | 207 base::FilePath user_policy_key_file() { |
206 return user_policy_dir().AppendASCII(kSanitizedUsername) | 208 return user_policy_dir().AppendASCII(kSanitizedUsername) |
207 .AppendASCII("policy.pub"); | 209 .AppendASCII("policy.pub"); |
208 } | 210 } |
209 | 211 |
210 base::MessageLoopForUI loop_; | 212 base::test::ScopedTaskEnvironment scoped_task_environment_; |
211 chromeos::MockCryptohomeClient cryptohome_client_; | 213 chromeos::MockCryptohomeClient cryptohome_client_; |
212 chromeos::MockSessionManagerClient session_manager_client_; | 214 chromeos::MockSessionManagerClient session_manager_client_; |
213 UserPolicyBuilder policy_; | 215 UserPolicyBuilder policy_; |
214 MockCloudPolicyStoreObserver observer_; | 216 MockCloudPolicyStoreObserver observer_; |
215 std::unique_ptr<UserCloudPolicyStoreChromeOS> store_; | 217 std::unique_ptr<UserCloudPolicyStoreChromeOS> store_; |
216 const AccountId account_id_ = | 218 const AccountId account_id_ = |
217 AccountId::FromUserEmail(PolicyBuilder::kFakeUsername); | 219 AccountId::FromUserEmail(PolicyBuilder::kFakeUsername); |
218 const cryptohome::Identification cryptohome_id_ = | 220 const cryptohome::Identification cryptohome_id_ = |
219 cryptohome::Identification(account_id_); | 221 cryptohome::Identification(account_id_); |
220 | 222 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 588 |
587 EXPECT_FALSE(store_->policy()); | 589 EXPECT_FALSE(store_->policy()); |
588 EXPECT_TRUE(store_->policy_map().empty()); | 590 EXPECT_TRUE(store_->policy_map().empty()); |
589 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); | 591 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, store_->status()); |
590 EXPECT_EQ(std::string(), store_->policy_signature_public_key()); | 592 EXPECT_EQ(std::string(), store_->policy_signature_public_key()); |
591 } | 593 } |
592 | 594 |
593 } // namespace | 595 } // namespace |
594 | 596 |
595 } // namespace policy | 597 } // namespace policy |
OLD | NEW |