| 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.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
| 13 #include "base/run_loop.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" |
| 17 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 18 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 19 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 19 #include "chrome/browser/chromeos/system/mock_statistics_provider.h" | 20 #include "chrome/browser/chromeos/system/mock_statistics_provider.h" |
| 20 #include "chrome/browser/chromeos/system/statistics_provider.h" | 21 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 21 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 22 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| 25 #include "chromeos/dbus/shill_device_client.h" |
| 26 #include "chromeos/network/network_handler.h" |
| 23 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/geolocation_provider.h" | 28 #include "content/public/browser/geolocation_provider.h" |
| 25 #include "content/public/test/test_browser_thread.h" | 29 #include "content/public/test/test_browser_thread.h" |
| 26 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 29 | 34 |
| 30 using ::testing::DoAll; | 35 using ::testing::DoAll; |
| 31 using ::testing::NotNull; | 36 using ::testing::NotNull; |
| 32 using ::testing::Return; | 37 using ::testing::Return; |
| 33 using ::testing::SetArgPointee; | 38 using ::testing::SetArgPointee; |
| 34 using ::testing::_; | 39 using ::testing::_; |
| 35 using base::Time; | 40 using base::Time; |
| 36 using base::TimeDelta; | 41 using base::TimeDelta; |
| 37 | 42 |
| 38 namespace em = enterprise_management; | 43 namespace em = enterprise_management; |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 | 580 |
| 576 // Check that after enabling location reporting again, an error is reported | 581 // Check that after enabling location reporting again, an error is reported |
| 577 // if no valid fix is available. | 582 // if no valid fix is available. |
| 578 SetMockPositionToReturnNext(invalid_fix); | 583 SetMockPositionToReturnNext(invalid_fix); |
| 579 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); | 584 cros_settings_->SetBoolean(chromeos::kReportDeviceLocation, true); |
| 580 // Allow the new pref to propagate to the status collector. | 585 // Allow the new pref to propagate to the status collector. |
| 581 message_loop_.RunUntilIdle(); | 586 message_loop_.RunUntilIdle(); |
| 582 CheckThatALocationErrorIsReported(); | 587 CheckThatALocationErrorIsReported(); |
| 583 } | 588 } |
| 584 | 589 |
| 590 // Fake device state. |
| 591 struct FakeDeviceData { |
| 592 const char* device_path; |
| 593 const char* type; |
| 594 const char* object_path; |
| 595 const char* mac_address; |
| 596 const char* meid; |
| 597 const char* imei; |
| 598 int expected_type; // proto enum type value, -1 for not present. |
| 599 }; |
| 600 |
| 601 static const FakeDeviceData kFakeDevices[] = { |
| 602 { "/device/ethernet", flimflam::kTypeEthernet, "ethernet", |
| 603 "112233445566", "", "", |
| 604 em::NetworkInterface::TYPE_ETHERNET }, |
| 605 { "/device/cellular1", flimflam::kTypeCellular, "cellular1", |
| 606 "abcdefabcdef", "A10000009296F2", "", |
| 607 em::NetworkInterface::TYPE_CELLULAR }, |
| 608 { "/device/cellular2", flimflam::kTypeCellular, "cellular2", |
| 609 "abcdefabcdef", "", "352099001761481", |
| 610 em::NetworkInterface::TYPE_CELLULAR }, |
| 611 { "/device/wifi", flimflam::kTypeWifi, "wifi", |
| 612 "aabbccddeeff", "", "", |
| 613 em::NetworkInterface::TYPE_WIFI }, |
| 614 { "/device/bluetooth", flimflam::kTypeBluetooth, "bluetooth", |
| 615 "", "", "", |
| 616 em::NetworkInterface::TYPE_BLUETOOTH }, |
| 617 { "/device/vpn", flimflam::kTypeVPN, "vpn", |
| 618 "", "", "", |
| 619 -1 }, |
| 620 }; |
| 621 |
| 622 class DeviceStatusCollectorNetworkInterfacesTest |
| 623 : public DeviceStatusCollectorTest { |
| 624 protected: |
| 625 virtual void SetUp() OVERRIDE { |
| 626 chromeos::DBusThreadManager::InitializeWithStub(); |
| 627 chromeos::NetworkHandler::Initialize(); |
| 628 chromeos::ShillDeviceClient::TestInterface* test_device_client = |
| 629 chromeos::DBusThreadManager::Get()->GetShillDeviceClient()-> |
| 630 GetTestInterface(); |
| 631 test_device_client->ClearDevices(); |
| 632 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { |
| 633 const FakeDeviceData& dev = kFakeDevices[i]; |
| 634 test_device_client->AddDevice(dev.device_path, dev.type, |
| 635 dev.object_path); |
| 636 if (*dev.mac_address) { |
| 637 test_device_client->SetDeviceProperty( |
| 638 dev.device_path, flimflam::kAddressProperty, |
| 639 base::StringValue(dev.mac_address)); |
| 640 } |
| 641 if (*dev.meid) { |
| 642 test_device_client->SetDeviceProperty( |
| 643 dev.device_path, flimflam::kMeidProperty, |
| 644 base::StringValue(dev.meid)); |
| 645 } |
| 646 if (*dev.imei) { |
| 647 test_device_client->SetDeviceProperty( |
| 648 dev.device_path, flimflam::kImeiProperty, |
| 649 base::StringValue(dev.imei)); |
| 650 } |
| 651 } |
| 652 |
| 653 // Flush out pending state updates. |
| 654 base::RunLoop().RunUntilIdle(); |
| 655 } |
| 656 |
| 657 virtual void TearDown() OVERRIDE { |
| 658 chromeos::NetworkHandler::Shutdown(); |
| 659 chromeos::DBusThreadManager::Shutdown(); |
| 660 } |
| 661 }; |
| 662 |
| 663 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { |
| 664 // No interfaces should be reported if the policy is off. |
| 665 GetStatus(); |
| 666 EXPECT_EQ(0, status_.network_interface_size()); |
| 667 |
| 668 // Switch the policy on and verify the interface list is present. |
| 669 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); |
| 670 GetStatus(); |
| 671 |
| 672 int count = 0; |
| 673 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { |
| 674 const FakeDeviceData& dev = kFakeDevices[i]; |
| 675 if (dev.expected_type == -1) |
| 676 continue; |
| 677 |
| 678 // Find the corresponding entry in reporting data. |
| 679 bool found_match = false; |
| 680 google::protobuf::RepeatedPtrField<em::NetworkInterface>::const_iterator |
| 681 iface; |
| 682 for (iface = status_.network_interface().begin(); |
| 683 iface != status_.network_interface().end(); |
| 684 ++iface) { |
| 685 // Check whether type, field presence and field values match. |
| 686 if (dev.expected_type == iface->type() && |
| 687 iface->has_mac_address() == !!*dev.mac_address && |
| 688 iface->has_meid() == !!*dev.meid && |
| 689 iface->has_imei() == !!*dev.imei && |
| 690 iface->mac_address() == dev.mac_address && |
| 691 iface->meid() == dev.meid && |
| 692 iface->imei() == dev.imei) { |
| 693 found_match = true; |
| 694 break; |
| 695 } |
| 696 } |
| 697 |
| 698 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; |
| 699 count++; |
| 700 } |
| 701 |
| 702 EXPECT_EQ(count, status_.network_interface_size()); |
| 703 } |
| 704 |
| 585 } // namespace policy | 705 } // namespace policy |
| OLD | NEW |