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/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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/environment.h" | 16 #include "base/environment.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
| 23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 24 #include "base/sys_info.h" | 24 #include "base/sys_info.h" |
| 25 #include "base/test/scoped_path_override.h" | 25 #include "base/test/scoped_path_override.h" |
| 26 #include "base/threading/sequenced_worker_pool.h" | 26 #include "base/threading/sequenced_worker_pool.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 28 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 29 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 29 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 30 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | |
| 30 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 31 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 32 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 32 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" | 33 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" |
| 33 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 34 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 34 #include "chrome/browser/chromeos/policy/device_local_account.h" | 35 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 35 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" | 36 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" |
| 36 #include "chrome/browser/chromeos/settings/stub_install_attributes.h" | 37 #include "chrome/browser/chromeos/settings/stub_install_attributes.h" |
| 37 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
| 38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/test/base/testing_browser_process.h" | 40 #include "chrome/test/base/testing_browser_process.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 74 |
| 74 namespace em = enterprise_management; | 75 namespace em = enterprise_management; |
| 75 | 76 |
| 76 namespace { | 77 namespace { |
| 77 | 78 |
| 78 const int64_t kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000; | 79 const int64_t kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000; |
| 79 const char kKioskAccountId[] = "kiosk_user@localhost"; | 80 const char kKioskAccountId[] = "kiosk_user@localhost"; |
| 80 const char kKioskAppId[] = "kiosk_app_id"; | 81 const char kKioskAppId[] = "kiosk_app_id"; |
| 81 const char kExternalMountPoint[] = "/a/b/c"; | 82 const char kExternalMountPoint[] = "/a/b/c"; |
| 82 const char kPublicAccountId[] = "public_user@localhost"; | 83 const char kPublicAccountId[] = "public_user@localhost"; |
| 84 const std::string kArcStatus = "{\"applications\":[ { " | |
|
bartfab (slow)
2016/10/13 13:18:04
Nit: You are adding static initializers, which are
phweiss
2016/10/13 13:28:25
Done.
| |
| 85 "\"packageName\":\"com.android.providers.telephony\"," | |
| 86 "\"versionName\":\"6.0.1\"," | |
| 87 "\"permissions\": [\"android.permission.INTERNET\"] }]," | |
| 88 "\"userEmail\":\"xxx@google.com\"}"; | |
| 89 const std::string kDroidGuardInfo = "{\"droid_guard_info\":42}"; | |
| 83 | 90 |
| 84 class TestingDeviceStatusCollector : public policy::DeviceStatusCollector { | 91 class TestingDeviceStatusCollector : public policy::DeviceStatusCollector { |
| 85 public: | 92 public: |
| 86 TestingDeviceStatusCollector( | 93 TestingDeviceStatusCollector( |
| 87 PrefService* local_state, | 94 PrefService* local_state, |
| 88 chromeos::system::StatisticsProvider* provider, | 95 chromeos::system::StatisticsProvider* provider, |
| 89 const policy::DeviceStatusCollector::VolumeInfoFetcher& | 96 const policy::DeviceStatusCollector::VolumeInfoFetcher& |
| 90 volume_info_fetcher, | 97 volume_info_fetcher, |
| 91 const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_fetcher, | 98 const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_fetcher, |
| 92 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher, | 99 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 return std::vector<em::CPUTempInfo>(); | 225 return std::vector<em::CPUTempInfo>(); |
| 219 } | 226 } |
| 220 | 227 |
| 221 void CallAndroidStatusReceiver( | 228 void CallAndroidStatusReceiver( |
| 222 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver, | 229 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver, |
| 223 mojo::String status, | 230 mojo::String status, |
| 224 mojo::String droid_guard_info) { | 231 mojo::String droid_guard_info) { |
| 225 receiver.Run(status, droid_guard_info); | 232 receiver.Run(status, droid_guard_info); |
| 226 } | 233 } |
| 227 | 234 |
| 235 bool GetFakeAndroidStatus( | |
| 236 mojo::String status, | |
| 237 mojo::String droid_guard_info, | |
| 238 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver) { | |
| 239 // Post it to the thread because this call is expected to be asynchronous. | |
| 240 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 241 FROM_HERE, base::Bind(&CallAndroidStatusReceiver, receiver, | |
| 242 status, droid_guard_info)); | |
| 243 return true; | |
| 244 } | |
| 245 | |
| 228 bool GetEmptyAndroidStatus( | 246 bool GetEmptyAndroidStatus( |
| 229 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver) { | 247 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver) { |
| 230 // Post it to the thread because this call is expected to be asynchronous. | 248 // Post it to the thread because this call is expected to be asynchronous. |
| 231 base::ThreadTaskRunnerHandle::Get()->PostTask( | 249 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 232 FROM_HERE, base::Bind(&CallAndroidStatusReceiver, receiver, "", "")); | 250 FROM_HERE, base::Bind(&CallAndroidStatusReceiver, receiver, "", "")); |
| 233 return true; | 251 return true; |
| 234 } | 252 } |
| 235 | 253 |
| 236 std::vector<em::CPUTempInfo> GetFakeCPUTempInfo( | 254 std::vector<em::CPUTempInfo> GetFakeCPUTempInfo( |
| 237 const std::vector<em::CPUTempInfo>& cpu_temp_info) { | 255 const std::vector<em::CPUTempInfo>& cpu_temp_info) { |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 975 EXPECT_TRUE(found) << "No matching CPUTempInfo for " | 993 EXPECT_TRUE(found) << "No matching CPUTempInfo for " |
| 976 << expected_info.cpu_label(); | 994 << expected_info.cpu_label(); |
| 977 } | 995 } |
| 978 | 996 |
| 979 // Now turn off hardware status reporting - should have no data. | 997 // Now turn off hardware status reporting - should have no data. |
| 980 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 998 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); |
| 981 GetStatus(); | 999 GetStatus(); |
| 982 EXPECT_EQ(0, device_status_.cpu_temp_info_size()); | 1000 EXPECT_EQ(0, device_status_.cpu_temp_info_size()); |
| 983 } | 1001 } |
| 984 | 1002 |
| 985 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { | 1003 TEST_F(DeviceStatusCollectorTest, TestAndroidReporting) { |
| 1004 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), | |
| 1005 base::Bind(&GetEmptyCPUStatistics), | |
| 1006 base::Bind(&GetEmptyCPUTempInfo), | |
| 1007 base::Bind(&GetFakeAndroidStatus, kArcStatus, | |
| 1008 kDroidGuardInfo)); | |
| 1009 GetStatus(); | |
| 1010 EXPECT_EQ(kArcStatus, session_status_.android_status().status_payload()); | |
| 1011 EXPECT_EQ(kDroidGuardInfo, | |
| 1012 session_status_.android_status().droid_guard_info()); | |
| 1013 } | |
| 1014 | |
| 1015 TEST_F(DeviceStatusCollectorTest, NoAndroidReportingWhenDisabled) { | |
| 1016 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), | |
| 1017 base::Bind(&GetEmptyCPUStatistics), | |
| 1018 base::Bind(&GetEmptyCPUTempInfo), | |
| 1019 base::Bind(&GetFakeAndroidStatus, kArcStatus, | |
| 1020 kDroidGuardInfo)); | |
| 1021 | |
| 1022 prefs_.SetBoolean(prefs::kReportArcStatus, false); | |
| 1023 // Mock Kiosk app, so some session status is reported | |
| 1024 status_collector_->set_kiosk_account( | |
| 1025 base::MakeUnique<DeviceLocalAccount>(fake_device_local_account_)); | |
| 1026 MockRunningKioskApp(fake_device_local_account_); | |
| 1027 | |
| 1028 GetStatus(); | |
| 1029 EXPECT_TRUE(got_session_status_); | |
| 1030 EXPECT_FALSE(session_status_.has_android_status()); | |
| 1031 } | |
| 1032 | |
| 1033 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskAndNoArcReporting) { | |
| 986 // Should not report session status if we don't have an active kiosk app. | 1034 // Should not report session status if we don't have an active kiosk app. |
| 987 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 1035 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); |
| 1036 prefs_.SetBoolean(prefs::kReportArcStatus, false); | |
| 988 GetStatus(); | 1037 GetStatus(); |
| 989 EXPECT_FALSE(got_session_status_); | 1038 EXPECT_FALSE(got_session_status_); |
| 990 } | 1039 } |
| 991 | 1040 |
| 992 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { | 1041 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { |
| 993 // Should not report session status if session status reporting is disabled. | 1042 // Should not report session status if session status reporting is disabled. |
| 994 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); | 1043 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); |
| 1044 // ReportDeviceSessionStatus only controls Kiosk reporting, ARC reporting | |
| 1045 // has to be disabled serarately. | |
| 1046 prefs_.SetBoolean(prefs::kReportArcStatus, false); | |
| 995 status_collector_->set_kiosk_account( | 1047 status_collector_->set_kiosk_account( |
| 996 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); | 1048 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); |
| 997 // Set up a device-local account for single-app kiosk mode. | 1049 // Set up a device-local account for single-app kiosk mode. |
| 998 MockRunningKioskApp(fake_device_local_account_); | 1050 MockRunningKioskApp(fake_device_local_account_); |
| 999 | 1051 |
| 1000 GetStatus(); | 1052 GetStatus(); |
| 1001 EXPECT_FALSE(got_session_status_); | 1053 EXPECT_FALSE(got_session_status_); |
| 1002 } | 1054 } |
| 1003 | 1055 |
| 1004 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { | 1056 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1435 AccountId::FromUserEmail(kPublicAccountId)); | 1487 AccountId::FromUserEmail(kPublicAccountId)); |
| 1436 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) | 1488 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) |
| 1437 .WillRepeatedly(Return(true)); | 1489 .WillRepeatedly(Return(true)); |
| 1438 | 1490 |
| 1439 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); | 1491 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); |
| 1440 GetStatus(); | 1492 GetStatus(); |
| 1441 VerifyNetworkReporting(); | 1493 VerifyNetworkReporting(); |
| 1442 } | 1494 } |
| 1443 | 1495 |
| 1444 } // namespace policy | 1496 } // namespace policy |
| OLD | NEW |