| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/policy/device_status_collector.h" | 5 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "chromeos/network/network_state.h" | 47 #include "chromeos/network/network_state.h" |
| 48 #include "chromeos/network/network_state_handler.h" | 48 #include "chromeos/network/network_state_handler.h" |
| 49 #include "chromeos/settings/cros_settings_names.h" | 49 #include "chromeos/settings/cros_settings_names.h" |
| 50 #include "chromeos/system/fake_statistics_provider.h" | 50 #include "chromeos/system/fake_statistics_provider.h" |
| 51 #include "components/policy/proto/device_management_backend.pb.h" | 51 #include "components/policy/proto/device_management_backend.pb.h" |
| 52 #include "components/prefs/pref_service.h" | 52 #include "components/prefs/pref_service.h" |
| 53 #include "components/prefs/testing_pref_service.h" | 53 #include "components/prefs/testing_pref_service.h" |
| 54 #include "content/public/browser/browser_thread.h" | 54 #include "content/public/browser/browser_thread.h" |
| 55 #include "content/public/test/test_browser_thread.h" | 55 #include "content/public/test/test_browser_thread.h" |
| 56 #include "content/public/test/test_utils.h" | 56 #include "content/public/test/test_utils.h" |
| 57 #include "device/geolocation/geolocation_provider.h" | |
| 58 #include "storage/browser/fileapi/external_mount_points.h" | 57 #include "storage/browser/fileapi/external_mount_points.h" |
| 59 #include "storage/browser/fileapi/mount_points.h" | 58 #include "storage/browser/fileapi/mount_points.h" |
| 60 #include "storage/common/fileapi/file_system_mount_option.h" | 59 #include "storage/common/fileapi/file_system_mount_option.h" |
| 61 #include "storage/common/fileapi/file_system_types.h" | 60 #include "storage/common/fileapi/file_system_types.h" |
| 62 #include "testing/gmock/include/gmock/gmock.h" | 61 #include "testing/gmock/include/gmock/gmock.h" |
| 63 #include "testing/gtest/include/gtest/gtest.h" | 62 #include "testing/gtest/include/gtest/gtest.h" |
| 64 #include "third_party/cros_system_api/dbus/service_constants.h" | 63 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 65 | 64 |
| 66 using ::testing::Return; | 65 using ::testing::Return; |
| 67 using ::testing::ReturnRef; | 66 using ::testing::ReturnRef; |
| 68 using base::Time; | 67 using base::Time; |
| 69 using base::TimeDelta; | 68 using base::TimeDelta; |
| 70 using chromeos::disks::DiskMountManager; | 69 using chromeos::disks::DiskMountManager; |
| 71 | 70 |
| 72 namespace em = enterprise_management; | 71 namespace em = enterprise_management; |
| 73 | 72 |
| 74 namespace { | 73 namespace { |
| 75 | 74 |
| 76 const int64_t kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000; | 75 const int64_t kMillisecondsPerDay = Time::kMicrosecondsPerDay / 1000; |
| 77 const char kKioskAccountId[] = "kiosk_user@localhost"; | 76 const char kKioskAccountId[] = "kiosk_user@localhost"; |
| 78 const char kKioskAppId[] = "kiosk_app_id"; | 77 const char kKioskAppId[] = "kiosk_app_id"; |
| 79 const char kExternalMountPoint[] = "/a/b/c"; | 78 const char kExternalMountPoint[] = "/a/b/c"; |
| 80 const char kPublicAccountId[] = "public_user@localhost"; | 79 const char kPublicAccountId[] = "public_user@localhost"; |
| 81 | 80 |
| 82 std::unique_ptr<device::Geoposition> mock_position_to_return_next; | |
| 83 | |
| 84 void SetMockPositionToReturnNext(const device::Geoposition& position) { | |
| 85 mock_position_to_return_next.reset(new device::Geoposition(position)); | |
| 86 } | |
| 87 | |
| 88 void MockPositionUpdateRequester( | |
| 89 const device::GeolocationProvider::LocationUpdateCallback& callback) { | |
| 90 if (!mock_position_to_return_next.get()) | |
| 91 return; | |
| 92 | |
| 93 // If the fix is invalid, the DeviceStatusCollector will immediately request | |
| 94 // another update when it receives the callback. This is desirable and safe in | |
| 95 // real life where geolocation updates arrive asynchronously. In this testing | |
| 96 // harness, the callback is invoked synchronously upon request, leading to a | |
| 97 // request-callback loop. The loop is broken by returning the mock position | |
| 98 // only once. | |
| 99 std::unique_ptr<device::Geoposition> position( | |
| 100 mock_position_to_return_next.release()); | |
| 101 callback.Run(*position); | |
| 102 } | |
| 103 | |
| 104 class TestingDeviceStatusCollector : public policy::DeviceStatusCollector { | 81 class TestingDeviceStatusCollector : public policy::DeviceStatusCollector { |
| 105 public: | 82 public: |
| 106 TestingDeviceStatusCollector( | 83 TestingDeviceStatusCollector( |
| 107 PrefService* local_state, | 84 PrefService* local_state, |
| 108 chromeos::system::StatisticsProvider* provider, | 85 chromeos::system::StatisticsProvider* provider, |
| 109 const policy::DeviceStatusCollector::LocationUpdateRequester& | |
| 110 location_update_requester, | |
| 111 const policy::DeviceStatusCollector::VolumeInfoFetcher& | 86 const policy::DeviceStatusCollector::VolumeInfoFetcher& |
| 112 volume_info_fetcher, | 87 volume_info_fetcher, |
| 113 const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_fetcher, | 88 const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_fetcher, |
| 114 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) | 89 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) |
| 115 : policy::DeviceStatusCollector(local_state, | 90 : policy::DeviceStatusCollector(local_state, |
| 116 provider, | 91 provider, |
| 117 location_update_requester, | |
| 118 volume_info_fetcher, | 92 volume_info_fetcher, |
| 119 cpu_fetcher, | 93 cpu_fetcher, |
| 120 cpu_temp_fetcher) { | 94 cpu_temp_fetcher) { |
| 121 // Set the baseline time to a fixed value (1 AM) to prevent test flakiness | 95 // Set the baseline time to a fixed value (1 AM) to prevent test flakiness |
| 122 // due to a single activity period spanning two days. | 96 // due to a single activity period spanning two days. |
| 123 SetBaselineTime(Time::Now().LocalMidnight() + TimeDelta::FromHours(1)); | 97 SetBaselineTime(Time::Now().LocalMidnight() + TimeDelta::FromHours(1)); |
| 124 } | 98 } |
| 125 | 99 |
| 126 void Simulate(ui::IdleState* states, int len) { | 100 void Simulate(ui::IdleState* states, int len) { |
| 127 for (int i = 0; i < len; i++) | 101 for (int i = 0; i < len; i++) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 153 return std::unique_ptr<policy::DeviceLocalAccount>(); | 127 return std::unique_ptr<policy::DeviceLocalAccount>(); |
| 154 } | 128 } |
| 155 | 129 |
| 156 std::string GetAppVersion(const std::string& app_id) override { | 130 std::string GetAppVersion(const std::string& app_id) override { |
| 157 // Just return the app_id as the version - this makes it easy for tests | 131 // Just return the app_id as the version - this makes it easy for tests |
| 158 // to confirm that the correct app's version was requested. | 132 // to confirm that the correct app's version was requested. |
| 159 return app_id; | 133 return app_id; |
| 160 } | 134 } |
| 161 | 135 |
| 162 void RefreshSampleResourceUsage() { | 136 void RefreshSampleResourceUsage() { |
| 163 SampleHardwareStatus(); | 137 SampleResourceUsage(); |
| 164 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 138 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 165 } | 139 } |
| 166 | 140 |
| 167 protected: | 141 protected: |
| 168 void CheckIdleState() override { | 142 void CheckIdleState() override { |
| 169 // This should never be called in testing, as it results in a dbus call. | 143 // This should never be called in testing, as it results in a dbus call. |
| 170 ADD_FAILURE(); | 144 ADD_FAILURE(); |
| 171 } | 145 } |
| 172 | 146 |
| 173 // Each time this is called, returns a time that is a fixed increment | 147 // Each time this is called, returns a time that is a fixed increment |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 320 } |
| 347 | 321 |
| 348 void TearDown() override { | 322 void TearDown() override { |
| 349 settings_helper_.RestoreProvider(); | 323 settings_helper_.RestoreProvider(); |
| 350 } | 324 } |
| 351 | 325 |
| 352 void RestartStatusCollector( | 326 void RestartStatusCollector( |
| 353 const policy::DeviceStatusCollector::VolumeInfoFetcher& volume_info, | 327 const policy::DeviceStatusCollector::VolumeInfoFetcher& volume_info, |
| 354 const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_stats, | 328 const policy::DeviceStatusCollector::CPUStatisticsFetcher& cpu_stats, |
| 355 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) { | 329 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) { |
| 356 policy::DeviceStatusCollector::LocationUpdateRequester callback = | |
| 357 base::Bind(&MockPositionUpdateRequester); | |
| 358 std::vector<em::VolumeInfo> expected_volume_info; | 330 std::vector<em::VolumeInfo> expected_volume_info; |
| 359 status_collector_.reset(new TestingDeviceStatusCollector( | 331 status_collector_.reset(new TestingDeviceStatusCollector( |
| 360 &prefs_, &fake_statistics_provider_, callback, volume_info, cpu_stats, | 332 &prefs_, &fake_statistics_provider_, volume_info, cpu_stats, |
| 361 cpu_temp_fetcher)); | 333 cpu_temp_fetcher)); |
| 362 } | 334 } |
| 363 | 335 |
| 364 void GetDeviceStatus() { | 336 void GetStatus() { |
| 365 device_status_.Clear(); | 337 device_status_.Clear(); |
| 338 session_status_.Clear(); |
| 339 got_session_status_ = false; |
| 366 run_loop_.reset(new base::RunLoop()); | 340 run_loop_.reset(new base::RunLoop()); |
| 367 status_collector_->GetDeviceStatusAsync( | 341 status_collector_->GetDeviceAndSessionStatusAsync(base::Bind( |
| 368 base::Bind(&DeviceStatusCollectorTest::OnDeviceStatusReceived, | 342 &DeviceStatusCollectorTest::OnStatusReceived, base::Unretained(this))); |
| 369 base::Unretained(this))); | |
| 370 run_loop_->Run(); | 343 run_loop_->Run(); |
| 371 run_loop_.reset(); | 344 run_loop_.reset(); |
| 372 } | 345 } |
| 373 | 346 |
| 374 void OnDeviceStatusReceived( | 347 void OnStatusReceived( |
| 375 std::unique_ptr<em::DeviceStatusReportRequest> status) { | 348 std::unique_ptr<em::DeviceStatusReportRequest> device_status, |
| 376 if (status) | 349 std::unique_ptr<em::SessionStatusReportRequest> session_status) { |
| 377 device_status_ = *status; | 350 if (device_status) |
| 351 device_status_ = *device_status; |
| 352 got_session_status_ = session_status != nullptr; |
| 353 if (got_session_status_) |
| 354 session_status_ = *session_status; |
| 378 EXPECT_TRUE(run_loop_); | 355 EXPECT_TRUE(run_loop_); |
| 379 run_loop_->Quit(); | 356 run_loop_->Quit(); |
| 380 } | 357 } |
| 381 | 358 |
| 382 void GetSessionStatus() { | |
| 383 session_status_.Clear(); | |
| 384 got_session_status_ = false; | |
| 385 run_loop_.reset(new base::RunLoop()); | |
| 386 status_collector_->GetDeviceSessionStatusAsync( | |
| 387 base::Bind(&DeviceStatusCollectorTest::OnSessionStatusReceived, | |
| 388 base::Unretained(this))); | |
| 389 run_loop_->Run(); | |
| 390 run_loop_.reset(); | |
| 391 } | |
| 392 | |
| 393 void OnSessionStatusReceived( | |
| 394 std::unique_ptr<em::SessionStatusReportRequest> status) { | |
| 395 got_session_status_ = status != nullptr; | |
| 396 if (got_session_status_) | |
| 397 session_status_ = *status; | |
| 398 EXPECT_TRUE(run_loop_); | |
| 399 run_loop_->Quit(); | |
| 400 } | |
| 401 | |
| 402 void CheckThatNoLocationIsReported() { | |
| 403 GetDeviceStatus(); | |
| 404 EXPECT_FALSE(device_status_.has_device_location()); | |
| 405 } | |
| 406 | |
| 407 void CheckThatAValidLocationIsReported() { | |
| 408 // Checks that a location is being reported which matches the valid fix | |
| 409 // set using SetMockPositionToReturnNext(). | |
| 410 GetDeviceStatus(); | |
| 411 EXPECT_TRUE(device_status_.has_device_location()); | |
| 412 em::DeviceLocation location = device_status_.device_location(); | |
| 413 if (location.has_error_code()) | |
| 414 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_NONE, location.error_code()); | |
| 415 EXPECT_TRUE(location.has_latitude()); | |
| 416 EXPECT_TRUE(location.has_longitude()); | |
| 417 EXPECT_TRUE(location.has_accuracy()); | |
| 418 EXPECT_TRUE(location.has_timestamp()); | |
| 419 EXPECT_FALSE(location.has_altitude()); | |
| 420 EXPECT_FALSE(location.has_altitude_accuracy()); | |
| 421 EXPECT_FALSE(location.has_heading()); | |
| 422 EXPECT_FALSE(location.has_speed()); | |
| 423 EXPECT_FALSE(location.has_error_message()); | |
| 424 EXPECT_DOUBLE_EQ(4.3, location.latitude()); | |
| 425 EXPECT_DOUBLE_EQ(-7.8, location.longitude()); | |
| 426 EXPECT_DOUBLE_EQ(3., location.accuracy()); | |
| 427 // Check that the timestamp is not older than ten minutes. | |
| 428 EXPECT_TRUE(Time::Now() - Time::FromDoubleT(location.timestamp() / 1000.) < | |
| 429 TimeDelta::FromMinutes(10)); | |
| 430 } | |
| 431 | |
| 432 void CheckThatALocationErrorIsReported() { | |
| 433 GetDeviceStatus(); | |
| 434 EXPECT_TRUE(device_status_.has_device_location()); | |
| 435 em::DeviceLocation location = device_status_.device_location(); | |
| 436 EXPECT_TRUE(location.has_error_code()); | |
| 437 EXPECT_EQ(em::DeviceLocation::ERROR_CODE_POSITION_UNAVAILABLE, | |
| 438 location.error_code()); | |
| 439 } | |
| 440 | |
| 441 void MockRunningKioskApp(const DeviceLocalAccount& account) { | 359 void MockRunningKioskApp(const DeviceLocalAccount& account) { |
| 442 std::vector<DeviceLocalAccount> accounts; | 360 std::vector<DeviceLocalAccount> accounts; |
| 443 accounts.push_back(account); | 361 accounts.push_back(account); |
| 444 SetDeviceLocalAccounts(owner_settings_service_.get(), accounts); | 362 SetDeviceLocalAccounts(owner_settings_service_.get(), accounts); |
| 445 user_manager_->CreateKioskAppUser( | 363 user_manager_->CreateKioskAppUser( |
| 446 AccountId::FromUserEmail(account.user_id)); | 364 AccountId::FromUserEmail(account.user_id)); |
| 447 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly( | 365 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()).WillRepeatedly( |
| 448 Return(true)); | 366 Return(true)); |
| 449 } | 367 } |
| 450 | 368 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 435 |
| 518 TEST_F(DeviceStatusCollectorTest, AllIdle) { | 436 TEST_F(DeviceStatusCollectorTest, AllIdle) { |
| 519 ui::IdleState test_states[] = { | 437 ui::IdleState test_states[] = { |
| 520 ui::IDLE_STATE_IDLE, | 438 ui::IDLE_STATE_IDLE, |
| 521 ui::IDLE_STATE_IDLE, | 439 ui::IDLE_STATE_IDLE, |
| 522 ui::IDLE_STATE_IDLE | 440 ui::IDLE_STATE_IDLE |
| 523 }; | 441 }; |
| 524 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 442 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 525 | 443 |
| 526 // Test reporting with no data. | 444 // Test reporting with no data. |
| 527 GetDeviceStatus(); | 445 GetStatus(); |
| 528 EXPECT_EQ(0, device_status_.active_period_size()); | 446 EXPECT_EQ(0, device_status_.active_period_size()); |
| 529 EXPECT_EQ(0, GetActiveMilliseconds(device_status_)); | 447 EXPECT_EQ(0, GetActiveMilliseconds(device_status_)); |
| 530 | 448 |
| 531 // Test reporting with a single idle sample. | 449 // Test reporting with a single idle sample. |
| 532 status_collector_->Simulate(test_states, 1); | 450 status_collector_->Simulate(test_states, 1); |
| 533 GetDeviceStatus(); | 451 GetStatus(); |
| 534 EXPECT_EQ(0, device_status_.active_period_size()); | 452 EXPECT_EQ(0, device_status_.active_period_size()); |
| 535 EXPECT_EQ(0, GetActiveMilliseconds(device_status_)); | 453 EXPECT_EQ(0, GetActiveMilliseconds(device_status_)); |
| 536 | 454 |
| 537 // Test reporting with multiple consecutive idle samples. | 455 // Test reporting with multiple consecutive idle samples. |
| 538 status_collector_->Simulate(test_states, | 456 status_collector_->Simulate(test_states, |
| 539 sizeof(test_states) / sizeof(ui::IdleState)); | 457 sizeof(test_states) / sizeof(ui::IdleState)); |
| 540 GetDeviceStatus(); | 458 GetStatus(); |
| 541 EXPECT_EQ(0, device_status_.active_period_size()); | 459 EXPECT_EQ(0, device_status_.active_period_size()); |
| 542 EXPECT_EQ(0, GetActiveMilliseconds(device_status_)); | 460 EXPECT_EQ(0, GetActiveMilliseconds(device_status_)); |
| 543 } | 461 } |
| 544 | 462 |
| 545 TEST_F(DeviceStatusCollectorTest, AllActive) { | 463 TEST_F(DeviceStatusCollectorTest, AllActive) { |
| 546 ui::IdleState test_states[] = { | 464 ui::IdleState test_states[] = { |
| 547 ui::IDLE_STATE_ACTIVE, | 465 ui::IDLE_STATE_ACTIVE, |
| 548 ui::IDLE_STATE_ACTIVE, | 466 ui::IDLE_STATE_ACTIVE, |
| 549 ui::IDLE_STATE_ACTIVE | 467 ui::IDLE_STATE_ACTIVE |
| 550 }; | 468 }; |
| 551 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 469 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 552 | 470 |
| 553 // Test a single active sample. | 471 // Test a single active sample. |
| 554 status_collector_->Simulate(test_states, 1); | 472 status_collector_->Simulate(test_states, 1); |
| 555 GetDeviceStatus(); | 473 GetStatus(); |
| 556 EXPECT_EQ(1, device_status_.active_period_size()); | 474 EXPECT_EQ(1, device_status_.active_period_size()); |
| 557 EXPECT_EQ(1 * ActivePeriodMilliseconds(), | 475 EXPECT_EQ(1 * ActivePeriodMilliseconds(), |
| 558 GetActiveMilliseconds(device_status_)); | 476 GetActiveMilliseconds(device_status_)); |
| 559 device_status_.clear_active_period(); // Clear the result protobuf. | 477 device_status_.clear_active_period(); // Clear the result protobuf. |
| 560 | 478 |
| 561 // Test multiple consecutive active samples. | 479 // Test multiple consecutive active samples. |
| 562 status_collector_->Simulate(test_states, | 480 status_collector_->Simulate(test_states, |
| 563 sizeof(test_states) / sizeof(ui::IdleState)); | 481 sizeof(test_states) / sizeof(ui::IdleState)); |
| 564 GetDeviceStatus(); | 482 GetStatus(); |
| 565 EXPECT_EQ(1, device_status_.active_period_size()); | 483 EXPECT_EQ(1, device_status_.active_period_size()); |
| 566 EXPECT_EQ(4 * ActivePeriodMilliseconds(), | 484 EXPECT_EQ(4 * ActivePeriodMilliseconds(), |
| 567 GetActiveMilliseconds(device_status_)); | 485 GetActiveMilliseconds(device_status_)); |
| 568 } | 486 } |
| 569 | 487 |
| 570 TEST_F(DeviceStatusCollectorTest, MixedStates) { | 488 TEST_F(DeviceStatusCollectorTest, MixedStates) { |
| 571 ui::IdleState test_states[] = { | 489 ui::IdleState test_states[] = { |
| 572 ui::IDLE_STATE_ACTIVE, | 490 ui::IDLE_STATE_ACTIVE, |
| 573 ui::IDLE_STATE_IDLE, | 491 ui::IDLE_STATE_IDLE, |
| 574 ui::IDLE_STATE_ACTIVE, | 492 ui::IDLE_STATE_ACTIVE, |
| 575 ui::IDLE_STATE_ACTIVE, | 493 ui::IDLE_STATE_ACTIVE, |
| 576 ui::IDLE_STATE_IDLE, | 494 ui::IDLE_STATE_IDLE, |
| 577 ui::IDLE_STATE_IDLE, | 495 ui::IDLE_STATE_IDLE, |
| 578 ui::IDLE_STATE_ACTIVE | 496 ui::IDLE_STATE_ACTIVE |
| 579 }; | 497 }; |
| 580 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 498 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 581 status_collector_->Simulate(test_states, | 499 status_collector_->Simulate(test_states, |
| 582 sizeof(test_states) / sizeof(ui::IdleState)); | 500 sizeof(test_states) / sizeof(ui::IdleState)); |
| 583 GetDeviceStatus(); | 501 GetStatus(); |
| 584 EXPECT_EQ(4 * ActivePeriodMilliseconds(), | 502 EXPECT_EQ(4 * ActivePeriodMilliseconds(), |
| 585 GetActiveMilliseconds(device_status_)); | 503 GetActiveMilliseconds(device_status_)); |
| 586 } | 504 } |
| 587 | 505 |
| 588 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { | 506 TEST_F(DeviceStatusCollectorTest, StateKeptInPref) { |
| 589 ui::IdleState test_states[] = { | 507 ui::IdleState test_states[] = { |
| 590 ui::IDLE_STATE_ACTIVE, | 508 ui::IDLE_STATE_ACTIVE, |
| 591 ui::IDLE_STATE_IDLE, | 509 ui::IDLE_STATE_IDLE, |
| 592 ui::IDLE_STATE_ACTIVE, | 510 ui::IDLE_STATE_ACTIVE, |
| 593 ui::IDLE_STATE_ACTIVE, | 511 ui::IDLE_STATE_ACTIVE, |
| 594 ui::IDLE_STATE_IDLE, | 512 ui::IDLE_STATE_IDLE, |
| 595 ui::IDLE_STATE_IDLE | 513 ui::IDLE_STATE_IDLE |
| 596 }; | 514 }; |
| 597 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 515 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 598 status_collector_->Simulate(test_states, | 516 status_collector_->Simulate(test_states, |
| 599 sizeof(test_states) / sizeof(ui::IdleState)); | 517 sizeof(test_states) / sizeof(ui::IdleState)); |
| 600 | 518 |
| 601 // Process the list a second time after restarting the collector. It should be | 519 // Process the list a second time after restarting the collector. It should be |
| 602 // able to count the active periods found by the original collector, because | 520 // able to count the active periods found by the original collector, because |
| 603 // the results are stored in a pref. | 521 // the results are stored in a pref. |
| 604 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), | 522 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), |
| 605 base::Bind(&GetEmptyCPUStatistics), | 523 base::Bind(&GetEmptyCPUStatistics), |
| 606 base::Bind(&GetEmptyCPUTempInfo)); | 524 base::Bind(&GetEmptyCPUTempInfo)); |
| 607 status_collector_->Simulate(test_states, | 525 status_collector_->Simulate(test_states, |
| 608 sizeof(test_states) / sizeof(ui::IdleState)); | 526 sizeof(test_states) / sizeof(ui::IdleState)); |
| 609 | 527 |
| 610 GetDeviceStatus(); | 528 GetStatus(); |
| 611 EXPECT_EQ(6 * ActivePeriodMilliseconds(), | 529 EXPECT_EQ(6 * ActivePeriodMilliseconds(), |
| 612 GetActiveMilliseconds(device_status_)); | 530 GetActiveMilliseconds(device_status_)); |
| 613 } | 531 } |
| 614 | 532 |
| 615 TEST_F(DeviceStatusCollectorTest, Times) { | 533 TEST_F(DeviceStatusCollectorTest, Times) { |
| 616 ui::IdleState test_states[] = { | 534 ui::IdleState test_states[] = { |
| 617 ui::IDLE_STATE_ACTIVE, | 535 ui::IDLE_STATE_ACTIVE, |
| 618 ui::IDLE_STATE_IDLE, | 536 ui::IDLE_STATE_IDLE, |
| 619 ui::IDLE_STATE_ACTIVE, | 537 ui::IDLE_STATE_ACTIVE, |
| 620 ui::IDLE_STATE_ACTIVE, | 538 ui::IDLE_STATE_ACTIVE, |
| 621 ui::IDLE_STATE_IDLE, | 539 ui::IDLE_STATE_IDLE, |
| 622 ui::IDLE_STATE_IDLE | 540 ui::IDLE_STATE_IDLE |
| 623 }; | 541 }; |
| 624 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 542 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 625 status_collector_->Simulate(test_states, | 543 status_collector_->Simulate(test_states, |
| 626 sizeof(test_states) / sizeof(ui::IdleState)); | 544 sizeof(test_states) / sizeof(ui::IdleState)); |
| 627 GetDeviceStatus(); | 545 GetStatus(); |
| 628 EXPECT_EQ(3 * ActivePeriodMilliseconds(), | 546 EXPECT_EQ(3 * ActivePeriodMilliseconds(), |
| 629 GetActiveMilliseconds(device_status_)); | 547 GetActiveMilliseconds(device_status_)); |
| 630 } | 548 } |
| 631 | 549 |
| 632 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { | 550 TEST_F(DeviceStatusCollectorTest, MaxStoredPeriods) { |
| 633 ui::IdleState test_states[] = { | 551 ui::IdleState test_states[] = { |
| 634 ui::IDLE_STATE_ACTIVE, | 552 ui::IDLE_STATE_ACTIVE, |
| 635 ui::IDLE_STATE_IDLE | 553 ui::IDLE_STATE_IDLE |
| 636 }; | 554 }; |
| 637 const int kMaxDays = 10; | 555 const int kMaxDays = 10; |
| 638 | 556 |
| 639 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 557 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 640 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); | 558 status_collector_->set_max_stored_past_activity_days(kMaxDays - 1); |
| 641 status_collector_->set_max_stored_future_activity_days(1); | 559 status_collector_->set_max_stored_future_activity_days(1); |
| 642 Time baseline = Time::Now().LocalMidnight(); | 560 Time baseline = Time::Now().LocalMidnight(); |
| 643 | 561 |
| 644 // Simulate 12 active periods. | 562 // Simulate 12 active periods. |
| 645 for (int i = 0; i < kMaxDays + 2; i++) { | 563 for (int i = 0; i < kMaxDays + 2; i++) { |
| 646 status_collector_->Simulate(test_states, | 564 status_collector_->Simulate(test_states, |
| 647 sizeof(test_states) / sizeof(ui::IdleState)); | 565 sizeof(test_states) / sizeof(ui::IdleState)); |
| 648 // Advance the simulated clock by a day. | 566 // Advance the simulated clock by a day. |
| 649 baseline += TimeDelta::FromDays(1); | 567 baseline += TimeDelta::FromDays(1); |
| 650 status_collector_->SetBaselineTime(baseline); | 568 status_collector_->SetBaselineTime(baseline); |
| 651 } | 569 } |
| 652 | 570 |
| 653 // Check that we don't exceed the max number of periods. | 571 // Check that we don't exceed the max number of periods. |
| 654 GetDeviceStatus(); | 572 GetStatus(); |
| 655 EXPECT_EQ(kMaxDays - 1, device_status_.active_period_size()); | 573 EXPECT_EQ(kMaxDays - 1, device_status_.active_period_size()); |
| 656 | 574 |
| 657 // Simulate some future times. | 575 // Simulate some future times. |
| 658 for (int i = 0; i < kMaxDays + 2; i++) { | 576 for (int i = 0; i < kMaxDays + 2; i++) { |
| 659 status_collector_->Simulate(test_states, | 577 status_collector_->Simulate(test_states, |
| 660 sizeof(test_states) / sizeof(ui::IdleState)); | 578 sizeof(test_states) / sizeof(ui::IdleState)); |
| 661 // Advance the simulated clock by a day. | 579 // Advance the simulated clock by a day. |
| 662 baseline += TimeDelta::FromDays(1); | 580 baseline += TimeDelta::FromDays(1); |
| 663 status_collector_->SetBaselineTime(baseline); | 581 status_collector_->SetBaselineTime(baseline); |
| 664 } | 582 } |
| 665 // Set the clock back so the previous simulated times are in the future. | 583 // Set the clock back so the previous simulated times are in the future. |
| 666 baseline -= TimeDelta::FromDays(20); | 584 baseline -= TimeDelta::FromDays(20); |
| 667 status_collector_->SetBaselineTime(baseline); | 585 status_collector_->SetBaselineTime(baseline); |
| 668 | 586 |
| 669 // Collect one more data point to trigger pruning. | 587 // Collect one more data point to trigger pruning. |
| 670 status_collector_->Simulate(test_states, 1); | 588 status_collector_->Simulate(test_states, 1); |
| 671 | 589 |
| 672 // Check that we don't exceed the max number of periods. | 590 // Check that we don't exceed the max number of periods. |
| 673 device_status_.clear_active_period(); | 591 device_status_.clear_active_period(); |
| 674 GetDeviceStatus(); | 592 GetStatus(); |
| 675 EXPECT_LT(device_status_.active_period_size(), kMaxDays); | 593 EXPECT_LT(device_status_.active_period_size(), kMaxDays); |
| 676 } | 594 } |
| 677 | 595 |
| 678 TEST_F(DeviceStatusCollectorTest, ActivityTimesEnabledByDefault) { | 596 TEST_F(DeviceStatusCollectorTest, ActivityTimesEnabledByDefault) { |
| 679 // Device activity times should be reported by default. | 597 // Device activity times should be reported by default. |
| 680 ui::IdleState test_states[] = { | 598 ui::IdleState test_states[] = { |
| 681 ui::IDLE_STATE_ACTIVE, | 599 ui::IDLE_STATE_ACTIVE, |
| 682 ui::IDLE_STATE_ACTIVE, | 600 ui::IDLE_STATE_ACTIVE, |
| 683 ui::IDLE_STATE_ACTIVE | 601 ui::IDLE_STATE_ACTIVE |
| 684 }; | 602 }; |
| 685 status_collector_->Simulate(test_states, | 603 status_collector_->Simulate(test_states, |
| 686 sizeof(test_states) / sizeof(ui::IdleState)); | 604 sizeof(test_states) / sizeof(ui::IdleState)); |
| 687 GetDeviceStatus(); | 605 GetStatus(); |
| 688 EXPECT_EQ(1, device_status_.active_period_size()); | 606 EXPECT_EQ(1, device_status_.active_period_size()); |
| 689 EXPECT_EQ(3 * ActivePeriodMilliseconds(), | 607 EXPECT_EQ(3 * ActivePeriodMilliseconds(), |
| 690 GetActiveMilliseconds(device_status_)); | 608 GetActiveMilliseconds(device_status_)); |
| 691 } | 609 } |
| 692 | 610 |
| 693 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { | 611 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { |
| 694 // Device activity times should not be reported if explicitly disabled. | 612 // Device activity times should not be reported if explicitly disabled. |
| 695 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, false); | 613 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, false); |
| 696 | 614 |
| 697 ui::IdleState test_states[] = { | 615 ui::IdleState test_states[] = { |
| 698 ui::IDLE_STATE_ACTIVE, | 616 ui::IDLE_STATE_ACTIVE, |
| 699 ui::IDLE_STATE_ACTIVE, | 617 ui::IDLE_STATE_ACTIVE, |
| 700 ui::IDLE_STATE_ACTIVE | 618 ui::IDLE_STATE_ACTIVE |
| 701 }; | 619 }; |
| 702 status_collector_->Simulate(test_states, | 620 status_collector_->Simulate(test_states, |
| 703 sizeof(test_states) / sizeof(ui::IdleState)); | 621 sizeof(test_states) / sizeof(ui::IdleState)); |
| 704 GetDeviceStatus(); | 622 GetStatus(); |
| 705 EXPECT_EQ(0, device_status_.active_period_size()); | 623 EXPECT_EQ(0, device_status_.active_period_size()); |
| 706 EXPECT_EQ(0, GetActiveMilliseconds(device_status_)); | 624 EXPECT_EQ(0, GetActiveMilliseconds(device_status_)); |
| 707 } | 625 } |
| 708 | 626 |
| 709 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { | 627 TEST_F(DeviceStatusCollectorTest, ActivityCrossingMidnight) { |
| 710 ui::IdleState test_states[] = { | 628 ui::IdleState test_states[] = { |
| 711 ui::IDLE_STATE_ACTIVE | 629 ui::IDLE_STATE_ACTIVE |
| 712 }; | 630 }; |
| 713 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 631 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 714 | 632 |
| 715 // Set the baseline time to 10 seconds after midnight. | 633 // Set the baseline time to 10 seconds after midnight. |
| 716 status_collector_->SetBaselineTime( | 634 status_collector_->SetBaselineTime( |
| 717 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); | 635 Time::Now().LocalMidnight() + TimeDelta::FromSeconds(10)); |
| 718 | 636 |
| 719 status_collector_->Simulate(test_states, 1); | 637 status_collector_->Simulate(test_states, 1); |
| 720 GetDeviceStatus(); | 638 GetStatus(); |
| 721 ASSERT_EQ(2, device_status_.active_period_size()); | 639 ASSERT_EQ(2, device_status_.active_period_size()); |
| 722 | 640 |
| 723 em::ActiveTimePeriod period0 = device_status_.active_period(0); | 641 em::ActiveTimePeriod period0 = device_status_.active_period(0); |
| 724 em::ActiveTimePeriod period1 = device_status_.active_period(1); | 642 em::ActiveTimePeriod period1 = device_status_.active_period(1); |
| 725 EXPECT_EQ(ActivePeriodMilliseconds() - 10000, period0.active_duration()); | 643 EXPECT_EQ(ActivePeriodMilliseconds() - 10000, period0.active_duration()); |
| 726 EXPECT_EQ(10000, period1.active_duration()); | 644 EXPECT_EQ(10000, period1.active_duration()); |
| 727 | 645 |
| 728 em::TimePeriod time_period0 = period0.time_period(); | 646 em::TimePeriod time_period0 = period0.time_period(); |
| 729 em::TimePeriod time_period1 = period1.time_period(); | 647 em::TimePeriod time_period1 = period1.time_period(); |
| 730 | 648 |
| 731 EXPECT_EQ(time_period0.end_timestamp(), time_period1.start_timestamp()); | 649 EXPECT_EQ(time_period0.end_timestamp(), time_period1.start_timestamp()); |
| 732 | 650 |
| 733 // Ensure that the start and end times for the period are a day apart. | 651 // Ensure that the start and end times for the period are a day apart. |
| 734 EXPECT_EQ(time_period0.end_timestamp() - time_period0.start_timestamp(), | 652 EXPECT_EQ(time_period0.end_timestamp() - time_period0.start_timestamp(), |
| 735 kMillisecondsPerDay); | 653 kMillisecondsPerDay); |
| 736 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(), | 654 EXPECT_EQ(time_period1.end_timestamp() - time_period1.start_timestamp(), |
| 737 kMillisecondsPerDay); | 655 kMillisecondsPerDay); |
| 738 } | 656 } |
| 739 | 657 |
| 740 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { | 658 TEST_F(DeviceStatusCollectorTest, ActivityTimesKeptUntilSubmittedSuccessfully) { |
| 741 ui::IdleState test_states[] = { | 659 ui::IdleState test_states[] = { |
| 742 ui::IDLE_STATE_ACTIVE, | 660 ui::IDLE_STATE_ACTIVE, |
| 743 ui::IDLE_STATE_ACTIVE, | 661 ui::IDLE_STATE_ACTIVE, |
| 744 }; | 662 }; |
| 663 // Make sure CPU stats get reported in time. If we don't run this, the second |
| 664 // call to |GetStatus()| will contain these stats, but the first call won't |
| 665 // and the EXPECT_EQ test below fails. |
| 745 base::RunLoop().RunUntilIdle(); | 666 base::RunLoop().RunUntilIdle(); |
| 667 |
| 746 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); | 668 settings_helper_.SetBoolean(chromeos::kReportDeviceActivityTimes, true); |
| 747 | 669 |
| 748 status_collector_->Simulate(test_states, 2); | 670 status_collector_->Simulate(test_states, 2); |
| 749 GetDeviceStatus(); | 671 GetStatus(); |
| 750 EXPECT_EQ(2 * ActivePeriodMilliseconds(), | 672 EXPECT_EQ(2 * ActivePeriodMilliseconds(), |
| 751 GetActiveMilliseconds(device_status_)); | 673 GetActiveMilliseconds(device_status_)); |
| 752 em::DeviceStatusReportRequest first_status(device_status_); | 674 em::DeviceStatusReportRequest first_status(device_status_); |
| 753 | 675 |
| 754 // The collector returns the same status again. | 676 // The collector returns the same status again. |
| 755 GetDeviceStatus(); | 677 GetStatus(); |
| 756 EXPECT_EQ(first_status.SerializeAsString(), | 678 EXPECT_EQ(first_status.SerializeAsString(), |
| 757 device_status_.SerializeAsString()); | 679 device_status_.SerializeAsString()); |
| 758 | 680 |
| 759 // After indicating a successful submit, the submitted status gets cleared, | 681 // After indicating a successful submit, the submitted status gets cleared, |
| 760 // but what got collected meanwhile sticks around. | 682 // but what got collected meanwhile sticks around. |
| 761 status_collector_->Simulate(test_states, 1); | 683 status_collector_->Simulate(test_states, 1); |
| 762 status_collector_->OnSubmittedSuccessfully(); | 684 status_collector_->OnSubmittedSuccessfully(); |
| 763 GetDeviceStatus(); | 685 GetStatus(); |
| 764 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(device_status_)); | 686 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(device_status_)); |
| 765 } | 687 } |
| 766 | 688 |
| 767 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { | 689 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { |
| 768 // Test that boot mode data is reported by default. | 690 // Test that boot mode data is reported by default. |
| 769 fake_statistics_provider_.SetMachineStatistic( | 691 fake_statistics_provider_.SetMachineStatistic( |
| 770 chromeos::system::kDevSwitchBootKey, | 692 chromeos::system::kDevSwitchBootKey, |
| 771 chromeos::system::kDevSwitchBootValueVerified); | 693 chromeos::system::kDevSwitchBootValueVerified); |
| 772 GetDeviceStatus(); | 694 GetStatus(); |
| 773 EXPECT_EQ("Verified", device_status_.boot_mode()); | 695 EXPECT_EQ("Verified", device_status_.boot_mode()); |
| 774 | 696 |
| 775 // Test that boot mode data is not reported if the pref turned off. | 697 // Test that boot mode data is not reported if the pref turned off. |
| 776 settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, false); | 698 settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, false); |
| 777 | 699 |
| 778 GetDeviceStatus(); | 700 GetStatus(); |
| 779 EXPECT_FALSE(device_status_.has_boot_mode()); | 701 EXPECT_FALSE(device_status_.has_boot_mode()); |
| 780 | 702 |
| 781 // Turn the pref on, and check that the status is reported iff the | 703 // Turn the pref on, and check that the status is reported iff the |
| 782 // statistics provider returns valid data. | 704 // statistics provider returns valid data. |
| 783 settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, true); | 705 settings_helper_.SetBoolean(chromeos::kReportDeviceBootMode, true); |
| 784 | 706 |
| 785 fake_statistics_provider_.SetMachineStatistic( | 707 fake_statistics_provider_.SetMachineStatistic( |
| 786 chromeos::system::kDevSwitchBootKey, "(error)"); | 708 chromeos::system::kDevSwitchBootKey, "(error)"); |
| 787 GetDeviceStatus(); | 709 GetStatus(); |
| 788 EXPECT_FALSE(device_status_.has_boot_mode()); | 710 EXPECT_FALSE(device_status_.has_boot_mode()); |
| 789 | 711 |
| 790 fake_statistics_provider_.SetMachineStatistic( | 712 fake_statistics_provider_.SetMachineStatistic( |
| 791 chromeos::system::kDevSwitchBootKey, " "); | 713 chromeos::system::kDevSwitchBootKey, " "); |
| 792 GetDeviceStatus(); | 714 GetStatus(); |
| 793 EXPECT_FALSE(device_status_.has_boot_mode()); | 715 EXPECT_FALSE(device_status_.has_boot_mode()); |
| 794 | 716 |
| 795 fake_statistics_provider_.SetMachineStatistic( | 717 fake_statistics_provider_.SetMachineStatistic( |
| 796 chromeos::system::kDevSwitchBootKey, | 718 chromeos::system::kDevSwitchBootKey, |
| 797 chromeos::system::kDevSwitchBootValueVerified); | 719 chromeos::system::kDevSwitchBootValueVerified); |
| 798 GetDeviceStatus(); | 720 GetStatus(); |
| 799 EXPECT_EQ("Verified", device_status_.boot_mode()); | 721 EXPECT_EQ("Verified", device_status_.boot_mode()); |
| 800 | 722 |
| 801 fake_statistics_provider_.SetMachineStatistic( | 723 fake_statistics_provider_.SetMachineStatistic( |
| 802 chromeos::system::kDevSwitchBootKey, | 724 chromeos::system::kDevSwitchBootKey, |
| 803 chromeos::system::kDevSwitchBootValueDev); | 725 chromeos::system::kDevSwitchBootValueDev); |
| 804 GetDeviceStatus(); | 726 GetStatus(); |
| 805 EXPECT_EQ("Dev", device_status_.boot_mode()); | 727 EXPECT_EQ("Dev", device_status_.boot_mode()); |
| 806 } | 728 } |
| 807 | 729 |
| 808 TEST_F(DeviceStatusCollectorTest, VersionInfo) { | 730 TEST_F(DeviceStatusCollectorTest, VersionInfo) { |
| 809 // Expect the version info to be reported by default. | 731 // Expect the version info to be reported by default. |
| 810 GetDeviceStatus(); | 732 GetStatus(); |
| 811 EXPECT_TRUE(device_status_.has_browser_version()); | 733 EXPECT_TRUE(device_status_.has_browser_version()); |
| 812 EXPECT_TRUE(device_status_.has_os_version()); | 734 EXPECT_TRUE(device_status_.has_os_version()); |
| 813 EXPECT_TRUE(device_status_.has_firmware_version()); | 735 EXPECT_TRUE(device_status_.has_firmware_version()); |
| 814 | 736 |
| 815 // When the pref to collect this data is not enabled, expect that none of | 737 // When the pref to collect this data is not enabled, expect that none of |
| 816 // the fields are present in the protobuf. | 738 // the fields are present in the protobuf. |
| 817 settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, false); | 739 settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, false); |
| 818 GetDeviceStatus(); | 740 GetStatus(); |
| 819 EXPECT_FALSE(device_status_.has_browser_version()); | 741 EXPECT_FALSE(device_status_.has_browser_version()); |
| 820 EXPECT_FALSE(device_status_.has_os_version()); | 742 EXPECT_FALSE(device_status_.has_os_version()); |
| 821 EXPECT_FALSE(device_status_.has_firmware_version()); | 743 EXPECT_FALSE(device_status_.has_firmware_version()); |
| 822 | 744 |
| 823 settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, true); | 745 settings_helper_.SetBoolean(chromeos::kReportDeviceVersionInfo, true); |
| 824 GetDeviceStatus(); | 746 GetStatus(); |
| 825 EXPECT_TRUE(device_status_.has_browser_version()); | 747 EXPECT_TRUE(device_status_.has_browser_version()); |
| 826 EXPECT_TRUE(device_status_.has_os_version()); | 748 EXPECT_TRUE(device_status_.has_os_version()); |
| 827 EXPECT_TRUE(device_status_.has_firmware_version()); | 749 EXPECT_TRUE(device_status_.has_firmware_version()); |
| 828 | 750 |
| 829 // Check that the browser version is not empty. OS version & firmware | 751 // Check that the browser version is not empty. OS version & firmware |
| 830 // don't have any reasonable values inside the unit test, so those | 752 // don't have any reasonable values inside the unit test, so those |
| 831 // aren't checked. | 753 // aren't checked. |
| 832 EXPECT_NE("", device_status_.browser_version()); | 754 EXPECT_NE("", device_status_.browser_version()); |
| 833 } | 755 } |
| 834 | 756 |
| 835 TEST_F(DeviceStatusCollectorTest, Location) { | |
| 836 device::Geoposition valid_fix; | |
| 837 valid_fix.latitude = 4.3; | |
| 838 valid_fix.longitude = -7.8; | |
| 839 valid_fix.accuracy = 3.; | |
| 840 valid_fix.timestamp = Time::Now(); | |
| 841 | |
| 842 device::Geoposition invalid_fix; | |
| 843 invalid_fix.error_code = device::Geoposition::ERROR_CODE_POSITION_UNAVAILABLE; | |
| 844 invalid_fix.timestamp = Time::Now(); | |
| 845 | |
| 846 // Check that when device location reporting is disabled, no location is | |
| 847 // reported. | |
| 848 SetMockPositionToReturnNext(valid_fix); | |
| 849 CheckThatNoLocationIsReported(); | |
| 850 | |
| 851 // Check that when device location reporting is enabled and a valid fix is | |
| 852 // available, the location is reported and is stored in local state. | |
| 853 SetMockPositionToReturnNext(valid_fix); | |
| 854 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, true); | |
| 855 EXPECT_FALSE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); | |
| 856 CheckThatAValidLocationIsReported(); | |
| 857 | |
| 858 // Restart the status collector. Check that the last known location has been | |
| 859 // retrieved from local state without requesting a geolocation update. | |
| 860 SetMockPositionToReturnNext(valid_fix); | |
| 861 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), | |
| 862 base::Bind(&GetEmptyCPUStatistics), | |
| 863 base::Bind(&GetEmptyCPUTempInfo)); | |
| 864 CheckThatAValidLocationIsReported(); | |
| 865 EXPECT_TRUE(mock_position_to_return_next.get()); | |
| 866 | |
| 867 // Check that after disabling location reporting again, the last known | |
| 868 // location has been cleared from local state and is no longer reported. | |
| 869 SetMockPositionToReturnNext(valid_fix); | |
| 870 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, false); | |
| 871 // Allow the new pref to propagate to the status collector. | |
| 872 base::RunLoop().RunUntilIdle(); | |
| 873 EXPECT_TRUE(prefs_.GetDictionary(prefs::kDeviceLocation)->empty()); | |
| 874 CheckThatNoLocationIsReported(); | |
| 875 | |
| 876 // Check that after enabling location reporting again, an error is reported | |
| 877 // if no valid fix is available. | |
| 878 SetMockPositionToReturnNext(invalid_fix); | |
| 879 settings_helper_.SetBoolean(chromeos::kReportDeviceLocation, true); | |
| 880 // Allow the new pref to propagate to the status collector. | |
| 881 base::RunLoop().RunUntilIdle(); | |
| 882 CheckThatALocationErrorIsReported(); | |
| 883 } | |
| 884 | |
| 885 TEST_F(DeviceStatusCollectorTest, ReportUsers) { | 757 TEST_F(DeviceStatusCollectorTest, ReportUsers) { |
| 886 const AccountId public_account_id( | 758 const AccountId public_account_id( |
| 887 AccountId::FromUserEmail("public@localhost")); | 759 AccountId::FromUserEmail("public@localhost")); |
| 888 const AccountId account_id0(AccountId::FromUserEmail("user0@managed.com")); | 760 const AccountId account_id0(AccountId::FromUserEmail("user0@managed.com")); |
| 889 const AccountId account_id1(AccountId::FromUserEmail("user1@managed.com")); | 761 const AccountId account_id1(AccountId::FromUserEmail("user1@managed.com")); |
| 890 const AccountId account_id2(AccountId::FromUserEmail("user2@managed.com")); | 762 const AccountId account_id2(AccountId::FromUserEmail("user2@managed.com")); |
| 891 const AccountId account_id3(AccountId::FromUserEmail("user3@unmanaged.com")); | 763 const AccountId account_id3(AccountId::FromUserEmail("user3@unmanaged.com")); |
| 892 const AccountId account_id4(AccountId::FromUserEmail("user4@managed.com")); | 764 const AccountId account_id4(AccountId::FromUserEmail("user4@managed.com")); |
| 893 const AccountId account_id5(AccountId::FromUserEmail("user5@managed.com")); | 765 const AccountId account_id5(AccountId::FromUserEmail("user5@managed.com")); |
| 894 | 766 |
| 895 user_manager_->CreatePublicAccountUser(public_account_id); | 767 user_manager_->CreatePublicAccountUser(public_account_id); |
| 896 user_manager_->AddUserWithAffiliation(account_id0, true); | 768 user_manager_->AddUserWithAffiliation(account_id0, true); |
| 897 user_manager_->AddUserWithAffiliation(account_id1, true); | 769 user_manager_->AddUserWithAffiliation(account_id1, true); |
| 898 user_manager_->AddUserWithAffiliation(account_id2, true); | 770 user_manager_->AddUserWithAffiliation(account_id2, true); |
| 899 user_manager_->AddUserWithAffiliation(account_id3, false); | 771 user_manager_->AddUserWithAffiliation(account_id3, false); |
| 900 user_manager_->AddUserWithAffiliation(account_id4, true); | 772 user_manager_->AddUserWithAffiliation(account_id4, true); |
| 901 user_manager_->AddUserWithAffiliation(account_id5, true); | 773 user_manager_->AddUserWithAffiliation(account_id5, true); |
| 902 | 774 |
| 903 // Verify that users are reported by default. | 775 // Verify that users are reported by default. |
| 904 GetDeviceStatus(); | 776 GetStatus(); |
| 905 EXPECT_EQ(6, device_status_.user_size()); | 777 EXPECT_EQ(6, device_status_.user_size()); |
| 906 | 778 |
| 907 // Verify that users are reported after enabling the setting. | 779 // Verify that users are reported after enabling the setting. |
| 908 settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, true); | 780 settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, true); |
| 909 GetDeviceStatus(); | 781 GetStatus(); |
| 910 EXPECT_EQ(6, device_status_.user_size()); | 782 EXPECT_EQ(6, device_status_.user_size()); |
| 911 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(0).type()); | 783 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(0).type()); |
| 912 EXPECT_EQ(account_id0.GetUserEmail(), device_status_.user(0).email()); | 784 EXPECT_EQ(account_id0.GetUserEmail(), device_status_.user(0).email()); |
| 913 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(1).type()); | 785 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(1).type()); |
| 914 EXPECT_EQ(account_id1.GetUserEmail(), device_status_.user(1).email()); | 786 EXPECT_EQ(account_id1.GetUserEmail(), device_status_.user(1).email()); |
| 915 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(2).type()); | 787 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(2).type()); |
| 916 EXPECT_EQ(account_id2.GetUserEmail(), device_status_.user(2).email()); | 788 EXPECT_EQ(account_id2.GetUserEmail(), device_status_.user(2).email()); |
| 917 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, device_status_.user(3).type()); | 789 EXPECT_EQ(em::DeviceUser::USER_TYPE_UNMANAGED, device_status_.user(3).type()); |
| 918 EXPECT_FALSE(device_status_.user(3).has_email()); | 790 EXPECT_FALSE(device_status_.user(3).has_email()); |
| 919 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(4).type()); | 791 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(4).type()); |
| 920 EXPECT_EQ(account_id4.GetUserEmail(), device_status_.user(4).email()); | 792 EXPECT_EQ(account_id4.GetUserEmail(), device_status_.user(4).email()); |
| 921 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(5).type()); | 793 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, device_status_.user(5).type()); |
| 922 EXPECT_EQ(account_id5.GetUserEmail(), device_status_.user(5).email()); | 794 EXPECT_EQ(account_id5.GetUserEmail(), device_status_.user(5).email()); |
| 923 | 795 |
| 924 // Verify that users are no longer reported if setting is disabled. | 796 // Verify that users are no longer reported if setting is disabled. |
| 925 settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, false); | 797 settings_helper_.SetBoolean(chromeos::kReportDeviceUsers, false); |
| 926 GetDeviceStatus(); | 798 GetStatus(); |
| 927 EXPECT_EQ(0, device_status_.user_size()); | 799 EXPECT_EQ(0, device_status_.user_size()); |
| 928 } | 800 } |
| 929 | 801 |
| 930 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { | 802 TEST_F(DeviceStatusCollectorTest, TestVolumeInfo) { |
| 931 std::vector<std::string> expected_mount_points; | 803 std::vector<std::string> expected_mount_points; |
| 932 std::vector<em::VolumeInfo> expected_volume_info; | 804 std::vector<em::VolumeInfo> expected_volume_info; |
| 933 int size = 12345678; | 805 int size = 12345678; |
| 934 for (const auto& mount_info : | 806 for (const auto& mount_info : |
| 935 DiskMountManager::GetInstance()->mount_points()) { | 807 DiskMountManager::GetInstance()->mount_points()) { |
| 936 expected_mount_points.push_back(mount_info.first); | 808 expected_mount_points.push_back(mount_info.first); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 947 } | 819 } |
| 948 EXPECT_FALSE(expected_volume_info.empty()); | 820 EXPECT_FALSE(expected_volume_info.empty()); |
| 949 | 821 |
| 950 RestartStatusCollector(base::Bind(&GetFakeVolumeInfo, expected_volume_info), | 822 RestartStatusCollector(base::Bind(&GetFakeVolumeInfo, expected_volume_info), |
| 951 base::Bind(&GetEmptyCPUStatistics), | 823 base::Bind(&GetEmptyCPUStatistics), |
| 952 base::Bind(&GetEmptyCPUTempInfo)); | 824 base::Bind(&GetEmptyCPUTempInfo)); |
| 953 // Force finishing tasks posted by ctor of DeviceStatusCollector. | 825 // Force finishing tasks posted by ctor of DeviceStatusCollector. |
| 954 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 826 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 955 base::RunLoop().RunUntilIdle(); | 827 base::RunLoop().RunUntilIdle(); |
| 956 | 828 |
| 957 GetDeviceStatus(); | 829 GetStatus(); |
| 958 EXPECT_EQ(expected_mount_points.size(), | 830 EXPECT_EQ(expected_mount_points.size(), |
| 959 static_cast<size_t>(device_status_.volume_info_size())); | 831 static_cast<size_t>(device_status_.volume_info_size())); |
| 960 | 832 |
| 961 // Walk the returned VolumeInfo to make sure it matches. | 833 // Walk the returned VolumeInfo to make sure it matches. |
| 962 for (const em::VolumeInfo& expected_info : expected_volume_info) { | 834 for (const em::VolumeInfo& expected_info : expected_volume_info) { |
| 963 bool found = false; | 835 bool found = false; |
| 964 for (const em::VolumeInfo& info : device_status_.volume_info()) { | 836 for (const em::VolumeInfo& info : device_status_.volume_info()) { |
| 965 if (info.volume_id() == expected_info.volume_id()) { | 837 if (info.volume_id() == expected_info.volume_id()) { |
| 966 EXPECT_EQ(expected_info.storage_total(), info.storage_total()); | 838 EXPECT_EQ(expected_info.storage_total(), info.storage_total()); |
| 967 EXPECT_EQ(expected_info.storage_free(), info.storage_free()); | 839 EXPECT_EQ(expected_info.storage_free(), info.storage_free()); |
| 968 found = true; | 840 found = true; |
| 969 break; | 841 break; |
| 970 } | 842 } |
| 971 } | 843 } |
| 972 EXPECT_TRUE(found) << "No matching VolumeInfo for " | 844 EXPECT_TRUE(found) << "No matching VolumeInfo for " |
| 973 << expected_info.volume_id(); | 845 << expected_info.volume_id(); |
| 974 } | 846 } |
| 975 | 847 |
| 976 // Now turn off hardware status reporting - should have no data. | 848 // Now turn off hardware status reporting - should have no data. |
| 977 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 849 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); |
| 978 GetDeviceStatus(); | 850 GetStatus(); |
| 979 EXPECT_EQ(0, device_status_.volume_info_size()); | 851 EXPECT_EQ(0, device_status_.volume_info_size()); |
| 980 } | 852 } |
| 981 | 853 |
| 982 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { | 854 TEST_F(DeviceStatusCollectorTest, TestAvailableMemory) { |
| 983 // Refresh our samples. Sample more than kMaxHardwareSamples times to | 855 // Refresh our samples. Sample more than kMaxHardwareSamples times to |
| 984 // make sure that the code correctly caps the number of cached samples. | 856 // make sure that the code correctly caps the number of cached samples. |
| 985 for (int i = 0; i < static_cast<int>( | 857 for (int i = 0; i < static_cast<int>( |
| 986 DeviceStatusCollector::kMaxResourceUsageSamples + 1); | 858 DeviceStatusCollector::kMaxResourceUsageSamples + 1); |
| 987 ++i) { | 859 ++i) { |
| 988 status_collector_->RefreshSampleResourceUsage(); | 860 status_collector_->RefreshSampleResourceUsage(); |
| 989 base::RunLoop().RunUntilIdle(); | 861 base::RunLoop().RunUntilIdle(); |
| 990 } | 862 } |
| 991 GetDeviceStatus(); | 863 GetStatus(); |
| 992 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), | 864 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), |
| 993 device_status_.system_ram_free().size()); | 865 device_status_.system_ram_free().size()); |
| 994 EXPECT_TRUE(device_status_.has_system_ram_total()); | 866 EXPECT_TRUE(device_status_.has_system_ram_total()); |
| 995 // No good way to inject specific test values for available system RAM, so | 867 // No good way to inject specific test values for available system RAM, so |
| 996 // just make sure it's > 0. | 868 // just make sure it's > 0. |
| 997 EXPECT_GT(device_status_.system_ram_total(), 0); | 869 EXPECT_GT(device_status_.system_ram_total(), 0); |
| 998 } | 870 } |
| 999 | 871 |
| 1000 TEST_F(DeviceStatusCollectorTest, TestCPUSamples) { | 872 TEST_F(DeviceStatusCollectorTest, TestCPUSamples) { |
| 1001 // Mock 100% CPU usage. | 873 // Mock 100% CPU usage. |
| 1002 std::string full_cpu_usage("cpu 500 0 500 0 0 0 0"); | 874 std::string full_cpu_usage("cpu 500 0 500 0 0 0 0"); |
| 1003 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), | 875 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), |
| 1004 base::Bind(&GetFakeCPUStatistics, full_cpu_usage), | 876 base::Bind(&GetFakeCPUStatistics, full_cpu_usage), |
| 1005 base::Bind(&GetEmptyCPUTempInfo)); | 877 base::Bind(&GetEmptyCPUTempInfo)); |
| 1006 // Force finishing tasks posted by ctor of DeviceStatusCollector. | 878 // Force finishing tasks posted by ctor of DeviceStatusCollector. |
| 1007 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 879 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 1008 base::RunLoop().RunUntilIdle(); | 880 base::RunLoop().RunUntilIdle(); |
| 1009 GetDeviceStatus(); | 881 GetStatus(); |
| 1010 ASSERT_EQ(1, device_status_.cpu_utilization_pct().size()); | 882 ASSERT_EQ(1, device_status_.cpu_utilization_pct().size()); |
| 1011 EXPECT_EQ(100, device_status_.cpu_utilization_pct(0)); | 883 EXPECT_EQ(100, device_status_.cpu_utilization_pct(0)); |
| 1012 | 884 |
| 1013 // Now sample CPU usage again (active usage counters will not increase | 885 // Now sample CPU usage again (active usage counters will not increase |
| 1014 // so should show 0% cpu usage). | 886 // so should show 0% cpu usage). |
| 1015 status_collector_->RefreshSampleResourceUsage(); | 887 status_collector_->RefreshSampleResourceUsage(); |
| 1016 base::RunLoop().RunUntilIdle(); | 888 base::RunLoop().RunUntilIdle(); |
| 1017 GetDeviceStatus(); | 889 GetStatus(); |
| 1018 ASSERT_EQ(2, device_status_.cpu_utilization_pct().size()); | 890 ASSERT_EQ(2, device_status_.cpu_utilization_pct().size()); |
| 1019 EXPECT_EQ(0, device_status_.cpu_utilization_pct(1)); | 891 EXPECT_EQ(0, device_status_.cpu_utilization_pct(1)); |
| 1020 | 892 |
| 1021 // Now store a bunch of 0% cpu usage and make sure we cap the max number of | 893 // Now store a bunch of 0% cpu usage and make sure we cap the max number of |
| 1022 // samples. | 894 // samples. |
| 1023 for (int i = 0; | 895 for (int i = 0; |
| 1024 i < static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples); | 896 i < static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples); |
| 1025 ++i) { | 897 ++i) { |
| 1026 status_collector_->RefreshSampleResourceUsage(); | 898 status_collector_->RefreshSampleResourceUsage(); |
| 1027 base::RunLoop().RunUntilIdle(); | 899 base::RunLoop().RunUntilIdle(); |
| 1028 } | 900 } |
| 1029 GetDeviceStatus(); | 901 GetStatus(); |
| 1030 | 902 |
| 1031 // Should not be more than kMaxResourceUsageSamples, and they should all show | 903 // Should not be more than kMaxResourceUsageSamples, and they should all show |
| 1032 // the CPU is idle. | 904 // the CPU is idle. |
| 1033 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), | 905 EXPECT_EQ(static_cast<int>(DeviceStatusCollector::kMaxResourceUsageSamples), |
| 1034 device_status_.cpu_utilization_pct().size()); | 906 device_status_.cpu_utilization_pct().size()); |
| 1035 for (const auto utilization : device_status_.cpu_utilization_pct()) | 907 for (const auto utilization : device_status_.cpu_utilization_pct()) |
| 1036 EXPECT_EQ(0, utilization); | 908 EXPECT_EQ(0, utilization); |
| 1037 | 909 |
| 1038 // Turning off hardware reporting should not report CPU utilization. | 910 // Turning off hardware reporting should not report CPU utilization. |
| 1039 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 911 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); |
| 1040 GetDeviceStatus(); | 912 GetStatus(); |
| 1041 EXPECT_EQ(0, device_status_.cpu_utilization_pct().size()); | 913 EXPECT_EQ(0, device_status_.cpu_utilization_pct().size()); |
| 1042 } | 914 } |
| 1043 | 915 |
| 1044 TEST_F(DeviceStatusCollectorTest, TestCPUTemp) { | 916 TEST_F(DeviceStatusCollectorTest, TestCPUTemp) { |
| 1045 std::vector<em::CPUTempInfo> expected_temp_info; | 917 std::vector<em::CPUTempInfo> expected_temp_info; |
| 1046 int cpu_cnt = 12; | 918 int cpu_cnt = 12; |
| 1047 for (int i = 0; i < cpu_cnt; ++i) { | 919 for (int i = 0; i < cpu_cnt; ++i) { |
| 1048 em::CPUTempInfo info; | 920 em::CPUTempInfo info; |
| 1049 info.set_cpu_temp(i * 10 + 100); | 921 info.set_cpu_temp(i * 10 + 100); |
| 1050 info.set_cpu_label(base::StringPrintf("Core %d", i)); | 922 info.set_cpu_label(base::StringPrintf("Core %d", i)); |
| 1051 expected_temp_info.push_back(info); | 923 expected_temp_info.push_back(info); |
| 1052 } | 924 } |
| 1053 | 925 |
| 1054 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), | 926 RestartStatusCollector(base::Bind(&GetEmptyVolumeInfo), |
| 1055 base::Bind(&GetEmptyCPUStatistics), | 927 base::Bind(&GetEmptyCPUStatistics), |
| 1056 base::Bind(&GetFakeCPUTempInfo, expected_temp_info)); | 928 base::Bind(&GetFakeCPUTempInfo, expected_temp_info)); |
| 1057 // Force finishing tasks posted by ctor of DeviceStatusCollector. | 929 // Force finishing tasks posted by ctor of DeviceStatusCollector. |
| 1058 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 930 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 1059 base::RunLoop().RunUntilIdle(); | 931 base::RunLoop().RunUntilIdle(); |
| 1060 | 932 |
| 1061 GetDeviceStatus(); | 933 GetStatus(); |
| 1062 EXPECT_EQ(expected_temp_info.size(), | 934 EXPECT_EQ(expected_temp_info.size(), |
| 1063 static_cast<size_t>(device_status_.cpu_temp_info_size())); | 935 static_cast<size_t>(device_status_.cpu_temp_info_size())); |
| 1064 | 936 |
| 1065 // Walk the returned CPUTempInfo to make sure it matches. | 937 // Walk the returned CPUTempInfo to make sure it matches. |
| 1066 for (const em::CPUTempInfo& expected_info : expected_temp_info) { | 938 for (const em::CPUTempInfo& expected_info : expected_temp_info) { |
| 1067 bool found = false; | 939 bool found = false; |
| 1068 for (const em::CPUTempInfo& info : device_status_.cpu_temp_info()) { | 940 for (const em::CPUTempInfo& info : device_status_.cpu_temp_info()) { |
| 1069 if (info.cpu_label() == expected_info.cpu_label()) { | 941 if (info.cpu_label() == expected_info.cpu_label()) { |
| 1070 EXPECT_EQ(expected_info.cpu_temp(), info.cpu_temp()); | 942 EXPECT_EQ(expected_info.cpu_temp(), info.cpu_temp()); |
| 1071 found = true; | 943 found = true; |
| 1072 break; | 944 break; |
| 1073 } | 945 } |
| 1074 } | 946 } |
| 1075 EXPECT_TRUE(found) << "No matching CPUTempInfo for " | 947 EXPECT_TRUE(found) << "No matching CPUTempInfo for " |
| 1076 << expected_info.cpu_label(); | 948 << expected_info.cpu_label(); |
| 1077 } | 949 } |
| 1078 | 950 |
| 1079 // Now turn off hardware status reporting - should have no data. | 951 // Now turn off hardware status reporting - should have no data. |
| 1080 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); | 952 settings_helper_.SetBoolean(chromeos::kReportDeviceHardwareStatus, false); |
| 1081 GetDeviceStatus(); | 953 GetStatus(); |
| 1082 EXPECT_EQ(0, device_status_.cpu_temp_info_size()); | 954 EXPECT_EQ(0, device_status_.cpu_temp_info_size()); |
| 1083 } | 955 } |
| 1084 | 956 |
| 1085 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { | 957 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfNotKioskMode) { |
| 1086 // Should not report session status if we don't have an active kiosk app. | 958 // Should not report session status if we don't have an active kiosk app. |
| 1087 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 959 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); |
| 1088 GetSessionStatus(); | 960 GetStatus(); |
| 1089 EXPECT_FALSE(got_session_status_); | 961 EXPECT_FALSE(got_session_status_); |
| 1090 } | 962 } |
| 1091 | 963 |
| 1092 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { | 964 TEST_F(DeviceStatusCollectorTest, NoSessionStatusIfSessionReportingDisabled) { |
| 1093 // Should not report session status if session status reporting is disabled. | 965 // Should not report session status if session status reporting is disabled. |
| 1094 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); | 966 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, false); |
| 1095 status_collector_->set_kiosk_account( | 967 status_collector_->set_kiosk_account( |
| 1096 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); | 968 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); |
| 1097 // Set up a device-local account for single-app kiosk mode. | 969 // Set up a device-local account for single-app kiosk mode. |
| 1098 MockRunningKioskApp(fake_device_local_account_); | 970 MockRunningKioskApp(fake_device_local_account_); |
| 1099 | 971 |
| 1100 GetSessionStatus(); | 972 GetStatus(); |
| 1101 EXPECT_FALSE(got_session_status_); | 973 EXPECT_FALSE(got_session_status_); |
| 1102 } | 974 } |
| 1103 | 975 |
| 1104 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { | 976 TEST_F(DeviceStatusCollectorTest, ReportSessionStatus) { |
| 1105 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); | 977 settings_helper_.SetBoolean(chromeos::kReportDeviceSessionStatus, true); |
| 1106 status_collector_->set_kiosk_account( | 978 status_collector_->set_kiosk_account( |
| 1107 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); | 979 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); |
| 1108 | 980 |
| 1109 // Set up a device-local account for single-app kiosk mode. | 981 // Set up a device-local account for single-app kiosk mode. |
| 1110 MockRunningKioskApp(fake_device_local_account_); | 982 MockRunningKioskApp(fake_device_local_account_); |
| 1111 | 983 |
| 1112 GetSessionStatus(); | 984 GetStatus(); |
| 1113 EXPECT_TRUE(got_session_status_); | 985 EXPECT_TRUE(got_session_status_); |
| 1114 ASSERT_EQ(1, session_status_.installed_apps_size()); | 986 ASSERT_EQ(1, session_status_.installed_apps_size()); |
| 1115 EXPECT_EQ(kKioskAccountId, session_status_.device_local_account_id()); | 987 EXPECT_EQ(kKioskAccountId, session_status_.device_local_account_id()); |
| 1116 const em::AppStatus app = session_status_.installed_apps(0); | 988 const em::AppStatus app = session_status_.installed_apps(0); |
| 1117 EXPECT_EQ(kKioskAppId, app.app_id()); | 989 EXPECT_EQ(kKioskAppId, app.app_id()); |
| 1118 // Test code just sets the version to the app ID. | 990 // Test code just sets the version to the app ID. |
| 1119 EXPECT_EQ(kKioskAppId, app.extension_version()); | 991 EXPECT_EQ(kKioskAppId, app.extension_version()); |
| 1120 EXPECT_FALSE(app.has_status()); | 992 EXPECT_FALSE(app.has_status()); |
| 1121 EXPECT_FALSE(app.has_error()); | 993 EXPECT_FALSE(app.has_error()); |
| 1122 } | 994 } |
| 1123 | 995 |
| 1124 TEST_F(DeviceStatusCollectorTest, NoOsUpdateStatusByDefault) { | 996 TEST_F(DeviceStatusCollectorTest, NoOsUpdateStatusByDefault) { |
| 1125 MockPlatformVersion("1234.0.0"); | 997 MockPlatformVersion("1234.0.0"); |
| 1126 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, | 998 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, |
| 1127 "1234.0.0"); | 999 "1234.0.0"); |
| 1128 | 1000 |
| 1129 GetDeviceStatus(); | 1001 GetStatus(); |
| 1130 EXPECT_FALSE(device_status_.has_os_update_status()); | 1002 EXPECT_FALSE(device_status_.has_os_update_status()); |
| 1131 } | 1003 } |
| 1132 | 1004 |
| 1133 TEST_F(DeviceStatusCollectorTest, ReportOsUpdateStatusUpToDate) { | 1005 TEST_F(DeviceStatusCollectorTest, ReportOsUpdateStatusUpToDate) { |
| 1134 MockPlatformVersion("1234.0.0"); | 1006 MockPlatformVersion("1234.0.0"); |
| 1135 settings_helper_.SetBoolean(chromeos::kReportOsUpdateStatus, true); | 1007 settings_helper_.SetBoolean(chromeos::kReportOsUpdateStatus, true); |
| 1136 | 1008 |
| 1137 const char* kRequiredPlatformVersions[] = {"1234", "1234.0", "1234.0.0"}; | 1009 const char* kRequiredPlatformVersions[] = {"1234", "1234.0", "1234.0.0"}; |
| 1138 | 1010 |
| 1139 for (size_t i = 0; i < arraysize(kRequiredPlatformVersions); ++i) { | 1011 for (size_t i = 0; i < arraysize(kRequiredPlatformVersions); ++i) { |
| 1140 MockAutoLaunchKioskAppWithRequiredPlatformVersion( | 1012 MockAutoLaunchKioskAppWithRequiredPlatformVersion( |
| 1141 fake_device_local_account_, kRequiredPlatformVersions[i]); | 1013 fake_device_local_account_, kRequiredPlatformVersions[i]); |
| 1142 | 1014 |
| 1143 GetDeviceStatus(); | 1015 GetStatus(); |
| 1144 ASSERT_TRUE(device_status_.has_os_update_status()) | 1016 ASSERT_TRUE(device_status_.has_os_update_status()) |
| 1145 << "Required platform version=" << kRequiredPlatformVersions[i]; | 1017 << "Required platform version=" << kRequiredPlatformVersions[i]; |
| 1146 EXPECT_EQ(em::OsUpdateStatus::OS_UP_TO_DATE, | 1018 EXPECT_EQ(em::OsUpdateStatus::OS_UP_TO_DATE, |
| 1147 device_status_.os_update_status().update_status()) | 1019 device_status_.os_update_status().update_status()) |
| 1148 << "Required platform version=" << kRequiredPlatformVersions[i]; | 1020 << "Required platform version=" << kRequiredPlatformVersions[i]; |
| 1149 EXPECT_EQ(kRequiredPlatformVersions[i], | 1021 EXPECT_EQ(kRequiredPlatformVersions[i], |
| 1150 device_status_.os_update_status().new_required_platform_version()) | 1022 device_status_.os_update_status().new_required_platform_version()) |
| 1151 << "Required platform version=" << kRequiredPlatformVersions[i]; | 1023 << "Required platform version=" << kRequiredPlatformVersions[i]; |
| 1152 } | 1024 } |
| 1153 } | 1025 } |
| 1154 | 1026 |
| 1155 TEST_F(DeviceStatusCollectorTest, ReportOsUpdateStatus) { | 1027 TEST_F(DeviceStatusCollectorTest, ReportOsUpdateStatus) { |
| 1156 MockPlatformVersion("1234.0.0"); | 1028 MockPlatformVersion("1234.0.0"); |
| 1157 settings_helper_.SetBoolean(chromeos::kReportOsUpdateStatus, true); | 1029 settings_helper_.SetBoolean(chromeos::kReportOsUpdateStatus, true); |
| 1158 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, | 1030 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, |
| 1159 "1235"); | 1031 "1235"); |
| 1160 | 1032 |
| 1161 chromeos::UpdateEngineClient::Status update_status; | 1033 chromeos::UpdateEngineClient::Status update_status; |
| 1162 update_status.status = chromeos::UpdateEngineClient::UPDATE_STATUS_IDLE; | 1034 update_status.status = chromeos::UpdateEngineClient::UPDATE_STATUS_IDLE; |
| 1163 | 1035 |
| 1164 GetDeviceStatus(); | 1036 GetStatus(); |
| 1165 ASSERT_TRUE(device_status_.has_os_update_status()); | 1037 ASSERT_TRUE(device_status_.has_os_update_status()); |
| 1166 EXPECT_EQ(em::OsUpdateStatus::OS_IMAGE_DOWNLOAD_NOT_STARTED, | 1038 EXPECT_EQ(em::OsUpdateStatus::OS_IMAGE_DOWNLOAD_NOT_STARTED, |
| 1167 device_status_.os_update_status().update_status()); | 1039 device_status_.os_update_status().update_status()); |
| 1168 | 1040 |
| 1169 const chromeos::UpdateEngineClient::UpdateStatusOperation kUpdateEngineOps[] = | 1041 const chromeos::UpdateEngineClient::UpdateStatusOperation kUpdateEngineOps[] = |
| 1170 { | 1042 { |
| 1171 chromeos::UpdateEngineClient::UPDATE_STATUS_DOWNLOADING, | 1043 chromeos::UpdateEngineClient::UPDATE_STATUS_DOWNLOADING, |
| 1172 chromeos::UpdateEngineClient::UPDATE_STATUS_VERIFYING, | 1044 chromeos::UpdateEngineClient::UPDATE_STATUS_VERIFYING, |
| 1173 chromeos::UpdateEngineClient::UPDATE_STATUS_FINALIZING, | 1045 chromeos::UpdateEngineClient::UPDATE_STATUS_FINALIZING, |
| 1174 }; | 1046 }; |
| 1175 | 1047 |
| 1176 for (size_t i = 0; i < arraysize(kUpdateEngineOps); ++i) { | 1048 for (size_t i = 0; i < arraysize(kUpdateEngineOps); ++i) { |
| 1177 update_status.status = kUpdateEngineOps[i]; | 1049 update_status.status = kUpdateEngineOps[i]; |
| 1178 update_status.new_version = "1235.1.2"; | 1050 update_status.new_version = "1235.1.2"; |
| 1179 update_engine_client_->PushLastStatus(update_status); | 1051 update_engine_client_->PushLastStatus(update_status); |
| 1180 | 1052 |
| 1181 GetDeviceStatus(); | 1053 GetStatus(); |
| 1182 ASSERT_TRUE(device_status_.has_os_update_status()); | 1054 ASSERT_TRUE(device_status_.has_os_update_status()); |
| 1183 EXPECT_EQ(em::OsUpdateStatus::OS_IMAGE_DOWNLOAD_IN_PROGRESS, | 1055 EXPECT_EQ(em::OsUpdateStatus::OS_IMAGE_DOWNLOAD_IN_PROGRESS, |
| 1184 device_status_.os_update_status().update_status()); | 1056 device_status_.os_update_status().update_status()); |
| 1185 EXPECT_EQ("1235.1.2", | 1057 EXPECT_EQ("1235.1.2", |
| 1186 device_status_.os_update_status().new_platform_version()); | 1058 device_status_.os_update_status().new_platform_version()); |
| 1187 EXPECT_EQ( | 1059 EXPECT_EQ( |
| 1188 "1235", | 1060 "1235", |
| 1189 device_status_.os_update_status().new_required_platform_version()); | 1061 device_status_.os_update_status().new_required_platform_version()); |
| 1190 } | 1062 } |
| 1191 | 1063 |
| 1192 update_status.status = | 1064 update_status.status = |
| 1193 chromeos::UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; | 1065 chromeos::UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; |
| 1194 update_engine_client_->PushLastStatus(update_status); | 1066 update_engine_client_->PushLastStatus(update_status); |
| 1195 GetDeviceStatus(); | 1067 GetStatus(); |
| 1196 ASSERT_TRUE(device_status_.has_os_update_status()); | 1068 ASSERT_TRUE(device_status_.has_os_update_status()); |
| 1197 EXPECT_EQ(em::OsUpdateStatus::OS_UPDATE_NEED_REBOOT, | 1069 EXPECT_EQ(em::OsUpdateStatus::OS_UPDATE_NEED_REBOOT, |
| 1198 device_status_.os_update_status().update_status()); | 1070 device_status_.os_update_status().update_status()); |
| 1199 } | 1071 } |
| 1200 | 1072 |
| 1201 TEST_F(DeviceStatusCollectorTest, NoRunningKioskAppByDefault) { | 1073 TEST_F(DeviceStatusCollectorTest, NoRunningKioskAppByDefault) { |
| 1202 MockPlatformVersion("1234.0.0"); | 1074 MockPlatformVersion("1234.0.0"); |
| 1203 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, | 1075 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, |
| 1204 "1234.0.0"); | 1076 "1234.0.0"); |
| 1205 status_collector_->set_kiosk_account( | 1077 status_collector_->set_kiosk_account( |
| 1206 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); | 1078 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); |
| 1207 MockRunningKioskApp(fake_device_local_account_); | 1079 MockRunningKioskApp(fake_device_local_account_); |
| 1208 | 1080 |
| 1209 GetDeviceStatus(); | 1081 GetStatus(); |
| 1210 EXPECT_FALSE(device_status_.has_running_kiosk_app()); | 1082 EXPECT_FALSE(device_status_.has_running_kiosk_app()); |
| 1211 } | 1083 } |
| 1212 | 1084 |
| 1213 TEST_F(DeviceStatusCollectorTest, NoRunningKioskAppWhenNotInKioskSession) { | 1085 TEST_F(DeviceStatusCollectorTest, NoRunningKioskAppWhenNotInKioskSession) { |
| 1214 settings_helper_.SetBoolean(chromeos::kReportRunningKioskApp, true); | 1086 settings_helper_.SetBoolean(chromeos::kReportRunningKioskApp, true); |
| 1215 MockPlatformVersion("1234.0.0"); | 1087 MockPlatformVersion("1234.0.0"); |
| 1216 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, | 1088 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, |
| 1217 "1234.0.0"); | 1089 "1234.0.0"); |
| 1218 | 1090 |
| 1219 GetDeviceStatus(); | 1091 GetStatus(); |
| 1220 EXPECT_FALSE(device_status_.has_running_kiosk_app()); | 1092 EXPECT_FALSE(device_status_.has_running_kiosk_app()); |
| 1221 } | 1093 } |
| 1222 | 1094 |
| 1223 TEST_F(DeviceStatusCollectorTest, ReportRunningKioskApp) { | 1095 TEST_F(DeviceStatusCollectorTest, ReportRunningKioskApp) { |
| 1224 settings_helper_.SetBoolean(chromeos::kReportRunningKioskApp, true); | 1096 settings_helper_.SetBoolean(chromeos::kReportRunningKioskApp, true); |
| 1225 MockPlatformVersion("1234.0.0"); | 1097 MockPlatformVersion("1234.0.0"); |
| 1226 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, | 1098 MockAutoLaunchKioskAppWithRequiredPlatformVersion(fake_device_local_account_, |
| 1227 "1235"); | 1099 "1235"); |
| 1228 MockRunningKioskApp(fake_device_local_account_); | 1100 MockRunningKioskApp(fake_device_local_account_); |
| 1229 status_collector_->set_kiosk_account( | 1101 status_collector_->set_kiosk_account( |
| 1230 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); | 1102 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); |
| 1231 | 1103 |
| 1232 GetDeviceStatus(); | 1104 GetStatus(); |
| 1233 ASSERT_TRUE(device_status_.has_running_kiosk_app()); | 1105 ASSERT_TRUE(device_status_.has_running_kiosk_app()); |
| 1234 const em::AppStatus app = device_status_.running_kiosk_app(); | 1106 const em::AppStatus app = device_status_.running_kiosk_app(); |
| 1235 EXPECT_EQ(kKioskAppId, app.app_id()); | 1107 EXPECT_EQ(kKioskAppId, app.app_id()); |
| 1236 EXPECT_EQ("1235", app.required_platform_version()); | 1108 EXPECT_EQ("1235", app.required_platform_version()); |
| 1237 EXPECT_FALSE(app.has_status()); | 1109 EXPECT_FALSE(app.has_status()); |
| 1238 EXPECT_FALSE(app.has_error()); | 1110 EXPECT_FALSE(app.has_error()); |
| 1239 } | 1111 } |
| 1240 | 1112 |
| 1241 // Fake device state. | 1113 // Fake device state. |
| 1242 struct FakeDeviceData { | 1114 struct FakeDeviceData { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1494 } | 1366 } |
| 1495 EXPECT_TRUE(found_match) << "No matching state for fake network " | 1367 EXPECT_TRUE(found_match) << "No matching state for fake network " |
| 1496 << " (" << state.name << ")"; | 1368 << " (" << state.name << ")"; |
| 1497 } | 1369 } |
| 1498 } | 1370 } |
| 1499 }; | 1371 }; |
| 1500 | 1372 |
| 1501 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NoNetworkStateIfNotKiosk) { | 1373 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NoNetworkStateIfNotKiosk) { |
| 1502 // If not in an active kiosk session, there should be network interfaces | 1374 // If not in an active kiosk session, there should be network interfaces |
| 1503 // reported, but no network state. | 1375 // reported, but no network state. |
| 1504 GetDeviceStatus(); | 1376 GetStatus(); |
| 1505 EXPECT_LT(0, device_status_.network_interface_size()); | 1377 EXPECT_LT(0, device_status_.network_interface_size()); |
| 1506 EXPECT_EQ(0, device_status_.network_state_size()); | 1378 EXPECT_EQ(0, device_status_.network_state_size()); |
| 1507 } | 1379 } |
| 1508 | 1380 |
| 1509 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { | 1381 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { |
| 1510 // Mock that we are in kiosk mode so we report network state. | 1382 // Mock that we are in kiosk mode so we report network state. |
| 1511 status_collector_->set_kiosk_account( | 1383 status_collector_->set_kiosk_account( |
| 1512 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); | 1384 base::MakeUnique<policy::DeviceLocalAccount>(fake_device_local_account_)); |
| 1513 | 1385 |
| 1514 // Interfaces should be reported by default. | 1386 // Interfaces should be reported by default. |
| 1515 GetDeviceStatus(); | 1387 GetStatus(); |
| 1516 EXPECT_LT(0, device_status_.network_interface_size()); | 1388 EXPECT_LT(0, device_status_.network_interface_size()); |
| 1517 EXPECT_LT(0, device_status_.network_state_size()); | 1389 EXPECT_LT(0, device_status_.network_state_size()); |
| 1518 | 1390 |
| 1519 // No interfaces should be reported if the policy is off. | 1391 // No interfaces should be reported if the policy is off. |
| 1520 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); | 1392 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); |
| 1521 GetDeviceStatus(); | 1393 GetStatus(); |
| 1522 EXPECT_EQ(0, device_status_.network_interface_size()); | 1394 EXPECT_EQ(0, device_status_.network_interface_size()); |
| 1523 EXPECT_EQ(0, device_status_.network_state_size()); | 1395 EXPECT_EQ(0, device_status_.network_state_size()); |
| 1524 | 1396 |
| 1525 // Switch the policy on and verify the interface list is present. | 1397 // Switch the policy on and verify the interface list is present. |
| 1526 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); | 1398 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); |
| 1527 GetDeviceStatus(); | 1399 GetStatus(); |
| 1528 | 1400 |
| 1529 VerifyNetworkReporting(); | 1401 VerifyNetworkReporting(); |
| 1530 } | 1402 } |
| 1531 | 1403 |
| 1532 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, ReportIfPublicSession) { | 1404 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, ReportIfPublicSession) { |
| 1533 // Report netowork state for public accounts. | 1405 // Report netowork state for public accounts. |
| 1534 user_manager_->CreatePublicAccountUser( | 1406 user_manager_->CreatePublicAccountUser( |
| 1535 AccountId::FromUserEmail(kPublicAccountId)); | 1407 AccountId::FromUserEmail(kPublicAccountId)); |
| 1536 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) | 1408 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) |
| 1537 .WillRepeatedly(Return(true)); | 1409 .WillRepeatedly(Return(true)); |
| 1538 | 1410 |
| 1539 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); | 1411 settings_helper_.SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); |
| 1540 GetDeviceStatus(); | 1412 GetStatus(); |
| 1541 VerifyNetworkReporting(); | 1413 VerifyNetworkReporting(); |
| 1542 } | 1414 } |
| 1543 | 1415 |
| 1544 } // namespace policy | 1416 } // namespace policy |
| OLD | NEW |