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

Side by Side Diff: chrome/browser/policy/device_policy_cache_unittest.cc

Issue 10918027: Revert 154457 - Switch from SignedSettings to DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/device_policy_cache.cc ('k') | chrome/browser/prefs/browser_prefs.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/policy/device_policy_cache.h" 5 #include "chrome/browser/policy/device_policy_cache.h"
6 6
7 #include <vector>
8
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/threading/sequenced_worker_pool.h"
14 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 7 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
15 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 8 #include "chrome/browser/chromeos/settings/mock_signed_settings_helper.h"
16 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h"
17 #include "chrome/browser/policy/cloud_policy_data_store.h" 9 #include "chrome/browser/policy/cloud_policy_data_store.h"
18 #include "chrome/browser/policy/enterprise_install_attributes.h" 10 #include "chrome/browser/policy/enterprise_install_attributes.h"
19 #include "chrome/browser/policy/policy_builder.h"
20 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" 11 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
21 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
22 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
23 #include "policy/policy_constants.h" 13 #include "policy/policy_constants.h"
24 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
26 16
27 using ::testing::Mock;
28
29 namespace em = enterprise_management; 17 namespace em = enterprise_management;
30 18
31 namespace policy { 19 namespace policy {
32 20
33 namespace { 21 namespace {
34 22
23 // Test registration user name.
24 const char kTestUser[] = "test@example.com";
25
26 using ::chromeos::SignedSettings;
27 using ::testing::InSequence;
28 using ::testing::Mock;
29 using ::testing::SaveArg;
30 using ::testing::_;
31
35 class MockCloudPolicyCacheObserver : public CloudPolicyCacheBase::Observer { 32 class MockCloudPolicyCacheObserver : public CloudPolicyCacheBase::Observer {
36 public: 33 public:
37 virtual ~MockCloudPolicyCacheObserver() {}
38
39 MOCK_METHOD1(OnCacheGoingAway, void(CloudPolicyCacheBase*)); 34 MOCK_METHOD1(OnCacheGoingAway, void(CloudPolicyCacheBase*));
40 MOCK_METHOD1(OnCacheUpdate, void(CloudPolicyCacheBase*)); 35 MOCK_METHOD1(OnCacheUpdate, void(CloudPolicyCacheBase*));
41 }; 36 };
42 37
38 void CreatePolicy(em::PolicyFetchResponse* policy,
39 const std::string& user,
40 em::ChromeDeviceSettingsProto& settings) {
41 // This method omits a few fields which currently aren't needed by tests:
42 // timestamp, machine_name, public key info.
43 em::PolicyData signed_response;
44 signed_response.set_username(user);
45 signed_response.set_request_token("dmtoken");
46 signed_response.set_device_id("deviceid");
47 EXPECT_TRUE(
48 settings.SerializeToString(signed_response.mutable_policy_value()));
49 std::string serialized_signed_response;
50 EXPECT_TRUE(signed_response.SerializeToString(&serialized_signed_response));
51 policy->set_policy_data(serialized_signed_response);
52 }
53
54 void CreateRefreshRatePolicy(em::PolicyFetchResponse* policy,
55 const std::string& user,
56 int refresh_rate) {
57 em::ChromeDeviceSettingsProto settings;
58 settings.mutable_device_policy_refresh_rate()->
59 set_device_policy_refresh_rate(refresh_rate);
60 CreatePolicy(policy, user, settings);
61 }
62
63 void CreateProxyPolicy(em::PolicyFetchResponse* policy,
64 const std::string& user,
65 const std::string& proxy_mode,
66 const std::string& proxy_server,
67 const std::string& proxy_pac_url,
68 const std::string& proxy_bypass_list) {
69 em::ChromeDeviceSettingsProto settings;
70 em::DeviceProxySettingsProto* proxy_settings =
71 settings.mutable_device_proxy_settings();
72 proxy_settings->set_proxy_mode(proxy_mode);
73 proxy_settings->set_proxy_server(proxy_server);
74 proxy_settings->set_proxy_pac_url(proxy_pac_url);
75 proxy_settings->set_proxy_bypass_list(proxy_bypass_list);
76 CreatePolicy(policy, user, settings);
77 }
78
43 } // namespace 79 } // namespace
44 80
45 class DevicePolicyCacheTest : public testing::Test { 81 class DevicePolicyCacheTest : public testing::Test {
46 protected: 82 protected:
47 DevicePolicyCacheTest() 83 DevicePolicyCacheTest()
48 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)), 84 : cryptohome_(chromeos::CryptohomeLibrary::GetImpl(true)),
49 owner_key_util_(new chromeos::MockOwnerKeyUtil()),
50 install_attributes_(cryptohome_.get()), 85 install_attributes_(cryptohome_.get()),
51 message_loop_(MessageLoop::TYPE_UI), 86 message_loop_(MessageLoop::TYPE_UI),
52 ui_thread_(content::BrowserThread::UI, &message_loop_), 87 ui_thread_(content::BrowserThread::UI, &message_loop_),
53 file_thread_(content::BrowserThread::FILE, &message_loop_) {} 88 file_thread_(content::BrowserThread::FILE, &message_loop_) {}
54 89
55 virtual void SetUp() OVERRIDE { 90 virtual void SetUp() {
56 policy_.payload().mutable_device_policy_refresh_rate()-> 91 data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies());
57 set_device_policy_refresh_rate(120);
58 policy_.Build();
59 device_settings_test_helper_.set_policy_blob(policy_.GetBlob());
60
61 owner_key_util_->SetPublicKeyFromPrivateKey(policy_.signing_key());
62
63 device_settings_service_.Initialize(&device_settings_test_helper_,
64 owner_key_util_);
65
66 data_store_.reset(CloudPolicyDataStore::CreateForDevicePolicies());
67 cache_.reset(new DevicePolicyCache(data_store_.get(), 92 cache_.reset(new DevicePolicyCache(data_store_.get(),
68 &install_attributes_, 93 &install_attributes_,
69 &device_settings_service_)); 94 &signed_settings_helper_));
70 cache_->AddObserver(&observer_); 95 cache_->AddObserver(&observer_);
71 } 96 }
72 97
73 virtual void TearDown() OVERRIDE { 98 virtual void TearDown() {
74 device_settings_test_helper_.Flush();
75 device_settings_service_.Shutdown();
76
77 cache_->RemoveObserver(&observer_); 99 cache_->RemoveObserver(&observer_);
78 cache_.reset(); 100 cache_.reset();
79 } 101 }
80 102
81 void Startup() { 103 void MakeEnterpriseDevice(const char* registration_user) {
82 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
83 device_settings_service_.Load();
84 device_settings_test_helper_.Flush();
85 cache_->Load();
86 Mock::VerifyAndClearExpectations(&observer_);
87 }
88
89 void MakeEnterpriseDevice() {
90 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, 104 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS,
91 install_attributes_.LockDevice( 105 install_attributes_.LockDevice(
92 policy_.policy_data().username(), 106 registration_user,
93 DEVICE_MODE_ENTERPRISE, 107 DEVICE_MODE_ENTERPRISE,
94 std::string())); 108 std::string()));
95 } 109 }
96 110
97 const Value* GetPolicy(const char* policy_name) { 111 const Value* GetPolicy(const char* policy_name) {
98 return cache_->policy()->GetValue(policy_name); 112 return cache_->policy()->GetValue(policy_name);
99 } 113 }
100 114
101 MockCloudPolicyCacheObserver observer_; 115 MockCloudPolicyCacheObserver observer_;
102
103 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_; 116 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_;
104 scoped_refptr<chromeos::MockOwnerKeyUtil> owner_key_util_;
105 chromeos::DeviceSettingsTestHelper device_settings_test_helper_;
106 chromeos::DeviceSettingsService device_settings_service_;
107 EnterpriseInstallAttributes install_attributes_; 117 EnterpriseInstallAttributes install_attributes_;
108
109 scoped_ptr<CloudPolicyDataStore> data_store_; 118 scoped_ptr<CloudPolicyDataStore> data_store_;
119 chromeos::MockSignedSettingsHelper signed_settings_helper_;
110 scoped_ptr<DevicePolicyCache> cache_; 120 scoped_ptr<DevicePolicyCache> cache_;
111 DevicePolicyBuilder policy_;
112 121
113 MessageLoop message_loop_; 122 MessageLoop message_loop_;
114 content::TestBrowserThread ui_thread_; 123 content::TestBrowserThread ui_thread_;
115 content::TestBrowserThread file_thread_; 124 content::TestBrowserThread file_thread_;
116 125
117 private: 126 private:
118 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest); 127 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCacheTest);
119 }; 128 };
120 129
121 TEST_F(DevicePolicyCacheTest, ColdStartup) { 130 TEST_F(DevicePolicyCacheTest, Startup) {
131 em::PolicyFetchResponse policy;
132 CreateRefreshRatePolicy(&policy, kTestUser, 120);
133 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
134 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
135 policy));
136 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
137 cache_->Load();
138 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
139 base::FundamentalValue expected(120);
140 EXPECT_TRUE(Value::Equals(&expected,
141 GetPolicy(key::kDevicePolicyRefreshRate)));
142 }
143
144 TEST_F(DevicePolicyCacheTest, SetPolicy) {
145 InSequence s;
146
147 MakeEnterpriseDevice(kTestUser);
148
149 // Startup.
150 em::PolicyFetchResponse policy;
151 CreateRefreshRatePolicy(&policy, kTestUser, 120);
152 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
153 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
154 policy));
155 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
156 cache_->Load();
157 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
158 Mock::VerifyAndClearExpectations(&observer_);
159 base::FundamentalValue expected(120);
160 EXPECT_TRUE(Value::Equals(&expected,
161 GetPolicy(key::kDevicePolicyRefreshRate)));
162
163 // Set new policy information.
164 chromeos::SignedSettingsHelper::StorePolicyCallback store_callback;
165 em::PolicyFetchResponse new_policy;
166 CreateRefreshRatePolicy(&new_policy, kTestUser, 300);
167 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce(
168 SaveArg<1>(&store_callback));
122 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0); 169 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0);
123 cache_->Load(); 170 EXPECT_TRUE(cache_->SetPolicy(new_policy));
171 cache_->SetFetchingDone();
172 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
173 Mock::VerifyAndClearExpectations(&observer_);
174 ASSERT_FALSE(store_callback.is_null());
175
176 chromeos::SignedSettingsHelper::RetrievePolicyCallback retrieve_callback;
177 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
178 SaveArg<0>(&retrieve_callback));
179 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0);
180 store_callback.Run(chromeos::SignedSettings::SUCCESS);
181 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
182 Mock::VerifyAndClearExpectations(&observer_);
183 ASSERT_FALSE(retrieve_callback.is_null());
184
185 // Cache update notification should only fire in the retrieve callback.
186 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
187 retrieve_callback.Run(chromeos::SignedSettings::SUCCESS, new_policy);
188 base::FundamentalValue updated_expected(300);
189 EXPECT_TRUE(Value::Equals(&updated_expected,
190 GetPolicy(key::kDevicePolicyRefreshRate)));
124 Mock::VerifyAndClearExpectations(&observer_); 191 Mock::VerifyAndClearExpectations(&observer_);
125 192
193 cache_->RemoveObserver(&observer_);
194 }
195
196 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserSameDomain) {
197 InSequence s;
198
199 MakeEnterpriseDevice(kTestUser);
200
201 // Startup.
202 em::PolicyFetchResponse policy;
203 CreateRefreshRatePolicy(&policy, kTestUser, 120);
204 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
205 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
206 policy));
126 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())); 207 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
127 device_settings_service_.Load(); 208 cache_->Load();
128 device_settings_test_helper_.Flush(); 209 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
210
211 // Set new policy information. This should succeed as the domain is the same.
212 chromeos::SignedSettingsHelper::StorePolicyCallback store_callback;
213 em::PolicyFetchResponse new_policy;
214 CreateRefreshRatePolicy(&new_policy, "another_user@example.com", 300);
215 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).WillOnce(
216 SaveArg<1>(&store_callback));
217 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(1);
218 EXPECT_TRUE(cache_->SetPolicy(new_policy));
219 cache_->SetFetchingDone();
220 store_callback.Run(chromeos::SignedSettings::OPERATION_FAILED);
221 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
129 Mock::VerifyAndClearExpectations(&observer_); 222 Mock::VerifyAndClearExpectations(&observer_);
223 }
224
225 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserOtherDomain) {
226 InSequence s;
227
228 MakeEnterpriseDevice(kTestUser);
229
230 // Startup.
231 em::PolicyFetchResponse policy;
232 CreateRefreshRatePolicy(&policy, kTestUser, 120);
233 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
234 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
235 policy));
236 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
237 cache_->Load();
238 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
239
240 // Set new policy information. This should fail because the user is from
241 // different domain.
242 em::PolicyFetchResponse new_policy;
243 CreateRefreshRatePolicy(&new_policy, "foreign_user@hackers.com", 300);
244 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0);
245 EXPECT_FALSE(cache_->SetPolicy(new_policy));
246 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
130 247
131 base::FundamentalValue expected(120); 248 base::FundamentalValue expected(120);
132 EXPECT_TRUE(Value::Equals(&expected, 249 EXPECT_TRUE(Value::Equals(&expected,
133 GetPolicy(key::kDevicePolicyRefreshRate))); 250 GetPolicy(key::kDevicePolicyRefreshRate)));
134 } 251 }
135 252
136 TEST_F(DevicePolicyCacheTest, WarmStartup) { 253 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) {
137 Startup(); 254 InSequence s;
255
256 // Startup.
257 em::PolicyFetchResponse policy;
258 CreateRefreshRatePolicy(&policy, kTestUser, 120);
259 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
260 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
261 policy));
262 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
263 cache_->Load();
264 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
265
266 // Set new policy information. This should fail due to invalid user.
267 em::PolicyFetchResponse new_policy;
268 CreateRefreshRatePolicy(&new_policy, kTestUser, 120);
269 EXPECT_CALL(signed_settings_helper_, StartStorePolicyOp(_, _)).Times(0);
270 EXPECT_FALSE(cache_->SetPolicy(new_policy));
271 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
138 272
139 base::FundamentalValue expected(120); 273 base::FundamentalValue expected(120);
140 EXPECT_TRUE(Value::Equals(&expected, 274 EXPECT_TRUE(Value::Equals(&expected,
141 GetPolicy(key::kDevicePolicyRefreshRate))); 275 GetPolicy(key::kDevicePolicyRefreshRate)));
142 } 276 }
143 277
144 TEST_F(DevicePolicyCacheTest, SetPolicy) { 278 TEST_F(DevicePolicyCacheTest, SetProxyPolicy) {
145 MakeEnterpriseDevice(); 279 MakeEnterpriseDevice(kTestUser);
146 Startup();
147 280
148 base::FundamentalValue expected(120); 281 // Startup.
282 em::PolicyFetchResponse policy;
283 CreateProxyPolicy(&policy, kTestUser, "direct", "http://proxy:8080",
284 "http://proxy:8080/pac.js", "127.0.0.1,example.com");
285 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
286 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
287 policy));
288 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
289 cache_->Load();
290 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
291 DictionaryValue expected;
292 expected.SetString(key::kProxyMode, "direct");
293 expected.SetString(key::kProxyServer, "http://proxy:8080");
294 expected.SetString(key::kProxyPacUrl, "http://proxy:8080/pac.js");
295 expected.SetString(key::kProxyBypassList, "127.0.0.1,example.com");
149 EXPECT_TRUE(Value::Equals(&expected, 296 EXPECT_TRUE(Value::Equals(&expected,
150 GetPolicy(key::kDevicePolicyRefreshRate))); 297 GetPolicy(key::kProxySettings)));
151
152 // Set new policy information.
153 policy_.payload().mutable_device_policy_refresh_rate()->
154 set_device_policy_refresh_rate(300);
155 policy_.Build();
156 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0);
157 EXPECT_TRUE(cache_->SetPolicy(policy_.policy()));
158 cache_->SetFetchingDone();
159 Mock::VerifyAndClearExpectations(&observer_);
160
161 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get())).Times(0);
162 device_settings_test_helper_.FlushStore();
163 Mock::VerifyAndClearExpectations(&observer_);
164
165 // Cache update notification should only fire in the retrieve callback.
166 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
167 device_settings_test_helper_.Flush();
168 Mock::VerifyAndClearExpectations(&observer_);
169
170 base::FundamentalValue updated_expected(300);
171 EXPECT_TRUE(Value::Equals(&updated_expected,
172 GetPolicy(key::kDevicePolicyRefreshRate)));
173
174 cache_->RemoveObserver(&observer_);
175 }
176
177 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserSameDomain) {
178 MakeEnterpriseDevice();
179 Startup();
180
181 // Set new policy information. This should succeed as the domain is the same.
182 policy_.policy_data().set_username("another_user@example.com");
183 policy_.Build();
184
185 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
186 EXPECT_TRUE(cache_->SetPolicy(policy_.policy()));
187 device_settings_test_helper_.Flush();
188 Mock::VerifyAndClearExpectations(&observer_);
189 EXPECT_EQ(policy_.GetBlob(), device_settings_test_helper_.policy_blob());
190 }
191
192 TEST_F(DevicePolicyCacheTest, SetPolicyOtherUserOtherDomain) {
193 MakeEnterpriseDevice();
194 Startup();
195
196 // Set new policy information. This should fail because the user is from
197 // different domain.
198 policy_.policy_data().set_username("foreign_user@hackers.com");
199 policy_.Build();
200 EXPECT_NE(policy_.GetBlob(), device_settings_test_helper_.policy_blob());
201
202 EXPECT_FALSE(cache_->SetPolicy(policy_.policy()));
203 device_settings_test_helper_.Flush();
204 EXPECT_NE(policy_.GetBlob(), device_settings_test_helper_.policy_blob());
205 }
206
207 TEST_F(DevicePolicyCacheTest, SetPolicyNonEnterpriseDevice) {
208 Startup();
209
210 // Set new policy information. This should fail due to invalid user.
211 device_settings_test_helper_.set_policy_blob(std::string());
212
213 EXPECT_FALSE(cache_->SetPolicy(policy_.policy()));
214 device_settings_test_helper_.Flush();
215 EXPECT_TRUE(device_settings_test_helper_.policy_blob().empty());
216 }
217
218 TEST_F(DevicePolicyCacheTest, SetProxyPolicy) {
219 MakeEnterpriseDevice();
220
221 em::DeviceProxySettingsProto proxy_settings;
222 proxy_settings.set_proxy_mode("direct");
223 proxy_settings.set_proxy_server("http://proxy:8080");
224 proxy_settings.set_proxy_pac_url("http://proxy:8080/pac.js");
225 proxy_settings.set_proxy_bypass_list("127.0.0.1,example.com");
226 policy_.payload().mutable_device_proxy_settings()->CopyFrom(proxy_settings);
227 policy_.Build();
228 device_settings_test_helper_.set_policy_blob(policy_.GetBlob());
229 Startup();
230
231 DictionaryValue expected;
232 expected.SetString(key::kProxyMode, proxy_settings.proxy_mode());
233 expected.SetString(key::kProxyServer, proxy_settings.proxy_server());
234 expected.SetString(key::kProxyPacUrl, proxy_settings.proxy_pac_url());
235 expected.SetString(key::kProxyBypassList, proxy_settings.proxy_bypass_list());
236 EXPECT_TRUE(Value::Equals(&expected, GetPolicy(key::kProxySettings)));
237 } 298 }
238 299
239 TEST_F(DevicePolicyCacheTest, SetDeviceNetworkConfigurationPolicy) { 300 TEST_F(DevicePolicyCacheTest, SetDeviceNetworkConfigurationPolicy) {
240 MakeEnterpriseDevice(); 301 MakeEnterpriseDevice(kTestUser);
241 302
303 // Startup.
242 std::string fake_config("{ 'NetworkConfigurations': [] }"); 304 std::string fake_config("{ 'NetworkConfigurations': [] }");
243 policy_.payload().mutable_open_network_configuration()-> 305 em::PolicyFetchResponse policy;
244 set_open_network_configuration(fake_config); 306 em::ChromeDeviceSettingsProto settings;
245 policy_.Build(); 307 settings.mutable_open_network_configuration()->set_open_network_configuration(
246 device_settings_test_helper_.set_policy_blob(policy_.GetBlob()); 308 fake_config);
247 Startup(); 309 CreatePolicy(&policy, kTestUser, settings);
248 310 EXPECT_CALL(signed_settings_helper_, StartRetrievePolicyOp(_)).WillOnce(
311 MockSignedSettingsHelperRetrievePolicy(SignedSettings::SUCCESS,
312 policy));
313 EXPECT_CALL(observer_, OnCacheUpdate(cache_.get()));
314 cache_->Load();
315 Mock::VerifyAndClearExpectations(&signed_settings_helper_);
249 StringValue expected_config(fake_config); 316 StringValue expected_config(fake_config);
250 EXPECT_TRUE( 317 EXPECT_TRUE(
251 Value::Equals(&expected_config, 318 Value::Equals(&expected_config,
252 GetPolicy(key::kDeviceOpenNetworkConfiguration))); 319 GetPolicy(key::kDeviceOpenNetworkConfiguration)));
253 } 320 }
254 321
255 } // namespace policy 322 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_policy_cache.cc ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698