| 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/settings_provider_test_base.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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return volume_info; | 222 return volume_info; |
| 225 } | 223 } |
| 226 | 224 |
| 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, |
| 233 public chromeos::SettingsProviderTestBase { |
| 235 public: | 234 public: |
| 236 DeviceStatusCollectorTest() | 235 DeviceStatusCollectorTest() |
| 237 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 236 : chromeos::SettingsProviderTestBase(false), |
| 238 file_thread_(content::BrowserThread::FILE, &message_loop_), | 237 ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 239 io_thread_(content::BrowserThread::IO, &message_loop_), | 238 file_thread_(content::BrowserThread::FILE, &message_loop_), |
| 240 install_attributes_("managed.com", | 239 io_thread_(content::BrowserThread::IO, &message_loop_), |
| 241 "user@managed.com", | 240 install_attributes_("managed.com", |
| 242 "device_id", | 241 "user@managed.com", |
| 243 DEVICE_MODE_ENTERPRISE), | 242 "device_id", |
| 244 user_manager_(new chromeos::MockUserManager()), | 243 DEVICE_MODE_ENTERPRISE), |
| 245 user_manager_enabler_(user_manager_), | 244 user_manager_(new chromeos::MockUserManager()), |
| 246 fake_device_local_account_( | 245 user_manager_enabler_(user_manager_), |
| 247 policy::DeviceLocalAccount::TYPE_KIOSK_APP, | 246 fake_device_local_account_(policy::DeviceLocalAccount::TYPE_KIOSK_APP, |
| 248 kKioskAccountId, | 247 kKioskAccountId, |
| 249 kKioskAppId, | 248 kKioskAppId, |
| 250 std::string() /* kiosk_app_update_url */) { | 249 std::string() /* kiosk_app_update_url */) { |
| 251 // Run this test with a well-known timezone so that Time::LocalMidnight() | 250 // Run this test with a well-known timezone so that Time::LocalMidnight() |
| 252 // returns the same values on all machines. | 251 // returns the same values on all machines. |
| 253 scoped_ptr<base::Environment> env(base::Environment::Create()); | 252 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 254 env->SetVar("TZ", "UTC"); | 253 env->SetVar("TZ", "UTC"); |
| 255 | 254 |
| 256 // Initialize our mock mounted disk volumes. | 255 // Initialize our mock mounted disk volumes. |
| 257 scoped_ptr<chromeos::disks::MockDiskMountManager> mock_disk_mount_manager = | 256 scoped_ptr<chromeos::disks::MockDiskMountManager> mock_disk_mount_manager = |
| 258 make_scoped_ptr(new chromeos::disks::MockDiskMountManager()); | 257 make_scoped_ptr(new chromeos::disks::MockDiskMountManager()); |
| 259 AddMountPoint("/mount/volume1"); | 258 AddMountPoint("/mount/volume1"); |
| 260 AddMountPoint("/mount/volume2"); | 259 AddMountPoint("/mount/volume2"); |
| 261 EXPECT_CALL(*mock_disk_mount_manager, mount_points()) | 260 EXPECT_CALL(*mock_disk_mount_manager, mount_points()) |
| 262 .WillRepeatedly(ReturnRef(mount_point_map_)); | 261 .WillRepeatedly(ReturnRef(mount_point_map_)); |
| 263 | 262 |
| 264 // DiskMountManager takes ownership of the MockDiskMountManager. | 263 // DiskMountManager takes ownership of the MockDiskMountManager. |
| 265 DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release()); | 264 DiskMountManager::InitializeForTesting(mock_disk_mount_manager.release()); |
| 266 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry()); | 265 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry()); |
| 267 | 266 |
| 268 // Remove the real DeviceSettingsProvider and replace it with a stub. | 267 ReplaceProvider(chromeos::kReportDeviceActivityTimes); |
| 269 cros_settings_ = chromeos::CrosSettings::Get(); | 268 InitOwnerSettingsService(nullptr); |
| 270 device_settings_provider_ = | |
| 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 | 286 |
| 294 // Restore the real DeviceSettingsProvider. | 287 RestoreProvider(); |
| 295 EXPECT_TRUE( | |
| 296 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); | |
| 297 cros_settings_->AddSettingsProvider(device_settings_provider_); | |
| 298 } | 288 } |
| 299 | 289 |
| 300 void SetUp() override { | 290 void SetUp() override { |
| 301 // Disable network interface reporting since it requires additional setup. | 291 // Disable network interface reporting since it requires additional setup. |
| 302 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); | 292 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, |
| 293 false); |
| 303 } | 294 } |
| 304 | 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_, |
| (...skipping 41 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_; | |
| 391 chromeos::CrosSettingsProvider* device_settings_provider_; | |
| 392 chromeos::StubCrosSettingsProvider stub_settings_provider_; | |
| 393 chromeos::MockUserManager* user_manager_; | 381 chromeos::MockUserManager* user_manager_; |
| 394 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 382 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 395 em::DeviceStatusReportRequest status_; | 383 em::DeviceStatusReportRequest status_; |
| 396 scoped_ptr<TestingDeviceStatusCollector> status_collector_; | 384 scoped_ptr<TestingDeviceStatusCollector> status_collector_; |
| 397 const policy::DeviceLocalAccount fake_device_local_account_; | 385 const policy::DeviceLocalAccount fake_device_local_account_; |
| 398 }; | 386 }; |
| 399 | 387 |
| 400 TEST_F(DeviceStatusCollectorTest, AllIdle) { | 388 TEST_F(DeviceStatusCollectorTest, AllIdle) { |
| 401 ui::IdleState test_states[] = { | 389 ui::IdleState test_states[] = { |
| 402 ui::IDLE_STATE_IDLE, | 390 ui::IDLE_STATE_IDLE, |
| 403 ui::IDLE_STATE_IDLE, | 391 ui::IDLE_STATE_IDLE, |
| 404 ui::IDLE_STATE_IDLE | 392 ui::IDLE_STATE_IDLE |
| 405 }; | 393 }; |
| 406 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 394 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 395 true); |
| 407 | 396 |
| 408 // Test reporting with no data. | 397 // Test reporting with no data. |
| 409 GetStatus(); | 398 GetStatus(); |
| 410 EXPECT_EQ(0, status_.active_period_size()); | 399 EXPECT_EQ(0, status_.active_period_size()); |
| 411 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 400 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
| 412 | 401 |
| 413 // Test reporting with a single idle sample. | 402 // Test reporting with a single idle sample. |
| 414 status_collector_->Simulate(test_states, 1); | 403 status_collector_->Simulate(test_states, 1); |
| 415 GetStatus(); | 404 GetStatus(); |
| 416 EXPECT_EQ(0, status_.active_period_size()); | 405 EXPECT_EQ(0, status_.active_period_size()); |
| 417 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 406 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
| 418 | 407 |
| 419 // Test reporting with multiple consecutive idle samples. | 408 // Test reporting with multiple consecutive idle samples. |
| 420 status_collector_->Simulate(test_states, | 409 status_collector_->Simulate(test_states, |
| 421 sizeof(test_states) / sizeof(ui::IdleState)); | 410 sizeof(test_states) / sizeof(ui::IdleState)); |
| 422 GetStatus(); | 411 GetStatus(); |
| 423 EXPECT_EQ(0, status_.active_period_size()); | 412 EXPECT_EQ(0, status_.active_period_size()); |
| 424 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 413 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
| 425 } | 414 } |
| 426 | 415 |
| 427 TEST_F(DeviceStatusCollectorTest, AllActive) { | 416 TEST_F(DeviceStatusCollectorTest, AllActive) { |
| 428 ui::IdleState test_states[] = { | 417 ui::IdleState test_states[] = { |
| 429 ui::IDLE_STATE_ACTIVE, | 418 ui::IDLE_STATE_ACTIVE, |
| 430 ui::IDLE_STATE_ACTIVE, | 419 ui::IDLE_STATE_ACTIVE, |
| 431 ui::IDLE_STATE_ACTIVE | 420 ui::IDLE_STATE_ACTIVE |
| 432 }; | 421 }; |
| 433 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 422 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 423 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 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 451 true); |
| 461 status_collector_->Simulate(test_states, | 452 status_collector_->Simulate(test_states, |
| 462 sizeof(test_states) / sizeof(ui::IdleState)); | 453 sizeof(test_states) / sizeof(ui::IdleState)); |
| 463 GetStatus(); | 454 GetStatus(); |
| 464 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 455 EXPECT_EQ(4 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
| 465 } | 456 } |
| 466 | 457 |
| 467 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { | 458 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { |
| 468 ui::IdleState test_states[] = { | 459 ui::IdleState test_states[] = { |
| 469 ui::IDLE_STATE_ACTIVE, | 460 ui::IDLE_STATE_ACTIVE, |
| 470 ui::IDLE_STATE_IDLE, | 461 ui::IDLE_STATE_IDLE, |
| 471 ui::IDLE_STATE_ACTIVE, | 462 ui::IDLE_STATE_ACTIVE, |
| 472 ui::IDLE_STATE_ACTIVE, | 463 ui::IDLE_STATE_ACTIVE, |
| 473 ui::IDLE_STATE_IDLE, | 464 ui::IDLE_STATE_IDLE, |
| 474 ui::IDLE_STATE_IDLE | 465 ui::IDLE_STATE_IDLE |
| 475 }; | 466 }; |
| 476 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 467 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 468 true); |
| 477 status_collector_->Simulate(test_states, | 469 status_collector_->Simulate(test_states, |
| 478 sizeof(test_states) / sizeof(ui::IdleState)); | 470 sizeof(test_states) / sizeof(ui::IdleState)); |
| 479 | 471 |
| 480 // Process the list a second time after restarting the collector. It should be | 472 // 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 | 473 // able to count the active periods found by the original collector, because |
| 482 // the results are stored in a pref. | 474 // the results are stored in a pref. |
| 483 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); | 475 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); |
| 484 status_collector_->Simulate(test_states, | 476 status_collector_->Simulate(test_states, |
| 485 sizeof(test_states) / sizeof(ui::IdleState)); | 477 sizeof(test_states) / sizeof(ui::IdleState)); |
| 486 | 478 |
| 487 GetStatus(); | 479 GetStatus(); |
| 488 EXPECT_EQ(6 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 480 EXPECT_EQ(6 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
| 489 } | 481 } |
| 490 | 482 |
| 491 TEST_F(DeviceStatusCollectorTest, Times) { | 483 TEST_F(DeviceStatusCollectorTest, Times) { |
| 492 ui::IdleState test_states[] = { | 484 ui::IdleState test_states[] = { |
| 493 ui::IDLE_STATE_ACTIVE, | 485 ui::IDLE_STATE_ACTIVE, |
| 494 ui::IDLE_STATE_IDLE, | 486 ui::IDLE_STATE_IDLE, |
| 495 ui::IDLE_STATE_ACTIVE, | 487 ui::IDLE_STATE_ACTIVE, |
| 496 ui::IDLE_STATE_ACTIVE, | 488 ui::IDLE_STATE_ACTIVE, |
| 497 ui::IDLE_STATE_IDLE, | 489 ui::IDLE_STATE_IDLE, |
| 498 ui::IDLE_STATE_IDLE | 490 ui::IDLE_STATE_IDLE |
| 499 }; | 491 }; |
| 500 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 492 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 493 true); |
| 501 status_collector_->Simulate(test_states, | 494 status_collector_->Simulate(test_states, |
| 502 sizeof(test_states) / sizeof(ui::IdleState)); | 495 sizeof(test_states) / sizeof(ui::IdleState)); |
| 503 GetStatus(); | 496 GetStatus(); |
| 504 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 497 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
| 505 } | 498 } |
| 506 | 499 |
| 507 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { | 500 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { |
| 508 ui::IdleState test_states[] = { | 501 ui::IdleState test_states[] = { |
| 509 ui::IDLE_STATE_ACTIVE, | 502 ui::IDLE_STATE_ACTIVE, |
| 510 ui::IDLE_STATE_IDLE | 503 ui::IDLE_STATE_IDLE |
| 511 }; | 504 }; |
| 512 const int kMaxDays = 10; | 505 const int kMaxDays = 10; |
| 513 | 506 |
| 514 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 507 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 508 true); |
| 515 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); | 509 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); |
| 516 status_collector_->set_max_stored_future_activity_days(1); | 510 status_collector_->set_max_stored_future_activity_days(1); |
| 517 Time baseline = Time::Now().LocalMidnight(); | 511 Time baseline = Time::Now().LocalMidnight(); |
| 518 | 512 |
| 519 // Simulate 12 active periods. | 513 // Simulate 12 active periods. |
| 520 for (int i = 0; i < kMaxDays + 2; i++) { | 514 for (int i = 0; i < kMaxDays + 2; i++) { |
| 521 status_collector_->Simulate(test_states, | 515 status_collector_->Simulate(test_states, |
| 522 sizeof(test_states) / sizeof(ui::IdleState)); | 516 sizeof(test_states) / sizeof(ui::IdleState)); |
| 523 // Advance the simulated clock by a day. | 517 // Advance the simulated clock by a day. |
| 524 baseline += TimeDelta::FromDays(1); | 518 baseline += TimeDelta::FromDays(1); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 }; | 553 }; |
| 560 status_collector_->Simulate(test_states, | 554 status_collector_->Simulate(test_states, |
| 561 sizeof(test_states) / sizeof(ui::IdleState)); | 555 sizeof(test_states) / sizeof(ui::IdleState)); |
| 562 GetStatus(); | 556 GetStatus(); |
| 563 EXPECT_EQ(1, status_.active_period_size()); | 557 EXPECT_EQ(1, status_.active_period_size()); |
| 564 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 558 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
| 565 } | 559 } |
| 566 | 560 |
| 567 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { | 561 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { |
| 568 // Device activity times should not be reported if explicitly disabled. | 562 // Device activity times should not be reported if explicitly disabled. |
| 569 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, false); | 563 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 564 false); |
| 570 | 565 |
| 571 ui::IdleState test_states[] = { | 566 ui::IdleState test_states[] = { |
| 572 ui::IDLE_STATE_ACTIVE, | 567 ui::IDLE_STATE_ACTIVE, |
| 573 ui::IDLE_STATE_ACTIVE, | 568 ui::IDLE_STATE_ACTIVE, |
| 574 ui::IDLE_STATE_ACTIVE | 569 ui::IDLE_STATE_ACTIVE |
| 575 }; | 570 }; |
| 576 status_collector_->Simulate(test_states, | 571 status_collector_->Simulate(test_states, |
| 577 sizeof(test_states) / sizeof(ui::IdleState)); | 572 sizeof(test_states) / sizeof(ui::IdleState)); |
| 578 GetStatus(); | 573 GetStatus(); |
| 579 EXPECT_EQ(0, status_.active_period_size()); | 574 EXPECT_EQ(0, status_.active_period_size()); |
| 580 EXPECT_EQ(0, GetActiveMilliseconds(status_)); | 575 EXPECT_EQ(0, GetActiveMilliseconds(status_)); |
| 581 } | 576 } |
| 582 | 577 |
| 583 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { | 578 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { |
| 584 ui::IdleState test_states[] = { | 579 ui::IdleState test_states[] = { |
| 585 ui::IDLE_STATE_ACTIVE | 580 ui::IDLE_STATE_ACTIVE |
| 586 }; | 581 }; |
| 587 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 582 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 583 true); |
| 588 | 584 |
| 589 // Set the baseline time to 10 seconds after midnight. | 585 // Set the baseline time to 10 seconds after midnight. |
| 590 status_collector_->SetBaselineTime( | 586 status_collector_->SetBaselineTime( |
| 591 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); | 587 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); |
| 592 | 588 |
| 593 status_collector_->Simulate(test_states, 1); | 589 status_collector_->Simulate(test_states, 1); |
| 594 GetStatus(); | 590 GetStatus(); |
| 595 ASSERT_EQ(2, status_.active_period_size()); | 591 ASSERT_EQ(2, status_.active_period_size()); |
| 596 | 592 |
| 597 em::ActiveTimePeriod period0 = status_.active_period(0); | 593 em::ActiveTimePeriod period0 = status_.active_period(0); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 609 kMillisecondsPerDay); | 605 kMillisecondsPerDay); |
| 610 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(), | 606 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(), |
| 611 kMillisecondsPerDay); | 607 kMillisecondsPerDay); |
| 612 } | 608 } |
| 613 | 609 |
| 614 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { | 610 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { |
| 615 ui::IdleState test_states[] = { | 611 ui::IdleState test_states[] = { |
| 616 ui::IDLE_STATE_ACTIVE, | 612 ui::IDLE_STATE_ACTIVE, |
| 617 ui::IDLE_STATE_ACTIVE, | 613 ui::IDLE_STATE_ACTIVE, |
| 618 }; | 614 }; |
| 619 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 615 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceActivityTimes, |
| 616 true); |
| 620 | 617 |
| 621 status_collector_->Simulate(test_states, 2); | 618 status_collector_->Simulate(test_states, 2); |
| 622 GetStatus(); | 619 GetStatus(); |
| 623 EXPECT_EQ(2 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 620 EXPECT_EQ(2 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
| 624 em::DeviceStatusReportRequest first_status(status_); | 621 em::DeviceStatusReportRequest first_status(status_); |
| 625 | 622 |
| 626 // The collector returns the same status again. | 623 // The collector returns the same status again. |
| 627 GetStatus(); | 624 GetStatus(); |
| 628 EXPECT_EQ(first_status.SerializeAsString(), status_.SerializeAsString()); | 625 EXPECT_EQ(first_status.SerializeAsString(), status_.SerializeAsString()); |
| 629 | 626 |
| 630 // After indicating a successful submit, the submitted status gets cleared, | 627 // After indicating a successful submit, the submitted status gets cleared, |
| 631 // but what got collected meanwhile sticks around. | 628 // but what got collected meanwhile sticks around. |
| 632 status_collector_->Simulate(test_states, 1); | 629 status_collector_->Simulate(test_states, 1); |
| 633 status_collector_->OnSubmittedSuccessfully(); | 630 status_collector_->OnSubmittedSuccessfully(); |
| 634 GetStatus(); | 631 GetStatus(); |
| 635 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 632 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
| 636 } | 633 } |
| 637 | 634 |
| 638 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { | 635 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { |
| 639 // Test that boot mode data is reported by default. | 636 // Test that boot mode data is reported by default. |
| 640 fake_statistics_provider_.SetMachineStatistic( | 637 fake_statistics_provider_.SetMachineStatistic( |
| 641 chromeos::system::kDevSwitchBootKey, | 638 chromeos::system::kDevSwitchBootKey, |
| 642 chromeos::system::kDevSwitchBootValueVerified); | 639 chromeos::system::kDevSwitchBootValueVerified); |
| 643 GetStatus(); | 640 GetStatus(); |
| 644 EXPECT_EQ("Verified", status_.boot_mode()); | 641 EXPECT_EQ("Verified", status_.boot_mode()); |
| 645 | 642 |
| 646 // Test that boot mode data is not reported if the pref turned off. | 643 // Test that boot mode data is not reported if the pref turned off. |
| 647 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, false); | 644 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceBootMode, false); |
| 648 | 645 |
| 649 GetStatus(); | 646 GetStatus(); |
| 650 EXPECT_FALSE(status_.has_boot_mode()); | 647 EXPECT_FALSE(status_.has_boot_mode()); |
| 651 | 648 |
| 652 // Turn the pref on, and check that the status is reported iff the | 649 // Turn the pref on, and check that the status is reported iff the |
| 653 // statistics provider returns valid data. | 650 // statistics provider returns valid data. |
| 654 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, true); | 651 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceBootMode, true); |
| 655 | 652 |
| 656 fake_statistics_provider_.SetMachineStatistic( | 653 fake_statistics_provider_.SetMachineStatistic( |
| 657 chromeos::system::kDevSwitchBootKey, "(error)"); | 654 chromeos::system::kDevSwitchBootKey, "(error)"); |
| 658 GetStatus(); | 655 GetStatus(); |
| 659 EXPECT_FALSE(status_.has_boot_mode()); | 656 EXPECT_FALSE(status_.has_boot_mode()); |
| 660 | 657 |
| 661 fake_statistics_provider_.SetMachineStatistic( | 658 fake_statistics_provider_.SetMachineStatistic( |
| 662 chromeos::system::kDevSwitchBootKey, " "); | 659 chromeos::system::kDevSwitchBootKey, " "); |
| 663 GetStatus(); | 660 GetStatus(); |
| 664 EXPECT_FALSE(status_.has_boot_mode()); | 661 EXPECT_FALSE(status_.has_boot_mode()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 678 | 675 |
| 679 TEST_F(DeviceStatusCollectorTest, VersionInfo) { | 676 TEST_F(DeviceStatusCollectorTest, VersionInfo) { |
| 680 // Expect the version info to be reported by default. | 677 // Expect the version info to be reported by default. |
| 681 GetStatus(); | 678 GetStatus(); |
| 682 EXPECT_TRUE(status_.has_browser_version()); | 679 EXPECT_TRUE(status_.has_browser_version()); |
| 683 EXPECT_TRUE(status_.has_os_version()); | 680 EXPECT_TRUE(status_.has_os_version()); |
| 684 EXPECT_TRUE(status_.has_firmware_version()); | 681 EXPECT_TRUE(status_.has_firmware_version()); |
| 685 | 682 |
| 686 // When the pref to collect this data is not enabled, expect that none of | 683 // When the pref to collect this data is not enabled, expect that none of |
| 687 // the fields are present in the protobuf. | 684 // the fields are present in the protobuf. |
| 688 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, false); | 685 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceVersionInfo, false); |
| 689 GetStatus(); | 686 GetStatus(); |
| 690 EXPECT_FALSE(status_.has_browser_version()); | 687 EXPECT_FALSE(status_.has_browser_version()); |
| 691 EXPECT_FALSE(status_.has_os_version()); | 688 EXPECT_FALSE(status_.has_os_version()); |
| 692 EXPECT_FALSE(status_.has_firmware_version()); | 689 EXPECT_FALSE(status_.has_firmware_version()); |
| 693 | 690 |
| 694 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, true); | 691 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceVersionInfo, true); |
| 695 GetStatus(); | 692 GetStatus(); |
| 696 EXPECT_TRUE(status_.has_browser_version()); | 693 EXPECT_TRUE(status_.has_browser_version()); |
| 697 EXPECT_TRUE(status_.has_os_version()); | 694 EXPECT_TRUE(status_.has_os_version()); |
| 698 EXPECT_TRUE(status_.has_firmware_version()); | 695 EXPECT_TRUE(status_.has_firmware_version()); |
| 699 | 696 |
| 700 // Check that the browser version is not empty. OS version & firmware | 697 // Check that the browser version is not empty. OS version & firmware |
| 701 // don't have any reasonable values inside the unit test, so those | 698 // don't have any reasonable values inside the unit test, so those |
| 702 // aren't checked. | 699 // aren't checked. |
| 703 EXPECT_NE("", status_.browser_version()); | 700 EXPECT_NE("", status_.browser_version()); |
| 704 } | 701 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 716 invalid_fix.timestamp = Time::Now(); | 713 invalid_fix.timestamp = Time::Now(); |
| 717 | 714 |
| 718 // Check that when device location reporting is disabled, no location is | 715 // Check that when device location reporting is disabled, no location is |
| 719 // reported. | 716 // reported. |
| 720 SetMockPositionToReturnNext(valid_fix); | 717 SetMockPositionToReturnNext(valid_fix); |
| 721 CheckThatNoLocationIsReported(); | 718 CheckThatNoLocationIsReported(); |
| 722 | 719 |
| 723 // Check that when device location reporting is enabled and a valid fix is | 720 // 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. | 721 // available, the location is reported and is stored in local state. |
| 725 SetMockPositionToReturnNext(valid_fix); | 722 SetMockPositionToReturnNext(valid_fix); |
| 726 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); | 723 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceLocation, true); |
| 727 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); | 724 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); |
| 728 CheckThatAValidLocationIsReported(); | 725 CheckThatAValidLocationIsReported(); |
| 729 | 726 |
| 730 // Restart the status collector. Check that the last known location has been | 727 // Restart the status collector. Check that the last known location has been |
| 731 // retrieved from local state without requesting a geolocation update. | 728 // retrieved from local state without requesting a geolocation update. |
| 732 SetMockPositionToReturnNext(valid_fix); | 729 SetMockPositionToReturnNext(valid_fix); |
| 733 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); | 730 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo)); |
| 734 CheckThatAValidLocationIsReported(); | 731 CheckThatAValidLocationIsReported(); |
| 735 EXPECT_TRUE(mock_position_to_return_next.get()); | 732 EXPECT_TRUE(mock_position_to_return_next.get()); |
| 736 | 733 |
| 737 // Check that after disabling location reporting again, the last known | 734 // Check that after disabling location reporting again, the last known |
| 738 // location has been cleared from local state and is no longer reported. | 735 // location has been cleared from local state and is no longer reported. |
| 739 SetMockPositionToReturnNext(valid_fix); | 736 SetMockPositionToReturnNext(valid_fix); |
| 740 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, false); | 737 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceLocation, false); |
| 741 // Allow the new pref to propagate to the status collector. | 738 // Allow the new pref to propagate to the status collector. |
| 742 message_loop_.RunUntilIdle(); | 739 message_loop_.RunUntilIdle(); |
| 743 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); | 740 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); |
| 744 CheckThatNoLocationIsReported(); | 741 CheckThatNoLocationIsReported(); |
| 745 | 742 |
| 746 // Check that after enabling location reporting again, an error is reported | 743 // Check that after enabling location reporting again, an error is reported |
| 747 // if no valid fix is available. | 744 // if no valid fix is available. |
| 748 SetMockPositionToReturnNext(invalid_fix); | 745 SetMockPositionToReturnNext(invalid_fix); |
| 749 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); | 746 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceLocation, true); |
| 750 // Allow the new pref to propagate to the status collector. | 747 // Allow the new pref to propagate to the status collector. |
| 751 message_loop_.RunUntilIdle(); | 748 message_loop_.RunUntilIdle(); |
| 752 CheckThatALocationErrorIsReported(); | 749 CheckThatALocationErrorIsReported(); |
| 753 } | 750 } |
| 754 | 751 |
| 755 TEST_F(DeviceStatusCollectorTest, ReportUsers) { | 752 TEST_F(DeviceStatusCollectorTest, ReportUsers) { |
| 756 user_manager_->CreatePublicAccountUser("public@localhost"); | 753 user_manager_->CreatePublicAccountUser("public@localhost"); |
| 757 user_manager_->AddUser("user0@managed.com"); | 754 user_manager_->AddUser("user0@managed.com"); |
| 758 user_manager_->AddUser("user1@managed.com"); | 755 user_manager_->AddUser("user1@managed.com"); |
| 759 user_manager_->AddUser("user2@managed.com"); | 756 user_manager_->AddUser("user2@managed.com"); |
| 760 user_manager_->AddUser("user3@unmanaged.com"); | 757 user_manager_->AddUser("user3@unmanaged.com"); |
| 761 user_manager_->AddUser("user4@managed.com"); | 758 user_manager_->AddUser("user4@managed.com"); |
| 762 user_manager_->AddUser("user5@managed.com"); | 759 user_manager_->AddUser("user5@managed.com"); |
| 763 | 760 |
| 764 // Verify that users are reported by default. | 761 // Verify that users are reported by default. |
| 765 GetStatus(); | 762 GetStatus(); |
| 766 EXPECT_EQ(6, status_.user_size()); | 763 EXPECT_EQ(6, status_.user_size()); |
| 767 | 764 |
| 768 // Verify that users are reported after enabling the setting. | 765 // Verify that users are reported after enabling the setting. |
| 769 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, true); | 766 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceUsers, true); |
| 770 GetStatus(); | 767 GetStatus(); |
| 771 EXPECT_EQ(6, status_.user_size()); | 768 EXPECT_EQ(6, status_.user_size()); |
| 772 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); | 769 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); |
| 773 EXPECT_EQ("user0@managed.com", status_.user(0).email()); | 770 EXPECT_EQ("user0@managed.com", status_.user(0).email()); |
| 774 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type()); | 771 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type()); |
| 775 EXPECT_EQ("user1@managed.com", status_.user(1).email()); | 772 EXPECT_EQ("user1@managed.com", status_.user(1).email()); |
| 776 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type()); | 773 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type()); |
| 777 EXPECT_EQ("user2@managed.com", status_.user(2).email()); | 774 EXPECT_EQ("user2@managed.com", status_.user(2).email()); |
| 778 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, status_.user(3).type()); | 775 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, status_.user(3).type()); |
| 779 EXPECT_FALSE(status_.user(3).has_email()); | 776 EXPECT_FALSE(status_.user(3).has_email()); |
| 780 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(4).type()); | 777 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(4).type()); |
| 781 EXPECT_EQ("user4@managed.com", status_.user(4).email()); | 778 EXPECT_EQ("user4@managed.com", status_.user(4).email()); |
| 782 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(5).type()); | 779 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(5).type()); |
| 783 EXPECT_EQ("user5@managed.com", status_.user(5).email()); | 780 EXPECT_EQ("user5@managed.com", status_.user(5).email()); |
| 784 | 781 |
| 785 // Verify that users are no longer reported if setting is disabled. | 782 // Verify that users are no longer reported if setting is disabled. |
| 786 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, false); | 783 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceUsers, false); |
| 787 GetStatus(); | 784 GetStatus(); |
| 788 EXPECT_EQ(0, status_.user_size()); | 785 EXPECT_EQ(0, status_.user_size()); |
| 789 } | 786 } |
| 790 | 787 |
| 791 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { | 788 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { |
| 792 std::vector<std::string> expected_mount_points; | 789 std::vector<std::string> expected_mount_points; |
| 793 std::vector<em::VolumeInfo> expected_volume_info; | 790 std::vector<em::VolumeInfo> expected_volume_info; |
| 794 int size = 12345678; | 791 int size = 12345678; |
| 795 for (const auto& mount_info : | 792 for (const auto& mount_info : |
| 796 DiskMountManager::GetInstance()->mount_points()) { | 793 DiskMountManager::GetInstance()->mount_points()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 821 EXPECT_EQ(expected_info.storage_free(), info.storage_free()); | 818 EXPECT_EQ(expected_info.storage_free(), info.storage_free()); |
| 822 found = true; | 819 found = true; |
| 823 break; | 820 break; |
| 824 } | 821 } |
| 825 } | 822 } |
| 826 EXPECT_TRUE(found) << "No matching VolumeInfo for " | 823 EXPECT_TRUE(found) << "No matching VolumeInfo for " |
| 827 << expected_info.volume_id(); | 824 << expected_info.volume_id(); |
| 828 } | 825 } |
| 829 | 826 |
| 830 // Now turn off hardware status reporting - should have no data. | 827 // Now turn off hardware status reporting - should have no data. |
| 831 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 828 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceHardwareStatus, |
| 829 false); |
| 832 GetStatus(); | 830 GetStatus(); |
| 833 EXPECT_EQ(0, status_.volume_info_size()); | 831 EXPECT_EQ(0, status_.volume_info_size()); |
| 834 } | 832 } |
| 835 | 833 |
| 836 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { | 834 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { |
| 837 status_collector_->RefreshSampleResourceUsage(); | 835 status_collector_->RefreshSampleResourceUsage(); |
| 838 GetStatus(); | 836 GetStatus(); |
| 839 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), | 837 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), |
| 840 status_.system_ram_free().size()); | 838 status_.system_ram_free().size()); |
| 841 EXPECT_TRUE(status_.has_system_ram_total()); | 839 EXPECT_TRUE(status_.has_system_ram_total()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 857 // Now set CPU usage to 0. | 855 // Now set CPU usage to 0. |
| 858 const int idle_cpu_usage = 0; | 856 const int idle_cpu_usage = 0; |
| 859 status_collector_->set_mock_cpu_usage(idle_cpu_usage, 2); | 857 status_collector_->set_mock_cpu_usage(idle_cpu_usage, 2); |
| 860 GetStatus(); | 858 GetStatus(); |
| 861 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), | 859 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), |
| 862 status_.cpu_utilization_pct().size()); | 860 status_.cpu_utilization_pct().size()); |
| 863 for (const auto utilization : status_.cpu_utilization_pct()) | 861 for (const auto utilization : status_.cpu_utilization_pct()) |
| 864 EXPECT_EQ(idle_cpu_usage, utilization); | 862 EXPECT_EQ(idle_cpu_usage, utilization); |
| 865 | 863 |
| 866 // Turning off hardware reporting should not report CPU utilization. | 864 // Turning off hardware reporting should not report CPU utilization. |
| 867 cros_settings_->SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 865 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceHardwareStatus, |
| 866 false); |
| 868 GetStatus(); | 867 GetStatus(); |
| 869 EXPECT_EQ(0, status_.cpu_utilization_pct().size()); | 868 EXPECT_EQ(0, status_.cpu_utilization_pct().size()); |
| 870 } | 869 } |
| 871 | 870 |
| 872 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { | 871 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { |
| 873 // Should not report session status if we don't have an active kiosk app. | 872 // Should not report session status if we don't have an active kiosk app. |
| 874 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 873 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceSessionStatus, |
| 874 true); |
| 875 em::SessionStatusReportRequest session_status; | 875 em::SessionStatusReportRequest session_status; |
| 876 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); | 876 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); |
| 877 } | 877 } |
| 878 | 878 |
| 879 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { | 879 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { |
| 880 // Should not report session status if session status reporting is disabled. | 880 // Should not report session status if session status reporting is disabled. |
| 881 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, false); | 881 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceSessionStatus, |
| 882 false); |
| 882 status_collector_->set_kiosk_account(make_scoped_ptr( | 883 status_collector_->set_kiosk_account(make_scoped_ptr( |
| 883 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 884 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); |
| 884 // Set up a device-local account for single-app kiosk mode. | 885 // Set up a device-local account for single-app kiosk mode. |
| 885 MockRunningKioskApp(fake_device_local_account_); | 886 MockRunningKioskApp(fake_device_local_account_); |
| 886 | 887 |
| 887 em::SessionStatusReportRequest session_status; | 888 em::SessionStatusReportRequest session_status; |
| 888 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); | 889 EXPECT_FALSE(status_collector_->GetDeviceSessionStatus(&session_status)); |
| 889 } | 890 } |
| 890 | 891 |
| 891 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { | 892 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { |
| 892 cros_settings_->SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 893 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceSessionStatus, |
| 894 true); |
| 893 status_collector_->set_kiosk_account(make_scoped_ptr( | 895 status_collector_->set_kiosk_account(make_scoped_ptr( |
| 894 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 896 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); |
| 895 | 897 |
| 896 // Set up a device-local account for single-app kiosk mode. | 898 // Set up a device-local account for single-app kiosk mode. |
| 897 MockRunningKioskApp(fake_device_local_account_); | 899 MockRunningKioskApp(fake_device_local_account_); |
| 898 | 900 |
| 899 em::SessionStatusReportRequest session_status; | 901 em::SessionStatusReportRequest session_status; |
| 900 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status)); | 902 EXPECT_TRUE(status_collector_->GetDeviceSessionStatus(&session_status)); |
| 901 ASSERT_EQ(1, session_status.installed_apps_size()); | 903 ASSERT_EQ(1, session_status.installed_apps_size()); |
| 902 EXPECT_EQ(kKioskAccountId, session_status.device_local_account_id()); | 904 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. | 1117 // Mock that we are in kiosk mode so we report network state. |
| 1116 status_collector_->set_kiosk_account(make_scoped_ptr( | 1118 status_collector_->set_kiosk_account(make_scoped_ptr( |
| 1117 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); | 1119 new policy::DeviceLocalAccount(fake_device_local_account_)).Pass()); |
| 1118 | 1120 |
| 1119 // Interfaces should be reported by default. | 1121 // Interfaces should be reported by default. |
| 1120 GetStatus(); | 1122 GetStatus(); |
| 1121 EXPECT_LT(0, status_.network_interface_size()); | 1123 EXPECT_LT(0, status_.network_interface_size()); |
| 1122 EXPECT_LT(0, status_.network_state_size()); | 1124 EXPECT_LT(0, status_.network_state_size()); |
| 1123 | 1125 |
| 1124 // No interfaces should be reported if the policy is off. | 1126 // No interfaces should be reported if the policy is off. |
| 1125 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); | 1127 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, |
| 1128 false); |
| 1126 GetStatus(); | 1129 GetStatus(); |
| 1127 EXPECT_EQ(0, status_.network_interface_size()); | 1130 EXPECT_EQ(0, status_.network_interface_size()); |
| 1128 EXPECT_EQ(0, status_.network_state_size()); | 1131 EXPECT_EQ(0, status_.network_state_size()); |
| 1129 | 1132 |
| 1130 // Switch the policy on and verify the interface list is present. | 1133 // Switch the policy on and verify the interface list is present. |
| 1131 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); | 1134 stub_settings_provider_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, |
| 1135 true); |
| 1132 GetStatus(); | 1136 GetStatus(); |
| 1133 | 1137 |
| 1134 int count = 0; | 1138 int count = 0; |
| 1135 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { | 1139 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { |
| 1136 const FakeDeviceData& dev = kFakeDevices[i]; | 1140 const FakeDeviceData& dev = kFakeDevices[i]; |
| 1137 if (dev.expected_type == -1) | 1141 if (dev.expected_type == -1) |
| 1138 continue; | 1142 continue; |
| 1139 | 1143 |
| 1140 // Find the corresponding entry in reporting data. | 1144 // Find the corresponding entry in reporting data. |
| 1141 bool found_match = false; | 1145 bool found_match = false; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 found_match = true; | 1189 found_match = true; |
| 1186 break; | 1190 break; |
| 1187 } | 1191 } |
| 1188 } | 1192 } |
| 1189 EXPECT_TRUE(found_match) << "No matching state for fake network " | 1193 EXPECT_TRUE(found_match) << "No matching state for fake network " |
| 1190 << " (" << state.name << ")"; | 1194 << " (" << state.name << ")"; |
| 1191 } | 1195 } |
| 1192 } | 1196 } |
| 1193 | 1197 |
| 1194 } // namespace policy | 1198 } // namespace policy |
| OLD | NEW |