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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 return std::vector<em::CPUTempInfo>(); | 219 return std::vector<em::CPUTempInfo>(); |
| 219 } | 220 } |
| 220 | 221 |
| 221 void CallAndroidStatusReceiver( | 222 void CallAndroidStatusReceiver( |
| 222 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver, | 223 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver, |
| 223 mojo::String status, | 224 mojo::String status, |
| 224 mojo::String droid_guard_info) { | 225 mojo::String droid_guard_info) { |
| 225 receiver.Run(status, droid_guard_info); | 226 receiver.Run(status, droid_guard_info); |
| 226 } | 227 } |
| 227 | 228 |
| 229 bool GetFakeAndroidStatus( | |
| 230 mojo::String status, | |
| 231 mojo::String droid_guard_info, | |
| 232 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver) { | |
| 233 // Post it to the thread because this call is expected to be asynchronous. | |
| 234 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 235 FROM_HERE, Bind(&CallAndroidStatusReceiver, receiver, | |
|
bartfab (slow)
2016/10/10 15:49:16
Nit: s/Bind/base::Bind/ (why does this even compil
phweiss
2016/10/11 12:14:39
Done.
| |
| 236 status, droid_guard_info)); | |
| 237 return true; | |
| 238 } | |
| 239 | |
| 228 bool GetEmptyAndroidStatus( | 240 bool GetEmptyAndroidStatus( |
| 229 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver) { | 241 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver) { |
| 230 // Post it to the thread because this call is expected to be asynchronous. | 242 // Post it to the thread because this call is expected to be asynchronous. |
| 231 base::ThreadTaskRunnerHandle::Get()->PostTask( | 243 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 232 FROM_HERE, base::Bind(&CallAndroidStatusReceiver, receiver, "", "")); | 244 FROM_HERE, base::Bind(&CallAndroidStatusReceiver, receiver, "", "")); |
| 233 return true; | 245 return true; |
| 234 } | 246 } |
| 235 | 247 |
| 236 std::vector<em::CPUTempInfo> GetFakeCPUTempInfo( | 248 std::vector<em::CPUTempInfo> GetFakeCPUTempInfo( |
| 237 const std::vector<em::CPUTempInfo>& cpu_temp_info) { | 249 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 " | 987 EXPECT_TRUE(found) << "No matching CPUTempInfo for " |
| 976 << expected_info.cpu_label(); | 988 << expected_info.cpu_label(); |
| 977 } | 989 } |
| 978 | 990 |
| 979 // Now turn off hardware status reporting - should have no data. | 991 // Now turn off hardware status reporting - should have no data. |
| 980 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 992 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); |
| 981 GetStatus(); | 993 GetStatus(); |
| 982 EXPECT_EQ(0, device_status_.cpu_temp_info_size()); | 994 EXPECT_EQ(0, device_status_.cpu_temp_info_size()); |
| 983 } | 995 } |
| 984 | 996 |
| 985 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { | 997 TEST_F(DeviceStatusCollectorTest, TestAndroidReporting) { |
| 998 mojo::String status = "{\"applications\":[ { " | |
|
bartfab (slow)
2016/10/10 15:49:16
Here and below:
Nit 1: const.
Nit 2: You can use
phweiss
2016/10/11 12:14:39
Done.
| |
| 999 "\"packageName\":\"com.android.providers.telephony\"," | |
| 1000 "\"versionName\":\"6.0.1\"," | |
| 1001 "\"permissions\": [\"android.permission.INTERNET\"] }]," | |
| 1002 "\"userEmail\":\"xxx@google.com\"}"; | |
| 1003 mojo::String droid_guard_info = "{\"droid_guard_info\":42}"; | |
| 1004 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), | |
| 1005 base::Bind(&GetEmptyCPUStatistics), | |
| 1006 base::Bind(&GetEmptyCPUTempInfo), | |
| 1007 base::Bind(&GetFakeAndroidStatus, status, | |
| 1008 droid_guard_info)); | |
| 1009 GetStatus(); | |
| 1010 EXPECT_EQ(status, session_status_.android_status().status_payload()); | |
| 1011 EXPECT_EQ(droid_guard_info, | |
| 1012 session_status_.android_status().droid_guard_info()); | |
| 1013 } | |
| 1014 | |
| 1015 TEST_F(DeviceStatusCollectorTest, NoAndroidReportingWhenDisabled) { | |
| 1016 mojo::String status = "{\"applications\":[ { " | |
|
bartfab (slow)
2016/10/10 15:49:16
Nit: Can you move these lengthy constants to an an
phweiss
2016/10/11 12:14:39
Done.
| |
| 1017 "\"packageName\":\"com.android.providers.telephony\"," | |
| 1018 "\"versionName\":\"6.0.1\"," | |
| 1019 "\"permissions\": [\"android.permission.INTERNET\"] }]," | |
| 1020 "\"userEmail\":\"xxx@google.com\"}"; | |
| 1021 mojo::String droid_guard_info = "{\"droid_guard_info\":42}"; | |
| 1022 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), | |
| 1023 base::Bind(&GetEmptyCPUStatistics), | |
| 1024 base::Bind(&GetEmptyCPUTempInfo), | |
| 1025 base::Bind(&GetFakeAndroidStatus, status, | |
| 1026 droid_guard_info)); | |
| 1027 | |
| 1028 prefs_.SetBoolean(prefs::kReportArcStatus, false); | |
| 1029 // Mock Kiosk app, so some session status is reported | |
| 1030 status_collector_->set_kiosk_account( | |
| 1031 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); | |
|
bartfab (slow)
2016/10/10 15:49:16
Nit: s/policy:://
phweiss
2016/10/11 12:14:39
Done.
| |
| 1032 MockRunningKioskApp(fake_device_local_account_); | |
| 1033 | |
| 1034 GetStatus(); | |
| 1035 EXPECT_TRUE(got_session_status_); | |
| 1036 EXPECT_FALSE(session_status_.has_android_status()); | |
| 1037 } | |
| 1038 | |
| 1039 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskAndNoArcReporting) { | |
| 986 // Should not report session status if we don't have an active kiosk app. | 1040 // Should not report session status if we don't have an active kiosk app. |
| 987 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 1041 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); |
| 1042 prefs_.SetBoolean(prefs::kReportArcStatus, false); | |
| 988 GetStatus(); | 1043 GetStatus(); |
| 989 EXPECT_FALSE(got_session_status_); | 1044 EXPECT_FALSE(got_session_status_); |
| 990 } | 1045 } |
| 991 | 1046 |
| 992 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { | 1047 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { |
| 993 // Should not report session status if session status reporting is disabled. | 1048 // Should not report session status if session status reporting is disabled. |
| 994 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); | 1049 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); |
| 1050 prefs_.SetBoolean(prefs::kReportArcStatus, false); | |
|
bartfab (slow)
2016/10/10 15:49:16
Nit: Even if this was true, reproting should retur
phweiss
2016/10/11 12:14:39
In the current implementation, kReportDeviceSessio
| |
| 995 status_collector_->set_kiosk_account( | 1051 status_collector_->set_kiosk_account( |
| 996 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); | 1052 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); |
| 997 // Set up a device-local account for single-app kiosk mode. | 1053 // Set up a device-local account for single-app kiosk mode. |
| 998 MockRunningKioskApp(fake_device_local_account_); | 1054 MockRunningKioskApp(fake_device_local_account_); |
| 999 | 1055 |
| 1000 GetStatus(); | 1056 GetStatus(); |
| 1001 EXPECT_FALSE(got_session_status_); | 1057 EXPECT_FALSE(got_session_status_); |
| 1002 } | 1058 } |
| 1003 | 1059 |
| 1004 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { | 1060 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1435 AccountId::FromUserEmail(kPublicAccountId)); | 1491 AccountId::FromUserEmail(kPublicAccountId)); |
| 1436 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) | 1492 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) |
| 1437 .WillRepeatedly(Return(true)); | 1493 .WillRepeatedly(Return(true)); |
| 1438 | 1494 |
| 1439 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); | 1495 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); |
| 1440 GetStatus(); | 1496 GetStatus(); |
| 1441 VerifyNetworkReporting(); | 1497 VerifyNetworkReporting(); |
| 1442 } | 1498 } |
| 1443 | 1499 |
| 1444 } // namespace policy | 1500 } // namespace policy |
| OLD | NEW |