OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/policy/device_policy_cache.h" | 5 #include "chrome/browser/policy/device_policy_cache.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 7 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
8 #include "chrome/browser/chromeos/login/mock_signed_settings_helper.h" | 8 #include "chrome/browser/chromeos/login/mock_signed_settings_helper.h" |
9 #include "chrome/browser/policy/cloud_policy_data_store.h" | 9 #include "chrome/browser/policy/cloud_policy_data_store.h" |
10 #include "chrome/browser/policy/enterprise_install_attributes.h" | 10 #include "chrome/browser/policy/enterprise_install_attributes.h" |
11 #include "content/test/test_browser_thread.h" | |
11 #include "policy/configuration_policy_type.h" | 12 #include "policy/configuration_policy_type.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace policy { | 16 namespace policy { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Test registration user name. | 20 // Test registration user name. |
20 const char kTestUser[] = "test@example.com"; | 21 const char kTestUser[] = "test@example.com"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 proxy_settings->set_proxy_bypass_list(proxy_bypass_list); | 64 proxy_settings->set_proxy_bypass_list(proxy_bypass_list); |
64 CreatePolicy(policy, user, settings); | 65 CreatePolicy(policy, user, settings); |
65 } | 66 } |
66 | 67 |
67 } // namespace | 68 } // namespace |
68 | 69 |
69 class DevicePolicyCacheTest : public testing::Test { | 70 class DevicePolicyCacheTest : public testing::Test { |
70 protected: | 71 protected: |
71 DevicePolicyCacheTest() | 72 DevicePolicyCacheTest() |
72 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)), | 73 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)), |
73 install_attributes_(cryptohome_.get()) {} | 74 install_attributes_(cryptohome_.get()), |
75 message_loop_(MessageLoop::TYPE_UI), | |
76 ui_thread_(content::BrowserThread::UI, &message_loop_), | |
77 file_thread_(content::BrowserThread::FILE, &message_loop_) {} | |
Mattias Nissler (ping if slow)
2011/12/01 11:17:49
I don't see why this test would need to setup thre
pastarmovj
2011/12/01 15:34:49
OwnershipCheck needs to have FILE thread.
| |
74 | 78 |
75 virtual void SetUp() { | 79 virtual void SetUp() { |
76 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); | 80 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); |
77 cache_.reset(new DevicePolicyCache(data_store_.get(), | 81 cache_.reset(new DevicePolicyCache(data_store_.get(), |
78 &install_attributes_, | 82 &install_attributes_, |
79 &signed_settings_helper_)); | 83 &signed_settings_helper_)); |
80 } | 84 } |
81 | 85 |
82 virtual void TearDown() { | 86 virtual void TearDown() { |
83 EXPECT_CALL(signed_settings_helper_, CancelCallback(_)); | |
84 cache_.reset(); | 87 cache_.reset(); |
85 } | 88 } |
86 | 89 |
87 void MakeEnterpriseDevice(const char* registration_user) { | 90 void MakeEnterpriseDevice(const char* registration_user) { |
88 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, | 91 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, |
89 install_attributes_.LockDevice(registration_user)); | 92 install_attributes_.LockDevice(registration_user)); |
90 } | 93 } |
91 | 94 |
92 const Value* GetMandatoryPolicy(ConfigurationPolicyType policy) { | 95 const Value* GetMandatoryPolicy(ConfigurationPolicyType policy) { |
93 return cache_->mandatory_policy_.Get(policy); | 96 return cache_->mandatory_policy_.Get(policy); |
94 } | 97 } |
95 | 98 |
96 const Value* GetRecommendedPolicy(ConfigurationPolicyType policy) { | 99 const Value* GetRecommendedPolicy(ConfigurationPolicyType policy) { |
97 return cache_->recommended_policy_.Get(policy); | 100 return cache_->recommended_policy_.Get(policy); |
98 } | 101 } |
99 | 102 |
100 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; | 103 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; |
101 EnterpriseInstallAttributes install_attributes_; | 104 EnterpriseInstallAttributes install_attributes_; |
102 scoped_ptr<CloudPolicyDataStore> data_store_; | 105 scoped_ptr<CloudPolicyDataStore> data_store_; |
103 chromeos::MockSignedSettingsHelper signed_settings_helper_; | 106 chromeos::MockSignedSettingsHelper signed_settings_helper_; |
104 scoped_ptr<DevicePolicyCache> cache_; | 107 scoped_ptr<DevicePolicyCache> cache_; |
105 | 108 |
109 MessageLoop message_loop_; | |
110 content::TestBrowserThread ui_thread_; | |
111 content::TestBrowserThread file_thread_; | |
112 | |
106 private: | 113 private: |
107 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest); | 114 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest); |
108 }; | 115 }; |
109 | 116 |
110 TEST_F(DevicePolicyCacheTest, Startup) { | 117 TEST_F(DevicePolicyCacheTest, Startup) { |
111 em::PolicyFetchResponse policy; | 118 em::PolicyFetchResponse policy; |
112 CreateRefreshRatePolicy(&policy, kTestUser, 120); | 119 CreateRefreshRatePolicy(&policy, kTestUser, 120); |
113 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 120 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
114 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 121 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
115 policy)); | 122 policy)); |
(...skipping 24 matching lines...) Expand all Loading... | |
140 kPolicyDevicePolicyRefreshRate))); | 147 kPolicyDevicePolicyRefreshRate))); |
141 | 148 |
142 // Set new policy information. | 149 // Set new policy information. |
143 em::PolicyFetchResponse new_policy; | 150 em::PolicyFetchResponse new_policy; |
144 CreateRefreshRatePolicy(&new_policy, kTestUser, 300); | 151 CreateRefreshRatePolicy(&new_policy, kTestUser, 300); |
145 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce( | 152 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce( |
146 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS)); | 153 MockSignedSettingsHelperStorePolicy(chromeos::SignedSettings::SUCCESS)); |
147 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( | 154 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce( |
148 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, | 155 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS, |
149 new_policy)); | 156 new_policy)); |
150 EXPECT_CALL(signed_settings_helper_, CancelCallback(_)); | |
151 cache_->SetPolicy(new_policy); | 157 cache_->SetPolicy(new_policy); |
152 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 158 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
153 base::FundamentalValue updated_expected(300); | 159 base::FundamentalValue updated_expected(300); |
154 EXPECT_TRUE(Value::Equals(&updated_expected, | 160 EXPECT_TRUE(Value::Equals(&updated_expected, |
155 GetMandatoryPolicy( | 161 GetMandatoryPolicy( |
156 kPolicyDevicePolicyRefreshRate))); | 162 kPolicyDevicePolicyRefreshRate))); |
157 } | 163 } |
158 | 164 |
159 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) { | 165 TEST_F(DevicePolicyCacheTest, SetPolicyWrongUser) { |
160 InSequence s; | 166 InSequence s; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 policy)); | 255 policy)); |
250 cache_->Load(); | 256 cache_->Load(); |
251 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); | 257 testing::Mock::VerifyAndClearExpectations(&signed_settings_helper_); |
252 StringValue expected_config(fake_config); | 258 StringValue expected_config(fake_config); |
253 EXPECT_TRUE( | 259 EXPECT_TRUE( |
254 Value::Equals(&expected_config, | 260 Value::Equals(&expected_config, |
255 GetMandatoryPolicy(kPolicyDeviceOpenNetworkConfiguration))); | 261 GetMandatoryPolicy(kPolicyDeviceOpenNetworkConfiguration))); |
256 } | 262 } |
257 | 263 |
258 } // namespace policy | 264 } // namespace policy |
OLD | NEW |