Chromium Code Reviews| Index: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc |
| diff --git a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc |
| index 4f683f78dbad7b574103d386436d8648bf7ea1ed..48b4a7a5813851cd9600e649886bcc00560cd8b7 100644 |
| --- a/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc |
| +++ b/chrome/browser/chromeos/policy/device_status_collector_browsertest.cc |
| @@ -23,6 +23,7 @@ |
| #include "base/sys_info.h" |
| #include "base/test/scoped_path_override.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| @@ -86,12 +87,15 @@ class TestingDeviceStatusCollector : public policy::DeviceStatusCollector { |
| const policy::DeviceStatusCollector::VolumeInfoFetcher& |
| volume_info_fetcher, |
| const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_fetcher, |
| - const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) |
| + const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher, |
| + const policy::DeviceStatusCollector::AndroidStatusFetcher& |
| + android_status_fetcher) |
| : policy::DeviceStatusCollector(local_state, |
| provider, |
| volume_info_fetcher, |
| cpu_fetcher, |
| - cpu_temp_fetcher) { |
| + cpu_temp_fetcher, |
| + android_status_fetcher) { |
| // Set the baseline time to a fixed value (1 AM) to prevent test flakiness |
| // due to a single activity period spanning two days. |
| SetBaselineTime(Time::Now().LocalMidnight() + TimeDelta::FromHours(1)); |
| @@ -212,6 +216,21 @@ std::vector<em::CPUTempInfo> GetEmptyCPUTempInfo() { |
| return std::vector<em::CPUTempInfo>(); |
| } |
| +void CallAndroidStatusReceiver( |
| + policy::DeviceStatusCollector::AndroidStatusReceiver receiver, |
|
ljusten (tachyonic)
2016/10/05 16:10:42
Can you use const AndroidStatusReceiver&?
phweiss
2016/10/05 16:33:39
Done.
|
| + mojo::String status, |
| + mojo::String droid_guard_info) { |
| + receiver.Run(status, droid_guard_info); |
| +} |
| + |
| +bool GetEmptyAndroidStatus( |
| + policy::DeviceStatusCollector::AndroidStatusReceiver receiver) { |
| + // Post it to the thread because this call is expected to be asynchronous. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, Bind(&CallAndroidStatusReceiver, receiver, "", "")); |
| + return true; |
| +} |
| + |
| std::vector<em::CPUTempInfo> GetFakeCPUTempInfo( |
| const std::vector<em::CPUTempInfo>& cpu_temp_info) { |
| return cpu_temp_info; |
| @@ -279,9 +298,9 @@ class DeviceStatusCollectorTest : public testing::Test { |
| owner_settings_service_ = |
| settings_helper_.CreateOwnerSettingsService(nullptr); |
| - RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), |
| - base::Bind(&GetEmptyCPUStatistics), |
| - base::Bind(&GetEmptyCPUTempInfo)); |
| + RestartStatusCollector( |
| + base::Bind(&GetEmptyVolumeInfo), base::Bind(&GetEmptyCPUStatistics), |
| + base::Bind(&GetEmptyCPUTempInfo), base::Bind(&GetEmptyAndroidStatus)); |
| // Set up a fake local state for KioskAppManager. |
| TestingBrowserProcess::GetGlobal()->SetLocalState(&local_state_); |
| @@ -326,11 +345,13 @@ class DeviceStatusCollectorTest : public testing::Test { |
| void RestartStatusCollector( |
| const policy::DeviceStatusCollector::VolumeInfoFetcher& volume_info, |
| const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_stats, |
| - const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) { |
| + const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher, |
| + const policy::DeviceStatusCollector::AndroidStatusFetcher& |
| + android_status_fetcher) { |
| std::vector<em::VolumeInfo> expected_volume_info; |
| status_collector_.reset(new TestingDeviceStatusCollector( |
| &prefs_, &fake_statistics_provider_, volume_info, cpu_stats, |
| - cpu_temp_fetcher)); |
| + cpu_temp_fetcher, android_status_fetcher)); |
| } |
| void GetStatus() { |
| @@ -519,9 +540,9 @@ TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { |
| // Process the list a second time after restarting the collector. It should be |
| // able to count the active periods found by the original collector, because |
| // the results are stored in a pref. |
| - RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), |
| - base::Bind(&GetEmptyCPUStatistics), |
| - base::Bind(&GetEmptyCPUTempInfo)); |
| + RestartStatusCollector( |
| + base::Bind(&GetEmptyVolumeInfo), base::Bind(&GetEmptyCPUStatistics), |
| + base::Bind(&GetEmptyCPUTempInfo), base::Bind(&GetEmptyAndroidStatus)); |
| status_collector_->Simulate(test_states, |
| sizeof(test_states) / sizeof(ui::IdleState)); |
| @@ -821,7 +842,8 @@ TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { |
| RestartStatusCollector(base::Bind(&GetFakeVolumeInfo, expected_volume_info), |
| base::Bind(&GetEmptyCPUStatistics), |
| - base::Bind(&GetEmptyCPUTempInfo)); |
| + base::Bind(&GetEmptyCPUTempInfo), |
| + base::Bind(&GetEmptyAndroidStatus)); |
| // Force finishing tasks posted by ctor of DeviceStatusCollector. |
| content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| base::RunLoop().RunUntilIdle(); |
| @@ -874,7 +896,8 @@ TEST_F(DeviceStatusCollectorTest, TestCPUSamples) { |
| std::string full_cpu_usage("cpu 500 0 500 0 0 0 0"); |
| RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), |
| base::Bind(&GetFakeCPUStatistics, full_cpu_usage), |
| - base::Bind(&GetEmptyCPUTempInfo)); |
| + base::Bind(&GetEmptyCPUTempInfo), |
| + base::Bind(&GetEmptyAndroidStatus)); |
| // Force finishing tasks posted by ctor of DeviceStatusCollector. |
| content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| base::RunLoop().RunUntilIdle(); |
| @@ -925,7 +948,8 @@ TEST_F(DeviceStatusCollectorTest, TestCPUTemp) { |
| RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), |
| base::Bind(&GetEmptyCPUStatistics), |
| - base::Bind(&GetFakeCPUTempInfo, expected_temp_info)); |
| + base::Bind(&GetFakeCPUTempInfo, expected_temp_info), |
| + base::Bind(&GetEmptyAndroidStatus)); |
| // Force finishing tasks posted by ctor of DeviceStatusCollector. |
| content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| base::RunLoop().RunUntilIdle(); |