OLD | NEW |
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_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/testing_pref_service.h" | 14 #include "base/prefs/testing_pref_service.h" |
13 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
14 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 16 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 17 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
16 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 18 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 256 |
255 manager_->Connect(&local_state_, | 257 manager_->Connect(&local_state_, |
256 &device_management_service_, | 258 &device_management_service_, |
257 scoped_ptr<CloudPolicyClient::StatusProvider>()); | 259 scoped_ptr<CloudPolicyClient::StatusProvider>()); |
258 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 260 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
259 | 261 |
260 manager_->Shutdown(); | 262 manager_->Shutdown(); |
261 EXPECT_TRUE(manager_->policies().Equals(bundle)); | 263 EXPECT_TRUE(manager_->policies().Equals(bundle)); |
262 } | 264 } |
263 | 265 |
| 266 class DeviceCloudPolicyManagerChromeOSStateKeyTest : public testing::Test { |
| 267 protected: |
| 268 DeviceCloudPolicyManagerChromeOSStateKeyTest() {} |
| 269 |
| 270 virtual void SetUp() OVERRIDE { |
| 271 chromeos::system::StatisticsProvider::SetTestProvider( |
| 272 &statistics_provider_); |
| 273 EXPECT_CALL(statistics_provider_, GetMachineStatistic(_, _)) |
| 274 .WillRepeatedly(Invoke(this, |
| 275 &DeviceCloudPolicyManagerChromeOSStateKeyTest:: |
| 276 GetMachineStatistic)); |
| 277 } |
| 278 |
| 279 virtual void TearDown() OVERRIDE { |
| 280 chromeos::system::StatisticsProvider::SetTestProvider(NULL); |
| 281 } |
| 282 |
| 283 bool GetMachineStatistic(const std::string& name, std::string* result) { |
| 284 *result = "fake-" + name; |
| 285 return true; |
| 286 } |
| 287 |
| 288 private: |
| 289 chromeos::system::MockStatisticsProvider statistics_provider_; |
| 290 |
| 291 DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSStateKeyTest); |
| 292 }; |
| 293 |
| 294 TEST_F(DeviceCloudPolicyManagerChromeOSStateKeyTest, GetDeviceStateKeys) { |
| 295 base::Time current = base::Time::UnixEpoch() + base::TimeDelta::FromDays(100); |
| 296 |
| 297 // The correct number of state keys gets returned. |
| 298 std::vector<std::string> state_keys; |
| 299 EXPECT_TRUE(DeviceCloudPolicyManagerChromeOS::GetDeviceStateKeys( |
| 300 current, &state_keys)); |
| 301 EXPECT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta, |
| 302 static_cast<int>(state_keys.size())); |
| 303 |
| 304 // All state keys are different. |
| 305 std::set<std::string> state_key_set(state_keys.begin(), state_keys.end()); |
| 306 EXPECT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta, |
| 307 static_cast<int>(state_key_set.size())); |
| 308 |
| 309 // Moving forward just a little yields the same keys. |
| 310 std::vector<std::string> new_state_keys; |
| 311 current += base::TimeDelta::FromDays(1); |
| 312 EXPECT_TRUE(DeviceCloudPolicyManagerChromeOS::GetDeviceStateKeys( |
| 313 current, &new_state_keys)); |
| 314 EXPECT_EQ(state_keys, new_state_keys); |
| 315 |
| 316 // Jumping to a future quantum results in the state keys rolling forward. |
| 317 int64 step = |
| 318 GG_INT64_C(1) |
| 319 << DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyTimeQuantumPower; |
| 320 current += 2 * base::TimeDelta::FromSeconds(step); |
| 321 |
| 322 EXPECT_TRUE(DeviceCloudPolicyManagerChromeOS::GetDeviceStateKeys( |
| 323 current, &new_state_keys)); |
| 324 ASSERT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta, |
| 325 static_cast<int>(new_state_keys.size())); |
| 326 EXPECT_TRUE(std::equal(state_keys.begin() + 2, state_keys.end(), |
| 327 new_state_keys.begin())); |
| 328 } |
| 329 |
264 class DeviceCloudPolicyManagerChromeOSEnrollmentTest | 330 class DeviceCloudPolicyManagerChromeOSEnrollmentTest |
265 : public DeviceCloudPolicyManagerChromeOSTest { | 331 : public DeviceCloudPolicyManagerChromeOSTest { |
266 public: | 332 public: |
267 void Done(EnrollmentStatus status) { | 333 void Done(EnrollmentStatus status) { |
268 status_ = status; | 334 status_ = status; |
269 done_ = true; | 335 done_ = true; |
270 } | 336 } |
271 | 337 |
272 protected: | 338 protected: |
273 DeviceCloudPolicyManagerChromeOSEnrollmentTest() | 339 DeviceCloudPolicyManagerChromeOSEnrollmentTest() |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 641 |
576 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 642 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
577 RobotRefreshSaveFailed) { | 643 RobotRefreshSaveFailed) { |
578 // Without the system salt, the robot token can't be stored. | 644 // Without the system salt, the robot token can't be stored. |
579 RunTest(); | 645 RunTest(); |
580 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); | 646 ExpectFailedEnrollment(EnrollmentStatus::STATUS_ROBOT_REFRESH_STORE_FAILED); |
581 } | 647 } |
582 | 648 |
583 } // namespace | 649 } // namespace |
584 } // namespace policy | 650 } // namespace policy |
OLD | NEW |