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

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

Issue 822523003: Implement device-local account policy pushing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_2_442800_switch_device_cloud_policy_invalidator
Patch Set: Removed the need to initialize singletons in unit tests. Created 5 years, 10 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
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/message_loop/message_loop_proxy.h" 16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/test/scoped_path_override.h" 21 #include "base/test/scoped_path_override.h"
22 #include "base/test/test_simple_task_runner.h" 22 #include "base/test/test_simple_task_runner.h"
23 #include "chrome/browser/chromeos/policy/device_local_account.h" 23 #include "chrome/browser/chromeos/policy/device_local_account.h"
24 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" 24 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h"
25 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 25 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
26 #include "chrome/browser/chromeos/settings/cros_settings.h" 26 #include "chrome/browser/chromeos/settings/cros_settings.h"
27 #include "chrome/browser/chromeos/settings/device_settings_service.h" 27 #include "chrome/browser/chromeos/settings/device_settings_service.h"
28 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 28 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
29 #include "chrome/browser/invalidation/fake_invalidation_service.h"
30 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h"
29 #include "chrome/common/chrome_paths.h" 31 #include "chrome/common/chrome_paths.h"
32 #include "chrome/test/base/testing_browser_process.h"
33 #include "chrome/test/base/testing_profile_manager.h"
30 #include "chromeos/chromeos_paths.h" 34 #include "chromeos/chromeos_paths.h"
31 #include "chromeos/dbus/power_policy_controller.h" 35 #include "chromeos/dbus/power_policy_controller.h"
36 #include "components/invalidation/invalidation.h"
37 #include "components/invalidation/object_id_invalidation_map.h"
32 #include "components/policy/core/common/cloud/cloud_policy_client.h" 38 #include "components/policy/core/common/cloud/cloud_policy_client.h"
33 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 39 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
34 #include "components/policy/core/common/cloud/cloud_policy_service.h" 40 #include "components/policy/core/common/cloud/cloud_policy_service.h"
35 #include "components/policy/core/common/cloud/mock_device_management_service.h" 41 #include "components/policy/core/common/cloud/mock_device_management_service.h"
36 #include "components/policy/core/common/cloud/policy_builder.h" 42 #include "components/policy/core/common/cloud/policy_builder.h"
37 #include "components/policy/core/common/external_data_fetcher.h" 43 #include "components/policy/core/common/external_data_fetcher.h"
38 #include "components/policy/core/common/mock_configuration_policy_provider.h" 44 #include "components/policy/core/common/mock_configuration_policy_provider.h"
39 #include "components/policy/core/common/policy_bundle.h" 45 #include "components/policy/core/common/policy_bundle.h"
40 #include "components/policy/core/common/policy_map.h" 46 #include "components/policy/core/common/policy_map.h"
41 #include "components/policy/core/common/schema_registry.h" 47 #include "components/policy/core/common/schema_registry.h"
48 #include "google/cacheinvalidation/include/types.h"
42 #include "net/url_request/url_request_context_getter.h" 49 #include "net/url_request/url_request_context_getter.h"
43 #include "net/url_request/url_request_test_util.h" 50 #include "net/url_request/url_request_test_util.h"
44 #include "policy/policy_constants.h" 51 #include "policy/policy_constants.h"
45 #include "policy/proto/cloud_policy.pb.h" 52 #include "policy/proto/cloud_policy.pb.h"
46 #include "policy/proto/device_management_backend.pb.h" 53 #include "policy/proto/device_management_backend.pb.h"
47 #include "testing/gtest/include/gtest/gtest.h" 54 #include "testing/gtest/include/gtest/gtest.h"
48 55
49 using testing::AnyNumber; 56 using testing::AnyNumber;
50 using testing::AtLeast; 57 using testing::AtLeast;
51 using testing::Mock; 58 using testing::Mock;
52 using testing::SaveArg; 59 using testing::SaveArg;
53 using testing::_; 60 using testing::_;
54 61
55 namespace em = enterprise_management; 62 namespace em = enterprise_management;
56 63
57 namespace policy { 64 namespace policy {
58 65
59 namespace { 66 namespace {
60 67
61 const char kAccount1[] = "account1@localhost"; 68 const char kAccount1[] = "account1@localhost";
62 const char kAccount2[] = "account2@localhost"; 69 const char kAccount2[] = "account2@localhost";
63 const char kAccount3[] = "account3@localhost"; 70 const char kAccount3[] = "account3@localhost";
64 71
65 const char kExtensionID[] = "kbmnembihfiondgfjekmnmcbddelicoi"; 72 const char kExtensionID[] = "kbmnembihfiondgfjekmnmcbddelicoi";
66 const char kExtensionVersion[] = "1.0.0.0"; 73 const char kExtensionVersion[] = "1.0.0.0";
67 const char kExtensionCRXPath[] = "extensions/hosted_app.crx"; 74 const char kExtensionCRXPath[] = "extensions/hosted_app.crx";
68 const char kUpdateURL[] = "https://clients2.google.com/service/update2/crx"; 75 const char kUpdateURL[] = "https://clients2.google.com/service/update2/crx";
69 76
77 const int kInvalidationSource = 123;
78 const char kInvalidationName[] = "invalidation";
79
70 } // namespace 80 } // namespace
71 81
72 class MockDeviceLocalAccountPolicyServiceObserver 82 class MockDeviceLocalAccountPolicyServiceObserver
73 : public DeviceLocalAccountPolicyService::Observer { 83 : public DeviceLocalAccountPolicyService::Observer {
74 public: 84 public:
75 MOCK_METHOD1(OnPolicyUpdated, void(const std::string&)); 85 MOCK_METHOD1(OnPolicyUpdated, void(const std::string&));
76 MOCK_METHOD0(OnDeviceLocalAccountsChanged, void(void)); 86 MOCK_METHOD0(OnDeviceLocalAccountsChanged, void(void));
77 }; 87 };
78 88
79 class DeviceLocalAccountPolicyServiceTestBase 89 class DeviceLocalAccountPolicyServiceTestBase
(...skipping 11 matching lines...) Expand all
91 virtual void InstallDevicePolicy(); 101 virtual void InstallDevicePolicy();
92 102
93 const std::string account_1_user_id_; 103 const std::string account_1_user_id_;
94 const std::string account_2_user_id_; 104 const std::string account_2_user_id_;
95 105
96 PolicyMap expected_policy_map_; 106 PolicyMap expected_policy_map_;
97 UserPolicyBuilder device_local_account_policy_; 107 UserPolicyBuilder device_local_account_policy_;
98 chromeos::CrosSettings cros_settings_; 108 chromeos::CrosSettings cros_settings_;
99 scoped_refptr<base::TestSimpleTaskRunner> extension_cache_task_runner_; 109 scoped_refptr<base::TestSimpleTaskRunner> extension_cache_task_runner_;
100 MockDeviceManagementService mock_device_management_service_; 110 MockDeviceManagementService mock_device_management_service_;
111 TestingProfileManager profile_manager_;
112 scoped_ptr<AffiliatedInvalidationServiceProvider>
113 affiliated_invalidation_service_provider_;
101 scoped_ptr<DeviceLocalAccountPolicyService> service_; 114 scoped_ptr<DeviceLocalAccountPolicyService> service_;
102 115
103 private: 116 private:
104 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyServiceTestBase); 117 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyServiceTestBase);
105 }; 118 };
106 119
107 class DeviceLocalAccountPolicyServiceTest 120 class DeviceLocalAccountPolicyServiceTest
108 : public DeviceLocalAccountPolicyServiceTestBase { 121 : public DeviceLocalAccountPolicyServiceTestBase {
109 public: 122 public:
110 MOCK_METHOD1(OnRefreshDone, void(bool)); 123 MOCK_METHOD1(OnRefreshDone, void(bool));
111 124
112 protected: 125 protected:
113 DeviceLocalAccountPolicyServiceTest(); 126 DeviceLocalAccountPolicyServiceTest();
114 127
115 virtual void SetUp() override; 128 virtual void SetUp() override;
116 virtual void TearDown() override; 129 virtual void TearDown() override;
117 130
118 void InstallDevicePolicy() override; 131 void InstallDevicePolicy() override;
119 132
133 void FlushDeviceLocalAccountPolicyFetch();
pneubeck (no reviews) 2015/01/30 14:23:58 i think this function has enough side effect that
bartfab (slow) 2015/02/03 18:31:06 Obsolete.
134
120 MockDeviceLocalAccountPolicyServiceObserver service_observer_; 135 MockDeviceLocalAccountPolicyServiceObserver service_observer_;
121 136
122 private: 137 private:
123 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyServiceTest); 138 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyServiceTest);
124 }; 139 };
125 140
126 DeviceLocalAccountPolicyServiceTestBase:: 141 DeviceLocalAccountPolicyServiceTestBase::
127 DeviceLocalAccountPolicyServiceTestBase() 142 DeviceLocalAccountPolicyServiceTestBase()
128 : account_1_user_id_(GenerateDeviceLocalAccountUserId( 143 : account_1_user_id_(GenerateDeviceLocalAccountUserId(
129 kAccount1, 144 kAccount1,
130 DeviceLocalAccount::TYPE_PUBLIC_SESSION)), 145 DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
131 account_2_user_id_(GenerateDeviceLocalAccountUserId( 146 account_2_user_id_(GenerateDeviceLocalAccountUserId(
132 kAccount2, 147 kAccount2,
133 DeviceLocalAccount::TYPE_PUBLIC_SESSION)), 148 DeviceLocalAccount::TYPE_PUBLIC_SESSION)),
134 cros_settings_(&device_settings_service_), 149 cros_settings_(&device_settings_service_),
135 extension_cache_task_runner_(new base::TestSimpleTaskRunner) { 150 extension_cache_task_runner_(new base::TestSimpleTaskRunner),
151 profile_manager_(TestingBrowserProcess::GetGlobal()) {
136 } 152 }
137 153
138 void DeviceLocalAccountPolicyServiceTestBase::SetUp() { 154 void DeviceLocalAccountPolicyServiceTestBase::SetUp() {
139 chromeos::DeviceSettingsTestBase::SetUp(); 155 chromeos::DeviceSettingsTestBase::SetUp();
140 156
157 ASSERT_TRUE(profile_manager_.SetUp());
158
159 affiliated_invalidation_service_provider_.reset(
160 new AffiliatedInvalidationServiceProvider);
pneubeck (no reviews) 2015/01/30 14:23:58 you could make the relevant methods of the provide
bartfab (slow) 2015/02/03 18:31:06 Done.
161 // Mark the |affiliated_invalidation_service_provider_| as shut down
162 // immediately. This will prevent it from trying to find an available
163 // invalidation service, which pulls in a lot of additional run-time
164 // dependencies.
165 affiliated_invalidation_service_provider_->Shutdown();
166
141 expected_policy_map_.Set(key::kDisableSpdy, 167 expected_policy_map_.Set(key::kDisableSpdy,
142 POLICY_LEVEL_MANDATORY, 168 POLICY_LEVEL_MANDATORY,
143 POLICY_SCOPE_USER, 169 POLICY_SCOPE_USER,
144 new base::FundamentalValue(true), 170 new base::FundamentalValue(true),
145 NULL); 171 NULL);
146 172
147 device_local_account_policy_.payload().mutable_disablespdy()->set_value( 173 device_local_account_policy_.payload().mutable_disablespdy()->set_value(
148 true); 174 true);
149 device_local_account_policy_.policy_data().set_policy_type( 175 device_local_account_policy_.policy_data().set_policy_type(
150 dm_protocol::kChromePublicAccountPolicyType); 176 dm_protocol::kChromePublicAccountPolicyType);
151 } 177 }
152 178
153 void DeviceLocalAccountPolicyServiceTestBase::TearDown() { 179 void DeviceLocalAccountPolicyServiceTestBase::TearDown() {
154 service_->Shutdown(); 180 service_->Shutdown();
155 service_.reset(); 181 service_.reset();
156 extension_cache_task_runner_->RunUntilIdle(); 182 extension_cache_task_runner_->RunUntilIdle();
157 chromeos::DeviceSettingsTestBase::TearDown(); 183 chromeos::DeviceSettingsTestBase::TearDown();
158 } 184 }
159 185
160 void DeviceLocalAccountPolicyServiceTestBase::CreatePolicyService() { 186 void DeviceLocalAccountPolicyServiceTestBase::CreatePolicyService() {
161 service_.reset(new DeviceLocalAccountPolicyService( 187 service_.reset(new DeviceLocalAccountPolicyService(
162 &device_settings_test_helper_, 188 &device_settings_test_helper_,
163 &device_settings_service_, 189 &device_settings_service_,
164 &cros_settings_, 190 &cros_settings_,
191 affiliated_invalidation_service_provider_.get(),
165 base::MessageLoopProxy::current(), 192 base::MessageLoopProxy::current(),
166 extension_cache_task_runner_, 193 extension_cache_task_runner_,
167 base::MessageLoopProxy::current(), 194 base::MessageLoopProxy::current(),
168 base::MessageLoopProxy::current(), 195 base::MessageLoopProxy::current(),
169 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()))); 196 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current())));
170 } 197 }
171 198
172 void DeviceLocalAccountPolicyServiceTestBase:: 199 void DeviceLocalAccountPolicyServiceTestBase::
173 InstallDeviceLocalAccountPolicy(const std::string& account_id) { 200 InstallDeviceLocalAccountPolicy(const std::string& account_id) {
174 device_local_account_policy_.policy_data().set_settings_entity_id(account_id); 201 device_local_account_policy_.policy_data().set_settings_entity_id(account_id);
(...skipping 12 matching lines...) Expand all
187 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); 214 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
188 } 215 }
189 216
190 void DeviceLocalAccountPolicyServiceTestBase::InstallDevicePolicy() { 217 void DeviceLocalAccountPolicyServiceTestBase::InstallDevicePolicy() {
191 device_policy_.Build(); 218 device_policy_.Build();
192 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); 219 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
193 ReloadDeviceSettings(); 220 ReloadDeviceSettings();
194 } 221 }
195 222
196 DeviceLocalAccountPolicyServiceTest::DeviceLocalAccountPolicyServiceTest() { 223 DeviceLocalAccountPolicyServiceTest::DeviceLocalAccountPolicyServiceTest() {
197 CreatePolicyService();
198 } 224 }
199 225
200 void DeviceLocalAccountPolicyServiceTest::SetUp() { 226 void DeviceLocalAccountPolicyServiceTest::SetUp() {
201 DeviceLocalAccountPolicyServiceTestBase::SetUp(); 227 DeviceLocalAccountPolicyServiceTestBase::SetUp();
228
229 CreatePolicyService();
202 service_->AddObserver(&service_observer_); 230 service_->AddObserver(&service_observer_);
203 } 231 }
204 232
205 void DeviceLocalAccountPolicyServiceTest::TearDown() { 233 void DeviceLocalAccountPolicyServiceTest::TearDown() {
206 service_->RemoveObserver(&service_observer_); 234 service_->RemoveObserver(&service_observer_);
207 DeviceLocalAccountPolicyServiceTestBase::TearDown(); 235 DeviceLocalAccountPolicyServiceTestBase::TearDown();
208 } 236 }
209 237
210 void DeviceLocalAccountPolicyServiceTest::InstallDevicePolicy() { 238 void DeviceLocalAccountPolicyServiceTest::InstallDevicePolicy() {
211 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged()); 239 EXPECT_CALL(service_observer_, OnDeviceLocalAccountsChanged());
212 DeviceLocalAccountPolicyServiceTestBase::InstallDevicePolicy(); 240 DeviceLocalAccountPolicyServiceTestBase::InstallDevicePolicy();
213 Mock::VerifyAndClearExpectations(&service_observer_); 241 Mock::VerifyAndClearExpectations(&service_observer_);
214 } 242 }
215 243
244 void DeviceLocalAccountPolicyServiceTest::FlushDeviceLocalAccountPolicyFetch() {
245 em::DeviceManagementRequest request;
246 em::DeviceManagementResponse response;
247 response.mutable_policy_response()->add_response()->CopyFrom(
248 device_local_account_policy_.policy());
249 EXPECT_CALL(mock_device_management_service_,
250 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _))
251 .WillOnce(mock_device_management_service_.SucceedJob(response));
252 EXPECT_CALL(mock_device_management_service_,
253 StartJob(dm_protocol::kValueRequestPolicy,
254 std::string(), std::string(),
255 device_policy_.policy_data().request_token(),
256 dm_protocol::kValueUserAffiliationManaged,
257 device_policy_.policy_data().device_id(),
258 _))
259 .WillOnce(SaveArg<6>(&request));
260 // This will be called twice, because the ComponentCloudPolicyService will
261 // also become ready after flushing all the pending tasks.
262 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_)).Times(2);
263 FlushDeviceSettings();
264
265 Mock::VerifyAndClearExpectations(&service_observer_);
266 Mock::VerifyAndClearExpectations(&mock_device_management_service_);
267
268 EXPECT_TRUE(request.has_policy_request());
269 ASSERT_EQ(2, request.policy_request().request_size());
270
271 const em::PolicyFetchRequest* public_account =
272 &request.policy_request().request(0);
273 const em::PolicyFetchRequest* extensions =
274 &request.policy_request().request(1);
275 // The order is not guarateed.
276 if (extensions->policy_type() ==
277 dm_protocol::kChromePublicAccountPolicyType) {
278 std::swap(public_account, extensions);
279 }
280
281 EXPECT_EQ(dm_protocol::kChromePublicAccountPolicyType,
282 public_account->policy_type());
283 EXPECT_FALSE(public_account->has_machine_id());
284 EXPECT_EQ(kAccount1, public_account->settings_entity_id());
285
286 EXPECT_EQ(dm_protocol::kChromeExtensionPolicyType,
287 extensions->policy_type());
288 EXPECT_FALSE(extensions->has_machine_id());
289 EXPECT_FALSE(extensions->has_settings_entity_id());
290 }
291
216 TEST_F(DeviceLocalAccountPolicyServiceTest, NoAccounts) { 292 TEST_F(DeviceLocalAccountPolicyServiceTest, NoAccounts) {
217 EXPECT_FALSE(service_->GetBrokerForUser(account_1_user_id_)); 293 EXPECT_FALSE(service_->GetBrokerForUser(account_1_user_id_));
218 } 294 }
219 295
220 TEST_F(DeviceLocalAccountPolicyServiceTest, GetBroker) { 296 TEST_F(DeviceLocalAccountPolicyServiceTest, GetBroker) {
221 InstallDeviceLocalAccountPolicy(kAccount1); 297 InstallDeviceLocalAccountPolicy(kAccount1);
222 AddDeviceLocalAccountToPolicy(kAccount1); 298 AddDeviceLocalAccountToPolicy(kAccount1);
223 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_)); 299 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
224 InstallDevicePolicy(); 300 InstallDevicePolicy();
225 301
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_)); 462 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
387 InstallDevicePolicy(); 463 InstallDevicePolicy();
388 464
389 DeviceLocalAccountPolicyBroker* broker = 465 DeviceLocalAccountPolicyBroker* broker =
390 service_->GetBrokerForUser(account_1_user_id_); 466 service_->GetBrokerForUser(account_1_user_id_);
391 ASSERT_TRUE(broker); 467 ASSERT_TRUE(broker);
392 468
393 service_->Connect(&mock_device_management_service_); 469 service_->Connect(&mock_device_management_service_);
394 EXPECT_TRUE(broker->core()->client()); 470 EXPECT_TRUE(broker->core()->client());
395 471
396 em::DeviceManagementRequest request; 472 FlushDeviceLocalAccountPolicyFetch();
397 em::DeviceManagementResponse response;
398 response.mutable_policy_response()->add_response()->CopyFrom(
399 device_local_account_policy_.policy());
400 EXPECT_CALL(mock_device_management_service_,
401 CreateJob(DeviceManagementRequestJob::TYPE_POLICY_FETCH, _))
402 .WillOnce(mock_device_management_service_.SucceedJob(response));
403 EXPECT_CALL(mock_device_management_service_,
404 StartJob(dm_protocol::kValueRequestPolicy,
405 std::string(), std::string(),
406 device_policy_.policy_data().request_token(),
407 dm_protocol::kValueUserAffiliationManaged,
408 device_policy_.policy_data().device_id(),
409 _))
410 .WillOnce(SaveArg<6>(&request));
411 // This will be called twice, because the ComponentCloudPolicyService will
412 // also become ready after flushing all the pending tasks.
413 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_)).Times(2);
414 broker->core()->client()->FetchPolicy();
pneubeck (no reviews) 2015/01/30 14:23:58 you dropped this FetchPolicy call during the refac
bartfab (slow) 2015/02/03 18:31:06 Yes, this was intentional. We should test that the
415 FlushDeviceSettings();
416 Mock::VerifyAndClearExpectations(&service_observer_);
417 Mock::VerifyAndClearExpectations(&mock_device_management_service_);
418 EXPECT_TRUE(request.has_policy_request());
419 ASSERT_EQ(2, request.policy_request().request_size());
420
421 const em::PolicyFetchRequest* public_account =
422 &request.policy_request().request(0);
423 const em::PolicyFetchRequest* extensions =
424 &request.policy_request().request(1);
425 // The order is not guarateed.
426 if (extensions->policy_type() ==
427 dm_protocol::kChromePublicAccountPolicyType) {
428 std::swap(public_account, extensions);
429 }
430
431 EXPECT_EQ(dm_protocol::kChromePublicAccountPolicyType,
432 public_account->policy_type());
433 EXPECT_FALSE(public_account->has_machine_id());
434 EXPECT_EQ(kAccount1, public_account->settings_entity_id());
435
436 EXPECT_EQ(dm_protocol::kChromeExtensionPolicyType,
437 extensions->policy_type());
438 EXPECT_FALSE(extensions->has_machine_id());
439 EXPECT_FALSE(extensions->has_settings_entity_id());
440 473
441 ASSERT_TRUE(broker->core()->store()); 474 ASSERT_TRUE(broker->core()->store());
442 EXPECT_EQ(CloudPolicyStore::STATUS_OK, 475 EXPECT_EQ(CloudPolicyStore::STATUS_OK,
443 broker->core()->store()->status()); 476 broker->core()->store()->status());
444 ASSERT_TRUE(broker->core()->store()->policy()); 477 ASSERT_TRUE(broker->core()->store()->policy());
445 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(), 478 EXPECT_EQ(device_local_account_policy_.policy_data().SerializeAsString(),
446 broker->core()->store()->policy()->SerializeAsString()); 479 broker->core()->store()->policy()->SerializeAsString());
447 EXPECT_TRUE(expected_policy_map_.Equals( 480 EXPECT_TRUE(expected_policy_map_.Equals(
448 broker->core()->store()->policy_map())); 481 broker->core()->store()->policy_map()));
449 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_)); 482 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 Mock::VerifyAndClearExpectations(&mock_device_management_service_); 514 Mock::VerifyAndClearExpectations(&mock_device_management_service_);
482 515
483 ASSERT_TRUE(broker->core()->store()); 516 ASSERT_TRUE(broker->core()->store());
484 EXPECT_EQ(CloudPolicyStore::STATUS_OK, 517 EXPECT_EQ(CloudPolicyStore::STATUS_OK,
485 broker->core()->store()->status()); 518 broker->core()->store()->status());
486 EXPECT_TRUE(expected_policy_map_.Equals( 519 EXPECT_TRUE(expected_policy_map_.Equals(
487 broker->core()->store()->policy_map())); 520 broker->core()->store()->policy_map()));
488 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_)); 521 EXPECT_TRUE(service_->IsPolicyAvailableForUser(account_1_user_id_));
489 } 522 }
490 523
524 TEST_F(DeviceLocalAccountPolicyServiceTest, Invalidation) {
525 device_local_account_policy_.policy_data().set_invalidation_source(
526 kInvalidationSource);
527 device_local_account_policy_.policy_data().set_invalidation_name(
528 "invalidation");
529 InstallDeviceLocalAccountPolicy(kAccount1);
530
531 AddDeviceLocalAccountToPolicy(kAccount1);
532 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
533 InstallDevicePolicy();
534 Mock::VerifyAndClearExpectations(&service_observer_);
535
536 DeviceLocalAccountPolicyBroker* broker =
537 service_->GetBrokerForUser(account_1_user_id_);
538 ASSERT_TRUE(broker);
539 EXPECT_EQ(account_1_user_id_, broker->user_id());
pneubeck (no reviews) 2015/01/30 14:23:58 this seems to be tested already in TEST_F(..., Get
bartfab (slow) 2015/02/03 18:31:06 Obsolete.
540 ASSERT_TRUE(broker->core()->store());
541
542 // Make a first invalidation service available.
543 invalidation::FakeInvalidationService invalidation_service_1;
544 broker->OnInvalidationServiceSet(&invalidation_service_1);
545
546 // Verify that no invalidator exists initially.
547 EXPECT_FALSE(broker->GetInvalidatorForTest());
548
549 service_->Connect(&mock_device_management_service_);
550
551 // Verify that an invalidator backed by the first invalidation service has
552 // been created and its highest handled invalidation version starts out as 0.
553 CloudPolicyInvalidator* invalidator = broker->GetInvalidatorForTest();
554 ASSERT_TRUE(invalidator);
555 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version());
556 EXPECT_EQ(&invalidation_service_1,
557 invalidator->invalidation_service_for_test());
558
559 // Trigger an invalidation. The invalidation version is interpreted as a
560 // timestamp in microseconds. The policy blob contains a timestamp in
561 // milliseconds. Convert from one to the other by multiplying by 1000.
562 const int64 invalidation_version =
563 broker->core()->store()->policy()->timestamp() * 1000;
564 syncer::Invalidation invalidation = syncer::Invalidation::Init(
565 invalidation::ObjectId(kInvalidationSource, kInvalidationName),
566 invalidation_version,
567 "dummy payload");
568 syncer::ObjectIdInvalidationMap invalidation_map;
569 invalidation_map.Insert(invalidation);
570 invalidator->OnIncomingInvalidation(invalidation_map);
571
572 // Verify that the invalidation causes a policy refresh.
573 FlushDeviceLocalAccountPolicyFetch();
574
575 // Verify that the highest handled invalidation version has been recorded.
576 EXPECT_EQ(invalidation_version,
577 invalidator->highest_handled_invalidation_version());
578
579 // Make the first invalidation service unavailable.
580 broker->OnInvalidationServiceSet(nullptr);
581
582 // Verify that the invalidator has been destroyed.
583 EXPECT_FALSE(broker->GetInvalidatorForTest());
584
585 // Make a second invalidation service available instead.
586 invalidation::FakeInvalidationService invalidation_service_2;
587 broker->OnInvalidationServiceSet(&invalidation_service_2);
588
589 // Verify that an invalidator backed by the second invalidation service has
590 // been created and its highest handled invalidation version starts out as the
591 // highest invalidation version handled by the previous invalidator.
592 invalidator = broker->GetInvalidatorForTest();
593 ASSERT_TRUE(invalidator);
594 EXPECT_EQ(invalidation_version,
595 invalidator->highest_handled_invalidation_version());
596 EXPECT_EQ(&invalidation_service_2,
597 invalidator->invalidation_service_for_test());
598
599 // Make the first invalidation service available again. This implies that the
600 // second invalidation service is no longer available.
601 broker->OnInvalidationServiceSet(&invalidation_service_1);
602
603 // Verify that the invalidator backed by the second invalidation service was
604 // destroyed and an invalidation backed by the first invalidation service has
605 // been created instead. Also verify that its highest handled invalidation
606 // version starts out as 1.
607 invalidator = broker->GetInvalidatorForTest();
608 ASSERT_TRUE(invalidator);
609 EXPECT_EQ(invalidation_version,
610 invalidator->highest_handled_invalidation_version());
611 EXPECT_EQ(&invalidation_service_1,
612 invalidator->invalidation_service_for_test());
613
614 // Make the first invalidation service unavailable.
615 broker->OnInvalidationServiceSet(nullptr);
616 }
617
618 TEST_F(DeviceLocalAccountPolicyServiceTest,
pneubeck (no reviews) 2015/01/30 14:23:58 If I checked it correctly, by parameterizing Devic
bartfab (slow) 2015/02/03 18:31:06 Done. After making this change, I renamed DeviceCl
619 ConnectBeforeInvalidationServiceAvailable) {
620 device_local_account_policy_.policy_data().set_invalidation_source(123);
621 device_local_account_policy_.policy_data().set_invalidation_name(
622 kInvalidationName);
623 InstallDeviceLocalAccountPolicy(kAccount1);
624
625 AddDeviceLocalAccountToPolicy(kAccount1);
626 EXPECT_CALL(service_observer_, OnPolicyUpdated(account_1_user_id_));
627 InstallDevicePolicy();
628 Mock::VerifyAndClearExpectations(&service_observer_);
629
630 DeviceLocalAccountPolicyBroker* broker =
631 service_->GetBrokerForUser(account_1_user_id_);
632 ASSERT_TRUE(broker);
633 EXPECT_EQ(account_1_user_id_, broker->user_id());
pneubeck (no reviews) 2015/01/30 14:23:58 same as above, please remove
bartfab (slow) 2015/02/03 18:31:06 Obsolete.
634 ASSERT_TRUE(broker->core()->store());
635
636 service_->Connect(&mock_device_management_service_);
637
638 // Verify that no invalidator exists initially.
639 EXPECT_FALSE(broker->GetInvalidatorForTest());
640
641 // Make an invalidation service available.
642 invalidation::FakeInvalidationService invalidation_service;
643 broker->OnInvalidationServiceSet(&invalidation_service);
644
645 // Verify that an invalidator backed by the invalidation service has been
646 // created and its highest handled invalidation version starts out as 0.
647 CloudPolicyInvalidator* invalidator = broker->GetInvalidatorForTest();
648 ASSERT_TRUE(invalidator);
649 EXPECT_EQ(0, invalidator->highest_handled_invalidation_version());
650 EXPECT_EQ(&invalidation_service,
651 invalidator->invalidation_service_for_test());
652
653 // Make the invalidation service unavailable.
654 broker->OnInvalidationServiceSet(nullptr);
655 }
656
491 class DeviceLocalAccountPolicyExtensionCacheTest 657 class DeviceLocalAccountPolicyExtensionCacheTest
492 : public DeviceLocalAccountPolicyServiceTestBase { 658 : public DeviceLocalAccountPolicyServiceTestBase {
493 protected: 659 protected:
494 DeviceLocalAccountPolicyExtensionCacheTest(); 660 DeviceLocalAccountPolicyExtensionCacheTest();
495 661
496 void SetUp() override; 662 void SetUp() override;
497 663
498 base::FilePath GetCacheDirectoryForAccountID(const std::string& account_id); 664 base::FilePath GetCacheDirectoryForAccountID(const std::string& account_id);
499 665
500 base::ScopedTempDir cache_root_dir_; 666 base::ScopedTempDir cache_root_dir_;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 943
778 SchemaRegistry schema_registry_; 944 SchemaRegistry schema_registry_;
779 scoped_ptr<DeviceLocalAccountPolicyProvider> provider_; 945 scoped_ptr<DeviceLocalAccountPolicyProvider> provider_;
780 MockConfigurationPolicyObserver provider_observer_; 946 MockConfigurationPolicyObserver provider_observer_;
781 947
782 private: 948 private:
783 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProviderTest); 949 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProviderTest);
784 }; 950 };
785 951
786 DeviceLocalAccountPolicyProviderTest::DeviceLocalAccountPolicyProviderTest() { 952 DeviceLocalAccountPolicyProviderTest::DeviceLocalAccountPolicyProviderTest() {
953 }
954
955 void DeviceLocalAccountPolicyProviderTest::SetUp() {
956 DeviceLocalAccountPolicyServiceTestBase::SetUp();
957
787 CreatePolicyService(); 958 CreatePolicyService();
788 provider_ = DeviceLocalAccountPolicyProvider::Create( 959 provider_ = DeviceLocalAccountPolicyProvider::Create(
789 GenerateDeviceLocalAccountUserId(kAccount1, 960 GenerateDeviceLocalAccountUserId(kAccount1,
790 DeviceLocalAccount::TYPE_PUBLIC_SESSION), 961 DeviceLocalAccount::TYPE_PUBLIC_SESSION),
791 service_.get()); 962 service_.get());
792 }
793
794 void DeviceLocalAccountPolicyProviderTest::SetUp() {
795 DeviceLocalAccountPolicyServiceTestBase::SetUp();
796 provider_->Init(&schema_registry_); 963 provider_->Init(&schema_registry_);
797 provider_->AddObserver(&provider_observer_); 964 provider_->AddObserver(&provider_observer_);
798 965
799 // Values implicitly enforced for public accounts. 966 // Values implicitly enforced for public accounts.
800 expected_policy_map_.Set(key::kLidCloseAction, 967 expected_policy_map_.Set(key::kLidCloseAction,
801 POLICY_LEVEL_MANDATORY, 968 POLICY_LEVEL_MANDATORY,
802 POLICY_SCOPE_MACHINE, 969 POLICY_SCOPE_MACHINE,
803 new base::FundamentalValue( 970 new base::FundamentalValue(
804 chromeos::PowerPolicyController:: 971 chromeos::PowerPolicyController::
805 ACTION_STOP_SESSION), 972 ACTION_STOP_SESSION),
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 em::DeviceManagementResponse response; 1133 em::DeviceManagementResponse response;
967 device_local_account_policy_.Build(); 1134 device_local_account_policy_.Build();
968 response.mutable_policy_response()->add_response()->CopyFrom( 1135 response.mutable_policy_response()->add_response()->CopyFrom(
969 device_local_account_policy_.policy()); 1136 device_local_account_policy_.policy());
970 request_job->SendResponse(DM_STATUS_SUCCESS, response); 1137 request_job->SendResponse(DM_STATUS_SUCCESS, response);
971 FlushDeviceSettings(); 1138 FlushDeviceSettings();
972 Mock::VerifyAndClearExpectations(&provider_observer_); 1139 Mock::VerifyAndClearExpectations(&provider_observer_);
973 } 1140 }
974 1141
975 } // namespace policy 1142 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698