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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc

Issue 2767923002: Always use an async TaskScheduler in TestBrowserThreadBundle. (Closed)
Patch Set: fix-test-errors Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 147 }
148 148
149 std::string GetDMTokenForProfile(Profile* profile) override { 149 std::string GetDMTokenForProfile(Profile* profile) override {
150 // Return the profile user name (passed to CreateTestingProfile) to make it 150 // Return the profile user name (passed to CreateTestingProfile) to make it
151 // easy to confirm that the correct profile's DMToken was requested. 151 // easy to confirm that the correct profile's DMToken was requested.
152 return profile->GetProfileUserName(); 152 return profile->GetProfileUserName();
153 } 153 }
154 154
155 void RefreshSampleResourceUsage() { 155 void RefreshSampleResourceUsage() {
156 SampleResourceUsage(); 156 SampleResourceUsage();
157 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 157 content::RunAllBlockingPoolTasksUntilIdle();
158 } 158 }
159 159
160 protected: 160 protected:
161 void CheckIdleState() override { 161 void CheckIdleState() override {
162 // This should never be called in testing, as it results in a dbus call. 162 // This should never be called in testing, as it results in a dbus call.
163 ADD_FAILURE(); 163 ADD_FAILURE();
164 } 164 }
165 165
166 // Each time this is called, returns a time that is a fixed increment 166 // Each time this is called, returns a time that is a fixed increment
167 // later than the previous time. 167 // later than the previous time.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE, 353 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE,
354 chromeos::disks::MOUNT_CONDITION_NONE))); 354 chromeos::disks::MOUNT_CONDITION_NONE)));
355 } 355 }
356 356
357 ~DeviceStatusCollectorTest() override { 357 ~DeviceStatusCollectorTest() override {
358 chromeos::CrasAudioHandler::Shutdown(); 358 chromeos::CrasAudioHandler::Shutdown();
359 chromeos::KioskAppManager::Shutdown(); 359 chromeos::KioskAppManager::Shutdown();
360 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); 360 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
361 361
362 // Finish pending tasks. 362 // Finish pending tasks.
363 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 363 content::RunAllBlockingPoolTasksUntilIdle();
364 base::RunLoop().RunUntilIdle();
fdoray 2017/04/04 17:52:55 When a synchronous TaskScheduler was used, base::R
365 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems(); 364 storage::ExternalMountPoints::GetSystemInstance()->RevokeAllFileSystems();
366 DiskMountManager::Shutdown(); 365 DiskMountManager::Shutdown();
367 } 366 }
368 367
369 void SetUp() override { 368 void SetUp() override {
370 // Disable network interface reporting since it requires additional setup. 369 // Disable network interface reporting since it requires additional setup.
371 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, 370 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces,
372 false); 371 false);
373 } 372 }
374 373
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 info.set_storage_free(size++); 895 info.set_storage_free(size++);
897 expected_volume_info.push_back(info); 896 expected_volume_info.push_back(info);
898 } 897 }
899 EXPECT_FALSE(expected_volume_info.empty()); 898 EXPECT_FALSE(expected_volume_info.empty());
900 899
901 RestartStatusCollector(base::Bind(&GetFakeVolumeInfo, expected_volume_info), 900 RestartStatusCollector(base::Bind(&GetFakeVolumeInfo, expected_volume_info),
902 base::Bind(&GetEmptyCPUStatistics), 901 base::Bind(&GetEmptyCPUStatistics),
903 base::Bind(&GetEmptyCPUTempInfo), 902 base::Bind(&GetEmptyCPUTempInfo),
904 base::Bind(&GetEmptyAndroidStatus)); 903 base::Bind(&GetEmptyAndroidStatus));
905 // Force finishing tasks posted by ctor of DeviceStatusCollector. 904 // Force finishing tasks posted by ctor of DeviceStatusCollector.
906 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 905 content::RunAllBlockingPoolTasksUntilIdle();
907 base::RunLoop().RunUntilIdle();
908 906
909 GetStatus(); 907 GetStatus();
910 EXPECT_EQ(expected_mount_points.size(), 908 EXPECT_EQ(expected_mount_points.size(),
911 static_cast<size_t>(device_status_.volume_info_size())); 909 static_cast<size_t>(device_status_.volume_info_size()));
912 910
913 // Walk the returned VolumeInfo to make sure it matches. 911 // Walk the returned VolumeInfo to make sure it matches.
914 for (const em::VolumeInfo& expected_info : expected_volume_info) { 912 for (const em::VolumeInfo& expected_info : expected_volume_info) {
915 bool found = false; 913 bool found = false;
916 for (const em::VolumeInfo& info : device_status_.volume_info()) { 914 for (const em::VolumeInfo& info : device_status_.volume_info()) {
917 if (info.volume_id() == expected_info.volume_id()) { 915 if (info.volume_id() == expected_info.volume_id()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 } 948 }
951 949
952 TEST_F(DeviceStatusCollectorTest, TestCPUSamples) { 950 TEST_F(DeviceStatusCollectorTest, TestCPUSamples) {
953 // Mock 100% CPU usage. 951 // Mock 100% CPU usage.
954 std::string full_cpu_usage("cpu 500 0 500 0 0 0 0"); 952 std::string full_cpu_usage("cpu 500 0 500 0 0 0 0");
955 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), 953 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo),
956 base::Bind(&GetFakeCPUStatistics, full_cpu_usage), 954 base::Bind(&GetFakeCPUStatistics, full_cpu_usage),
957 base::Bind(&GetEmptyCPUTempInfo), 955 base::Bind(&GetEmptyCPUTempInfo),
958 base::Bind(&GetEmptyAndroidStatus)); 956 base::Bind(&GetEmptyAndroidStatus));
959 // Force finishing tasks posted by ctor of DeviceStatusCollector. 957 // Force finishing tasks posted by ctor of DeviceStatusCollector.
960 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 958 content::RunAllBlockingPoolTasksUntilIdle();
961 base::RunLoop().RunUntilIdle();
962 GetStatus(); 959 GetStatus();
963 ASSERT_EQ(1, device_status_.cpu_utilization_pct().size()); 960 ASSERT_EQ(1, device_status_.cpu_utilization_pct().size());
964 EXPECT_EQ(100, device_status_.cpu_utilization_pct(0)); 961 EXPECT_EQ(100, device_status_.cpu_utilization_pct(0));
965 962
966 // Now sample CPU usage again (active usage counters will not increase 963 // Now sample CPU usage again (active usage counters will not increase
967 // so should show 0% cpu usage). 964 // so should show 0% cpu usage).
968 status_collector_->RefreshSampleResourceUsage(); 965 status_collector_->RefreshSampleResourceUsage();
969 base::RunLoop().RunUntilIdle(); 966 base::RunLoop().RunUntilIdle();
970 GetStatus(); 967 GetStatus();
971 ASSERT_EQ(2, device_status_.cpu_utilization_pct().size()); 968 ASSERT_EQ(2, device_status_.cpu_utilization_pct().size());
(...skipping 30 matching lines...) Expand all
1002 info.set_cpu_temp(i * 10 + 100); 999 info.set_cpu_temp(i * 10 + 100);
1003 info.set_cpu_label(base::StringPrintf("Core %d", i)); 1000 info.set_cpu_label(base::StringPrintf("Core %d", i));
1004 expected_temp_info.push_back(info); 1001 expected_temp_info.push_back(info);
1005 } 1002 }
1006 1003
1007 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), 1004 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo),
1008 base::Bind(&GetEmptyCPUStatistics), 1005 base::Bind(&GetEmptyCPUStatistics),
1009 base::Bind(&GetFakeCPUTempInfo, expected_temp_info), 1006 base::Bind(&GetFakeCPUTempInfo, expected_temp_info),
1010 base::Bind(&GetEmptyAndroidStatus)); 1007 base::Bind(&GetEmptyAndroidStatus));
1011 // Force finishing tasks posted by ctor of DeviceStatusCollector. 1008 // Force finishing tasks posted by ctor of DeviceStatusCollector.
1012 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 1009 content::RunAllBlockingPoolTasksUntilIdle();
1013 base::RunLoop().RunUntilIdle();
1014 1010
1015 GetStatus(); 1011 GetStatus();
1016 EXPECT_EQ(expected_temp_info.size(), 1012 EXPECT_EQ(expected_temp_info.size(),
1017 static_cast<size_t>(device_status_.cpu_temp_info_size())); 1013 static_cast<size_t>(device_status_.cpu_temp_info_size()));
1018 1014
1019 // Walk the returned CPUTempInfo to make sure it matches. 1015 // Walk the returned CPUTempInfo to make sure it matches.
1020 for (const em::CPUTempInfo& expected_info : expected_temp_info) { 1016 for (const em::CPUTempInfo& expected_info : expected_temp_info) {
1021 bool found = false; 1017 bool found = false;
1022 for (const em::CPUTempInfo& info : device_status_.cpu_temp_info()) { 1018 for (const em::CPUTempInfo& info : device_status_.cpu_temp_info()) {
1023 if (info.cpu_label() == expected_info.cpu_label()) { 1019 if (info.cpu_label() == expected_info.cpu_label()) {
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 AccountId::FromUserEmail(kPublicAccountId)); 1603 AccountId::FromUserEmail(kPublicAccountId));
1608 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) 1604 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount())
1609 .WillRepeatedly(Return(true)); 1605 .WillRepeatedly(Return(true));
1610 1606
1611 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); 1607 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true);
1612 GetStatus(); 1608 GetStatus();
1613 VerifyNetworkReporting(); 1609 VerifyNetworkReporting();
1614 } 1610 }
1615 1611
1616 } // namespace policy 1612 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698