Chromium Code Reviews| 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 1dde8b640d7ca76ff7e70a745a1a27be0f72fa42..571738f56fff1cb9789c39e9b5024b9b5e7af057 100644 |
| --- a/chrome/browser/policy/device_status_collector_unittest.cc |
| +++ b/chrome/browser/policy/device_status_collector_unittest.cc |
| @@ -10,6 +10,7 @@ |
| #include "chrome/browser/chromeos/system/mock_statistics_provider.h" |
| #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chrome/test/base/testing_pref_service.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -117,6 +118,8 @@ TEST_F(DeviceStatusCollectorTest, AllIdle) { |
| IDLE_STATE_IDLE, |
| IDLE_STATE_IDLE |
| }; |
| + prefs_.SetBoolean(prefs::kReportDeviceActivityTimes, true); |
|
pastarmovj
2012/01/26 09:52:11
Those tests will then need some more mocking to wo
Patrick Dubroy
2012/01/27 15:20:29
Done.
|
| + |
| // Test reporting with no data. |
| status_collector_.GetStatus(&status_); |
| EXPECT_EQ(0, status_.active_time_size()); |
| @@ -142,6 +145,8 @@ TEST_F(DeviceStatusCollectorTest, AllActive) { |
| IDLE_STATE_ACTIVE, |
| IDLE_STATE_ACTIVE |
| }; |
| + prefs_.SetBoolean(prefs::kReportDeviceActivityTimes, true); |
| + |
| // Test a single active sample. |
| status_collector_.Simulate(test_states, 1); |
| status_collector_.GetStatus(&status_); |
| @@ -168,6 +173,7 @@ TEST_F(DeviceStatusCollectorTest, MixedStates) { |
| IDLE_STATE_IDLE, |
| IDLE_STATE_ACTIVE |
| }; |
| + prefs_.SetBoolean(prefs::kReportDeviceActivityTimes, true); |
| status_collector_.Simulate(test_states, |
| sizeof(test_states) / sizeof(IdleState)); |
| status_collector_.GetStatus(&status_); |
| @@ -184,6 +190,7 @@ TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { |
| IDLE_STATE_IDLE, |
| IDLE_STATE_IDLE |
| }; |
| + prefs_.SetBoolean(prefs::kReportDeviceActivityTimes, true); |
| status_collector_.Simulate(test_states, |
| sizeof(test_states) / sizeof(IdleState)); |
| @@ -209,6 +216,7 @@ TEST_F(DeviceStatusCollectorTest, Times) { |
| IDLE_STATE_IDLE, |
| IDLE_STATE_IDLE |
| }; |
| + prefs_.SetBoolean(prefs::kReportDeviceActivityTimes, true); |
| status_collector_.Simulate(test_states, |
| sizeof(test_states) / sizeof(IdleState)); |
| status_collector_.GetStatus(&status_); |
| @@ -224,6 +232,7 @@ TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { |
| }; |
| unsigned int max_periods = 10; |
| + prefs_.SetBoolean(prefs::kReportDeviceActivityTimes, true); |
| status_collector_.set_max_stored_active_periods(max_periods); |
| // Simulate 12 active periods. |
| @@ -237,12 +246,38 @@ TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { |
| EXPECT_EQ(static_cast<int>(max_periods), status_.active_time_size()); |
| } |
| +TEST_F(DeviceStatusCollectorTest, ActivityTimesDisabledByDefault) { |
| + // If the pref for collecting device activity times isn't explicitly turned |
| + // on, no data on activity times should be reported. |
| + |
| + IdleState test_states[] = { |
| + IDLE_STATE_ACTIVE, |
| + IDLE_STATE_ACTIVE, |
| + IDLE_STATE_ACTIVE |
| + }; |
| + status_collector_.Simulate(test_states, |
| + sizeof(test_states) / sizeof(IdleState)); |
| + status_collector_.GetStatus(&status_); |
| + EXPECT_EQ(0, status_.active_time_size()); |
| + EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
| +} |
| + |
| TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { |
| + // Test that boot mode data is not report if the pref is not turned on. |
| status_collector_.GetStatus(&status_); |
| EXPECT_EQ(false, status_.has_boot_mode()); |
| EXPECT_CALL(statistics_provider_, |
| GetMachineStatistic("devsw_boot", NotNull())) |
| + .WillRepeatedly(DoAll(SetArgPointee<1>("0"), Return(true))); |
| + EXPECT_EQ(false, status_.has_boot_mode()); |
| + |
| + // Turn the pref on, and check that the status is reported iff the |
| + // statistics provider returns valid data. |
| + prefs_.SetBoolean(prefs::kReportDeviceBootMode, true); |
| + |
| + EXPECT_CALL(statistics_provider_, |
| + GetMachineStatistic("devsw_boot", NotNull())) |
| .WillOnce(DoAll(SetArgPointee<1>("(error)"), Return(true))); |
| status_collector_.GetStatus(&status_); |
| EXPECT_EQ(false, status_.has_boot_mode()); |
| @@ -266,4 +301,24 @@ TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { |
| EXPECT_EQ("Dev", status_.boot_mode()); |
| } |
| +TEST_F(DeviceStatusCollectorTest, VersionInfo) { |
| + // When the pref to collect this data is not enabled, expect that none of |
| + // the fields are present in the protobuf. |
| + status_collector_.GetStatus(&status_); |
| + EXPECT_EQ(false, status_.has_browser_version()); |
| + EXPECT_EQ(false, status_.has_os_version()); |
| + EXPECT_EQ(false, status_.has_firmware_version()); |
| + |
| + prefs_.SetBoolean(prefs::kReportDeviceVersionInfo, true); |
| + status_collector_.GetStatus(&status_); |
| + EXPECT_EQ(true, status_.has_browser_version()); |
| + EXPECT_EQ(true, status_.has_os_version()); |
| + EXPECT_EQ(true, status_.has_firmware_version()); |
| + |
| + // Check that the browser version is not empty. OS version & firmware |
| + // don't have any reasonable values inside the unit test, so those |
| + // aren't checked. |
| + EXPECT_NE("", status_.browser_version()); |
| +} |
| + |
| } // namespace policy |