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 | |
10 #include <string> | 9 #include <string> |
| 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/environment.h" | 14 #include "base/environment.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
20 #include "base/prefs/testing_pref_service.h" | 20 #include "base/prefs/testing_pref_service.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 max_stored_future_activity_days_ = value; | 128 max_stored_future_activity_days_ = value; |
129 } | 129 } |
130 | 130 |
131 // Reset the baseline time. | 131 // Reset the baseline time. |
132 void SetBaselineTime(Time time) { | 132 void SetBaselineTime(Time time) { |
133 baseline_time_ = time; | 133 baseline_time_ = time; |
134 baseline_offset_periods_ = 0; | 134 baseline_offset_periods_ = 0; |
135 } | 135 } |
136 | 136 |
137 void set_kiosk_account(scoped_ptr<policy::DeviceLocalAccount> account) { | 137 void set_kiosk_account(scoped_ptr<policy::DeviceLocalAccount> account) { |
138 kiosk_account_ = account.Pass(); | 138 kiosk_account_ = std::move(account); |
139 } | 139 } |
140 | 140 |
141 scoped_ptr<policy::DeviceLocalAccount> | 141 scoped_ptr<policy::DeviceLocalAccount> |
142 GetAutoLaunchedKioskSessionInfo() override { | 142 GetAutoLaunchedKioskSessionInfo() override { |
143 if (kiosk_account_) | 143 if (kiosk_account_) |
144 return make_scoped_ptr(new policy::DeviceLocalAccount(*kiosk_account_)); | 144 return make_scoped_ptr(new policy::DeviceLocalAccount(*kiosk_account_)); |
145 return scoped_ptr<policy::DeviceLocalAccount>(); | 145 return scoped_ptr<policy::DeviceLocalAccount>(); |
146 } | 146 } |
147 | 147 |
148 std::string GetAppVersion(const std::string& app_id) override { | 148 std::string GetAppVersion(const std::string& app_id) override { |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 // Should not report session status if we don't have an active kiosk app. | 980 // Should not report session status if we don't have an active kiosk app. |
981 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 981 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); |
982 em::SessionStatusReportRequest session_status; | 982 em::SessionStatusReportRequest session_status; |
983 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); | 983 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); |
984 } | 984 } |
985 | 985 |
986 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { | 986 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { |
987 // Should not report session status if session status reporting is disabled. | 987 // Should not report session status if session status reporting is disabled. |
988 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); | 988 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); |
989 status_collector_->set_kiosk_account(make_scoped_ptr( | 989 status_collector_->set_kiosk_account(make_scoped_ptr( |
990 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 990 new policy::DeviceLocalAccount(fake_device_local_account_))); |
991 // Set up a device-local account for single-app kiosk mode. | 991 // Set up a device-local account for single-app kiosk mode. |
992 MockRunningKioskApp(fake_device_local_account_); | 992 MockRunningKioskApp(fake_device_local_account_); |
993 | 993 |
994 em::SessionStatusReportRequest session_status; | 994 em::SessionStatusReportRequest session_status; |
995 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); | 995 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); |
996 } | 996 } |
997 | 997 |
998 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { | 998 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { |
999 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 999 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); |
1000 status_collector_->set_kiosk_account(make_scoped_ptr( | 1000 status_collector_->set_kiosk_account(make_scoped_ptr( |
1001 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 1001 new policy::DeviceLocalAccount(fake_device_local_account_))); |
1002 | 1002 |
1003 // Set up a device-local account for single-app kiosk mode. | 1003 // Set up a device-local account for single-app kiosk mode. |
1004 MockRunningKioskApp(fake_device_local_account_); | 1004 MockRunningKioskApp(fake_device_local_account_); |
1005 | 1005 |
1006 em::SessionStatusReportRequest session_status; | 1006 em::SessionStatusReportRequest session_status; |
1007 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status)); | 1007 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status)); |
1008 ASSERT_EQ(1, session_status.installed_apps_size()); | 1008 ASSERT_EQ(1, session_status.installed_apps_size()); |
1009 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id()); | 1009 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id()); |
1010 const em::AppStatus app = session_status.installed_apps(0); | 1010 const em::AppStatus app = session_status.installed_apps(0); |
1011 EXPECT_EQ(kKioskAppId, app.app_id()); | 1011 EXPECT_EQ(kKioskAppId, app.app_id()); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 // If not in an active kiosk session, there should be network interfaces | 1278 // If not in an active kiosk session, there should be network interfaces |
1279 // reported, but no network state. | 1279 // reported, but no network state. |
1280 GetStatus(); | 1280 GetStatus(); |
1281 EXPECT_LT(0, status_.network_interface_size()); | 1281 EXPECT_LT(0, status_.network_interface_size()); |
1282 EXPECT_EQ(0, status_.network_state_size()); | 1282 EXPECT_EQ(0, status_.network_state_size()); |
1283 } | 1283 } |
1284 | 1284 |
1285 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { | 1285 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { |
1286 // Mock that we are in kiosk mode so we report network state. | 1286 // Mock that we are in kiosk mode so we report network state. |
1287 status_collector_->set_kiosk_account(make_scoped_ptr( | 1287 status_collector_->set_kiosk_account(make_scoped_ptr( |
1288 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 1288 new policy::DeviceLocalAccount(fake_device_local_account_))); |
1289 | 1289 |
1290 // Interfaces should be reported by default. | 1290 // Interfaces should be reported by default. |
1291 GetStatus(); | 1291 GetStatus(); |
1292 EXPECT_LT(0, status_.network_interface_size()); | 1292 EXPECT_LT(0, status_.network_interface_size()); |
1293 EXPECT_LT(0, status_.network_state_size()); | 1293 EXPECT_LT(0, status_.network_state_size()); |
1294 | 1294 |
1295 // No interfaces should be reported if the policy is off. | 1295 // No interfaces should be reported if the policy is off. |
1296 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); | 1296 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); |
1297 GetStatus(); | 1297 GetStatus(); |
1298 EXPECT_EQ(0, status_.network_interface_size()); | 1298 EXPECT_EQ(0, status_.network_interface_size()); |
(...skipping 12 matching lines...) Expand all Loading... |
1311 AccountId::FromUserEmail(kPublicAccountId)); | 1311 AccountId::FromUserEmail(kPublicAccountId)); |
1312 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) | 1312 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) |
1313 .WillRepeatedly(Return(true)); | 1313 .WillRepeatedly(Return(true)); |
1314 | 1314 |
1315 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); | 1315 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); |
1316 GetStatus(); | 1316 GetStatus(); |
1317 VerifyNetworkReporting(); | 1317 VerifyNetworkReporting(); |
1318 } | 1318 } |
1319 | 1319 |
1320 } // namespace policy | 1320 } // namespace policy |
OLD | NEW |