Chromium Code Reviews| 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/policy/device_status_collector.h" | 5 #include "chrome/browser/policy/device_status_collector.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/chromeos/settings/cros_settings.h" | 10 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 86 |
| 87 // Reset the baseline time. | 87 // Reset the baseline time. |
| 88 void SetBaselineTime(Time time) { | 88 void SetBaselineTime(Time time) { |
| 89 baseline_time_ = time; | 89 baseline_time_ = time; |
| 90 baseline_offset_periods_ = 0; | 90 baseline_offset_periods_ = 0; |
| 91 } | 91 } |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 virtual void CheckIdleState() OVERRIDE { | 94 virtual void CheckIdleState() OVERRIDE { |
| 95 // This should never be called in testing, as it results in a dbus call. | 95 // This should never be called in testing, as it results in a dbus call. |
| 96 NOTREACHED(); | 96 ADD_FAILURE(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Each time this is called, returns a time that is a fixed increment | 99 // Each time this is called, returns a time that is a fixed increment |
| 100 // later than the previous time. | 100 // later than the previous time. |
| 101 virtual Time GetCurrentTime() OVERRIDE { | 101 virtual Time GetCurrentTime() OVERRIDE { |
| 102 int poll_interval = policy::DeviceStatusCollector::kIdlePollIntervalSeconds; | 102 int poll_interval = policy::DeviceStatusCollector::kIdlePollIntervalSeconds; |
| 103 return baseline_time_ + | 103 return baseline_time_ + |
| 104 TimeDelta::FromSeconds(poll_interval * baseline_offset_periods_++); | 104 TimeDelta::FromSeconds(poll_interval * baseline_offset_periods_++); |
| 105 } | 105 } |
| 106 | 106 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 IDLE_STATE_IDLE, | 326 IDLE_STATE_IDLE, |
| 327 IDLE_STATE_IDLE | 327 IDLE_STATE_IDLE |
| 328 }; | 328 }; |
| 329 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 329 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 330 status_collector_->Simulate(test_states, | 330 status_collector_->Simulate(test_states, |
| 331 sizeof(test_states) / sizeof(IdleState)); | 331 sizeof(test_states) / sizeof(IdleState)); |
| 332 GetStatus(); | 332 GetStatus(); |
| 333 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 333 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
| 334 } | 334 } |
| 335 | 335 |
| 336 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { | 336 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { |
|
bartfab (slow)
2012/10/25 14:30:49
This test has been disabled in r164043. You will n
Joao da Silva
2012/10/25 15:24:17
Done.
| |
| 337 IdleState test_states[] = { | 337 IdleState test_states[] = { |
| 338 IDLE_STATE_ACTIVE, | 338 IDLE_STATE_ACTIVE, |
| 339 IDLE_STATE_IDLE | 339 IDLE_STATE_IDLE |
| 340 }; | 340 }; |
| 341 unsigned int max_days = 10; | 341 unsigned int max_days = 10; |
| 342 | 342 |
| 343 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 343 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 344 status_collector_->set_max_stored_past_activity_days(max_days - 1); | 344 status_collector_->set_max_stored_past_activity_days(max_days - 1); |
| 345 status_collector_->set_max_stored_future_activity_days(1); | 345 status_collector_->set_max_stored_future_activity_days(1); |
| 346 Time baseline = Time::Now().LocalMidnight(); | 346 Time baseline = Time::Now().LocalMidnight(); |
|
Mattias Nissler (ping if slow)
2012/10/25 14:27:19
One thing: Should we convert these tests to starti
Joao da Silva
2012/10/25 15:24:17
That's a good idea. Done.
| |
| 347 status_collector_->SetBaselineTime(baseline); | |
| 347 | 348 |
| 348 // Simulate 12 active periods. | 349 // Simulate 12 active periods. |
| 349 for (int i = 0; i < static_cast<int>(max_days) + 2; i++) { | 350 for (int i = 0; i < static_cast<int>(max_days) + 2; i++) { |
| 350 status_collector_->Simulate(test_states, | 351 status_collector_->Simulate(test_states, |
| 351 sizeof(test_states) / sizeof(IdleState)); | 352 sizeof(test_states) / sizeof(IdleState)); |
| 352 // Advance the simulated clock by a day. | 353 // Advance the simulated clock by a day. |
| 353 baseline += TimeDelta::FromDays(1); | 354 baseline += TimeDelta::FromDays(1); |
| 354 status_collector_->SetBaselineTime(baseline); | 355 status_collector_->SetBaselineTime(baseline); |
| 355 } | 356 } |
| 356 | 357 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 // Check that after enabling location reporting again, an error is reported | 527 // Check that after enabling location reporting again, an error is reported |
| 527 // if no valid fix is available. | 528 // if no valid fix is available. |
| 528 SetMockPositionToReturnNext(invalid_fix); | 529 SetMockPositionToReturnNext(invalid_fix); |
| 529 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); | 530 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); |
| 530 // Allow the new pref to propagate to the status collector. | 531 // Allow the new pref to propagate to the status collector. |
| 531 message_loop_.RunAllPending(); | 532 message_loop_.RunAllPending(); |
| 532 CheckThatALocationErrorIsReported(); | 533 CheckThatALocationErrorIsReported(); |
| 533 } | 534 } |
| 534 | 535 |
| 535 } // namespace policy | 536 } // namespace policy |
| OLD | NEW |