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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/prefs/testing_pref_service.h" | 16 #include "base/prefs/testing_pref_service.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
19 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 19 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 21 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h" |
21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
22 #include "chrome/browser/chromeos/policy/device_local_account.h" | 23 #include "chrome/browser/chromeos/policy/device_local_account.h" |
23 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" | 24 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" |
24 #include "chrome/browser/chromeos/settings/cros_settings.h" | 25 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" |
25 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
26 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | |
27 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
28 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
29 #include "chromeos/dbus/cros_disks_client.h" | 28 #include "chromeos/dbus/cros_disks_client.h" |
30 #include "chromeos/dbus/dbus_thread_manager.h" | 29 #include "chromeos/dbus/dbus_thread_manager.h" |
31 #include "chromeos/dbus/shill_device_client.h" | 30 #include "chromeos/dbus/shill_device_client.h" |
32 #include "chromeos/dbus/shill_ipconfig_client.h" | 31 #include "chromeos/dbus/shill_ipconfig_client.h" |
33 #include "chromeos/dbus/shill_service_client.h" | 32 #include "chromeos/dbus/shill_service_client.h" |
34 #include "chromeos/disks/disk_mount_manager.h" | 33 #include "chromeos/disks/disk_mount_manager.h" |
35 #include "chromeos/disks/mock_disk_mount_manager.h" | 34 #include "chromeos/disks/mock_disk_mount_manager.h" |
36 #include "chromeos/network/network_handler.h" | 35 #include "chromeos/network/network_handler.h" |
37 #include "chromeos/network/network_state.h" | 36 #include "chromeos/network/network_state.h" |
38 #include "chromeos/network/network_state_handler.h" | 37 #include "chromeos/network/network_state_handler.h" |
39 #include "chromeos/settings/cros_settings_names.h" | 38 #include "chromeos/settings/cros_settings_names.h" |
40 #include "chromeos/settings/cros_settings_provider.h" | |
41 #include "chromeos/system/fake_statistics_provider.h" | 39 #include "chromeos/system/fake_statistics_provider.h" |
42 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/geolocation_provider.h" | 41 #include "content/public/browser/geolocation_provider.h" |
44 #include "content/public/test/test_browser_thread.h" | 42 #include "content/public/test/test_browser_thread.h" |
45 #include "content/public/test/test_utils.h" | 43 #include "content/public/test/test_utils.h" |
46 #include "policy/proto/device_management_backend.pb.h" | 44 #include "policy/proto/device_management_backend.pb.h" |
47 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
49 #include "third_party/cros_system_api/dbus/service_constants.h" | 47 #include "third_party/cros_system_api/dbus/service_constants.h" |
50 | 48 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } // namespace | 225 } // namespace |
228 | 226 |
229 namespace policy { | 227 namespace policy { |
230 | 228 |
231 // Though it is a unit test, this test is linked with browser_tests so that it | 229 // Though it is a unit test, this test is linked with browser_tests so that it |
232 // runs in a separate process. The intention is to avoid overriding the timezone | 230 // runs in a separate process. The intention is to avoid overriding the timezone |
233 // environment variable for other tests. | 231 // environment variable for other tests. |
234 class DeviceStatusCollectorTest : public testing::Test { | 232 class DeviceStatusCollectorTest : public testing::Test { |
235 public: | 233 public: |
236 DeviceStatusCollectorTest() | 234 DeviceStatusCollectorTest() |
237 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 235 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
238 file_thread_(content::BrowserThread::FILE, &message_loop_), | 236 file_thread_(content::BrowserThread::FILE, &message_loop_), |
239 io_thread_(content::BrowserThread::IO, &message_loop_), | 237 io_thread_(content::BrowserThread::IO, &message_loop_), |
240 install_attributes_("managed.com", | 238 install_attributes_("managed.com", |
241 "user@managed.com", | 239 "user@managed.com", |
242 "device_id", | 240 "device_id", |
243 DEVICE_MODE_ENTERPRISE), | 241 DEVICE_MODE_ENTERPRISE), |
244 user_manager_(new chromeos::MockUserManager()), | 242 settings_helper_(false), |
245 user_manager_enabler_(user_manager_), | 243 user_manager_(new chromeos::MockUserManager()), |
246 fake_device_local_account_( | 244 user_manager_enabler_(user_manager_), |
247 policy::DeviceLocalAccount::TYPE_KIOSK_APP, | 245 fake_device_local_account_(policy::DeviceLocalAccount::TYPE_KIOSK_APP, |
248 kKioskAccountId, | 246 kKioskAccountId, |
249 kKioskAppId, | 247 kKioskAppId, |
250 std::string() /* kiosk_app_update_url */) { | 248 std::string() /* kiosk_app_update_url */) { |
251 // Run this test with a well-known timezone so that Time::LocalMidnight() | 249 // Run this test with a well-known timezone so that Time::LocalMidnight() |
252 // returns the same values on all machines. | 250 // returns the same values on all machines. |
253 scoped_ptr<base::Environment> env(base::Environment::Create()); | 251 scoped_ptr<base::Environment> env(base::Environment::Create()); |
254 env->SetVar("TZ", "UTC"); | 252 env->SetVar("TZ", "UTC"); |
255 | 253 |
256 // Initialize our mock mounted disk volumes. | 254 // Initialize our mock mounted disk volumes. |
257 scoped_ptr<chromeos::disks::MockDiskMountManager> mock_disk_mount_manager = | 255 scoped_ptr<chromeos::disks::MockDiskMountManager> mock_disk_mount_manager = |
258 make_scoped_ptr(new chromeos::disks::MockDiskMountManager()); | 256 make_scoped_ptr(new chromeos::disks::MockDiskMountManager()); |
259 AddMountPoint("/mount/volume1"); | 257 AddMountPoint("/mount/volume1"); |
260 AddMountPoint("/mount/volume2"); | 258 AddMountPoint("/mount/volume2"); |
261 EXPECT_CALL(*mock_disk_mount_manager, mount_points()) | 259 EXPECT_CALL(*mock_disk_mount_manager, mount_points()) |
262 .WillRepeatedly(ReturnRef(mount_point_map_)); | 260 .WillRepeatedly(ReturnRef(mount_point_map_)); |
263 | 261 |
264 // DiskMountManager takes ownership of the MockDiskMountManager. | 262 // DiskMountManager takes ownership of the MockDiskMountManager. |
265 DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release()); | 263 DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release()); |
266 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry()); | 264 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry()); |
267 | 265 |
268 // Remove the real DeviceSettingsProvider and replace it with a stub. | 266 settings_helper_.ReplaceProvider(chromeos::kReportDeviceActivityTimes); |
269 cros_settings_ = chromeos::CrosSettings::Get(); | 267 owner_settings_service_.reset( |
270 device_settings_provider_ = | 268 settings_helper_.CreateOwnerSettingsService(nullptr)); |
271 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); | |
272 EXPECT_TRUE(device_settings_provider_ != NULL); | |
273 EXPECT_TRUE( | |
274 cros_settings_->RemoveSettingsProvider(device_settings_provider_)); | |
275 cros_settings_->AddSettingsProvider(&stub_settings_provider_); | |
276 | 269 |
277 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); | 270 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); |
278 } | 271 } |
279 | 272 |
280 void AddMountPoint(const std::string& mount_point) { | 273 void AddMountPoint(const std::string& mount_point) { |
281 mount_point_map_.insert(DiskMountManager::MountPointMap::value_type( | 274 mount_point_map_.insert(DiskMountManager::MountPointMap::value_type( |
282 mount_point, | 275 mount_point, |
283 DiskMountManager::MountPointInfo( | 276 DiskMountManager::MountPointInfo( |
284 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE, | 277 mount_point, mount_point, chromeos::MOUNT_TYPE_DEVICE, |
285 chromeos::disks::MOUNT_CONDITION_NONE))); | 278 chromeos::disks::MOUNT_CONDITION_NONE))); |
286 } | 279 } |
287 | 280 |
288 ~DeviceStatusCollectorTest() override { | 281 ~DeviceStatusCollectorTest() override { |
289 // Finish pending tasks. | 282 // Finish pending tasks. |
290 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 283 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
291 message_loop_.RunUntilIdle(); | 284 message_loop_.RunUntilIdle(); |
292 DiskMountManager::Shutdown(); | 285 DiskMountManager::Shutdown(); |
293 | |
294 // Restore the real DeviceSettingsProvider. | |
295 EXPECT_TRUE( | |
296 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); | |
297 cros_settings_->AddSettingsProvider(device_settings_provider_); | |
298 } | 286 } |
299 | 287 |
300 void SetUp() override { | 288 void SetUp() override { |
301 // Disable network interface reporting since it requires additional setup. | 289 // Disable network interface reporting since it requires additional setup. |
302 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); | 290 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, |
| 291 false); |
303 } | 292 } |
304 | 293 |
| 294 void TearDown() override { settings_helper_.RestoreProvider(); } |
| 295 |
305 void RestartStatusCollector( | 296 void RestartStatusCollector( |
306 const policy::DeviceStatusCollector::VolumeInfoFetcher& fetcher) { | 297 const policy::DeviceStatusCollector::VolumeInfoFetcher& fetcher) { |
307 policy::DeviceStatusCollector::LocationUpdateRequester callback = | 298 policy::DeviceStatusCollector::LocationUpdateRequester callback = |
308 base::Bind(&MockPositionUpdateRequester); | 299 base::Bind(&MockPositionUpdateRequester); |
309 std::vector<em::VolumeInfo> expected_volume_info; | 300 std::vector<em::VolumeInfo> expected_volume_info; |
310 status_collector_.reset( | 301 status_collector_.reset( |
311 new TestingDeviceStatusCollector(&prefs_, | 302 new TestingDeviceStatusCollector(&prefs_, |
312 &fake_statistics_provider_, | 303 &fake_statistics_provider_, |
313 callback, | 304 callback, |
314 fetcher)); | 305 fetcher)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 EXPECT_TRUE(status_.has_device_location()); | 345 EXPECT_TRUE(status_.has_device_location()); |
355 em::DeviceLocation location = status_.device_location(); | 346 em::DeviceLocation location = status_.device_location(); |
356 EXPECT_TRUE(location.has_error_code()); | 347 EXPECT_TRUE(location.has_error_code()); |
357 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE, | 348 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE, |
358 location.error_code()); | 349 location.error_code()); |
359 } | 350 } |
360 | 351 |
361 void MockRunningKioskApp(const DeviceLocalAccount& account) { | 352 void MockRunningKioskApp(const DeviceLocalAccount& account) { |
362 std::vector<DeviceLocalAccount> accounts; | 353 std::vector<DeviceLocalAccount> accounts; |
363 accounts.push_back(account); | 354 accounts.push_back(account); |
364 SetDeviceLocalAccounts(cros_settings_, accounts); | 355 SetDeviceLocalAccounts(owner_settings_service_.get(), accounts); |
365 user_manager_->CreateKioskAppUser(account.user_id); | 356 user_manager_->CreateKioskAppUser(account.user_id); |
366 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly( | 357 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly( |
367 Return(true)); | 358 Return(true)); |
368 } | 359 } |
369 | 360 |
370 protected: | 361 protected: |
371 // Convenience method. | 362 // Convenience method. |
372 int64 ActivePeriodMilliseconds() { | 363 int64 ActivePeriodMilliseconds() { |
373 return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000; | 364 return policy::DeviceStatusCollector::kIdlePollIntervalSeconds * 1000; |
374 } | 365 } |
375 | 366 |
376 // Since this is a unit test running in browser_tests we must do additional | 367 // Since this is a unit test running in browser_tests we must do additional |
377 // unit test setup and make a TestingBrowserProcess. Must be first member. | 368 // unit test setup and make a TestingBrowserProcess. Must be first member. |
378 TestingBrowserProcessInitializer initializer_; | 369 TestingBrowserProcessInitializer initializer_; |
379 base::MessageLoopForUI message_loop_; | 370 base::MessageLoopForUI message_loop_; |
380 content::TestBrowserThread ui_thread_; | 371 content::TestBrowserThread ui_thread_; |
381 content::TestBrowserThread file_thread_; | 372 content::TestBrowserThread file_thread_; |
382 content::TestBrowserThread io_thread_; | 373 content::TestBrowserThread io_thread_; |
383 | 374 |
384 ScopedStubEnterpriseInstallAttributes install_attributes_; | 375 ScopedStubEnterpriseInstallAttributes install_attributes_; |
385 TestingPrefServiceSimple prefs_; | 376 TestingPrefServiceSimple prefs_; |
386 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; | 377 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; |
387 DiskMountManager::MountPointMap mount_point_map_; | 378 DiskMountManager::MountPointMap mount_point_map_; |
388 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 379 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
389 chromeos::ScopedTestCrosSettings test_cros_settings_; | 380 chromeos::ScopedTestCrosSettings test_cros_settings_; |
390 chromeos::CrosSettings* cros_settings_; | 381 chromeos::ScopedCrosSettingsTestHelper settings_helper_; |
391 chromeos::CrosSettingsProvider* device_settings_provider_; | 382 scoped_ptr<chromeos::FakeOwnerSettingsService> owner_settings_service_; |
392 chromeos::StubCrosSettingsProvider stub_settings_provider_; | |
393 chromeos::MockUserManager* user_manager_; | 383 chromeos::MockUserManager* user_manager_; |
394 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 384 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
395 em::DeviceStatusReportRequest status_; | 385 em::DeviceStatusReportRequest status_; |
396 scoped_ptr<TestingDeviceStatusCollector> status_collector_; | 386 scoped_ptr<TestingDeviceStatusCollector> status_collector_; |
397 const policy::DeviceLocalAccount fake_device_local_account_; | 387 const policy::DeviceLocalAccount fake_device_local_account_; |
398 }; | 388 }; |
399 | 389 |
400 TEST_F(DeviceStatusCollectorTest, AllIdle) { | 390 TEST_F(DeviceStatusCollectorTest, AllIdle) { |
401 ui::IdleState test_states[] = { | 391 ui::IdleState test_states[] = { |
402 ui::IDLE_STATE_IDLE, | 392 ui::IDLE_STATE_IDLE, |
403 ui::IDLE_STATE_IDLE, | 393 ui::IDLE_STATE_IDLE, |
404 ui::IDLE_STATE_IDLE | 394 ui::IDLE_STATE_IDLE |
405 }; | 395 }; |
406 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 396 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
407 | 397 |
408 // Test reporting with no data. | 398 // Test reporting with no data. |
409 GetStatus(); | 399 GetStatus(); |
410 EXPECT_EQ(0, status_.active_period_size()); | 400 EXPECT_EQ(0, status_.active_period_size()); |
411 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 401 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
412 | 402 |
413 // Test reporting with a single idle sample. | 403 // Test reporting with a single idle sample. |
414 status_collector_->Simulate(test_states, 1); | 404 status_collector_->Simulate(test_states, 1); |
415 GetStatus(); | 405 GetStatus(); |
416 EXPECT_EQ(0, status_.active_period_size()); | 406 EXPECT_EQ(0, status_.active_period_size()); |
417 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 407 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
418 | 408 |
419 // Test reporting with multiple consecutive idle samples. | 409 // Test reporting with multiple consecutive idle samples. |
420 status_collector_->Simulate(test_states, | 410 status_collector_->Simulate(test_states, |
421 sizeof(test_states) / sizeof(ui::IdleState)); | 411 sizeof(test_states) / sizeof(ui::IdleState)); |
422 GetStatus(); | 412 GetStatus(); |
423 EXPECT_EQ(0, status_.active_period_size()); | 413 EXPECT_EQ(0, status_.active_period_size()); |
424 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 414 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
425 } | 415 } |
426 | 416 |
427 TEST_F(DeviceStatusCollectorTest, AllActive) { | 417 TEST_F(DeviceStatusCollectorTest, AllActive) { |
428 ui::IdleState test_states[] = { | 418 ui::IdleState test_states[] = { |
429 ui::IDLE_STATE_ACTIVE, | 419 ui::IDLE_STATE_ACTIVE, |
430 ui::IDLE_STATE_ACTIVE, | 420 ui::IDLE_STATE_ACTIVE, |
431 ui::IDLE_STATE_ACTIVE | 421 ui::IDLE_STATE_ACTIVE |
432 }; | 422 }; |
433 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 423 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
434 | 424 |
435 // Test a single active sample. | 425 // Test a single active sample. |
436 status_collector_->Simulate(test_states, 1); | 426 status_collector_->Simulate(test_states, 1); |
437 GetStatus(); | 427 GetStatus(); |
438 EXPECT_EQ(1, status_.active_period_size()); | 428 EXPECT_EQ(1, status_.active_period_size()); |
439 EXPECT_EQ(1 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 429 EXPECT_EQ(1 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
440 status_.clear_active_period(); // Clear the result protobuf. | 430 status_.clear_active_period(); // Clear the result protobuf. |
441 | 431 |
442 // Test multiple consecutive active samples. | 432 // Test multiple consecutive active samples. |
443 status_collector_->Simulate(test_states, | 433 status_collector_->Simulate(test_states, |
444 sizeof(test_states) / sizeof(ui::IdleState)); | 434 sizeof(test_states) / sizeof(ui::IdleState)); |
445 GetStatus(); | 435 GetStatus(); |
446 EXPECT_EQ(1, status_.active_period_size()); | 436 EXPECT_EQ(1, status_.active_period_size()); |
447 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 437 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
448 } | 438 } |
449 | 439 |
450 TEST_F(DeviceStatusCollectorTest, MixedStates) { | 440 TEST_F(DeviceStatusCollectorTest, MixedStates) { |
451 ui::IdleState test_states[] = { | 441 ui::IdleState test_states[] = { |
452 ui::IDLE_STATE_ACTIVE, | 442 ui::IDLE_STATE_ACTIVE, |
453 ui::IDLE_STATE_IDLE, | 443 ui::IDLE_STATE_IDLE, |
454 ui::IDLE_STATE_ACTIVE, | 444 ui::IDLE_STATE_ACTIVE, |
455 ui::IDLE_STATE_ACTIVE, | 445 ui::IDLE_STATE_ACTIVE, |
456 ui::IDLE_STATE_IDLE, | 446 ui::IDLE_STATE_IDLE, |
457 ui::IDLE_STATE_IDLE, | 447 ui::IDLE_STATE_IDLE, |
458 ui::IDLE_STATE_ACTIVE | 448 ui::IDLE_STATE_ACTIVE |
459 }; | 449 }; |
460 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 450 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
461 status_collector_->Simulate(test_states, | 451 status_collector_->Simulate(test_states, |
462 sizeof(test_states) / sizeof(ui::IdleState)); | 452 sizeof(test_states) / sizeof(ui::IdleState)); |
463 GetStatus(); | 453 GetStatus(); |
464 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 454 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
465 } | 455 } |
466 | 456 |
467 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { | 457 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { |
468 ui::IdleState test_states[] = { | 458 ui::IdleState test_states[] = { |
469 ui::IDLE_STATE_ACTIVE, | 459 ui::IDLE_STATE_ACTIVE, |
470 ui::IDLE_STATE_IDLE, | 460 ui::IDLE_STATE_IDLE, |
471 ui::IDLE_STATE_ACTIVE, | 461 ui::IDLE_STATE_ACTIVE, |
472 ui::IDLE_STATE_ACTIVE, | 462 ui::IDLE_STATE_ACTIVE, |
473 ui::IDLE_STATE_IDLE, | 463 ui::IDLE_STATE_IDLE, |
474 ui::IDLE_STATE_IDLE | 464 ui::IDLE_STATE_IDLE |
475 }; | 465 }; |
476 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 466 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
477 status_collector_->Simulate(test_states, | 467 status_collector_->Simulate(test_states, |
478 sizeof(test_states) / sizeof(ui::IdleState)); | 468 sizeof(test_states) / sizeof(ui::IdleState)); |
479 | 469 |
480 // Process the list a second time after restarting the collector. It should be | 470 // Process the list a second time after restarting the collector. It should be |
481 // able to count the active periods found by the original collector, because | 471 // able to count the active periods found by the original collector, because |
482 // the results are stored in a pref. | 472 // the results are stored in a pref. |
483 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); | 473 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); |
484 status_collector_->Simulate(test_states, | 474 status_collector_->Simulate(test_states, |
485 sizeof(test_states) / sizeof(ui::IdleState)); | 475 sizeof(test_states) / sizeof(ui::IdleState)); |
486 | 476 |
487 GetStatus(); | 477 GetStatus(); |
488 EXPECT_EQ(6 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 478 EXPECT_EQ(6 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
489 } | 479 } |
490 | 480 |
491 TEST_F(DeviceStatusCollectorTest, Times) { | 481 TEST_F(DeviceStatusCollectorTest, Times) { |
492 ui::IdleState test_states[] = { | 482 ui::IdleState test_states[] = { |
493 ui::IDLE_STATE_ACTIVE, | 483 ui::IDLE_STATE_ACTIVE, |
494 ui::IDLE_STATE_IDLE, | 484 ui::IDLE_STATE_IDLE, |
495 ui::IDLE_STATE_ACTIVE, | 485 ui::IDLE_STATE_ACTIVE, |
496 ui::IDLE_STATE_ACTIVE, | 486 ui::IDLE_STATE_ACTIVE, |
497 ui::IDLE_STATE_IDLE, | 487 ui::IDLE_STATE_IDLE, |
498 ui::IDLE_STATE_IDLE | 488 ui::IDLE_STATE_IDLE |
499 }; | 489 }; |
500 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 490 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
501 status_collector_->Simulate(test_states, | 491 status_collector_->Simulate(test_states, |
502 sizeof(test_states) / sizeof(ui::IdleState)); | 492 sizeof(test_states) / sizeof(ui::IdleState)); |
503 GetStatus(); | 493 GetStatus(); |
504 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 494 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
505 } | 495 } |
506 | 496 |
507 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { | 497 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { |
508 ui::IdleState test_states[] = { | 498 ui::IdleState test_states[] = { |
509 ui::IDLE_STATE_ACTIVE, | 499 ui::IDLE_STATE_ACTIVE, |
510 ui::IDLE_STATE_IDLE | 500 ui::IDLE_STATE_IDLE |
511 }; | 501 }; |
512 const int kMaxDays = 10; | 502 const int kMaxDays = 10; |
513 | 503 |
514 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 504 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
515 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); | 505 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); |
516 status_collector_->set_max_stored_future_activity_days(1); | 506 status_collector_->set_max_stored_future_activity_days(1); |
517 Time baseline = Time::Now().LocalMidnight(); | 507 Time baseline = Time::Now().LocalMidnight(); |
518 | 508 |
519 // Simulate 12 active periods. | 509 // Simulate 12 active periods. |
520 for (int i = 0; i < kMaxDays + 2; i++) { | 510 for (int i = 0; i < kMaxDays + 2; i++) { |
521 status_collector_->Simulate(test_states, | 511 status_collector_->Simulate(test_states, |
522 sizeof(test_states) / sizeof(ui::IdleState)); | 512 sizeof(test_states) / sizeof(ui::IdleState)); |
523 // Advance the simulated clock by a day. | 513 // Advance the simulated clock by a day. |
524 baseline += TimeDelta::FromDays(1); | 514 baseline += TimeDelta::FromDays(1); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 }; | 549 }; |
560 status_collector_->Simulate(test_states, | 550 status_collector_->Simulate(test_states, |
561 sizeof(test_states) / sizeof(ui::IdleState)); | 551 sizeof(test_states) / sizeof(ui::IdleState)); |
562 GetStatus(); | 552 GetStatus(); |
563 EXPECT_EQ(1, status_.active_period_size()); | 553 EXPECT_EQ(1, status_.active_period_size()); |
564 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 554 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
565 } | 555 } |
566 | 556 |
567 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { | 557 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { |
568 // Device activity times should not be reported if explicitly disabled. | 558 // Device activity times should not be reported if explicitly disabled. |
569 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, false); | 559 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, false); |
570 | 560 |
571 ui::IdleState test_states[] = { | 561 ui::IdleState test_states[] = { |
572 ui::IDLE_STATE_ACTIVE, | 562 ui::IDLE_STATE_ACTIVE, |
573 ui::IDLE_STATE_ACTIVE, | 563 ui::IDLE_STATE_ACTIVE, |
574 ui::IDLE_STATE_ACTIVE | 564 ui::IDLE_STATE_ACTIVE |
575 }; | 565 }; |
576 status_collector_->Simulate(test_states, | 566 status_collector_->Simulate(test_states, |
577 sizeof(test_states) / sizeof(ui::IdleState)); | 567 sizeof(test_states) / sizeof(ui::IdleState)); |
578 GetStatus(); | 568 GetStatus(); |
579 EXPECT_EQ(0, status_.active_period_size()); | 569 EXPECT_EQ(0, status_.active_period_size()); |
580 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 570 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
581 } | 571 } |
582 | 572 |
583 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { | 573 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { |
584 ui::IdleState test_states[] = { | 574 ui::IdleState test_states[] = { |
585 ui::IDLE_STATE_ACTIVE | 575 ui::IDLE_STATE_ACTIVE |
586 }; | 576 }; |
587 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 577 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
588 | 578 |
589 // Set the baseline time to 10 seconds after midnight. | 579 // Set the baseline time to 10 seconds after midnight. |
590 status_collector_->SetBaselineTime( | 580 status_collector_->SetBaselineTime( |
591 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); | 581 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); |
592 | 582 |
593 status_collector_->Simulate(test_states, 1); | 583 status_collector_->Simulate(test_states, 1); |
594 GetStatus(); | 584 GetStatus(); |
595 ASSERT_EQ(2, status_.active_period_size()); | 585 ASSERT_EQ(2, status_.active_period_size()); |
596 | 586 |
597 em::ActiveTimePeriod period0 = status_.active_period(0); | 587 em::ActiveTimePeriod period0 = status_.active_period(0); |
(...skipping 11 matching lines...) Expand all Loading... |
609 kMillisecondsPerDay); | 599 kMillisecondsPerDay); |
610 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(), | 600 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(), |
611 kMillisecondsPerDay); | 601 kMillisecondsPerDay); |
612 } | 602 } |
613 | 603 |
614 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { | 604 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { |
615 ui::IdleState test_states[] = { | 605 ui::IdleState test_states[] = { |
616 ui::IDLE_STATE_ACTIVE, | 606 ui::IDLE_STATE_ACTIVE, |
617 ui::IDLE_STATE_ACTIVE, | 607 ui::IDLE_STATE_ACTIVE, |
618 }; | 608 }; |
619 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 609 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
620 | 610 |
621 status_collector_->Simulate(test_states, 2); | 611 status_collector_->Simulate(test_states, 2); |
622 GetStatus(); | 612 GetStatus(); |
623 EXPECT_EQ(2 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 613 EXPECT_EQ(2 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
624 em::DeviceStatusReportRequest first_status(status_); | 614 em::DeviceStatusReportRequest first_status(status_); |
625 | 615 |
626 // The collector returns the same status again. | 616 // The collector returns the same status again. |
627 GetStatus(); | 617 GetStatus(); |
628 EXPECT_EQ(first_status.SerializeAsString(), status_.SerializeAsString()); | 618 EXPECT_EQ(first_status.SerializeAsString(), status_.SerializeAsString()); |
629 | 619 |
630 // After indicating a successful submit, the submitted status gets cleared, | 620 // After indicating a successful submit, the submitted status gets cleared, |
631 // but what got collected meanwhile sticks around. | 621 // but what got collected meanwhile sticks around. |
632 status_collector_->Simulate(test_states, 1); | 622 status_collector_->Simulate(test_states, 1); |
633 status_collector_->OnSubmittedSuccessfully(); | 623 status_collector_->OnSubmittedSuccessfully(); |
634 GetStatus(); | 624 GetStatus(); |
635 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 625 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
636 } | 626 } |
637 | 627 |
638 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { | 628 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { |
639 // Test that boot mode data is reported by default. | 629 // Test that boot mode data is reported by default. |
640 fake_statistics_provider_.SetMachineStatistic( | 630 fake_statistics_provider_.SetMachineStatistic( |
641 chromeos::system::kDevSwitchBootKey, | 631 chromeos::system::kDevSwitchBootKey, |
642 chromeos::system::kDevSwitchBootValueVerified); | 632 chromeos::system::kDevSwitchBootValueVerified); |
643 GetStatus(); | 633 GetStatus(); |
644 EXPECT_EQ("Verified", status_.boot_mode()); | 634 EXPECT_EQ("Verified", status_.boot_mode()); |
645 | 635 |
646 // Test that boot mode data is not reported if the pref turned off. | 636 // Test that boot mode data is not reported if the pref turned off. |
647 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, false); | 637 settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, false); |
648 | 638 |
649 GetStatus(); | 639 GetStatus(); |
650 EXPECT_FALSE(status_.has_boot_mode()); | 640 EXPECT_FALSE(status_.has_boot_mode()); |
651 | 641 |
652 // Turn the pref on, and check that the status is reported iff the | 642 // Turn the pref on, and check that the status is reported iff the |
653 // statistics provider returns valid data. | 643 // statistics provider returns valid data. |
654 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, true); | 644 settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, true); |
655 | 645 |
656 fake_statistics_provider_.SetMachineStatistic( | 646 fake_statistics_provider_.SetMachineStatistic( |
657 chromeos::system::kDevSwitchBootKey, "(error)"); | 647 chromeos::system::kDevSwitchBootKey, "(error)"); |
658 GetStatus(); | 648 GetStatus(); |
659 EXPECT_FALSE(status_.has_boot_mode()); | 649 EXPECT_FALSE(status_.has_boot_mode()); |
660 | 650 |
661 fake_statistics_provider_.SetMachineStatistic( | 651 fake_statistics_provider_.SetMachineStatistic( |
662 chromeos::system::kDevSwitchBootKey, " "); | 652 chromeos::system::kDevSwitchBootKey, " "); |
663 GetStatus(); | 653 GetStatus(); |
664 EXPECT_FALSE(status_.has_boot_mode()); | 654 EXPECT_FALSE(status_.has_boot_mode()); |
(...skipping 13 matching lines...) Expand all Loading... |
678 | 668 |
679 TEST_F(DeviceStatusCollectorTest, VersionInfo) { | 669 TEST_F(DeviceStatusCollectorTest, VersionInfo) { |
680 // Expect the version info to be reported by default. | 670 // Expect the version info to be reported by default. |
681 GetStatus(); | 671 GetStatus(); |
682 EXPECT_TRUE(status_.has_browser_version()); | 672 EXPECT_TRUE(status_.has_browser_version()); |
683 EXPECT_TRUE(status_.has_os_version()); | 673 EXPECT_TRUE(status_.has_os_version()); |
684 EXPECT_TRUE(status_.has_firmware_version()); | 674 EXPECT_TRUE(status_.has_firmware_version()); |
685 | 675 |
686 // When the pref to collect this data is not enabled, expect that none of | 676 // When the pref to collect this data is not enabled, expect that none of |
687 // the fields are present in the protobuf. | 677 // the fields are present in the protobuf. |
688 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, false); | 678 settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, false); |
689 GetStatus(); | 679 GetStatus(); |
690 EXPECT_FALSE(status_.has_browser_version()); | 680 EXPECT_FALSE(status_.has_browser_version()); |
691 EXPECT_FALSE(status_.has_os_version()); | 681 EXPECT_FALSE(status_.has_os_version()); |
692 EXPECT_FALSE(status_.has_firmware_version()); | 682 EXPECT_FALSE(status_.has_firmware_version()); |
693 | 683 |
694 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, true); | 684 settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, true); |
695 GetStatus(); | 685 GetStatus(); |
696 EXPECT_TRUE(status_.has_browser_version()); | 686 EXPECT_TRUE(status_.has_browser_version()); |
697 EXPECT_TRUE(status_.has_os_version()); | 687 EXPECT_TRUE(status_.has_os_version()); |
698 EXPECT_TRUE(status_.has_firmware_version()); | 688 EXPECT_TRUE(status_.has_firmware_version()); |
699 | 689 |
700 // Check that the browser version is not empty. OS version & firmware | 690 // Check that the browser version is not empty. OS version & firmware |
701 // don't have any reasonable values inside the unit test, so those | 691 // don't have any reasonable values inside the unit test, so those |
702 // aren't checked. | 692 // aren't checked. |
703 EXPECT_NE("", status_.browser_version()); | 693 EXPECT_NE("", status_.browser_version()); |
704 } | 694 } |
(...skipping 11 matching lines...) Expand all Loading... |
716 invalid_fix.timestamp = Time::Now(); | 706 invalid_fix.timestamp = Time::Now(); |
717 | 707 |
718 // Check that when device location reporting is disabled, no location is | 708 // Check that when device location reporting is disabled, no location is |
719 // reported. | 709 // reported. |
720 SetMockPositionToReturnNext(valid_fix); | 710 SetMockPositionToReturnNext(valid_fix); |
721 CheckThatNoLocationIsReported(); | 711 CheckThatNoLocationIsReported(); |
722 | 712 |
723 // Check that when device location reporting is enabled and a valid fix is | 713 // Check that when device location reporting is enabled and a valid fix is |
724 // available, the location is reported and is stored in local state. | 714 // available, the location is reported and is stored in local state. |
725 SetMockPositionToReturnNext(valid_fix); | 715 SetMockPositionToReturnNext(valid_fix); |
726 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); | 716 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, true); |
727 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); | 717 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); |
728 CheckThatAValidLocationIsReported(); | 718 CheckThatAValidLocationIsReported(); |
729 | 719 |
730 // Restart the status collector. Check that the last known location has been | 720 // Restart the status collector. Check that the last known location has been |
731 // retrieved from local state without requesting a geolocation update. | 721 // retrieved from local state without requesting a geolocation update. |
732 SetMockPositionToReturnNext(valid_fix); | 722 SetMockPositionToReturnNext(valid_fix); |
733 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); | 723 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); |
734 CheckThatAValidLocationIsReported(); | 724 CheckThatAValidLocationIsReported(); |
735 EXPECT_TRUE(mock_position_to_return_next.get()); | 725 EXPECT_TRUE(mock_position_to_return_next.get()); |
736 | 726 |
737 // Check that after disabling location reporting again, the last known | 727 // Check that after disabling location reporting again, the last known |
738 // location has been cleared from local state and is no longer reported. | 728 // location has been cleared from local state and is no longer reported. |
739 SetMockPositionToReturnNext(valid_fix); | 729 SetMockPositionToReturnNext(valid_fix); |
740 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, false); | 730 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, false); |
741 // Allow the new pref to propagate to the status collector. | 731 // Allow the new pref to propagate to the status collector. |
742 message_loop_.RunUntilIdle(); | 732 message_loop_.RunUntilIdle(); |
743 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); | 733 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); |
744 CheckThatNoLocationIsReported(); | 734 CheckThatNoLocationIsReported(); |
745 | 735 |
746 // Check that after enabling location reporting again, an error is reported | 736 // Check that after enabling location reporting again, an error is reported |
747 // if no valid fix is available. | 737 // if no valid fix is available. |
748 SetMockPositionToReturnNext(invalid_fix); | 738 SetMockPositionToReturnNext(invalid_fix); |
749 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); | 739 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, true); |
750 // Allow the new pref to propagate to the status collector. | 740 // Allow the new pref to propagate to the status collector. |
751 message_loop_.RunUntilIdle(); | 741 message_loop_.RunUntilIdle(); |
752 CheckThatALocationErrorIsReported(); | 742 CheckThatALocationErrorIsReported(); |
753 } | 743 } |
754 | 744 |
755 TEST_F(DeviceStatusCollectorTest, ReportUsers) { | 745 TEST_F(DeviceStatusCollectorTest, ReportUsers) { |
756 user_manager_->CreatePublicAccountUser("public@localhost"); | 746 user_manager_->CreatePublicAccountUser("public@localhost"); |
757 user_manager_->AddUser("user0@managed.com"); | 747 user_manager_->AddUser("user0@managed.com"); |
758 user_manager_->AddUser("user1@managed.com"); | 748 user_manager_->AddUser("user1@managed.com"); |
759 user_manager_->AddUser("user2@managed.com"); | 749 user_manager_->AddUser("user2@managed.com"); |
760 user_manager_->AddUser("user3@unmanaged.com"); | 750 user_manager_->AddUser("user3@unmanaged.com"); |
761 user_manager_->AddUser("user4@managed.com"); | 751 user_manager_->AddUser("user4@managed.com"); |
762 user_manager_->AddUser("user5@managed.com"); | 752 user_manager_->AddUser("user5@managed.com"); |
763 | 753 |
764 // Verify that users are reported by default. | 754 // Verify that users are reported by default. |
765 GetStatus(); | 755 GetStatus(); |
766 EXPECT_EQ(6, status_.user_size()); | 756 EXPECT_EQ(6, status_.user_size()); |
767 | 757 |
768 // Verify that users are reported after enabling the setting. | 758 // Verify that users are reported after enabling the setting. |
769 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, true); | 759 settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, true); |
770 GetStatus(); | 760 GetStatus(); |
771 EXPECT_EQ(6, status_.user_size()); | 761 EXPECT_EQ(6, status_.user_size()); |
772 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); | 762 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); |
773 EXPECT_EQ("user0@managed.com", status_.user(0).email()); | 763 EXPECT_EQ("user0@managed.com", status_.user(0).email()); |
774 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type()); | 764 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type()); |
775 EXPECT_EQ("user1@managed.com", status_.user(1).email()); | 765 EXPECT_EQ("user1@managed.com", status_.user(1).email()); |
776 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type()); | 766 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type()); |
777 EXPECT_EQ("user2@managed.com", status_.user(2).email()); | 767 EXPECT_EQ("user2@managed.com", status_.user(2).email()); |
778 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, status_.user(3).type()); | 768 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, status_.user(3).type()); |
779 EXPECT_FALSE(status_.user(3).has_email()); | 769 EXPECT_FALSE(status_.user(3).has_email()); |
780 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(4).type()); | 770 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(4).type()); |
781 EXPECT_EQ("user4@managed.com", status_.user(4).email()); | 771 EXPECT_EQ("user4@managed.com", status_.user(4).email()); |
782 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(5).type()); | 772 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(5).type()); |
783 EXPECT_EQ("user5@managed.com", status_.user(5).email()); | 773 EXPECT_EQ("user5@managed.com", status_.user(5).email()); |
784 | 774 |
785 // Verify that users are no longer reported if setting is disabled. | 775 // Verify that users are no longer reported if setting is disabled. |
786 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, false); | 776 settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, false); |
787 GetStatus(); | 777 GetStatus(); |
788 EXPECT_EQ(0, status_.user_size()); | 778 EXPECT_EQ(0, status_.user_size()); |
789 } | 779 } |
790 | 780 |
791 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { | 781 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { |
792 std::vector<std::string> expected_mount_points; | 782 std::vector<std::string> expected_mount_points; |
793 std::vector<em::VolumeInfo> expected_volume_info; | 783 std::vector<em::VolumeInfo> expected_volume_info; |
794 int size = 12345678; | 784 int size = 12345678; |
795 for (const auto& mount_info : | 785 for (const auto& mount_info : |
796 DiskMountManager::GetInstance()->mount_points()) { | 786 DiskMountManager::GetInstance()->mount_points()) { |
(...skipping 24 matching lines...) Expand all Loading... |
821 EXPECT_EQ(expected_info.storage_free(), info.storage_free()); | 811 EXPECT_EQ(expected_info.storage_free(), info.storage_free()); |
822 found = true; | 812 found = true; |
823 break; | 813 break; |
824 } | 814 } |
825 } | 815 } |
826 EXPECT_TRUE(found) << "No matching VolumeInfo for " | 816 EXPECT_TRUE(found) << "No matching VolumeInfo for " |
827 << expected_info.volume_id(); | 817 << expected_info.volume_id(); |
828 } | 818 } |
829 | 819 |
830 // Now turn off hardware status reporting - should have no data. | 820 // Now turn off hardware status reporting - should have no data. |
831 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 821 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); |
832 GetStatus(); | 822 GetStatus(); |
833 EXPECT_EQ(0, status_.volume_info_size()); | 823 EXPECT_EQ(0, status_.volume_info_size()); |
834 } | 824 } |
835 | 825 |
836 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { | 826 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { |
837 status_collector_->RefreshSampleResourceUsage(); | 827 status_collector_->RefreshSampleResourceUsage(); |
838 GetStatus(); | 828 GetStatus(); |
839 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), | 829 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), |
840 status_.system_ram_free().size()); | 830 status_.system_ram_free().size()); |
841 EXPECT_TRUE(status_.has_system_ram_total()); | 831 EXPECT_TRUE(status_.has_system_ram_total()); |
(...skipping 15 matching lines...) Expand all Loading... |
857 // Now set CPU usage to 0. | 847 // Now set CPU usage to 0. |
858 const int idle_cpu_usage = 0; | 848 const int idle_cpu_usage = 0; |
859 status_collector_->set_mock_cpu_usage(idle_cpu_usage, 2); | 849 status_collector_->set_mock_cpu_usage(idle_cpu_usage, 2); |
860 GetStatus(); | 850 GetStatus(); |
861 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), | 851 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), |
862 status_.cpu_utilization_pct().size()); | 852 status_.cpu_utilization_pct().size()); |
863 for (const auto utilization : status_.cpu_utilization_pct()) | 853 for (const auto utilization : status_.cpu_utilization_pct()) |
864 EXPECT_EQ(idle_cpu_usage, utilization); | 854 EXPECT_EQ(idle_cpu_usage, utilization); |
865 | 855 |
866 // Turning off hardware reporting should not report CPU utilization. | 856 // Turning off hardware reporting should not report CPU utilization. |
867 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 857 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); |
868 GetStatus(); | 858 GetStatus(); |
869 EXPECT_EQ(0, status_.cpu_utilization_pct().size()); | 859 EXPECT_EQ(0, status_.cpu_utilization_pct().size()); |
870 } | 860 } |
871 | 861 |
872 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { | 862 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { |
873 // Should not report session status if we don't have an active kiosk app. | 863 // Should not report session status if we don't have an active kiosk app. |
874 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 864 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); |
875 em::SessionStatusReportRequest session_status; | 865 em::SessionStatusReportRequest session_status; |
876 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); | 866 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); |
877 } | 867 } |
878 | 868 |
879 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { | 869 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { |
880 // Should not report session status if session status reporting is disabled. | 870 // Should not report session status if session status reporting is disabled. |
881 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, false); | 871 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); |
882 status_collector_->set_kiosk_account(make_scoped_ptr( | 872 status_collector_->set_kiosk_account(make_scoped_ptr( |
883 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 873 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); |
884 // Set up a device-local account for single-app kiosk mode. | 874 // Set up a device-local account for single-app kiosk mode. |
885 MockRunningKioskApp(fake_device_local_account_); | 875 MockRunningKioskApp(fake_device_local_account_); |
886 | 876 |
887 em::SessionStatusReportRequest session_status; | 877 em::SessionStatusReportRequest session_status; |
888 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); | 878 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); |
889 } | 879 } |
890 | 880 |
891 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { | 881 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { |
892 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 882 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); |
893 status_collector_->set_kiosk_account(make_scoped_ptr( | 883 status_collector_->set_kiosk_account(make_scoped_ptr( |
894 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 884 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); |
895 | 885 |
896 // Set up a device-local account for single-app kiosk mode. | 886 // Set up a device-local account for single-app kiosk mode. |
897 MockRunningKioskApp(fake_device_local_account_); | 887 MockRunningKioskApp(fake_device_local_account_); |
898 | 888 |
899 em::SessionStatusReportRequest session_status; | 889 em::SessionStatusReportRequest session_status; |
900 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status)); | 890 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status)); |
901 ASSERT_EQ(1, session_status.installed_apps_size()); | 891 ASSERT_EQ(1, session_status.installed_apps_size()); |
902 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id()); | 892 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id()); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 // Mock that we are in kiosk mode so we report network state. | 1105 // Mock that we are in kiosk mode so we report network state. |
1116 status_collector_->set_kiosk_account(make_scoped_ptr( | 1106 status_collector_->set_kiosk_account(make_scoped_ptr( |
1117 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 1107 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); |
1118 | 1108 |
1119 // Interfaces should be reported by default. | 1109 // Interfaces should be reported by default. |
1120 GetStatus(); | 1110 GetStatus(); |
1121 EXPECT_LT(0, status_.network_interface_size()); | 1111 EXPECT_LT(0, status_.network_interface_size()); |
1122 EXPECT_LT(0, status_.network_state_size()); | 1112 EXPECT_LT(0, status_.network_state_size()); |
1123 | 1113 |
1124 // No interfaces should be reported if the policy is off. | 1114 // No interfaces should be reported if the policy is off. |
1125 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); | 1115 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); |
1126 GetStatus(); | 1116 GetStatus(); |
1127 EXPECT_EQ(0, status_.network_interface_size()); | 1117 EXPECT_EQ(0, status_.network_interface_size()); |
1128 EXPECT_EQ(0, status_.network_state_size()); | 1118 EXPECT_EQ(0, status_.network_state_size()); |
1129 | 1119 |
1130 // Switch the policy on and verify the interface list is present. | 1120 // Switch the policy on and verify the interface list is present. |
1131 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); | 1121 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); |
1132 GetStatus(); | 1122 GetStatus(); |
1133 | 1123 |
1134 int count = 0; | 1124 int count = 0; |
1135 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { | 1125 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { |
1136 const FakeDeviceData& dev = kFakeDevices[i]; | 1126 const FakeDeviceData& dev = kFakeDevices[i]; |
1137 if (dev.expected_type == -1) | 1127 if (dev.expected_type == -1) |
1138 continue; | 1128 continue; |
1139 | 1129 |
1140 // Find the corresponding entry in reporting data. | 1130 // Find the corresponding entry in reporting data. |
1141 bool found_match = false; | 1131 bool found_match = false; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 found_match = true; | 1175 found_match = true; |
1186 break; | 1176 break; |
1187 } | 1177 } |
1188 } | 1178 } |
1189 EXPECT_TRUE(found_match) << "No matching state for fake network " | 1179 EXPECT_TRUE(found_match) << "No matching state for fake network " |
1190 << " (" << state.name << ")"; | 1180 << " (" << state.name << ")"; |
1191 } | 1181 } |
1192 } | 1182 } |
1193 | 1183 |
1194 } // namespace policy | 1184 } // namespace policy |
OLD | NEW |