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

Unified Diff: chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos_unittest.cc

Issue 212653004: Update server-backed state key generation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix re-enrollment test. Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
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..5abfe5a030de328bb5ed7e73653c40a71c85f1e8 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,70 @@ 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_);
+ EXPECT_CALL(statistics_provider_, GetMachineStatistic(_, _))
+ .WillRepeatedly(Invoke(this,
+ &DeviceCloudPolicyManagerChromeOSStateKeyTest::
+ GetMachineStatistic));
+ }
+
+ virtual void TearDown() OVERRIDE {
+ chromeos::system::StatisticsProvider::SetTestProvider(NULL);
+ }
+
+ 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()));
+
+ // Moving forward just a little yields the same keys.
+ std::vector<std::string> new_state_keys;
+ current += base::TimeDelta::FromDays(1);
+ EXPECT_TRUE(DeviceCloudPolicyManagerChromeOS::GetDeviceStateKeys(
+ current, &new_state_keys));
+ EXPECT_EQ(state_keys, new_state_keys);
+
+ // Jumping to a future quantum results in the state keys rolling forward.
+ int64 step =
+ GG_INT64_C(1)
+ << DeviceCloudPolicyManagerChromeOS::kDeviceStateKeyTimeQuantumPower;
+ current += 2 * base::TimeDelta::FromSeconds(step);
+
+ 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()));
+}
+
class DeviceCloudPolicyManagerChromeOSEnrollmentTest
: public DeviceCloudPolicyManagerChromeOSTest {
public:
« no previous file with comments | « chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.cc ('k') | chromeos/system/statistics_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698