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

Unified Diff: chrome/browser/policy/device_status_collector_unittest.cc

Issue 11271024: Fix DeviceStatusCollectorTest.MaxStoredPeriods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using a fixed time, rebased Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/device_status_collector.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/device_status_collector_unittest.cc
diff --git a/chrome/browser/policy/device_status_collector_unittest.cc b/chrome/browser/policy/device_status_collector_unittest.cc
index 8c5e0f4ee6954c80fd2fd6b68465990151d4da0c..b7d3e496fa73c5363f25a96ca43bd46709bab22a 100644
--- a/chrome/browser/policy/device_status_collector_unittest.cc
+++ b/chrome/browser/policy/device_status_collector_unittest.cc
@@ -38,6 +38,10 @@ const int64 kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000;
scoped_ptr<content::Geoposition> mock_position_to_return_next;
+Time TestBaselineTime() {
+ return Time::UnixEpoch() + TimeDelta::FromDays(42);
+}
+
void SetMockPositionToReturnNext(const content::Geoposition &position) {
mock_position_to_return_next.reset(new content::Geoposition(position));
}
@@ -66,9 +70,12 @@ class TestingDeviceStatusCollector : public policy::DeviceStatusCollector {
: policy::DeviceStatusCollector(local_state,
provider,
&MockPositionUpdateRequester) {
- // Set the baseline time to a fixed value (1 AM) to prevent test flakiness
+ // Set the baseline time to a fixed value to prevent test flakiness
// due to a single activity period spanning two days.
- SetBaselineTime(Time::Now().LocalMidnight() + TimeDelta::FromHours(1));
+ SetBaselineTime(TestBaselineTime());
+
+ // Initialize the collector after setting the baseline time.
+ Init();
}
void Simulate(IdleState* states, int len) {
@@ -93,7 +100,7 @@ class TestingDeviceStatusCollector : public policy::DeviceStatusCollector {
protected:
virtual void CheckIdleState() OVERRIDE {
// This should never be called in testing, as it results in a dbus call.
- NOTREACHED();
+ ADD_FAILURE();
}
// Each time this is called, returns a time that is a fixed increment
@@ -193,8 +200,8 @@ class DeviceStatusCollectorTest : public testing::Test {
EXPECT_DOUBLE_EQ(-7.8, location.longitude());
EXPECT_DOUBLE_EQ(3., location.accuracy());
// Check that the timestamp is not older than ten minutes.
- EXPECT_TRUE(Time::Now() - Time::FromDoubleT(location.timestamp() / 1000.) <
- TimeDelta::FromMinutes(10));
+ Time timestamp = Time::FromDoubleT(location.timestamp() / 1000.0);
+ EXPECT_TRUE(TestBaselineTime() - timestamp < TimeDelta::FromMinutes(10));
Patrick Dubroy 2012/10/26 09:36:46 Isn't the delta always going to be negative here?
Joao da Silva 2012/11/15 13:25:48 The timestamp is expected to be some time in the p
Patrick Dubroy 2012/11/15 13:53:01 Ah, I see.
}
void CheckThatALocationErrorIsReported() {
@@ -333,9 +340,7 @@ TEST_F(DeviceStatusCollectorTest, Times) {
EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_));
}
-// Fails after after WebKit roll [132375:132450]
-// http://crbug.com/157848
-TEST_F(DeviceStatusCollectorTest, DISABLED_MaxStoredPeriods) {
+TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) {
IdleState test_states[] = {
IDLE_STATE_ACTIVE,
IDLE_STATE_IDLE
@@ -345,7 +350,7 @@ TEST_F(DeviceStatusCollectorTest, DISABLED_MaxStoredPeriods) {
cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true);
status_collector_->set_max_stored_past_activity_days(max_days - 1);
status_collector_->set_max_stored_future_activity_days(1);
- Time baseline = Time::Now().LocalMidnight();
+ Time baseline = TestBaselineTime();
// Simulate 12 active periods.
for (int i = 0; i < static_cast<int>(max_days) + 2; i++) {
@@ -405,7 +410,7 @@ TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) {
// Set the baseline time to 10 seconds after midnight.
status_collector_->SetBaselineTime(
- Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10));
+ TestBaselineTime().LocalMidnight() + TimeDelta::FromSeconds(10));
status_collector_->Simulate(test_states, 1);
GetStatus();
@@ -490,12 +495,12 @@ TEST_F(DeviceStatusCollectorTest, Location) {
valid_fix.latitude = 4.3;
valid_fix.longitude = -7.8;
valid_fix.accuracy = 3.;
- valid_fix.timestamp = Time::Now();
+ valid_fix.timestamp = TestBaselineTime() - TimeDelta::FromMinutes(5);
content::Geoposition invalid_fix;
invalid_fix.error_code =
content::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE;
- invalid_fix.timestamp = Time::Now();
+ invalid_fix.timestamp = TestBaselineTime() - TimeDelta::FromMinutes(4);
// Check that when device location reporting is disabled, no location is
// reported.
« no previous file with comments | « chrome/browser/policy/device_status_collector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698