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 "base/environment.h" | 7 #include "base/environment.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Finish pending tasks. | 184 // Finish pending tasks. |
185 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 185 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
186 message_loop_.RunUntilIdle(); | 186 message_loop_.RunUntilIdle(); |
187 | 187 |
188 // Restore the real DeviceSettingsProvider. | 188 // Restore the real DeviceSettingsProvider. |
189 EXPECT_TRUE( | 189 EXPECT_TRUE( |
190 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); | 190 cros_settings_->RemoveSettingsProvider(&stub_settings_provider_)); |
191 cros_settings_->AddSettingsProvider(device_settings_provider_); | 191 cros_settings_->AddSettingsProvider(device_settings_provider_); |
192 } | 192 } |
193 | 193 |
| 194 virtual void SetUp() OVERRIDE { |
| 195 // Disable network interface reporting since it requires additional setup. |
| 196 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); |
| 197 } |
| 198 |
194 void RestartStatusCollector() { | 199 void RestartStatusCollector() { |
195 policy::DeviceStatusCollector::LocationUpdateRequester callback = | 200 policy::DeviceStatusCollector::LocationUpdateRequester callback = |
196 base::Bind(&MockPositionUpdateRequester); | 201 base::Bind(&MockPositionUpdateRequester); |
197 status_collector_.reset( | 202 status_collector_.reset( |
198 new TestingDeviceStatusCollector(&prefs_, | 203 new TestingDeviceStatusCollector(&prefs_, |
199 &statistics_provider_, | 204 &statistics_provider_, |
200 &callback)); | 205 &callback)); |
201 } | 206 } |
202 | 207 |
203 void GetStatus() { | 208 void GetStatus() { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 423 |
419 // Collect one more data point to trigger pruning. | 424 // Collect one more data point to trigger pruning. |
420 status_collector_->Simulate(test_states, 1); | 425 status_collector_->Simulate(test_states, 1); |
421 | 426 |
422 // Check that we don't exceed the max number of periods. | 427 // Check that we don't exceed the max number of periods. |
423 status_.clear_active_period(); | 428 status_.clear_active_period(); |
424 GetStatus(); | 429 GetStatus(); |
425 EXPECT_LT(status_.active_period_size(), kMaxDays); | 430 EXPECT_LT(status_.active_period_size(), kMaxDays); |
426 } | 431 } |
427 | 432 |
428 TEST_F(DeviceStatusCollectorTest, ActivityTimesDisabledByDefault) { | 433 TEST_F(DeviceStatusCollectorTest, ActivityTimesEnabledByDefault) { |
429 // If the pref for collecting device activity times isn't explicitly turned | 434 // Device activity times should be reported by default. |
430 // on, no data on activity times should be reported. | 435 IdleState test_states[] = { |
| 436 IDLE_STATE_ACTIVE, |
| 437 IDLE_STATE_ACTIVE, |
| 438 IDLE_STATE_ACTIVE |
| 439 }; |
| 440 status_collector_->Simulate(test_states, |
| 441 sizeof(test_states) / sizeof(IdleState)); |
| 442 GetStatus(); |
| 443 EXPECT_EQ(1, status_.active_period_size()); |
| 444 EXPECT_EQ(3 * ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
| 445 } |
| 446 |
| 447 TEST_F(DeviceStatusCollectorTest, ActivityTimesOff) { |
| 448 // Device activity times should not be reported if explicitly disabled. |
| 449 cros_settings_->SetBoolean(chromeos::kReportDeviceActivityTimes, false); |
431 | 450 |
432 IdleState test_states[] = { | 451 IdleState test_states[] = { |
433 IDLE_STATE_ACTIVE, | 452 IDLE_STATE_ACTIVE, |
434 IDLE_STATE_ACTIVE, | 453 IDLE_STATE_ACTIVE, |
435 IDLE_STATE_ACTIVE | 454 IDLE_STATE_ACTIVE |
436 }; | 455 }; |
437 status_collector_->Simulate(test_states, | 456 status_collector_->Simulate(test_states, |
438 sizeof(test_states) / sizeof(IdleState)); | 457 sizeof(test_states) / sizeof(IdleState)); |
439 GetStatus(); | 458 GetStatus(); |
440 EXPECT_EQ(0, status_.active_period_size()); | 459 EXPECT_EQ(0, status_.active_period_size()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 509 |
491 // After indicating a successful submit, the submitted status gets cleared, | 510 // After indicating a successful submit, the submitted status gets cleared, |
492 // but what got collected meanwhile sticks around. | 511 // but what got collected meanwhile sticks around. |
493 status_collector_->Simulate(test_states, 1); | 512 status_collector_->Simulate(test_states, 1); |
494 status_collector_->OnSubmittedSuccessfully(); | 513 status_collector_->OnSubmittedSuccessfully(); |
495 GetStatus(); | 514 GetStatus(); |
496 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); | 515 EXPECT_EQ(ActivePeriodMilliseconds(), GetActiveMilliseconds(status_)); |
497 } | 516 } |
498 | 517 |
499 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { | 518 TEST_F(DeviceStatusCollectorTest, DevSwitchBootMode) { |
500 // Test that boot mode data is not reported if the pref is not turned on. | 519 // Test that boot mode data is reported by default. |
| 520 EXPECT_CALL(statistics_provider_, |
| 521 GetMachineStatistic("devsw_boot", NotNull())) |
| 522 .WillOnce(DoAll(SetArgPointee<1>("0"), Return(true))); |
| 523 GetStatus(); |
| 524 EXPECT_EQ("Verified", status_.boot_mode()); |
| 525 |
| 526 // Test that boot mode data is not reported if the pref turned off. |
| 527 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, false); |
| 528 |
501 EXPECT_CALL(statistics_provider_, | 529 EXPECT_CALL(statistics_provider_, |
502 GetMachineStatistic("devsw_boot", NotNull())) | 530 GetMachineStatistic("devsw_boot", NotNull())) |
503 .WillRepeatedly(DoAll(SetArgPointee<1>("0"), Return(true))); | 531 .WillRepeatedly(DoAll(SetArgPointee<1>("0"), Return(true))); |
504 GetStatus(); | 532 GetStatus(); |
505 EXPECT_FALSE(status_.has_boot_mode()); | 533 EXPECT_FALSE(status_.has_boot_mode()); |
506 | 534 |
507 // Turn the pref on, and check that the status is reported iff the | 535 // Turn the pref on, and check that the status is reported iff the |
508 // statistics provider returns valid data. | 536 // statistics provider returns valid data. |
509 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, true); | 537 cros_settings_->SetBoolean(chromeos::kReportDeviceBootMode, true); |
510 | 538 |
(...skipping 16 matching lines...) Expand all Loading... |
527 EXPECT_EQ("Verified", status_.boot_mode()); | 555 EXPECT_EQ("Verified", status_.boot_mode()); |
528 | 556 |
529 EXPECT_CALL(statistics_provider_, | 557 EXPECT_CALL(statistics_provider_, |
530 GetMachineStatistic("devsw_boot", NotNull())) | 558 GetMachineStatistic("devsw_boot", NotNull())) |
531 .WillOnce(DoAll(SetArgPointee<1>("1"), Return(true))); | 559 .WillOnce(DoAll(SetArgPointee<1>("1"), Return(true))); |
532 GetStatus(); | 560 GetStatus(); |
533 EXPECT_EQ("Dev", status_.boot_mode()); | 561 EXPECT_EQ("Dev", status_.boot_mode()); |
534 } | 562 } |
535 | 563 |
536 TEST_F(DeviceStatusCollectorTest, VersionInfo) { | 564 TEST_F(DeviceStatusCollectorTest, VersionInfo) { |
| 565 // Expect the version info to be reported by default. |
| 566 GetStatus(); |
| 567 EXPECT_TRUE(status_.has_browser_version()); |
| 568 EXPECT_TRUE(status_.has_os_version()); |
| 569 EXPECT_TRUE(status_.has_firmware_version()); |
| 570 |
537 // When the pref to collect this data is not enabled, expect that none of | 571 // When the pref to collect this data is not enabled, expect that none of |
538 // the fields are present in the protobuf. | 572 // the fields are present in the protobuf. |
| 573 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, false); |
539 GetStatus(); | 574 GetStatus(); |
540 EXPECT_FALSE(status_.has_browser_version()); | 575 EXPECT_FALSE(status_.has_browser_version()); |
541 EXPECT_FALSE(status_.has_os_version()); | 576 EXPECT_FALSE(status_.has_os_version()); |
542 EXPECT_FALSE(status_.has_firmware_version()); | 577 EXPECT_FALSE(status_.has_firmware_version()); |
543 | 578 |
544 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, true); | 579 cros_settings_->SetBoolean(chromeos::kReportDeviceVersionInfo, true); |
545 GetStatus(); | 580 GetStatus(); |
546 EXPECT_TRUE(status_.has_browser_version()); | 581 EXPECT_TRUE(status_.has_browser_version()); |
547 EXPECT_TRUE(status_.has_os_version()); | 582 EXPECT_TRUE(status_.has_os_version()); |
548 EXPECT_TRUE(status_.has_firmware_version()); | 583 EXPECT_TRUE(status_.has_firmware_version()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 | 639 |
605 TEST_F(DeviceStatusCollectorTest, ReportUsers) { | 640 TEST_F(DeviceStatusCollectorTest, ReportUsers) { |
606 user_manager_->CreatePublicAccountUser("public@localhost"); | 641 user_manager_->CreatePublicAccountUser("public@localhost"); |
607 user_manager_->AddUser("user0@managed.com"); | 642 user_manager_->AddUser("user0@managed.com"); |
608 user_manager_->AddUser("user1@managed.com"); | 643 user_manager_->AddUser("user1@managed.com"); |
609 user_manager_->AddUser("user2@managed.com"); | 644 user_manager_->AddUser("user2@managed.com"); |
610 user_manager_->AddUser("user3@unmanaged.com"); | 645 user_manager_->AddUser("user3@unmanaged.com"); |
611 user_manager_->AddUser("user4@managed.com"); | 646 user_manager_->AddUser("user4@managed.com"); |
612 user_manager_->AddUser("user5@managed.com"); | 647 user_manager_->AddUser("user5@managed.com"); |
613 | 648 |
614 // Verify that users are not reported by default. | 649 // Verify that users are reported by default. |
615 GetStatus(); | 650 GetStatus(); |
616 EXPECT_EQ(0, status_.user_size()); | 651 EXPECT_EQ(5, status_.user_size()); |
617 | 652 |
618 // Verify that users are reported after enabling the setting. | 653 // Verify that users are reported after enabling the setting. |
619 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, true); | 654 cros_settings_->SetBoolean(chromeos::kReportDeviceUsers, true); |
620 GetStatus(); | 655 GetStatus(); |
621 EXPECT_EQ(5, status_.user_size()); | 656 EXPECT_EQ(5, status_.user_size()); |
622 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); | 657 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(0).type()); |
623 EXPECT_EQ("user0@managed.com", status_.user(0).email()); | 658 EXPECT_EQ("user0@managed.com", status_.user(0).email()); |
624 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type()); | 659 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(1).type()); |
625 EXPECT_EQ("user1@managed.com", status_.user(1).email()); | 660 EXPECT_EQ("user1@managed.com", status_.user(1).email()); |
626 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type()); | 661 EXPECT_EQ(em::DeviceUser::USER_TYPE_MANAGED, status_.user(2).type()); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 base::RunLoop().RunUntilIdle(); | 758 base::RunLoop().RunUntilIdle(); |
724 } | 759 } |
725 | 760 |
726 virtual void TearDown() OVERRIDE { | 761 virtual void TearDown() OVERRIDE { |
727 chromeos::NetworkHandler::Shutdown(); | 762 chromeos::NetworkHandler::Shutdown(); |
728 chromeos::DBusThreadManager::Shutdown(); | 763 chromeos::DBusThreadManager::Shutdown(); |
729 } | 764 } |
730 }; | 765 }; |
731 | 766 |
732 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { | 767 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { |
| 768 // Interfaces should be reported by default. |
| 769 GetStatus(); |
| 770 EXPECT_TRUE(status_.network_interface_size() > 0); |
| 771 |
733 // No interfaces should be reported if the policy is off. | 772 // No interfaces should be reported if the policy is off. |
| 773 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); |
734 GetStatus(); | 774 GetStatus(); |
735 EXPECT_EQ(0, status_.network_interface_size()); | 775 EXPECT_EQ(0, status_.network_interface_size()); |
736 | 776 |
737 // Switch the policy on and verify the interface list is present. | 777 // Switch the policy on and verify the interface list is present. |
738 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); | 778 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); |
739 GetStatus(); | 779 GetStatus(); |
740 | 780 |
741 int count = 0; | 781 int count = 0; |
742 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { | 782 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { |
743 const FakeDeviceData& dev = kFakeDevices[i]; | 783 const FakeDeviceData& dev = kFakeDevices[i]; |
(...skipping 21 matching lines...) Expand all Loading... |
765 } | 805 } |
766 | 806 |
767 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; | 807 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; |
768 count++; | 808 count++; |
769 } | 809 } |
770 | 810 |
771 EXPECT_EQ(count, status_.network_interface_size()); | 811 EXPECT_EQ(count, status_.network_interface_size()); |
772 } | 812 } |
773 | 813 |
774 } // namespace policy | 814 } // namespace policy |
OLD | NEW |