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

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

Issue 14200028: Make CrosSettings and DeviceSettingsService non Lazy instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix LoginUtilsTest Created 7 years, 8 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
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/device_local_account_policy_service.h" 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" 10 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h"
(...skipping 23 matching lines...) Expand all
34 : public DeviceLocalAccountPolicyService::Observer { 34 : public DeviceLocalAccountPolicyService::Observer {
35 public: 35 public:
36 MOCK_METHOD1(OnPolicyUpdated, void(const std::string&)); 36 MOCK_METHOD1(OnPolicyUpdated, void(const std::string&));
37 MOCK_METHOD0(OnDeviceLocalAccountsChanged, void(void)); 37 MOCK_METHOD0(OnDeviceLocalAccountsChanged, void(void));
38 }; 38 };
39 39
40 class DeviceLocalAccountPolicyServiceTest 40 class DeviceLocalAccountPolicyServiceTest
41 : public chromeos::DeviceSettingsTestBase { 41 : public chromeos::DeviceSettingsTestBase {
42 public: 42 public:
43 DeviceLocalAccountPolicyServiceTest() 43 DeviceLocalAccountPolicyServiceTest()
44 : service_(&device_settings_test_helper_, &device_settings_service_) {} 44 : service_(&device_settings_test_helper_, device_settings_service_) {}
45 45
46 virtual void SetUp() OVERRIDE { 46 virtual void SetUp() OVERRIDE {
47 DeviceSettingsTestBase::SetUp(); 47 DeviceSettingsTestBase::SetUp();
48 48
49 // Values implicitly enforced for public accounts. 49 // Values implicitly enforced for public accounts.
50 expected_policy_map_.Set(key::kLidCloseAction, 50 expected_policy_map_.Set(key::kLidCloseAction,
51 POLICY_LEVEL_MANDATORY, 51 POLICY_LEVEL_MANDATORY,
52 POLICY_SCOPE_USER, 52 POLICY_SCOPE_USER,
53 base::Value::CreateIntegerValue( 53 base::Value::CreateIntegerValue(
54 chromeos::PowerPolicyController:: 54 chromeos::PowerPolicyController::
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 TEST_F(DeviceLocalAccountPolicyServiceTest, DevicePolicyChange) { 242 TEST_F(DeviceLocalAccountPolicyServiceTest, DevicePolicyChange) {
243 device_settings_test_helper_.set_device_local_account_policy_blob( 243 device_settings_test_helper_.set_device_local_account_policy_blob(
244 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 244 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob());
245 InstallDevicePolicy(); 245 InstallDevicePolicy();
246 246
247 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged()); 247 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged());
248 device_policy_.payload().mutable_device_local_accounts()->clear_account(); 248 device_policy_.payload().mutable_device_local_accounts()->clear_account();
249 device_policy_.Build(); 249 device_policy_.Build();
250 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 250 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
251 device_settings_service_.PropertyChangeComplete(true); 251 device_settings_service_->PropertyChangeComplete(true);
252 FlushDeviceSettings(); 252 FlushDeviceSettings();
253 EXPECT_FALSE(service_.GetBrokerForAccount(PolicyBuilder::kFakeUsername)); 253 EXPECT_FALSE(service_.GetBrokerForAccount(PolicyBuilder::kFakeUsername));
254 Mock::VerifyAndClearExpectations(&service_observer_); 254 Mock::VerifyAndClearExpectations(&service_observer_);
255 } 255 }
256 256
257 TEST_F(DeviceLocalAccountPolicyServiceTest, DuplicateAccounts) { 257 TEST_F(DeviceLocalAccountPolicyServiceTest, DuplicateAccounts) {
258 InstallDevicePolicy(); 258 InstallDevicePolicy();
259 DeviceLocalAccountPolicyBroker* broker = 259 DeviceLocalAccountPolicyBroker* broker =
260 service_.GetBrokerForAccount(PolicyBuilder::kFakeUsername); 260 service_.GetBrokerForAccount(PolicyBuilder::kFakeUsername);
261 ASSERT_TRUE(broker); 261 ASSERT_TRUE(broker);
262 262
263 // Add a second entry with a duplicate account name to device policy. 263 // Add a second entry with a duplicate account name to device policy.
264 device_policy_.payload().mutable_device_local_accounts()->add_account()-> 264 device_policy_.payload().mutable_device_local_accounts()->add_account()->
265 set_id(PolicyBuilder::kFakeUsername); 265 set_id(PolicyBuilder::kFakeUsername);
266 device_policy_.Build(); 266 device_policy_.Build();
267 device_settings_test_helper_.set_device_local_account_policy_blob( 267 device_settings_test_helper_.set_device_local_account_policy_blob(
268 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 268 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob());
269 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 269 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
270 270
271 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged()); 271 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged());
272 EXPECT_CALL(service_observer_, OnPolicyUpdated(PolicyBuilder::kFakeUsername)); 272 EXPECT_CALL(service_observer_, OnPolicyUpdated(PolicyBuilder::kFakeUsername));
273 device_settings_service_.PropertyChangeComplete(true); 273 device_settings_service_->PropertyChangeComplete(true);
274 FlushDeviceSettings(); 274 FlushDeviceSettings();
275 Mock::VerifyAndClearExpectations(&service_observer_); 275 Mock::VerifyAndClearExpectations(&service_observer_);
276 276
277 // Make sure the broker is accessible and policy got loaded. 277 // Make sure the broker is accessible and policy got loaded.
278 broker = service_.GetBrokerForAccount(PolicyBuilder::kFakeUsername); 278 broker = service_.GetBrokerForAccount(PolicyBuilder::kFakeUsername);
279 ASSERT_TRUE(broker); 279 ASSERT_TRUE(broker);
280 EXPECT_EQ(PolicyBuilder::kFakeUsername, broker->account_id()); 280 EXPECT_EQ(PolicyBuilder::kFakeUsername, broker->account_id());
281 EXPECT_TRUE(broker->core()->store()->policy()); 281 EXPECT_TRUE(broker->core()->store()->policy());
282 } 282 }
283 283
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 ASSERT_TRUE(request_job); 548 ASSERT_TRUE(request_job);
549 em::DeviceManagementResponse response; 549 em::DeviceManagementResponse response;
550 response.mutable_policy_response()->add_response()->CopyFrom( 550 response.mutable_policy_response()->add_response()->CopyFrom(
551 device_local_account_policy_.policy()); 551 device_local_account_policy_.policy());
552 request_job->SendResponse(DM_STATUS_SUCCESS, response); 552 request_job->SendResponse(DM_STATUS_SUCCESS, response);
553 FlushDeviceSettings(); 553 FlushDeviceSettings();
554 Mock::VerifyAndClearExpectations(&provider_observer_); 554 Mock::VerifyAndClearExpectations(&provider_observer_);
555 } 555 }
556 556
557 } // namespace policy 557 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698