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

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

Issue 27548004: Cache force-installed apps/extensions in device-local accounts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Ready to reland after revert due to conflicting concurrent commit. Created 7 years, 2 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/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h"
11 #include "base/files/file_path.h"
12 #include "base/files/scoped_temp_dir.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/message_loop/message_loop_proxy.h"
15 #include "base/path_service.h"
16 #include "base/run_loop.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h"
19 #include "base/test/scoped_path_override.h"
20 #include "base/test/test_simple_task_runner.h"
10 #include "chrome/browser/chromeos/policy/device_local_account.h" 21 #include "chrome/browser/chromeos/policy/device_local_account.h"
11 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" 22 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h"
12 #include "chrome/browser/chromeos/settings/cros_settings.h" 23 #include "chrome/browser/chromeos/settings/cros_settings.h"
13 #include "chrome/browser/chromeos/settings/device_settings_service.h" 24 #include "chrome/browser/chromeos/settings/device_settings_service.h"
14 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 25 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
15 #include "chrome/browser/policy/cloud/cloud_policy_client.h" 26 #include "chrome/browser/policy/cloud/cloud_policy_client.h"
16 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" 27 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
17 #include "chrome/browser/policy/cloud/cloud_policy_service.h" 28 #include "chrome/browser/policy/cloud/cloud_policy_service.h"
18 #include "chrome/browser/policy/cloud/mock_device_management_service.h" 29 #include "chrome/browser/policy/cloud/mock_device_management_service.h"
19 #include "chrome/browser/policy/cloud/policy_builder.h" 30 #include "chrome/browser/policy/cloud/policy_builder.h"
20 #include "chrome/browser/policy/external_data_fetcher.h" 31 #include "chrome/browser/policy/external_data_fetcher.h"
21 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 32 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
22 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" 33 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
34 #include "chrome/common/chrome_paths.h"
35 #include "chromeos/chromeos_paths.h"
23 #include "chromeos/dbus/power_policy_controller.h" 36 #include "chromeos/dbus/power_policy_controller.h"
24 #include "policy/policy_constants.h" 37 #include "policy/policy_constants.h"
38 #include "policy/proto/cloud_policy.pb.h"
25 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
26 40
27 using testing::AnyNumber; 41 using testing::AnyNumber;
28 using testing::AtLeast; 42 using testing::AtLeast;
29 using testing::Mock; 43 using testing::Mock;
30 using testing::SaveArg; 44 using testing::SaveArg;
31 using testing::_; 45 using testing::_;
32 46
33 namespace em = enterprise_management; 47 namespace em = enterprise_management;
34 48
35 namespace policy { 49 namespace policy {
36 50
51 namespace {
52
53 const char kAccount1[] = "account1@localhost";
54 const char kAccount2[] = "account2@localhost";
55 const char kAccount3[] = "account3@localhost";
56
57 const char kExtensionID[] = "kbmnembihfiondgfjekmnmcbddelicoi";
58 const char kExtensionVersion[] = "1.0.0.0";
59 const char kExtensionCRXPath[] = "extensions/hosted_app.crx";
60 const char kUpdateURL[] = "https://clients2.google.com/service/update2/crx";
61
62 } // namespace
63
37 class MockDeviceLocalAccountPolicyServiceObserver 64 class MockDeviceLocalAccountPolicyServiceObserver
38 : public DeviceLocalAccountPolicyService::Observer { 65 : public DeviceLocalAccountPolicyService::Observer {
39 public: 66 public:
40 MOCK_METHOD1(OnPolicyUpdated, void(const std::string&)); 67 MOCK_METHOD1(OnPolicyUpdated, void(const std::string&));
41 MOCK_METHOD0(OnDeviceLocalAccountsChanged, void(void)); 68 MOCK_METHOD0(OnDeviceLocalAccountsChanged, void(void));
42 }; 69 };
43 70
44 class DeviceLocalAccountPolicyServiceTest 71 class DeviceLocalAccountPolicyServiceTestBase
45 : public chromeos::DeviceSettingsTestBase { 72 : public chromeos::DeviceSettingsTestBase {
46 public: 73 public:
47 DeviceLocalAccountPolicyServiceTest() 74 DeviceLocalAccountPolicyServiceTestBase();
48 : public_session_user_id_(GenerateDeviceLocalAccountUserId( 75
49 PolicyBuilder::kFakeUsername, 76 virtual void SetUp() OVERRIDE;
50 DeviceLocalAccount::TYPE_PUBLIC_SESSION)), 77
51 cros_settings_(&device_settings_service_), 78 void CreatePolicyService();
52 service_(&device_settings_test_helper_, 79
53 &device_settings_service_, 80 void InstallDeviceLocalAccountPolicy(const std::string& account_id);
54 &cros_settings_, 81 void AddDeviceLocalAccountToPolicy(const std::string& account_id);
55 loop_.message_loop_proxy()) {} 82 virtual void InstallDevicePolicy();
56 83
57 virtual void SetUp() OVERRIDE { 84 const std::string account_1_user_id_;
58 DeviceSettingsTestBase::SetUp(); 85 const std::string account_2_user_id_;
59
60 // Values implicitly enforced for public accounts.
61 expected_policy_map_.Set(key::kLidCloseAction,
62 POLICY_LEVEL_MANDATORY,
63 POLICY_SCOPE_USER,
64 base::Value::CreateIntegerValue(
65 chromeos::PowerPolicyController::
66 ACTION_STOP_SESSION),
67 NULL);
68 expected_policy_map_.Set(key::kShelfAutoHideBehavior,
69 POLICY_LEVEL_MANDATORY,
70 POLICY_SCOPE_USER,
71 Value::CreateStringValue("Never"),
72 NULL);
73 expected_policy_map_.Set(key::kShowLogoutButtonInTray,
74 POLICY_LEVEL_MANDATORY,
75 POLICY_SCOPE_USER,
76 Value::CreateBooleanValue(true),
77 NULL);
78 expected_policy_map_.Set(key::kFullscreenAllowed,
79 POLICY_LEVEL_MANDATORY,
80 POLICY_SCOPE_USER,
81 Value::CreateBooleanValue(false),
82 NULL);
83
84 // Explicitly set value.
85 expected_policy_map_.Set(key::kDisableSpdy,
86 POLICY_LEVEL_MANDATORY,
87 POLICY_SCOPE_USER,
88 Value::CreateBooleanValue(true),
89 NULL);
90
91 device_local_account_policy_.payload().mutable_disablespdy()->set_value(
92 true);
93 device_local_account_policy_.policy_data().set_policy_type(
94 dm_protocol::kChromePublicAccountPolicyType);
95 device_local_account_policy_.policy_data().set_settings_entity_id(
96 PolicyBuilder::kFakeUsername);
97 device_local_account_policy_.Build();
98
99 em::DeviceLocalAccountInfoProto* account =
100 device_policy_.payload().mutable_device_local_accounts()->add_account();
101 account->set_account_id(PolicyBuilder::kFakeUsername);
102 account->set_type(
103 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
104 device_policy_.Build();
105
106 service_.AddObserver(&service_observer_);
107 }
108
109 virtual void TearDown() OVERRIDE {
110 service_.RemoveObserver(&service_observer_);
111
112 DeviceSettingsTestBase::TearDown();
113 }
114
115 void InstallDevicePolicy() {
116 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged());
117 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
118 ReloadDeviceSettings();
119 Mock::VerifyAndClearExpectations(&service_observer_);
120 }
121
122 MOCK_METHOD1(OnRefreshDone, void(bool));
123
124 const std::string public_session_user_id_;
125 86
126 PolicyMap expected_policy_map_; 87 PolicyMap expected_policy_map_;
127 UserPolicyBuilder device_local_account_policy_; 88 UserPolicyBuilder device_local_account_policy_;
128 chromeos::CrosSettings cros_settings_; 89 chromeos::CrosSettings cros_settings_;
90 scoped_refptr<base::TestSimpleTaskRunner> extension_cache_task_runner_;
91 MockDeviceManagementService mock_device_management_service_;
92 scoped_ptr<DeviceLocalAccountPolicyService> service_;
93
94 private:
95 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyServiceTestBase);
96 };
97
98 class DeviceLocalAccountPolicyServiceTest
99 : public DeviceLocalAccountPolicyServiceTestBase {
100 public:
101 MOCK_METHOD1(OnRefreshDone, void(bool));
102
103 protected:
104 DeviceLocalAccountPolicyServiceTest();
105
106 virtual void SetUp() OVERRIDE;
107 virtual void TearDown() OVERRIDE;
108
109 void InstallDevicePolicy() OVERRIDE;
110
129 MockDeviceLocalAccountPolicyServiceObserver service_observer_; 111 MockDeviceLocalAccountPolicyServiceObserver service_observer_;
130 MockDeviceManagementService mock_device_management_service_;
131 DeviceLocalAccountPolicyService service_;
132 112
133 private: 113 private:
134 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyServiceTest); 114 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyServiceTest);
135 }; 115 };
136 116
117 DeviceLocalAccountPolicyServiceTestBase::
118 DeviceLocalAccountPolicyServiceTestBase()
119 : account_1_user_id_(GenerateDeviceLocalAccountUserId(
120 kAccount1,
121 DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
122 account_2_user_id_(GenerateDeviceLocalAccountUserId(
123 kAccount2,
124 DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
125 cros_settings_(&device_settings_service_),
126 extension_cache_task_runner_(new base::TestSimpleTaskRunner) {
127 }
128
129 void DeviceLocalAccountPolicyServiceTestBase::SetUp() {
130 chromeos::DeviceSettingsTestBase::SetUp();
131
132 // Values implicitly enforced for public accounts.
133 expected_policy_map_.Set(key::kLidCloseAction,
134 POLICY_LEVEL_MANDATORY,
135 POLICY_SCOPE_USER,
136 base::Value::CreateIntegerValue(
137 chromeos::PowerPolicyController::
138 ACTION_STOP_SESSION),
139 NULL);
140 expected_policy_map_.Set(key::kShelfAutoHideBehavior,
141 POLICY_LEVEL_MANDATORY,
142 POLICY_SCOPE_USER,
143 Value::CreateStringValue("Never"),
144 NULL);
145 expected_policy_map_.Set(key::kShowLogoutButtonInTray,
146 POLICY_LEVEL_MANDATORY,
147 POLICY_SCOPE_USER,
148 Value::CreateBooleanValue(true),
149 NULL);
150 expected_policy_map_.Set(key::kFullscreenAllowed,
151 POLICY_LEVEL_MANDATORY,
152 POLICY_SCOPE_USER,
153 Value::CreateBooleanValue(false),
154 NULL);
155
156 // Explicitly set value.
157 expected_policy_map_.Set(key::kDisableSpdy,
158 POLICY_LEVEL_MANDATORY,
159 POLICY_SCOPE_USER,
160 Value::CreateBooleanValue(true),
161 NULL);
162
163 device_local_account_policy_.payload().mutable_disablespdy()->set_value(
164 true);
165 device_local_account_policy_.policy_data().set_policy_type(
166 dm_protocol::kChromePublicAccountPolicyType);
167 }
168
169 void DeviceLocalAccountPolicyServiceTestBase::CreatePolicyService() {
170 service_.reset(new DeviceLocalAccountPolicyService(
171 &device_settings_test_helper_,
172 &device_settings_service_,
173 &cros_settings_,
174 loop_.message_loop_proxy(),
175 extension_cache_task_runner_));
176 }
177
178 void DeviceLocalAccountPolicyServiceTestBase::
179 InstallDeviceLocalAccountPolicy(const std::string& account_id) {
180 device_local_account_policy_.policy_data().set_settings_entity_id(account_id);
181 device_local_account_policy_.policy_data().set_username(account_id);
182 device_local_account_policy_.Build();
183 device_settings_test_helper_.set_device_local_account_policy_blob(
184 account_id, device_local_account_policy_.GetBlob());
185 }
186
187 void DeviceLocalAccountPolicyServiceTestBase::AddDeviceLocalAccountToPolicy(
188 const std::string& account_id) {
189 em::DeviceLocalAccountInfoProto* account =
190 device_policy_.payload().mutable_device_local_accounts()->add_account();
191 account->set_account_id(account_id);
192 account->set_type(
193 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
194 }
195
196 void DeviceLocalAccountPolicyServiceTestBase::InstallDevicePolicy() {
197 device_policy_.Build();
198 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
199 ReloadDeviceSettings();
200 }
201
202 DeviceLocalAccountPolicyServiceTest::DeviceLocalAccountPolicyServiceTest() {
203 CreatePolicyService();
204 }
205
206 void DeviceLocalAccountPolicyServiceTest::SetUp() {
207 DeviceLocalAccountPolicyServiceTestBase::SetUp();
208 service_->AddObserver(&service_observer_);
209 }
210
211 void DeviceLocalAccountPolicyServiceTest::TearDown() {
212 service_->RemoveObserver(&service_observer_);
213 DeviceLocalAccountPolicyServiceTestBase::TearDown();
214 }
215
216 void DeviceLocalAccountPolicyServiceTest::InstallDevicePolicy() {
217 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged());
218 DeviceLocalAccountPolicyServiceTestBase::InstallDevicePolicy();
219 Mock::VerifyAndClearExpectations(&service_observer_);
220 }
221
137 TEST_F(DeviceLocalAccountPolicyServiceTest, NoAccounts) { 222 TEST_F(DeviceLocalAccountPolicyServiceTest, NoAccounts) {
138 EXPECT_FALSE(service_.GetBrokerForUser(public_session_user_id_)); 223 EXPECT_FALSE(service_->GetBrokerForUser(account_1_user_id_));
139 } 224 }
140 225
141 TEST_F(DeviceLocalAccountPolicyServiceTest, GetBroker) { 226 TEST_F(DeviceLocalAccountPolicyServiceTest, GetBroker) {
142 InstallDevicePolicy(); 227 InstallDeviceLocalAccountPolicy(kAccount1);
143 228 AddDeviceLocalAccountToPolicy(kAccount1);
144 DeviceLocalAccountPolicyBroker* broker = 229 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
145 service_.GetBrokerForUser(public_session_user_id_); 230 InstallDevicePolicy();
146 ASSERT_TRUE(broker); 231
147 EXPECT_EQ(public_session_user_id_, broker->user_id()); 232 DeviceLocalAccountPolicyBroker* broker =
233 service_->GetBrokerForUser(account_1_user_id_);
234 ASSERT_TRUE(broker);
235 EXPECT_EQ(account_1_user_id_, broker->user_id());
148 ASSERT_TRUE(broker->core()->store()); 236 ASSERT_TRUE(broker->core()->store());
149 EXPECT_EQ(CloudPolicyStore::STATUS_OK, broker->core()->store()->status()); 237 EXPECT_EQ(CloudPolicyStore::STATUS_OK, broker->core()->store()->status());
150 EXPECT_FALSE(broker->core()->client()); 238 EXPECT_FALSE(broker->core()->client());
151 EXPECT_TRUE(broker->core()->store()->policy_map().empty()); 239 EXPECT_FALSE(broker->core()->store()->policy_map().empty());
152 } 240 }
153 241
154 TEST_F(DeviceLocalAccountPolicyServiceTest, LoadNoPolicy) { 242 TEST_F(DeviceLocalAccountPolicyServiceTest, LoadNoPolicy) {
155 InstallDevicePolicy(); 243 AddDeviceLocalAccountToPolicy(kAccount1);
156 244 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
157 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_)); 245 InstallDevicePolicy();
158 DeviceLocalAccountPolicyBroker* broker = 246
159 service_.GetBrokerForUser(public_session_user_id_); 247 DeviceLocalAccountPolicyBroker* broker =
160 ASSERT_TRUE(broker); 248 service_->GetBrokerForUser(account_1_user_id_);
161 FlushDeviceSettings(); 249 ASSERT_TRUE(broker);
162 Mock::VerifyAndClearExpectations(&service_observer_); 250 EXPECT_EQ(account_1_user_id_, broker->user_id());
163
164 ASSERT_TRUE(broker->core()->store()); 251 ASSERT_TRUE(broker->core()->store());
165 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, 252 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR,
166 broker->core()->store()->status()); 253 broker->core()->store()->status());
167 EXPECT_TRUE(broker->core()->store()->policy_map().empty()); 254 EXPECT_TRUE(broker->core()->store()->policy_map().empty());
168 EXPECT_FALSE(service_.IsPolicyAvailableForUser(public_session_user_id_)); 255 EXPECT_FALSE(service_->IsPolicyAvailableForUser(account_1_user_id_));
169 } 256 }
170 257
171 TEST_F(DeviceLocalAccountPolicyServiceTest, LoadValidationFailure) { 258 TEST_F(DeviceLocalAccountPolicyServiceTest, LoadValidationFailure) {
172 device_local_account_policy_.policy_data().set_policy_type( 259 device_local_account_policy_.policy_data().set_policy_type(
173 dm_protocol::kChromeUserPolicyType); 260 dm_protocol::kChromeUserPolicyType);
174 device_local_account_policy_.Build(); 261 InstallDeviceLocalAccountPolicy(kAccount1);
175 device_settings_test_helper_.set_device_local_account_policy_blob( 262 AddDeviceLocalAccountToPolicy(kAccount1);
176 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 263 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
177 InstallDevicePolicy(); 264 InstallDevicePolicy();
178 265
179 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_)); 266 DeviceLocalAccountPolicyBroker* broker =
180 DeviceLocalAccountPolicyBroker* broker = 267 service_->GetBrokerForUser(account_1_user_id_);
181 service_.GetBrokerForUser(public_session_user_id_); 268 ASSERT_TRUE(broker);
182 ASSERT_TRUE(broker); 269 EXPECT_EQ(account_1_user_id_, broker->user_id());
183 FlushDeviceSettings();
184 Mock::VerifyAndClearExpectations(&service_observer_);
185
186 ASSERT_TRUE(broker->core()->store()); 270 ASSERT_TRUE(broker->core()->store());
187 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, 271 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR,
188 broker->core()->store()->status()); 272 broker->core()->store()->status());
189 EXPECT_TRUE(broker->core()->store()->policy_map().empty()); 273 EXPECT_TRUE(broker->core()->store()->policy_map().empty());
190 EXPECT_FALSE(service_.IsPolicyAvailableForUser(public_session_user_id_)); 274 EXPECT_FALSE(service_->IsPolicyAvailableForUser(account_1_user_id_));
191 } 275 }
192 276
193 TEST_F(DeviceLocalAccountPolicyServiceTest, LoadPolicy) { 277 TEST_F(DeviceLocalAccountPolicyServiceTest, LoadPolicy) {
194 device_settings_test_helper_.set_device_local_account_policy_blob( 278 InstallDeviceLocalAccountPolicy(kAccount1);
195 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 279 AddDeviceLocalAccountToPolicy(kAccount1);
196 InstallDevicePolicy(); 280 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
197 281 InstallDevicePolicy();
198 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_)); 282
199 DeviceLocalAccountPolicyBroker* broker = 283 DeviceLocalAccountPolicyBroker* broker =
200 service_.GetBrokerForUser(public_session_user_id_); 284 service_->GetBrokerForUser(account_1_user_id_);
201 ASSERT_TRUE(broker); 285 ASSERT_TRUE(broker);
202 FlushDeviceSettings(); 286 EXPECT_EQ(account_1_user_id_, broker->user_id());
203 Mock::VerifyAndClearExpectations(&service_observer_); 287 ASSERT_TRUE(broker->core()->store());
204 288 EXPECT_EQ(CloudPolicyStore::STATUS_OK, broker->core()->store()->status());
205 ASSERT_TRUE(broker->core()->store());
206 EXPECT_EQ(CloudPolicyStore::STATUS_OK,
207 broker->core()->store()->status());
208 ASSERT_TRUE(broker->core()->store()->policy()); 289 ASSERT_TRUE(broker->core()->store()->policy());
209 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(), 290 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(),
210 broker->core()->store()->policy()->SerializeAsString()); 291 broker->core()->store()->policy()->SerializeAsString());
211 EXPECT_TRUE(expected_policy_map_.Equals( 292 EXPECT_TRUE(expected_policy_map_.Equals(
212 broker->core()->store()->policy_map())); 293 broker->core()->store()->policy_map()));
213 EXPECT_TRUE(service_.IsPolicyAvailableForUser(public_session_user_id_)); 294 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_));
214 } 295 }
215 296
216 TEST_F(DeviceLocalAccountPolicyServiceTest, StoreValidationFailure) { 297 TEST_F(DeviceLocalAccountPolicyServiceTest, StoreValidationFailure) {
298 AddDeviceLocalAccountToPolicy(kAccount1);
299 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
300 InstallDevicePolicy();
301 Mock::VerifyAndClearExpectations(&service_observer_);
302
303 DeviceLocalAccountPolicyBroker* broker =
304 service_->GetBrokerForUser(account_1_user_id_);
305 ASSERT_TRUE(broker);
306 EXPECT_EQ(account_1_user_id_, broker->user_id());
307 ASSERT_TRUE(broker->core()->store());
308
217 device_local_account_policy_.policy_data().set_policy_type( 309 device_local_account_policy_.policy_data().set_policy_type(
218 dm_protocol::kChromeUserPolicyType); 310 dm_protocol::kChromeUserPolicyType);
219 device_local_account_policy_.Build(); 311 device_local_account_policy_.Build();
220 InstallDevicePolicy();
221
222 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_));
223 DeviceLocalAccountPolicyBroker* broker =
224 service_.GetBrokerForUser(public_session_user_id_);
225 ASSERT_TRUE(broker);
226 ASSERT_TRUE(broker->core()->store());
227 broker->core()->store()->Store(device_local_account_policy_.policy()); 312 broker->core()->store()->Store(device_local_account_policy_.policy());
313 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
228 FlushDeviceSettings(); 314 FlushDeviceSettings();
229 Mock::VerifyAndClearExpectations(&service_observer_); 315
230
231 ASSERT_TRUE(broker->core()->store());
232 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR, 316 EXPECT_EQ(CloudPolicyStore::STATUS_VALIDATION_ERROR,
233 broker->core()->store()->status()); 317 broker->core()->store()->status());
234 EXPECT_EQ(CloudPolicyValidatorBase::VALIDATION_WRONG_POLICY_TYPE, 318 EXPECT_EQ(CloudPolicyValidatorBase::VALIDATION_WRONG_POLICY_TYPE,
235 broker->core()->store()->validation_status()); 319 broker->core()->store()->validation_status());
236 EXPECT_FALSE(service_.IsPolicyAvailableForUser(public_session_user_id_)); 320 EXPECT_FALSE(service_->IsPolicyAvailableForUser(account_1_user_id_));
237 } 321 }
238 322
239 TEST_F(DeviceLocalAccountPolicyServiceTest, StorePolicy) { 323 TEST_F(DeviceLocalAccountPolicyServiceTest, StorePolicy) {
240 InstallDevicePolicy(); 324 AddDeviceLocalAccountToPolicy(kAccount1);
241 325 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
242 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_)); 326 InstallDevicePolicy();
243 DeviceLocalAccountPolicyBroker* broker = 327 Mock::VerifyAndClearExpectations(&service_observer_);
244 service_.GetBrokerForUser(public_session_user_id_); 328
245 ASSERT_TRUE(broker); 329 DeviceLocalAccountPolicyBroker* broker =
246 ASSERT_TRUE(broker->core()->store()); 330 service_->GetBrokerForUser(account_1_user_id_);
331 ASSERT_TRUE(broker);
332 EXPECT_EQ(account_1_user_id_, broker->user_id());
333 ASSERT_TRUE(broker->core()->store());
334
335 device_local_account_policy_.policy_data().set_settings_entity_id(kAccount1);
336 device_local_account_policy_.policy_data().set_username(kAccount1);
337 device_local_account_policy_.Build();
247 broker->core()->store()->Store(device_local_account_policy_.policy()); 338 broker->core()->store()->Store(device_local_account_policy_.policy());
339 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
248 FlushDeviceSettings(); 340 FlushDeviceSettings();
341
342 EXPECT_EQ(CloudPolicyStore::STATUS_OK, broker->core()->store()->status());
343 ASSERT_TRUE(broker->core()->store()->policy());
344 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(),
345 broker->core()->store()->policy()->SerializeAsString());
346 EXPECT_TRUE(expected_policy_map_.Equals(
347 broker->core()->store()->policy_map()));
348 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_));
349 }
350
351 TEST_F(DeviceLocalAccountPolicyServiceTest, DevicePolicyChange) {
352 InstallDeviceLocalAccountPolicy(kAccount1);
353 AddDeviceLocalAccountToPolicy(kAccount1);
354 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
355 InstallDevicePolicy();
356
357 device_policy_.payload().mutable_device_local_accounts()->clear_account();
358 InstallDevicePolicy();
359
360 EXPECT_FALSE(service_->GetBrokerForUser(account_1_user_id_));
361 }
362
363 TEST_F(DeviceLocalAccountPolicyServiceTest, DuplicateAccounts) {
364 InstallDeviceLocalAccountPolicy(kAccount1);
365 AddDeviceLocalAccountToPolicy(kAccount1);
366 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
367 InstallDevicePolicy();
249 Mock::VerifyAndClearExpectations(&service_observer_); 368 Mock::VerifyAndClearExpectations(&service_observer_);
250 369
251 EXPECT_EQ(device_local_account_policy_.GetBlob(),
252 device_settings_test_helper_.device_local_account_policy_blob(
253 PolicyBuilder::kFakeUsername));
254 EXPECT_TRUE(service_.IsPolicyAvailableForUser(public_session_user_id_));
255 }
256
257 TEST_F(DeviceLocalAccountPolicyServiceTest, DevicePolicyChange) {
258 device_settings_test_helper_.set_device_local_account_policy_blob(
259 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob());
260 InstallDevicePolicy();
261
262 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged());
263 device_policy_.payload().mutable_device_local_accounts()->clear_account();
264 device_policy_.Build();
265 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
266 device_settings_service_.PropertyChangeComplete(true);
267 FlushDeviceSettings();
268 EXPECT_FALSE(service_.GetBrokerForUser(public_session_user_id_));
269 Mock::VerifyAndClearExpectations(&service_observer_);
270 }
271
272 TEST_F(DeviceLocalAccountPolicyServiceTest, DuplicateAccounts) {
273 InstallDevicePolicy();
274 DeviceLocalAccountPolicyBroker* broker =
275 service_.GetBrokerForUser(public_session_user_id_);
276 ASSERT_TRUE(broker);
277
278 // Add a second entry with a duplicate account name to device policy. 370 // Add a second entry with a duplicate account name to device policy.
279 em::DeviceLocalAccountInfoProto* account = 371 AddDeviceLocalAccountToPolicy(kAccount1);
280 device_policy_.payload().mutable_device_local_accounts()->add_account(); 372 InstallDevicePolicy();
281 account->set_account_id(PolicyBuilder::kFakeUsername);
282 account->set_type(
283 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
284 device_policy_.Build();
285 device_settings_test_helper_.set_device_local_account_policy_blob(
286 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob());
287 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
288
289 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged());
290 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_));
291 device_settings_service_.PropertyChangeComplete(true);
292 FlushDeviceSettings();
293 Mock::VerifyAndClearExpectations(&service_observer_);
294 373
295 // Make sure the broker is accessible and policy got loaded. 374 // Make sure the broker is accessible and policy got loaded.
296 broker = service_.GetBrokerForUser(public_session_user_id_); 375 DeviceLocalAccountPolicyBroker* broker =
297 ASSERT_TRUE(broker); 376 service_->GetBrokerForUser(account_1_user_id_);
298 EXPECT_EQ(public_session_user_id_, broker->user_id()); 377 ASSERT_TRUE(broker);
299 EXPECT_TRUE(broker->core()->store()->policy()); 378 EXPECT_EQ(account_1_user_id_, broker->user_id());
379 ASSERT_TRUE(broker->core()->store());
380 EXPECT_EQ(CloudPolicyStore::STATUS_OK, broker->core()->store()->status());
381 ASSERT_TRUE(broker->core()->store()->policy());
382 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(),
383 broker->core()->store()->policy()->SerializeAsString());
384 EXPECT_TRUE(expected_policy_map_.Equals(
385 broker->core()->store()->policy_map()));
386 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_));
300 } 387 }
301 388
302 TEST_F(DeviceLocalAccountPolicyServiceTest, FetchPolicy) { 389 TEST_F(DeviceLocalAccountPolicyServiceTest, FetchPolicy) {
303 device_settings_test_helper_.set_device_local_account_policy_blob( 390 InstallDeviceLocalAccountPolicy(kAccount1);
304 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 391 AddDeviceLocalAccountToPolicy(kAccount1);
305 InstallDevicePolicy(); 392 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
306 393 InstallDevicePolicy();
307 DeviceLocalAccountPolicyBroker* broker = 394
308 service_.GetBrokerForUser(public_session_user_id_); 395 DeviceLocalAccountPolicyBroker* broker =
309 ASSERT_TRUE(broker); 396 service_->GetBrokerForUser(account_1_user_id_);
310 397 ASSERT_TRUE(broker);
311 service_.Connect(&mock_device_management_service_); 398
399 service_->Connect(&mock_device_management_service_);
312 EXPECT_TRUE(broker->core()->client()); 400 EXPECT_TRUE(broker->core()->client());
313 401
314 em::DeviceManagementRequest request; 402 em::DeviceManagementRequest request;
315 em::DeviceManagementResponse response; 403 em::DeviceManagementResponse response;
316 response.mutable_policy_response()->add_response()->CopyFrom( 404 response.mutable_policy_response()->add_response()->CopyFrom(
317 device_local_account_policy_.policy()); 405 device_local_account_policy_.policy());
318 EXPECT_CALL(mock_device_management_service_, 406 EXPECT_CALL(mock_device_management_service_,
319 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH)) 407 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH))
320 .WillOnce(mock_device_management_service_.SucceedJob(response)); 408 .WillOnce(mock_device_management_service_.SucceedJob(response));
321 EXPECT_CALL(mock_device_management_service_, 409 EXPECT_CALL(mock_device_management_service_,
322 StartJob(dm_protocol::kValueRequestPolicy, 410 StartJob(dm_protocol::kValueRequestPolicy,
323 std::string(), std::string(), 411 std::string(), std::string(),
324 device_policy_.policy_data().request_token(), 412 device_policy_.policy_data().request_token(),
325 dm_protocol::kValueUserAffiliationManaged, 413 dm_protocol::kValueUserAffiliationManaged,
326 device_policy_.policy_data().device_id(), 414 device_policy_.policy_data().device_id(),
327 _)) 415 _))
328 .WillOnce(SaveArg<6>(&request)); 416 .WillOnce(SaveArg<6>(&request));
329 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_)); 417 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
330 broker->core()->client()->FetchPolicy(); 418 broker->core()->client()->FetchPolicy();
331 FlushDeviceSettings(); 419 FlushDeviceSettings();
332 Mock::VerifyAndClearExpectations(&service_observer_); 420 Mock::VerifyAndClearExpectations(&service_observer_);
333 Mock::VerifyAndClearExpectations(&mock_device_management_service_); 421 Mock::VerifyAndClearExpectations(&mock_device_management_service_);
334 EXPECT_TRUE(request.has_policy_request()); 422 EXPECT_TRUE(request.has_policy_request());
335 EXPECT_EQ(1, request.policy_request().request_size()); 423 EXPECT_EQ(1, request.policy_request().request_size());
336 EXPECT_EQ(dm_protocol::kChromePublicAccountPolicyType, 424 EXPECT_EQ(dm_protocol::kChromePublicAccountPolicyType,
337 request.policy_request().request(0).policy_type()); 425 request.policy_request().request(0).policy_type());
338 EXPECT_FALSE(request.policy_request().request(0).has_machine_id()); 426 EXPECT_FALSE(request.policy_request().request(0).has_machine_id());
339 EXPECT_EQ(PolicyBuilder::kFakeUsername, 427 EXPECT_EQ(kAccount1,
340 request.policy_request().request(0).settings_entity_id()); 428 request.policy_request().request(0).settings_entity_id());
341 429
342 ASSERT_TRUE(broker->core()->store()); 430 ASSERT_TRUE(broker->core()->store());
343 EXPECT_EQ(CloudPolicyStore::STATUS_OK, 431 EXPECT_EQ(CloudPolicyStore::STATUS_OK,
344 broker->core()->store()->status()); 432 broker->core()->store()->status());
345 ASSERT_TRUE(broker->core()->store()->policy()); 433 ASSERT_TRUE(broker->core()->store()->policy());
346 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(), 434 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(),
347 broker->core()->store()->policy()->SerializeAsString()); 435 broker->core()->store()->policy()->SerializeAsString());
348 EXPECT_TRUE(expected_policy_map_.Equals( 436 EXPECT_TRUE(expected_policy_map_.Equals(
349 broker->core()->store()->policy_map())); 437 broker->core()->store()->policy_map()));
350 EXPECT_TRUE(service_.IsPolicyAvailableForUser(public_session_user_id_)); 438 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_));
351 439
352 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_)) 440 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_))
353 .Times(0); 441 .Times(0);
354 service_.Disconnect(); 442 service_->Disconnect();
355 EXPECT_FALSE(broker->core()->client()); 443 EXPECT_FALSE(broker->core()->client());
356 Mock::VerifyAndClearExpectations(&service_observer_); 444 Mock::VerifyAndClearExpectations(&service_observer_);
357 EXPECT_TRUE(service_.IsPolicyAvailableForUser(public_session_user_id_)); 445 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_));
358 } 446 }
359 447
360 TEST_F(DeviceLocalAccountPolicyServiceTest, RefreshPolicy) { 448 TEST_F(DeviceLocalAccountPolicyServiceTest, RefreshPolicy) {
361 device_settings_test_helper_.set_device_local_account_policy_blob( 449 InstallDeviceLocalAccountPolicy(kAccount1);
362 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 450 AddDeviceLocalAccountToPolicy(kAccount1);
451 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
363 InstallDevicePolicy(); 452 InstallDevicePolicy();
364 453
365 DeviceLocalAccountPolicyBroker* broker = 454 DeviceLocalAccountPolicyBroker* broker =
366 service_.GetBrokerForUser(public_session_user_id_); 455 service_->GetBrokerForUser(account_1_user_id_);
367 ASSERT_TRUE(broker); 456 ASSERT_TRUE(broker);
368 457
369 service_.Connect(&mock_device_management_service_); 458 service_->Connect(&mock_device_management_service_);
370 ASSERT_TRUE(broker->core()->service()); 459 ASSERT_TRUE(broker->core()->service());
371 460
372 em::DeviceManagementResponse response; 461 em::DeviceManagementResponse response;
373 response.mutable_policy_response()->add_response()->CopyFrom( 462 response.mutable_policy_response()->add_response()->CopyFrom(
374 device_local_account_policy_.policy()); 463 device_local_account_policy_.policy());
375 EXPECT_CALL(mock_device_management_service_, CreateJob(_)) 464 EXPECT_CALL(mock_device_management_service_, CreateJob(_))
376 .WillOnce(mock_device_management_service_.SucceedJob(response)); 465 .WillOnce(mock_device_management_service_.SucceedJob(response));
377 EXPECT_CALL(mock_device_management_service_, StartJob(_, _, _, _, _, _, _)); 466 EXPECT_CALL(mock_device_management_service_, StartJob(_, _, _, _, _, _, _));
378 EXPECT_CALL(*this, OnRefreshDone(true)).Times(1); 467 EXPECT_CALL(*this, OnRefreshDone(true)).Times(1);
379 EXPECT_CALL(service_observer_, OnPolicyUpdated(public_session_user_id_)); 468 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
380 broker->core()->service()->RefreshPolicy( 469 broker->core()->service()->RefreshPolicy(
381 base::Bind(&DeviceLocalAccountPolicyServiceTest::OnRefreshDone, 470 base::Bind(&DeviceLocalAccountPolicyServiceTest::OnRefreshDone,
382 base::Unretained(this))); 471 base::Unretained(this)));
383 FlushDeviceSettings(); 472 FlushDeviceSettings();
384 Mock::VerifyAndClearExpectations(&service_observer_); 473 Mock::VerifyAndClearExpectations(&service_observer_);
385 Mock::VerifyAndClearExpectations(this); 474 Mock::VerifyAndClearExpectations(this);
386 Mock::VerifyAndClearExpectations(&mock_device_management_service_); 475 Mock::VerifyAndClearExpectations(&mock_device_management_service_);
387 476
388 ASSERT_TRUE(broker->core()->store()); 477 ASSERT_TRUE(broker->core()->store());
389 EXPECT_EQ(CloudPolicyStore::STATUS_OK, 478 EXPECT_EQ(CloudPolicyStore::STATUS_OK,
390 broker->core()->store()->status()); 479 broker->core()->store()->status());
391 EXPECT_TRUE(expected_policy_map_.Equals( 480 EXPECT_TRUE(expected_policy_map_.Equals(
392 broker->core()->store()->policy_map())); 481 broker->core()->store()->policy_map()));
393 EXPECT_TRUE(service_.IsPolicyAvailableForUser(public_session_user_id_)); 482 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_));
483 }
484
485 class DeviceLocalAccountPolicyExtensionCacheTest
486 : public DeviceLocalAccountPolicyServiceTestBase {
487 protected:
488 DeviceLocalAccountPolicyExtensionCacheTest();
489
490 virtual void SetUp() OVERRIDE;
491
492 base::FilePath GetCacheDirectoryForAccountID(const std::string& account_id);
493
494 base::ScopedTempDir cache_root_dir_;
495 scoped_ptr<base::ScopedPathOverride> cache_root_dir_override_;
496
497 base::FilePath cache_dir_1_;
498 base::FilePath cache_dir_2_;
499 base::FilePath cache_dir_3_;
500
501 private:
502 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyExtensionCacheTest);
503 };
504
505 DeviceLocalAccountPolicyExtensionCacheTest::
506 DeviceLocalAccountPolicyExtensionCacheTest() {
507 }
508
509 void DeviceLocalAccountPolicyExtensionCacheTest::SetUp() {
510 DeviceLocalAccountPolicyServiceTestBase::SetUp();
511 ASSERT_TRUE(cache_root_dir_.CreateUniqueTempDir());
512 cache_root_dir_override_.reset(new base::ScopedPathOverride(
513 chromeos::DIR_DEVICE_LOCAL_ACCOUNT_CACHE,
514 cache_root_dir_.path()));
515
516 cache_dir_1_ = GetCacheDirectoryForAccountID(kAccount1);
517 cache_dir_2_ = GetCacheDirectoryForAccountID(kAccount2);
518 cache_dir_3_ = GetCacheDirectoryForAccountID(kAccount3);
519
520 em::StringList* forcelist = device_local_account_policy_.payload()
521 .mutable_extensioninstallforcelist()->mutable_value();
522 forcelist->add_entries(base::StringPrintf("%s;%s", kExtensionID, kUpdateURL));
523 }
524
525 base::FilePath DeviceLocalAccountPolicyExtensionCacheTest::
526 GetCacheDirectoryForAccountID(const std::string& account_id) {
527 return cache_root_dir_.path().Append(base::HexEncode(account_id.c_str(),
528 account_id.size()));
529 }
530
531 // Verifies that during startup, orphaned cache directories are deleted,
532 // cache directories belonging to an existing account are preserved and missing
533 // cache directories are created. Also verifies that when startup is complete,
534 // the caches for all existing accounts are running.
535 TEST_F(DeviceLocalAccountPolicyExtensionCacheTest, Startup) {
536 base::FilePath test_data_dir;
537 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
538 const base::FilePath source_crx_file =
539 test_data_dir.Append(kExtensionCRXPath);
540 const std::string target_crx_file_name =
541 base::StringPrintf("%s-%s.crx", kExtensionID, kExtensionVersion);
542
543 // Create and pre-populate a cache directory for account 1.
544 EXPECT_TRUE(file_util::CreateDirectory(cache_dir_1_));
545 EXPECT_TRUE(CopyFile(source_crx_file,
546 cache_dir_1_.Append(target_crx_file_name)));
547
548 // Create and pre-populate a cache directory for account 3.
549 EXPECT_TRUE(file_util::CreateDirectory(cache_dir_3_));
550 EXPECT_TRUE(CopyFile(source_crx_file,
551 cache_dir_3_.Append(target_crx_file_name)));
552
553 // Add accounts 1 and 2 to device policy.
554 InstallDeviceLocalAccountPolicy(kAccount1);
555 InstallDeviceLocalAccountPolicy(kAccount2);
556 AddDeviceLocalAccountToPolicy(kAccount1);
557 AddDeviceLocalAccountToPolicy(kAccount2);
558 InstallDevicePolicy();
559
560 // Create the DeviceLocalAccountPolicyService, allowing it to finish the
561 // deletion of orphaned cache directories.
562 CreatePolicyService();
563 FlushDeviceSettings();
564 extension_cache_task_runner_->RunUntilIdle();
565
566 // Verify that the cache directory for account 1 and its contents still exist.
567 EXPECT_TRUE(base::DirectoryExists(cache_dir_1_));
568 EXPECT_TRUE(ContentsEqual(source_crx_file,
569 cache_dir_1_.Append(target_crx_file_name)));
570
571 // Verify that a cache directory for account 2 was created.
572 EXPECT_TRUE(base::DirectoryExists(cache_dir_2_));
573
574 // Verify that the cache directory for account 3 was deleted.
575 EXPECT_FALSE(base::DirectoryExists(cache_dir_3_));
576
577 // Verify that the cache for account 1 has been started.
578 DeviceLocalAccountPolicyBroker* broker =
579 service_->GetBrokerForUser(account_1_user_id_);
580 ASSERT_TRUE(broker);
581 EXPECT_TRUE(broker->extension_loader()->IsCacheRunning());
582
583 // Verify that the cache for account 2 has been started.
584 broker = service_->GetBrokerForUser(account_2_user_id_);
585 ASSERT_TRUE(broker);
586 EXPECT_TRUE(broker->extension_loader()->IsCacheRunning());
587 }
588
589 // Verifies that while the deletion of orphaned cache directories is in
590 // progress, the caches for accounts which existed before the deletion started
591 // are running but caches for newly added accounts are not started.
592 TEST_F(DeviceLocalAccountPolicyExtensionCacheTest, RaceAgainstOrphanDeletion) {
593 // Add account 1 to device policy.
594 InstallDeviceLocalAccountPolicy(kAccount1);
595 AddDeviceLocalAccountToPolicy(kAccount1);
596 InstallDevicePolicy();
597
598 // Create the DeviceLocalAccountPolicyService, triggering the deletion of
599 // orphaned cache directories.
600 CreatePolicyService();
601 FlushDeviceSettings();
602
603 // Verify that the cache for account 1 has been started as it is unaffected by
604 // the orphan deletion.
605 DeviceLocalAccountPolicyBroker* broker =
606 service_->GetBrokerForUser(account_1_user_id_);
607 ASSERT_TRUE(broker);
608 EXPECT_TRUE(broker->extension_loader()->IsCacheRunning());
609
610 // Add account 2 to device policy.
611 InstallDeviceLocalAccountPolicy(kAccount2);
612 AddDeviceLocalAccountToPolicy(kAccount2);
613 InstallDevicePolicy();
614
615 // Verify that the cache for account 2 has not been started yet as the orphan
616 // deletion is still in progress.
617 broker = service_->GetBrokerForUser(account_2_user_id_);
618 ASSERT_TRUE(broker);
619 EXPECT_FALSE(broker->extension_loader()->IsCacheRunning());
620
621 // Allow the orphan deletion to finish.
622 extension_cache_task_runner_->RunUntilIdle();
623 base::RunLoop().RunUntilIdle();
624
625 // Verify that the cache for account 2 has been started.
626 EXPECT_TRUE(broker->extension_loader()->IsCacheRunning());
627 }
628
629 // Verifies that while the shutdown of a cache is in progress, no new cache is
630 // started if an account with the same ID is re-added.
631 TEST_F(DeviceLocalAccountPolicyExtensionCacheTest, RaceAgainstCacheShutdown) {
632 // Add account 1 to device policy.
633 InstallDeviceLocalAccountPolicy(kAccount1);
634 AddDeviceLocalAccountToPolicy(kAccount1);
635 InstallDevicePolicy();
636
637 // Create the DeviceLocalAccountPolicyService, allowing it to finish the
638 // deletion of orphaned cache directories.
639 CreatePolicyService();
640 FlushDeviceSettings();
641 extension_cache_task_runner_->RunUntilIdle();
642
643 // Remove account 1 from device policy, triggering a shutdown of its cache.
644 device_policy_.payload().mutable_device_local_accounts()->clear_account();
645 InstallDevicePolicy();
646
647 // Re-add account 1 to device policy.
648 AddDeviceLocalAccountToPolicy(kAccount1);
649 InstallDevicePolicy();
650
651 // Verify that the cache for account 1 has not been started yet as the
652 // shutdown of a previous cache for this account ID is still in progress.
653 DeviceLocalAccountPolicyBroker* broker =
654 service_->GetBrokerForUser(account_1_user_id_);
655 ASSERT_TRUE(broker);
656 EXPECT_FALSE(broker->extension_loader()->IsCacheRunning());
657
658 // Allow the cache shutdown to finish.
659 extension_cache_task_runner_->RunUntilIdle();
660 base::RunLoop().RunUntilIdle();
661
662 // Verify that the cache directory for account 1 still exists.
663 EXPECT_TRUE(base::DirectoryExists(cache_dir_1_));
664
665 // Verify that the cache for account 1 has been started, reusing the existing
666 // cache directory.
667 EXPECT_TRUE(broker->extension_loader()->IsCacheRunning());
668 }
669
670 // Verifies that while the deletion of an obsolete cache directory is in
671 // progress, no new cache is started if an account with the same ID is re-added.
672 TEST_F(DeviceLocalAccountPolicyExtensionCacheTest,
673 RaceAgainstObsoleteDeletion) {
674 // Add account 1 to device policy.
675 InstallDeviceLocalAccountPolicy(kAccount1);
676 AddDeviceLocalAccountToPolicy(kAccount1);
677 InstallDevicePolicy();
678
679 // Create the DeviceLocalAccountPolicyService, allowing it to finish the
680 // deletion of orphaned cache directories.
681 CreatePolicyService();
682 FlushDeviceSettings();
683 extension_cache_task_runner_->RunUntilIdle();
684
685 // Remove account 1 from device policy, allowing the shutdown of its cache to
686 // finish and the deletion of its now obsolete cache directory to begin.
687 device_policy_.payload().mutable_device_local_accounts()->clear_account();
688 InstallDevicePolicy();
689 extension_cache_task_runner_->RunUntilIdle();
690 base::RunLoop().RunUntilIdle();
691
692 // Re-add account 1 to device policy.
693 AddDeviceLocalAccountToPolicy(kAccount1);
694 InstallDevicePolicy();
695
696 // Verify that the cache for account 1 has not been started yet as the
697 // deletion of the cache directory for this account ID is still in progress.
698 DeviceLocalAccountPolicyBroker* broker =
699 service_->GetBrokerForUser(account_1_user_id_);
700 ASSERT_TRUE(broker);
701 EXPECT_FALSE(broker->extension_loader()->IsCacheRunning());
702
703 // Allow the deletion to finish.
704 extension_cache_task_runner_->RunUntilIdle();
705 base::RunLoop().RunUntilIdle();
706
707 // Verify that the cache directory for account 1 was deleted.
708 EXPECT_FALSE(base::DirectoryExists(cache_dir_1_));
709
710 // Verify that the cache for account 1 has been started.
711 EXPECT_TRUE(broker->extension_loader()->IsCacheRunning());
712 }
713
714 // Verifies that when an account is added and no deletion of cache directories
715 // affecting this account is in progress, its cache is started immediately.
716 TEST_F(DeviceLocalAccountPolicyExtensionCacheTest, AddAccount) {
717 // Create the DeviceLocalAccountPolicyService, allowing it to finish the
718 // deletion of orphaned cache directories.
719 InstallDevicePolicy();
720 CreatePolicyService();
721 FlushDeviceSettings();
722 extension_cache_task_runner_->RunUntilIdle();
723
724 // Add account 1 to device policy.
725 InstallDeviceLocalAccountPolicy(kAccount1);
726 AddDeviceLocalAccountToPolicy(kAccount1);
727 InstallDevicePolicy();
728
729 // Verify that the cache for account 1 has been started.
730 DeviceLocalAccountPolicyBroker* broker =
731 service_->GetBrokerForUser(account_1_user_id_);
732 ASSERT_TRUE(broker);
733 EXPECT_TRUE(broker->extension_loader()->IsCacheRunning());
734 }
735
736 // Verifies that when an account is removed, its cache directory is deleted.
737 TEST_F(DeviceLocalAccountPolicyExtensionCacheTest, RemoveAccount) {
738 // Add account 1 to device policy.
739 InstallDeviceLocalAccountPolicy(kAccount1);
740 AddDeviceLocalAccountToPolicy(kAccount1);
741 InstallDevicePolicy();
742
743 // Create the DeviceLocalAccountPolicyService, allowing it to finish the
744 // deletion of orphaned cache directories.
745 CreatePolicyService();
746 FlushDeviceSettings();
747 extension_cache_task_runner_->RunUntilIdle();
748
749 // Verify that a cache directory has been created for account 1.
750 EXPECT_TRUE(base::DirectoryExists(cache_dir_1_));
751
752 // Remove account 1 from device policy, allowing the deletion of its now
753 // obsolete cache directory to finish.
754 device_policy_.payload().mutable_device_local_accounts()->clear_account();
755 InstallDevicePolicy();
756 extension_cache_task_runner_->RunUntilIdle();
757 base::RunLoop().RunUntilIdle();
758 extension_cache_task_runner_->RunUntilIdle();
759
760 // Verify that the cache directory for account 1 was deleted.
761 EXPECT_FALSE(base::DirectoryExists(cache_dir_1_));
394 } 762 }
395 763
396 class DeviceLocalAccountPolicyProviderTest 764 class DeviceLocalAccountPolicyProviderTest
397 : public DeviceLocalAccountPolicyServiceTest { 765 : public DeviceLocalAccountPolicyServiceTestBase {
398 protected: 766 protected:
399 DeviceLocalAccountPolicyProviderTest() 767 DeviceLocalAccountPolicyProviderTest();
400 : provider_( 768
401 GenerateDeviceLocalAccountUserId( 769 virtual void SetUp() OVERRIDE;
402 PolicyBuilder::kFakeUsername, 770 virtual void TearDown() OVERRIDE;
403 DeviceLocalAccount::TYPE_PUBLIC_SESSION), 771
404 &service_) {} 772 scoped_ptr<DeviceLocalAccountPolicyProvider> provider_;
405
406 virtual void SetUp() OVERRIDE {
407 DeviceLocalAccountPolicyServiceTest::SetUp();
408 provider_.Init();
409 provider_.AddObserver(&provider_observer_);
410
411 EXPECT_CALL(service_observer_, OnPolicyUpdated(_)).Times(AnyNumber());
412 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged())
413 .Times(AnyNumber());
414 }
415
416 virtual void TearDown() OVERRIDE {
417 provider_.RemoveObserver(&provider_observer_);
418 provider_.Shutdown();
419 DeviceLocalAccountPolicyServiceTest::TearDown();
420 }
421
422 DeviceLocalAccountPolicyProvider provider_;
423 MockConfigurationPolicyObserver provider_observer_; 773 MockConfigurationPolicyObserver provider_observer_;
424 774
425 private: 775 private:
426 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProviderTest); 776 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProviderTest);
427 }; 777 };
428 778
779 DeviceLocalAccountPolicyProviderTest::DeviceLocalAccountPolicyProviderTest() {
780 CreatePolicyService();
781 provider_.reset(new DeviceLocalAccountPolicyProvider(
782 GenerateDeviceLocalAccountUserId(kAccount1,
783 DeviceLocalAccount::TYPE_PUBLIC_SESSION),
784 service_.get()));
785 }
786
787 void DeviceLocalAccountPolicyProviderTest::SetUp() {
788 DeviceLocalAccountPolicyServiceTestBase::SetUp();
789 provider_->Init();
790 provider_->AddObserver(&provider_observer_);
791 }
792
793 void DeviceLocalAccountPolicyProviderTest::TearDown() {
794 provider_->RemoveObserver(&provider_observer_);
795 provider_->Shutdown();
796 DeviceLocalAccountPolicyServiceTestBase::TearDown();
797 }
798
429 TEST_F(DeviceLocalAccountPolicyProviderTest, Initialization) { 799 TEST_F(DeviceLocalAccountPolicyProviderTest, Initialization) {
430 EXPECT_FALSE(provider_.IsInitializationComplete(POLICY_DOMAIN_CHROME)); 800 EXPECT_FALSE(provider_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
431 801
432 // Policy change should complete initialization. 802 // Policy change should complete initialization.
433 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)).Times(AtLeast(1)); 803 InstallDeviceLocalAccountPolicy(kAccount1);
434 device_settings_test_helper_.set_device_local_account_policy_blob( 804 AddDeviceLocalAccountToPolicy(kAccount1);
435 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 805 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
436 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 806 .Times(AtLeast(1));
437 ReloadDeviceSettings(); 807 InstallDevicePolicy();
438 Mock::VerifyAndClearExpectations(&provider_observer_); 808 Mock::VerifyAndClearExpectations(&provider_observer_);
439 809
440 EXPECT_TRUE(provider_.IsInitializationComplete(POLICY_DOMAIN_CHROME)); 810 EXPECT_TRUE(provider_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
441 811
442 // The account disappearing should *not* flip the initialization flag back. 812 // The account disappearing should *not* flip the initialization flag back.
443 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)) 813 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
444 .Times(AnyNumber()); 814 .Times(AnyNumber());
445 device_policy_.payload().mutable_device_local_accounts()->clear_account(); 815 device_policy_.payload().mutable_device_local_accounts()->clear_account();
446 device_policy_.Build(); 816 InstallDevicePolicy();
447 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
448 ReloadDeviceSettings();
449 Mock::VerifyAndClearExpectations(&provider_observer_); 817 Mock::VerifyAndClearExpectations(&provider_observer_);
450 818
451 EXPECT_TRUE(provider_.IsInitializationComplete(POLICY_DOMAIN_CHROME)); 819 EXPECT_TRUE(provider_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
452 } 820 }
453 821
454 TEST_F(DeviceLocalAccountPolicyProviderTest, Policy) { 822 TEST_F(DeviceLocalAccountPolicyProviderTest, Policy) {
455 // Policy should load successfully. 823 // Policy should load successfully.
456 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)).Times(AtLeast(1)); 824 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
457 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 825 .Times(AtLeast(1));
458 device_settings_test_helper_.set_device_local_account_policy_blob( 826 InstallDeviceLocalAccountPolicy(kAccount1);
459 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 827 AddDeviceLocalAccountToPolicy(kAccount1);
460 ReloadDeviceSettings(); 828 InstallDevicePolicy();
461 Mock::VerifyAndClearExpectations(&provider_observer_); 829 Mock::VerifyAndClearExpectations(&provider_observer_);
462 830
463 PolicyBundle expected_policy_bundle; 831 PolicyBundle expected_policy_bundle;
464 expected_policy_bundle.Get(PolicyNamespace( 832 expected_policy_bundle.Get(PolicyNamespace(
465 POLICY_DOMAIN_CHROME, std::string())).CopyFrom(expected_policy_map_); 833 POLICY_DOMAIN_CHROME, std::string())).CopyFrom(expected_policy_map_);
466 EXPECT_TRUE(expected_policy_bundle.Equals(provider_.policies())); 834 EXPECT_TRUE(expected_policy_bundle.Equals(provider_->policies()));
467 835
468 // Policy change should be reported. 836 // Policy change should be reported.
469 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)).Times(AtLeast(1)); 837 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
838 .Times(AtLeast(1));
470 device_local_account_policy_.payload().mutable_disablespdy()->set_value( 839 device_local_account_policy_.payload().mutable_disablespdy()->set_value(
471 false); 840 false);
472 device_local_account_policy_.Build(); 841 InstallDeviceLocalAccountPolicy(kAccount1);
473 device_settings_test_helper_.set_device_local_account_policy_blob( 842 DeviceLocalAccountPolicyBroker* broker =
474 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob()); 843 service_->GetBrokerForUser(account_1_user_id_);
475 DeviceLocalAccountPolicyBroker* broker =
476 service_.GetBrokerForUser(public_session_user_id_);
477 ASSERT_TRUE(broker); 844 ASSERT_TRUE(broker);
478 broker->core()->store()->Load(); 845 broker->core()->store()->Load();
479 FlushDeviceSettings(); 846 FlushDeviceSettings();
480 Mock::VerifyAndClearExpectations(&provider_observer_); 847 Mock::VerifyAndClearExpectations(&provider_observer_);
481 848
482 expected_policy_bundle.Get( 849 expected_policy_bundle.Get(
483 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 850 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
484 .Set(key::kDisableSpdy, 851 .Set(key::kDisableSpdy,
485 POLICY_LEVEL_MANDATORY, 852 POLICY_LEVEL_MANDATORY,
486 POLICY_SCOPE_USER, 853 POLICY_SCOPE_USER,
487 Value::CreateBooleanValue(false), 854 Value::CreateBooleanValue(false),
488 NULL); 855 NULL);
489 EXPECT_TRUE(expected_policy_bundle.Equals(provider_.policies())); 856 EXPECT_TRUE(expected_policy_bundle.Equals(provider_->policies()));
490 857
491 // Any values set for the |ShelfAutoHideBehavior|, |ShowLogoutButtonInTray| 858 // Any values set for the |ShelfAutoHideBehavior|, |ShowLogoutButtonInTray|
492 // and |ExtensionAllowedTypes| policies should be overridden. 859 // and |ExtensionAllowedTypes| policies should be overridden.
493 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)).Times(AtLeast(1)); 860 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
861 .Times(AtLeast(1));
494 device_local_account_policy_.payload().mutable_shelfautohidebehavior()-> 862 device_local_account_policy_.payload().mutable_shelfautohidebehavior()->
495 set_value("Always"); 863 set_value("Always");
496 device_local_account_policy_.payload().mutable_showlogoutbuttonintray()-> 864 device_local_account_policy_.payload().mutable_showlogoutbuttonintray()->
497 set_value(false); 865 set_value(false);
498 device_local_account_policy_.Build(); 866 InstallDeviceLocalAccountPolicy(kAccount1);
499 device_settings_test_helper_.set_device_local_account_policy_blob(
500 PolicyBuilder::kFakeUsername, device_local_account_policy_.GetBlob());
501 broker->core()->store()->Load(); 867 broker->core()->store()->Load();
502 FlushDeviceSettings(); 868 FlushDeviceSettings();
503 Mock::VerifyAndClearExpectations(&provider_observer_); 869 Mock::VerifyAndClearExpectations(&provider_observer_);
504 EXPECT_TRUE(expected_policy_bundle.Equals(provider_.policies())); 870 EXPECT_TRUE(expected_policy_bundle.Equals(provider_->policies()));
505 871
506 // Account disappears, policy should stay in effect. 872 // Account disappears, policy should stay in effect.
507 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)) 873 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
508 .Times(AnyNumber()); 874 .Times(AnyNumber());
509 device_policy_.payload().mutable_device_local_accounts()->clear_account(); 875 device_policy_.payload().mutable_device_local_accounts()->clear_account();
510 device_policy_.Build(); 876 InstallDevicePolicy();
511 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
512 ReloadDeviceSettings();
513 Mock::VerifyAndClearExpectations(&provider_observer_); 877 Mock::VerifyAndClearExpectations(&provider_observer_);
514 878
515 EXPECT_TRUE(expected_policy_bundle.Equals(provider_.policies())); 879 EXPECT_TRUE(expected_policy_bundle.Equals(provider_->policies()));
516 } 880 }
517 881
518 TEST_F(DeviceLocalAccountPolicyProviderTest, RefreshPolicies) { 882 TEST_F(DeviceLocalAccountPolicyProviderTest, RefreshPolicies) {
519 // If there's no device policy, the refresh completes immediately. 883 // If there's no device policy, the refresh completes immediately.
520 EXPECT_FALSE(service_.GetBrokerForUser(public_session_user_id_)); 884 EXPECT_FALSE(service_->GetBrokerForUser(account_1_user_id_));
521 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)).Times(AtLeast(1)); 885 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
522 provider_.RefreshPolicies(); 886 .Times(AtLeast(1));
887 provider_->RefreshPolicies();
523 Mock::VerifyAndClearExpectations(&provider_observer_); 888 Mock::VerifyAndClearExpectations(&provider_observer_);
524 889
525 // Make device settings appear. 890 // Make device settings appear.
526 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)) 891 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
527 .Times(AnyNumber()); 892 .Times(AnyNumber());
528 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 893 AddDeviceLocalAccountToPolicy(kAccount1);
529 ReloadDeviceSettings(); 894 InstallDevicePolicy();
530 Mock::VerifyAndClearExpectations(&provider_observer_); 895 EXPECT_TRUE(service_->GetBrokerForUser(account_1_user_id_));
531 EXPECT_TRUE(service_.GetBrokerForUser(public_session_user_id_));
532 896
533 // If there's no cloud connection, refreshes are still immediate. 897 // If there's no cloud connection, refreshes are still immediate.
534 DeviceLocalAccountPolicyBroker* broker = 898 DeviceLocalAccountPolicyBroker* broker =
535 service_.GetBrokerForUser(public_session_user_id_); 899 service_->GetBrokerForUser(account_1_user_id_);
536 ASSERT_TRUE(broker); 900 ASSERT_TRUE(broker);
537 EXPECT_FALSE(broker->core()->client()); 901 EXPECT_FALSE(broker->core()->client());
538 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)).Times(AtLeast(1)); 902 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
539 provider_.RefreshPolicies(); 903 .Times(AtLeast(1));
904 provider_->RefreshPolicies();
540 Mock::VerifyAndClearExpectations(&provider_observer_); 905 Mock::VerifyAndClearExpectations(&provider_observer_);
541 906
542 // Bring up the cloud connection. The refresh scheduler may fire refreshes at 907 // Bring up the cloud connection. The refresh scheduler may fire refreshes at
543 // this point which are not relevant for the test. 908 // this point which are not relevant for the test.
544 EXPECT_CALL(mock_device_management_service_, CreateJob(_)) 909 EXPECT_CALL(mock_device_management_service_, CreateJob(_))
545 .WillRepeatedly( 910 .WillRepeatedly(
546 mock_device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED)); 911 mock_device_management_service_.FailJob(DM_STATUS_REQUEST_FAILED));
547 EXPECT_CALL(mock_device_management_service_, StartJob(_, _, _, _, _, _, _)) 912 EXPECT_CALL(mock_device_management_service_, StartJob(_, _, _, _, _, _, _))
548 .Times(AnyNumber()); 913 .Times(AnyNumber());
549 service_.Connect(&mock_device_management_service_); 914 service_->Connect(&mock_device_management_service_);
550 FlushDeviceSettings(); 915 FlushDeviceSettings();
551 Mock::VerifyAndClearExpectations(&mock_device_management_service_); 916 Mock::VerifyAndClearExpectations(&mock_device_management_service_);
552 917
553 // No callbacks until the refresh completes. 918 // No callbacks until the refresh completes.
554 EXPECT_CALL(provider_observer_, OnUpdatePolicy(_)).Times(0); 919 EXPECT_CALL(provider_observer_, OnUpdatePolicy(_)).Times(0);
555 MockDeviceManagementJob* request_job; 920 MockDeviceManagementJob* request_job;
556 EXPECT_CALL(mock_device_management_service_, CreateJob(_)) 921 EXPECT_CALL(mock_device_management_service_, CreateJob(_))
557 .WillOnce(mock_device_management_service_.CreateAsyncJob(&request_job)); 922 .WillOnce(mock_device_management_service_.CreateAsyncJob(&request_job));
558 EXPECT_CALL(mock_device_management_service_, StartJob(_, _, _, _, _, _, _)); 923 EXPECT_CALL(mock_device_management_service_, StartJob(_, _, _, _, _, _, _));
559 provider_.RefreshPolicies(); 924 provider_->RefreshPolicies();
560 ReloadDeviceSettings(); 925 ReloadDeviceSettings();
561 Mock::VerifyAndClearExpectations(&provider_observer_); 926 Mock::VerifyAndClearExpectations(&provider_observer_);
562 Mock::VerifyAndClearExpectations(&mock_device_management_service_); 927 Mock::VerifyAndClearExpectations(&mock_device_management_service_);
563 EXPECT_TRUE(provider_.IsInitializationComplete(POLICY_DOMAIN_CHROME)); 928 EXPECT_TRUE(provider_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
564 929
565 // When the response comes in, it should propagate and fire the notification. 930 // When the response comes in, it should propagate and fire the notification.
566 EXPECT_CALL(provider_observer_, OnUpdatePolicy(&provider_)).Times(AtLeast(1)); 931 EXPECT_CALL(provider_observer_, OnUpdatePolicy(provider_.get()))
932 .Times(AtLeast(1));
567 ASSERT_TRUE(request_job); 933 ASSERT_TRUE(request_job);
568 em::DeviceManagementResponse response; 934 em::DeviceManagementResponse response;
935 device_local_account_policy_.Build();
569 response.mutable_policy_response()->add_response()->CopyFrom( 936 response.mutable_policy_response()->add_response()->CopyFrom(
570 device_local_account_policy_.policy()); 937 device_local_account_policy_.policy());
571 request_job->SendResponse(DM_STATUS_SUCCESS, response); 938 request_job->SendResponse(DM_STATUS_SUCCESS, response);
572 FlushDeviceSettings(); 939 FlushDeviceSettings();
573 Mock::VerifyAndClearExpectations(&provider_observer_); 940 Mock::VerifyAndClearExpectations(&provider_observer_);
574 } 941 }
575 942
576 } // namespace policy 943 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698