Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc

Issue 776803003: Updated DeviceStatusReportRequest to contain new monitoring data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed more feedback Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
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/run_loop.h"
14 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
15 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" 15 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 16 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
18 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" 18 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 19 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/settings/device_settings_service.h" 20 #include "chrome/browser/chromeos/settings/device_settings_service.h"
21 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 21 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/testing_browser_process.h" 23 #include "chrome/test/base/testing_browser_process.h"
24 #include "chromeos/dbus/dbus_thread_manager.h" 24 #include "chromeos/dbus/dbus_thread_manager.h"
25 #include "chromeos/dbus/shill_device_client.h" 25 #include "chromeos/dbus/shill_device_client.h"
26 #include "chromeos/dbus/shill_service_client.h"
26 #include "chromeos/network/network_handler.h" 27 #include "chromeos/network/network_handler.h"
28 #include "chromeos/network/network_state.h"
29 #include "chromeos/network/network_state_handler.h"
27 #include "chromeos/settings/cros_settings_names.h" 30 #include "chromeos/settings/cros_settings_names.h"
28 #include "chromeos/settings/cros_settings_provider.h" 31 #include "chromeos/settings/cros_settings_provider.h"
29 #include "chromeos/system/fake_statistics_provider.h" 32 #include "chromeos/system/fake_statistics_provider.h"
30 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
31 #include "content/public/browser/geolocation_provider.h" 34 #include "content/public/browser/geolocation_provider.h"
32 #include "content/public/test/test_browser_thread.h" 35 #include "content/public/test/test_browser_thread.h"
33 #include "content/public/test/test_utils.h" 36 #include "content/public/test/test_utils.h"
34 #include "policy/proto/device_management_backend.pb.h" 37 #include "policy/proto/device_management_backend.pb.h"
35 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
36 #include "third_party/cros_system_api/dbus/service_constants.h" 39 #include "third_party/cros_system_api/dbus/service_constants.h"
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 "aabbccddeeff", "", "", 679 "aabbccddeeff", "", "",
677 em::NetworkInterface::TYPE_WIFI }, 680 em::NetworkInterface::TYPE_WIFI },
678 { "/device/bluetooth", shill::kTypeBluetooth, "bluetooth", 681 { "/device/bluetooth", shill::kTypeBluetooth, "bluetooth",
679 "", "", "", 682 "", "", "",
680 em::NetworkInterface::TYPE_BLUETOOTH }, 683 em::NetworkInterface::TYPE_BLUETOOTH },
681 { "/device/vpn", shill::kTypeVPN, "vpn", 684 { "/device/vpn", shill::kTypeVPN, "vpn",
682 "", "", "", 685 "", "", "",
683 -1 }, 686 -1 },
684 }; 687 };
685 688
689 // Fake network state.
690 struct FakeNetworkState {
691 const char* name;
692 const char* device_path;
693 const char* type;
694 int signal_strength;
695 const char* connection_status;
696 int expected_state;
697 };
698
699 // List of fake networks - primarily used to make sure that signal strength
700 // and connection state are properly populated in status reports. Note that
701 // by convention shill will not report a signal strength of 0 for a visible
702 // network, so we use 1 below.
703 static const FakeNetworkState kFakeNetworks[] = {
704 { "offline", "/device/wifi", shill::kTypeWifi, 35,
705 shill::kStateOffline, em::NetworkState::OFFLINE },
706 { "ethernet", "/device/ethernet", shill::kTypeEthernet, 0,
707 shill::kStateOnline, em::NetworkState::ONLINE },
708 { "wifi", "/device/wifi", shill::kTypeWifi, 23, shill::kStatePortal,
709 em::NetworkState::PORTAL },
710 { "idle", "/device/cellular1", shill::kTypeCellular, 0, shill::kStateIdle,
711 em::NetworkState::IDLE },
712 { "carrier", "/device/cellular1", shill::kTypeCellular, 0,
713 shill::kStateCarrier, em::NetworkState::CARRIER },
714 { "association", "/device/cellular1", shill::kTypeCellular, 0,
715 shill::kStateAssociation, em::NetworkState::ASSOCIATION },
716 { "config", "/device/cellular1", shill::kTypeCellular, 0,
717 shill::kStateConfiguration, em::NetworkState::CONFIGURATION },
718 { "ready", "/device/cellular1", shill::kTypeCellular, 0, shill::kStateReady,
719 em::NetworkState::READY },
720 { "disconnect", "/device/wifi", shill::kTypeWifi, 1,
721 shill::kStateDisconnect, em::NetworkState::DISCONNECT },
722 { "failure", "/device/wifi", shill::kTypeWifi, 1, shill::kStateFailure,
723 em::NetworkState::FAILURE },
724 { "activation-failure", "/device/cellular1", shill::kTypeCellular, 0,
725 shill::kStateActivationFailure, em::NetworkState::ACTIVATION_FAILURE },
726 { "unknown", "", shill::kTypeWifi, 1, "unknown", em::NetworkState::UNKNOWN },
727 };
728
729 static const FakeNetworkState kUnconfiguredNetwork = {
730 "unconfigured", "/device/unconfigured", shill::kTypeWifi, 35,
731 shill::kStateOffline, em::NetworkState::OFFLINE
732 };
733
686 class DeviceStatusCollectorNetworkInterfacesTest 734 class DeviceStatusCollectorNetworkInterfacesTest
687 : public DeviceStatusCollectorTest { 735 : public DeviceStatusCollectorTest {
688 protected: 736 protected:
689 virtual void SetUp() override { 737 virtual void SetUp() override {
690 chromeos::DBusThreadManager::Initialize(); 738 chromeos::DBusThreadManager::Initialize();
691 chromeos::NetworkHandler::Initialize(); 739 chromeos::NetworkHandler::Initialize();
692 chromeos::ShillDeviceClient::TestInterface* test_device_client = 740 chromeos::ShillDeviceClient::TestInterface* test_device_client =
693 chromeos::DBusThreadManager::Get()->GetShillDeviceClient()-> 741 chromeos::DBusThreadManager::Get()->GetShillDeviceClient()->
694 GetTestInterface(); 742 GetTestInterface();
695 test_device_client->ClearDevices(); 743 test_device_client->ClearDevices();
(...skipping 11 matching lines...) Expand all
707 dev.device_path, shill::kMeidProperty, 755 dev.device_path, shill::kMeidProperty,
708 base::StringValue(dev.meid)); 756 base::StringValue(dev.meid));
709 } 757 }
710 if (*dev.imei) { 758 if (*dev.imei) {
711 test_device_client->SetDeviceProperty( 759 test_device_client->SetDeviceProperty(
712 dev.device_path, shill::kImeiProperty, 760 dev.device_path, shill::kImeiProperty,
713 base::StringValue(dev.imei)); 761 base::StringValue(dev.imei));
714 } 762 }
715 } 763 }
716 764
765 chromeos::ShillServiceClient::TestInterface* service_client =
766 chromeos::DBusThreadManager::Get()->GetShillServiceClient()->
767 GetTestInterface();
768 service_client->ClearServices();
769
770 // Now add services for every fake network.
771 for (const FakeNetworkState& fake_network : kFakeNetworks) {
772 // Non-visible networks report a disconnected state, so test
pneubeck (no reviews) 2014/12/12 02:02:47 maybe I'm just misreading the second part of this
Andrew T Wilson (Slow) 2014/12/15 17:00:49 Done.
773 // handling of non-visible networks.
774 bool is_visible =
775 fake_network.connection_status != shill::kStateDisconnect;
776 service_client->AddService(
777 fake_network.name, /* service_path */
778 fake_network.name /* guid */,
779 fake_network.name /* name */,
780 fake_network.type /* type */,
781 fake_network.connection_status,
782 is_visible);
783 service_client->SetServiceProperty(
784 fake_network.name, shill::kSignalStrengthProperty,
785 base::FundamentalValue(fake_network.signal_strength));
786 service_client->SetServiceProperty(
787 fake_network.name, shill::kDeviceProperty,
788 base::StringValue(fake_network.device_path));
789 // Set the profile so this shows up as a configured network.
790 service_client->SetServiceProperty(
791 fake_network.name, shill::kProfileProperty,
792 base::StringValue(fake_network.name));
793 }
794
795 // Now add an unconfigured network - it should not show up in the
796 // list of networks because it doesn't have a profile specified.
pneubeck (no reviews) 2014/12/12 02:02:47 nit: 'list of networks' -> 'reported list of netwo
Andrew T Wilson (Slow) 2014/12/15 17:00:49 Done.
797 service_client->AddService(
798 kUnconfiguredNetwork.name, /* service_path */
799 kUnconfiguredNetwork.name /* guid */,
800 kUnconfiguredNetwork.name /* name */,
801 kUnconfiguredNetwork.type /* type */,
802 kUnconfiguredNetwork.connection_status,
803 true /* visible */);
804 service_client->SetServiceProperty(
805 kUnconfiguredNetwork.name, shill::kSignalStrengthProperty,
806 base::FundamentalValue(kUnconfiguredNetwork.signal_strength));
807 service_client->SetServiceProperty(
808 kUnconfiguredNetwork.name, shill::kDeviceProperty,
809 base::StringValue(kUnconfiguredNetwork.device_path));
810
717 // Flush out pending state updates. 811 // Flush out pending state updates.
718 base::RunLoop().RunUntilIdle(); 812 base::RunLoop().RunUntilIdle();
813
814 chromeos::NetworkStateHandler::NetworkStateList state_list;
815 chromeos::NetworkStateHandler* network_state_handler =
816 chromeos::NetworkHandler::Get()->network_state_handler();
817 network_state_handler->GetNetworkListByType(
818 chromeos::NetworkTypePattern::Default(),
819 true, // configured_only
820 false, // visible_only,
821 0, // no limit to number of results
822 &state_list);
823 ASSERT_EQ(arraysize(kFakeNetworks), state_list.size());
719 } 824 }
720 825
721 virtual void TearDown() override { 826 virtual void TearDown() override {
722 chromeos::NetworkHandler::Shutdown(); 827 chromeos::NetworkHandler::Shutdown();
723 chromeos::DBusThreadManager::Shutdown(); 828 chromeos::DBusThreadManager::Shutdown();
724 } 829 }
725 }; 830 };
726 831
727 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) { 832 TEST_F(DeviceStatusCollectorNetworkInterfacesTest, NetworkInterfaces) {
728 // Interfaces should be reported by default. 833 // Interfaces should be reported by default.
729 GetStatus(); 834 GetStatus();
730 EXPECT_LT(0, status_.network_interface_size()); 835 EXPECT_LT(0, status_.network_interface_size());
836 EXPECT_LT(0, status_.network_state_size());
731 837
732 // No interfaces should be reported if the policy is off. 838 // No interfaces should be reported if the policy is off.
733 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false); 839 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, false);
734 GetStatus(); 840 GetStatus();
735 EXPECT_EQ(0, status_.network_interface_size()); 841 EXPECT_EQ(0, status_.network_interface_size());
842 EXPECT_EQ(0, status_.network_state_size());
736 843
737 // Switch the policy on and verify the interface list is present. 844 // Switch the policy on and verify the interface list is present.
738 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true); 845 cros_settings_->SetBoolean(chromeos::kReportDeviceNetworkInterfaces, true);
739 GetStatus(); 846 GetStatus();
740 847
741 int count = 0; 848 int count = 0;
742 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) { 849 for (size_t i = 0; i < arraysize(kFakeDevices); ++i) {
743 const FakeDeviceData& dev = kFakeDevices[i]; 850 const FakeDeviceData& dev = kFakeDevices[i];
744 if (dev.expected_type == -1) 851 if (dev.expected_type == -1)
745 continue; 852 continue;
746 853
747 // Find the corresponding entry in reporting data. 854 // Find the corresponding entry in reporting data.
748 bool found_match = false; 855 bool found_match = false;
749 google::protobuf::RepeatedPtrField<em::NetworkInterface>::const_iterator 856 google::protobuf::RepeatedPtrField<em::NetworkInterface>::const_iterator
750 iface; 857 iface;
751 for (iface = status_.network_interface().begin(); 858 for (iface = status_.network_interface().begin();
752 iface != status_.network_interface().end(); 859 iface != status_.network_interface().end();
753 ++iface) { 860 ++iface) {
754 // Check whether type, field presence and field values match. 861 // Check whether type, field presence and field values match.
755 if (dev.expected_type == iface->type() && 862 if (dev.expected_type == iface->type() &&
756 iface->has_mac_address() == !!*dev.mac_address && 863 iface->has_mac_address() == !!*dev.mac_address &&
757 iface->has_meid() == !!*dev.meid && 864 iface->has_meid() == !!*dev.meid &&
758 iface->has_imei() == !!*dev.imei && 865 iface->has_imei() == !!*dev.imei &&
759 iface->mac_address() == dev.mac_address && 866 iface->mac_address() == dev.mac_address &&
760 iface->meid() == dev.meid && 867 iface->meid() == dev.meid &&
761 iface->imei() == dev.imei) { 868 iface->imei() == dev.imei &&
869 iface->device_path() == dev.device_path) {
762 found_match = true; 870 found_match = true;
763 break; 871 break;
764 } 872 }
765 } 873 }
766 874
767 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; 875 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i;
768 count++; 876 count++;
769 } 877 }
770 878
771 EXPECT_EQ(count, status_.network_interface_size()); 879 EXPECT_EQ(count, status_.network_interface_size());
880
881 // Now make sure network state list is correct.
882 EXPECT_EQ(arraysize(kFakeNetworks),
883 static_cast<size_t>(status_.network_state_size()));
884 for (const FakeNetworkState& state : kFakeNetworks) {
885 bool found_match = false;
886 google::protobuf::RepeatedPtrField<em::NetworkState>::const_iterator
pneubeck (no reviews) 2014/12/12 02:02:47 this can be removed
Andrew T Wilson (Slow) 2014/12/15 17:00:49 Done.
887 proto_state;
888 for (const em::NetworkState& proto_state : status_.network_state()) {
889 // Make sure every item has a matching entry in the proto.
890 if (proto_state.has_device_path() == (strlen(state.device_path) > 0) &&
891 proto_state.signal_strength() == state.signal_strength &&
892 proto_state.connection_state() == state.expected_state) {
893 found_match = true;
894 break;
895 }
896 }
897 EXPECT_TRUE(found_match) << "No matching state for fake network "
898 << " (" << state.name << ")";
899 }
772 } 900 }
773 901
774 } // namespace policy 902 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698