Index: chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc |
diff --git a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc |
index 0562e5d410ea3a8b00256226b35a30f11b7a5315..b33633042aa872acbf616f3aec22179c928ac22b 100644 |
--- a/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc |
+++ b/chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc |
@@ -4,6 +4,8 @@ |
#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
+#include <algorithm> |
+ |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
#include "base/memory/scoped_ptr.h" |
@@ -261,6 +263,60 @@ TEST_F(DeviceCloudPolicyManagerChromeOSTest, ConsumerDevice) { |
EXPECT_TRUE(manager_->policies().Equals(bundle)); |
} |
+class DeviceCloudPolicyManagerChromeOSStateKeyTest : public testing::Test { |
+ protected: |
+ DeviceCloudPolicyManagerChromeOSStateKeyTest() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ chromeos::system::StatisticsProvider::SetTestProvider( |
+ &statistics_provider_); |
Joao da Silva
2014/03/27 15:45:40
Remove this on TearDown?
Mattias Nissler (ping if slow)
2014/03/27 16:12:41
I debated it as it's not strictly needed (i.e. tes
Joao da Silva
2014/03/27 16:29:48
Note that this mock object will remain as the stat
Mattias Nissler (ping if slow)
2014/03/27 17:04:08
Uh, good point. Fixed. Globals suck.
|
+ EXPECT_CALL(statistics_provider_, GetMachineStatistic(_, _)) |
+ .WillRepeatedly(Invoke(this, |
+ &DeviceCloudPolicyManagerChromeOSStateKeyTest:: |
+ GetMachineStatistic)); |
+ } |
+ |
+ bool GetMachineStatistic(const std::string& name, std::string* result) { |
+ *result = "fake-" + name; |
+ return true; |
+ } |
+ |
+ private: |
+ chromeos::system::MockStatisticsProvider statistics_provider_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DeviceCloudPolicyManagerChromeOSStateKeyTest); |
+}; |
+ |
+TEST_F(DeviceCloudPolicyManagerChromeOSStateKeyTest, GetDeviceStateKeys) { |
+ base::Time current = base::Time::UnixEpoch() + base::TimeDelta::FromDays(100); |
+ |
+ // The correct number of state keys gets returned. |
+ std::vector<std::string> state_keys; |
+ EXPECT_TRUE(DeviceCloudPolicyManagerChromeOS::GetDeviceStateKeys( |
+ current, &state_keys)); |
+ EXPECT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta, |
+ static_cast<int>(state_keys.size())); |
+ |
+ // All state keys are different. |
+ std::set<std::string> state_key_set(state_keys.begin(), state_keys.end()); |
+ EXPECT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta, |
+ static_cast<int>(state_key_set.size())); |
+ |
+ // Incrementing time results in the state keys rolling forward. |
+ int64 step = |
+ GG_INT64_C(1) |
+ << DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyTimeQuantumPower; |
+ current += 2 * base::TimeDelta::FromSeconds(step); |
+ |
+ std::vector<std::string> new_state_keys; |
+ EXPECT_TRUE(DeviceCloudPolicyManagerChromeOS::GetDeviceStateKeys( |
+ current, &new_state_keys)); |
+ ASSERT_EQ(DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyFutureQuanta, |
+ static_cast<int>(new_state_keys.size())); |
+ EXPECT_TRUE(std::equal(state_keys.begin() + 2, state_keys.end(), |
+ new_state_keys.begin())); |
+} |
Joao da Silva
2014/03/27 15:45:40
Suggestion: verify that a small time increase with
Mattias Nissler (ping if slow)
2014/03/27 16:12:41
Good idea, done.
|
+ |
class DeviceCloudPolicyManagerChromeOSEnrollmentTest |
: public DeviceCloudPolicyManagerChromeOSTest { |
public: |