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/chromeos/policy/device_status_collector.h" | 5 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
6 | 6 |
7 #include "base/environment.h" | 7 #include "base/environment.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 max_stored_future_activity_days_ = value; | 101 max_stored_future_activity_days_ = value; |
102 } | 102 } |
103 | 103 |
104 // Reset the baseline time. | 104 // Reset the baseline time. |
105 void SetBaselineTime(Time time) { | 105 void SetBaselineTime(Time time) { |
106 baseline_time_ = time; | 106 baseline_time_ = time; |
107 baseline_offset_periods_ = 0; | 107 baseline_offset_periods_ = 0; |
108 } | 108 } |
109 | 109 |
110 protected: | 110 protected: |
111 virtual void CheckIdleState() OVERRIDE { | 111 virtual void CheckIdleState() override { |
112 // This should never be called in testing, as it results in a dbus call. | 112 // This should never be called in testing, as it results in a dbus call. |
113 ADD_FAILURE(); | 113 ADD_FAILURE(); |
114 } | 114 } |
115 | 115 |
116 // Each time this is called, returns a time that is a fixed increment | 116 // Each time this is called, returns a time that is a fixed increment |
117 // later than the previous time. | 117 // later than the previous time. |
118 virtual Time GetCurrentTime() OVERRIDE { | 118 virtual Time GetCurrentTime() override { |
119 int poll_interval = policy::DeviceStatusCollector::kIdlePollIntervalSeconds; | 119 int poll_interval = policy::DeviceStatusCollector::kIdlePollIntervalSeconds; |
120 return baseline_time_ + | 120 return baseline_time_ + |
121 TimeDelta::FromSeconds(poll_interval * baseline_offset_periods_++); | 121 TimeDelta::FromSeconds(poll_interval * baseline_offset_periods_++); |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 // Baseline time for the fake times returned from GetCurrentTime(). | 125 // Baseline time for the fake times returned from GetCurrentTime(). |
126 Time baseline_time_; | 126 Time baseline_time_; |
127 | 127 |
128 // The number of simulated periods since the baseline time. | 128 // The number of simulated periods since the baseline time. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Finish pending tasks. | 184 // Finish pending tasks. |
185 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 185 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
186 message_loop_.RunUntilIdle(); | 186 message_loop_.RunUntilIdle(); |
187 | 187 |
188 // Restore the real DeviceSettingsProvider. | 188 // Restore the real DeviceSettingsProvider. |
189 EXPECT_TRUE( | 189 EXPECT_TRUE( |
190 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); | 190 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); |
191 cros_settings_->AddSettingsProvider(device_settings_provider_); | 191 cros_settings_->AddSettingsProvider(device_settings_provider_); |
192 } | 192 } |
193 | 193 |
194 virtual void SetUp() OVERRIDE { | 194 virtual void SetUp() override { |
195 // Disable network interface reporting since it requires additional setup. | 195 // Disable network interface reporting since it requires additional setup. |
196 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); | 196 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); |
197 } | 197 } |
198 | 198 |
199 void RestartStatusCollector() { | 199 void RestartStatusCollector() { |
200 policy::DeviceStatusCollector::LocationUpdateRequester callback = | 200 policy::DeviceStatusCollector::LocationUpdateRequester callback = |
201 base::Bind(&MockPositionUpdateRequester); | 201 base::Bind(&MockPositionUpdateRequester); |
202 status_collector_.reset( | 202 status_collector_.reset( |
203 new TestingDeviceStatusCollector(&prefs_, | 203 new TestingDeviceStatusCollector(&prefs_, |
204 &statistics_provider_, | 204 &statistics_provider_, |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 "", "", "", | 701 "", "", "", |
702 em::NetworkInterface::TYPE_BLUETOOTH }, | 702 em::NetworkInterface::TYPE_BLUETOOTH }, |
703 { "/device/vpn", shill::kTypeVPN, "vpn", | 703 { "/device/vpn", shill::kTypeVPN, "vpn", |
704 "", "", "", | 704 "", "", "", |
705 -1 }, | 705 -1 }, |
706 }; | 706 }; |
707 | 707 |
708 class DeviceStatusCollectorNetworkInterfacesTest | 708 class DeviceStatusCollectorNetworkInterfacesTest |
709 : public DeviceStatusCollectorTest { | 709 : public DeviceStatusCollectorTest { |
710 protected: | 710 protected: |
711 virtual void SetUp() OVERRIDE { | 711 virtual void SetUp() override { |
712 chromeos::DBusThreadManager::Initialize(); | 712 chromeos::DBusThreadManager::Initialize(); |
713 chromeos::NetworkHandler::Initialize(); | 713 chromeos::NetworkHandler::Initialize(); |
714 chromeos::ShillDeviceClient::TestInterface* test_device_client = | 714 chromeos::ShillDeviceClient::TestInterface* test_device_client = |
715 chromeos::DBusThreadManager::Get()->GetShillDeviceClient()-> | 715 chromeos::DBusThreadManager::Get()->GetShillDeviceClient()-> |
716 GetTestInterface(); | 716 GetTestInterface(); |
717 test_device_client->ClearDevices(); | 717 test_device_client->ClearDevices(); |
718 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { | 718 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { |
719 const FakeDeviceData& dev = kFakeDevices[i]; | 719 const FakeDeviceData& dev = kFakeDevices[i]; |
720 test_device_client->AddDevice(dev.device_path, dev.type, | 720 test_device_client->AddDevice(dev.device_path, dev.type, |
721 dev.object_path); | 721 dev.object_path); |
(...skipping 11 matching lines...) Expand all Loading... |
733 test_device_client->SetDeviceProperty( | 733 test_device_client->SetDeviceProperty( |
734 dev.device_path, shill::kImeiProperty, | 734 dev.device_path, shill::kImeiProperty, |
735 base::StringValue(dev.imei)); | 735 base::StringValue(dev.imei)); |
736 } | 736 } |
737 } | 737 } |
738 | 738 |
739 // Flush out pending state updates. | 739 // Flush out pending state updates. |
740 base::RunLoop().RunUntilIdle(); | 740 base::RunLoop().RunUntilIdle(); |
741 } | 741 } |
742 | 742 |
743 virtual void TearDown() OVERRIDE { | 743 virtual void TearDown() override { |
744 chromeos::NetworkHandler::Shutdown(); | 744 chromeos::NetworkHandler::Shutdown(); |
745 chromeos::DBusThreadManager::Shutdown(); | 745 chromeos::DBusThreadManager::Shutdown(); |
746 } | 746 } |
747 }; | 747 }; |
748 | 748 |
749 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { | 749 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { |
750 // Interfaces should be reported by default. | 750 // Interfaces should be reported by default. |
751 GetStatus(); | 751 GetStatus(); |
752 EXPECT_TRUE(status_.network_interface_size() > 0); | 752 EXPECT_TRUE(status_.network_interface_size() > 0); |
753 | 753 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 } | 787 } |
788 | 788 |
789 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; | 789 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; |
790 count++; | 790 count++; |
791 } | 791 } |
792 | 792 |
793 EXPECT_EQ(count, status_.network_interface_size()); | 793 EXPECT_EQ(count, status_.network_interface_size()); |
794 } | 794 } |
795 | 795 |
796 } // namespace policy | 796 } // namespace policy |
OLD | NEW |