| 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 "chromeos/network/network_state_handler.h" | 5 #include "chromeos/network/network_state_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 #include "chromeos/dbus/shill_device_client.h" | 16 #include "chromeos/dbus/shill_device_client.h" |
| 17 #include "chromeos/dbus/shill_manager_client.h" | 17 #include "chromeos/dbus/shill_manager_client.h" |
| 18 #include "chromeos/dbus/shill_profile_client.h" | 18 #include "chromeos/dbus/shill_profile_client.h" |
| 19 #include "chromeos/dbus/shill_service_client.h" | 19 #include "chromeos/dbus/shill_service_client.h" |
| 20 #include "chromeos/network/device_state.h" |
| 20 #include "chromeos/network/network_state.h" | 21 #include "chromeos/network/network_state.h" |
| 21 #include "chromeos/network/network_state_handler.h" | 22 #include "chromeos/network/network_state_handler.h" |
| 22 #include "chromeos/network/network_state_handler_observer.h" | 23 #include "chromeos/network/network_state_handler_observer.h" |
| 23 #include "dbus/object_path.h" | 24 #include "dbus/object_path.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "third_party/cros_system_api/dbus/service_constants.h" | 26 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 void ErrorCallbackFunction(const std::string& error_name, | 30 void ErrorCallbackFunction(const std::string& error_name, |
| 30 const std::string& error_message) { | 31 const std::string& error_message) { |
| 31 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; | 32 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; |
| 32 } | 33 } |
| 33 | 34 |
| 34 const std::string kShillManagerClientStubDefaultService = "/service/eth1"; | 35 const std::string kShillManagerClientStubDefaultService = "/service/eth1"; |
| 35 const std::string kShillManagerClientStubDefaultWifi = "/service/wifi1"; | 36 const std::string kShillManagerClientStubDefaultWifi = "/service/wifi1"; |
| 36 const std::string kShillManagerClientStubWifi2 = "/service/wifi2"; | 37 const std::string kShillManagerClientStubWifi2 = "/service/wifi2"; |
| 37 const std::string kShillManagerClientStubCellular = "/service/cellular1"; | 38 const std::string kShillManagerClientStubCellular = "/service/cellular1"; |
| 38 | 39 |
| 40 using chromeos::DeviceState; |
| 39 using chromeos::NetworkState; | 41 using chromeos::NetworkState; |
| 40 using chromeos::NetworkStateHandler; | 42 using chromeos::NetworkStateHandler; |
| 41 | 43 |
| 42 class TestObserver : public chromeos::NetworkStateHandlerObserver { | 44 class TestObserver : public chromeos::NetworkStateHandlerObserver { |
| 43 public: | 45 public: |
| 44 explicit TestObserver(NetworkStateHandler* handler) | 46 explicit TestObserver(NetworkStateHandler* handler) |
| 45 : handler_(handler), | 47 : handler_(handler), |
| 46 device_list_changed_count_(0), | 48 device_list_changed_count_(0), |
| 47 device_count_(0), | 49 device_count_(0), |
| 48 network_list_changed_count_(0), | 50 network_list_changed_count_(0), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const NetworkState* network) OVERRIDE { | 90 const NetworkState* network) OVERRIDE { |
| 89 network_connection_state_[network->path()] = network->connection_state(); | 91 network_connection_state_[network->path()] = network->connection_state(); |
| 90 connection_state_changes_[network->path()]++; | 92 connection_state_changes_[network->path()]++; |
| 91 } | 93 } |
| 92 | 94 |
| 93 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE { | 95 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE { |
| 94 DCHECK(network); | 96 DCHECK(network); |
| 95 property_updates_[network->path()]++; | 97 property_updates_[network->path()]++; |
| 96 } | 98 } |
| 97 | 99 |
| 100 virtual void DevicePropertiesUpdated(const DeviceState* device) OVERRIDE { |
| 101 DCHECK(device); |
| 102 device_property_updates_[device->path()]++; |
| 103 } |
| 104 |
| 98 size_t device_list_changed_count() { return device_list_changed_count_; } | 105 size_t device_list_changed_count() { return device_list_changed_count_; } |
| 99 size_t device_count() { return device_count_; } | 106 size_t device_count() { return device_count_; } |
| 100 size_t network_list_changed_count() { return network_list_changed_count_; } | 107 size_t network_list_changed_count() { return network_list_changed_count_; } |
| 101 size_t network_count() { return network_count_; } | 108 size_t network_count() { return network_count_; } |
| 102 size_t default_network_change_count() { | 109 size_t default_network_change_count() { |
| 103 return default_network_change_count_; | 110 return default_network_change_count_; |
| 104 } | 111 } |
| 105 void reset_change_counts() { | 112 void reset_change_counts() { |
| 106 DVLOG(1) << "=== RESET CHANGE COUNTS ==="; | 113 DVLOG(1) << "=== RESET CHANGE COUNTS ==="; |
| 107 default_network_change_count_ = 0; | 114 default_network_change_count_ = 0; |
| 108 device_list_changed_count_ = 0; | 115 device_list_changed_count_ = 0; |
| 109 network_list_changed_count_ = 0; | 116 network_list_changed_count_ = 0; |
| 110 } | 117 } |
| 111 std::string default_network() { return default_network_; } | 118 std::string default_network() { return default_network_; } |
| 112 std::string default_network_connection_state() { | 119 std::string default_network_connection_state() { |
| 113 return default_network_connection_state_; | 120 return default_network_connection_state_; |
| 114 } | 121 } |
| 115 | 122 |
| 116 int PropertyUpdatesForService(const std::string& service_path) { | 123 int PropertyUpdatesForService(const std::string& service_path) { |
| 117 return property_updates_[service_path]; | 124 return property_updates_[service_path]; |
| 118 } | 125 } |
| 119 | 126 |
| 127 int PropertyUpdatesForDevice(const std::string& device_path) { |
| 128 return device_property_updates_[device_path]; |
| 129 } |
| 130 |
| 120 int ConnectionStateChangesForService(const std::string& service_path) { | 131 int ConnectionStateChangesForService(const std::string& service_path) { |
| 121 return connection_state_changes_[service_path]; | 132 return connection_state_changes_[service_path]; |
| 122 } | 133 } |
| 123 | 134 |
| 124 std::string NetworkConnectionStateForService( | 135 std::string NetworkConnectionStateForService( |
| 125 const std::string& service_path) { | 136 const std::string& service_path) { |
| 126 return network_connection_state_[service_path]; | 137 return network_connection_state_[service_path]; |
| 127 } | 138 } |
| 128 | 139 |
| 129 private: | 140 private: |
| 130 NetworkStateHandler* handler_; | 141 NetworkStateHandler* handler_; |
| 131 size_t device_list_changed_count_; | 142 size_t device_list_changed_count_; |
| 132 size_t device_count_; | 143 size_t device_count_; |
| 133 size_t network_list_changed_count_; | 144 size_t network_list_changed_count_; |
| 134 size_t network_count_; | 145 size_t network_count_; |
| 135 size_t default_network_change_count_; | 146 size_t default_network_change_count_; |
| 136 std::string default_network_; | 147 std::string default_network_; |
| 137 std::string default_network_connection_state_; | 148 std::string default_network_connection_state_; |
| 138 std::map<std::string, int> property_updates_; | 149 std::map<std::string, int> property_updates_; |
| 150 std::map<std::string, int> device_property_updates_; |
| 139 std::map<std::string, int> connection_state_changes_; | 151 std::map<std::string, int> connection_state_changes_; |
| 140 std::map<std::string, std::string> network_connection_state_; | 152 std::map<std::string, std::string> network_connection_state_; |
| 141 | 153 |
| 142 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 154 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 143 }; | 155 }; |
| 144 | 156 |
| 145 } // namespace | 157 } // namespace |
| 146 | 158 |
| 147 namespace chromeos { | 159 namespace chromeos { |
| 148 | 160 |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 // Add the service (simulating a network coming back in range) and verify that | 708 // Add the service (simulating a network coming back in range) and verify that |
| 697 // the NetworkState was created with the same GUID. | 709 // the NetworkState was created with the same GUID. |
| 698 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); | 710 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); |
| 699 UpdateManagerProperties(); | 711 UpdateManagerProperties(); |
| 700 network = network_state_handler_->GetNetworkStateFromServicePath( | 712 network = network_state_handler_->GetNetworkStateFromServicePath( |
| 701 wifi_path, is_service_configured); | 713 wifi_path, is_service_configured); |
| 702 ASSERT_TRUE(network); | 714 ASSERT_TRUE(network); |
| 703 EXPECT_EQ(wifi_guid, network->guid()); | 715 EXPECT_EQ(wifi_guid, network->guid()); |
| 704 } | 716 } |
| 705 | 717 |
| 718 TEST_F(NetworkStateHandlerTest, DeviceListChanged) { |
| 719 size_t stub_device_count = test_observer_->device_count(); |
| 720 // Add an additional device. |
| 721 const std::string wifi_device = "/service/stub_wifi_device2"; |
| 722 device_test_->AddDevice(wifi_device, shill::kTypeWifi, "stub_wifi_device2"); |
| 723 UpdateManagerProperties(); |
| 724 // Expect a device list update. |
| 725 EXPECT_EQ(stub_device_count + 1, test_observer_->device_count()); |
| 726 EXPECT_EQ(0, test_observer_->PropertyUpdatesForDevice(wifi_device)); |
| 727 // Change a device property. |
| 728 device_test_->SetDeviceProperty( |
| 729 wifi_device, shill::kScanningProperty, base::FundamentalValue(true)); |
| 730 UpdateManagerProperties(); |
| 731 EXPECT_EQ(1, test_observer_->PropertyUpdatesForDevice(wifi_device)); |
| 732 } |
| 733 |
| 706 } // namespace chromeos | 734 } // namespace chromeos |
| OLD | NEW |