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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 const std::string kShillManagerClientStubCellular = "stub_cellular"; | 35 const std::string kShillManagerClientStubCellular = "stub_cellular"; |
36 | 36 |
37 using chromeos::NetworkState; | 37 using chromeos::NetworkState; |
38 using chromeos::NetworkStateHandler; | 38 using chromeos::NetworkStateHandler; |
39 | 39 |
40 class TestObserver : public chromeos::NetworkStateHandlerObserver { | 40 class TestObserver : public chromeos::NetworkStateHandlerObserver { |
41 public: | 41 public: |
42 explicit TestObserver(NetworkStateHandler* handler) | 42 explicit TestObserver(NetworkStateHandler* handler) |
43 : handler_(handler), | 43 : handler_(handler), |
44 manager_changed_count_(0), | 44 manager_changed_count_(0), |
45 network_count_(0) { | 45 network_count_(0), |
| 46 default_network_change_count_(0) { |
46 } | 47 } |
47 | 48 |
48 virtual ~TestObserver() { | 49 virtual ~TestObserver() { |
49 } | 50 } |
50 | 51 |
51 virtual void NetworkManagerChanged() OVERRIDE { | 52 virtual void NetworkManagerChanged() OVERRIDE { |
52 ++manager_changed_count_; | 53 ++manager_changed_count_; |
53 } | 54 } |
54 | 55 |
55 virtual void NetworkListChanged() OVERRIDE { | 56 virtual void NetworkListChanged() OVERRIDE { |
56 NetworkStateHandler::NetworkStateList networks; | 57 NetworkStateHandler::NetworkStateList networks; |
57 handler_->GetNetworkList(&networks); | 58 handler_->GetNetworkList(&networks); |
58 network_count_ = networks.size(); | 59 network_count_ = networks.size(); |
59 if (network_count_ == 0) { | 60 if (network_count_ == 0) { |
60 default_network_ = ""; | 61 default_network_ = ""; |
61 default_network_connection_state_ = ""; | 62 default_network_connection_state_ = ""; |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE { | 66 virtual void DefaultNetworkChanged(const NetworkState* network) OVERRIDE { |
| 67 ++default_network_change_count_; |
66 default_network_ = network ? network->path() : ""; | 68 default_network_ = network ? network->path() : ""; |
67 default_network_connection_state_ = | 69 default_network_connection_state_ = |
68 network ? network->connection_state() : ""; | 70 network ? network->connection_state() : ""; |
69 } | 71 } |
70 | 72 |
71 virtual void NetworkConnectionStateChanged( | 73 virtual void NetworkConnectionStateChanged( |
72 const NetworkState* network) OVERRIDE { | 74 const NetworkState* network) OVERRIDE { |
73 network_connection_state_[network->path()] = network->connection_state(); | 75 network_connection_state_[network->path()] = network->connection_state(); |
74 connection_state_changes_[network->path()]++; | 76 connection_state_changes_[network->path()]++; |
75 } | 77 } |
76 | 78 |
77 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE { | 79 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE { |
78 DCHECK(network); | 80 DCHECK(network); |
79 property_updates_[network->path()]++; | 81 property_updates_[network->path()]++; |
80 } | 82 } |
81 | 83 |
82 size_t manager_changed_count() { return manager_changed_count_; } | 84 size_t manager_changed_count() { return manager_changed_count_; } |
83 size_t network_count() { return network_count_; } | 85 size_t network_count() { return network_count_; } |
| 86 size_t default_network_change_count() { |
| 87 return default_network_change_count_; |
| 88 } |
84 std::string default_network() { return default_network_; } | 89 std::string default_network() { return default_network_; } |
85 std::string default_network_connection_state() { | 90 std::string default_network_connection_state() { |
86 return default_network_connection_state_; | 91 return default_network_connection_state_; |
87 } | 92 } |
88 | 93 |
89 int PropertyUpdatesForService(const std::string& service_path) { | 94 int PropertyUpdatesForService(const std::string& service_path) { |
90 return property_updates_[service_path]; | 95 return property_updates_[service_path]; |
91 } | 96 } |
92 | 97 |
93 int ConnectionStateChangesForService(const std::string& service_path) { | 98 int ConnectionStateChangesForService(const std::string& service_path) { |
94 return connection_state_changes_[service_path]; | 99 return connection_state_changes_[service_path]; |
95 } | 100 } |
96 | 101 |
97 std::string NetworkConnectionStateForService( | 102 std::string NetworkConnectionStateForService( |
98 const std::string& service_path) { | 103 const std::string& service_path) { |
99 return network_connection_state_[service_path]; | 104 return network_connection_state_[service_path]; |
100 } | 105 } |
101 | 106 |
102 private: | 107 private: |
103 NetworkStateHandler* handler_; | 108 NetworkStateHandler* handler_; |
104 size_t manager_changed_count_; | 109 size_t manager_changed_count_; |
105 size_t network_count_; | 110 size_t network_count_; |
| 111 size_t default_network_change_count_; |
106 std::string default_network_; | 112 std::string default_network_; |
107 std::string default_network_connection_state_; | 113 std::string default_network_connection_state_; |
108 std::map<std::string, int> property_updates_; | 114 std::map<std::string, int> property_updates_; |
109 std::map<std::string, int> connection_state_changes_; | 115 std::map<std::string, int> connection_state_changes_; |
110 std::map<std::string, std::string> network_connection_state_; | 116 std::map<std::string, std::string> network_connection_state_; |
111 | 117 |
112 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 118 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
113 }; | 119 }; |
114 | 120 |
115 } // namespace | 121 } // namespace |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 const std::string wifi1 = "stub_wifi1"; | 281 const std::string wifi1 = "stub_wifi1"; |
276 manager_test->AddServiceAtIndex(wifi1, 0, true); | 282 manager_test->AddServiceAtIndex(wifi1, 0, true); |
277 const std::string eth0 = "stub_ethernet"; | 283 const std::string eth0 = "stub_ethernet"; |
278 base::StringValue connection_state_idle_value(flimflam::kStateIdle); | 284 base::StringValue connection_state_idle_value(flimflam::kStateIdle); |
279 service_test->SetServiceProperty(eth0, flimflam::kStateProperty, | 285 service_test->SetServiceProperty(eth0, flimflam::kStateProperty, |
280 connection_state_idle_value); | 286 connection_state_idle_value); |
281 message_loop_.RunUntilIdle(); | 287 message_loop_.RunUntilIdle(); |
282 EXPECT_EQ(wifi1, test_observer_->default_network()); | 288 EXPECT_EQ(wifi1, test_observer_->default_network()); |
283 EXPECT_EQ(flimflam::kStateOnline, | 289 EXPECT_EQ(flimflam::kStateOnline, |
284 test_observer_->default_network_connection_state()); | 290 test_observer_->default_network_connection_state()); |
| 291 // We should have seen 2 default network updates - for the default |
| 292 // service change, and for the state change. |
| 293 EXPECT_EQ(2u, test_observer_->default_network_change_count()); |
| 294 |
| 295 // Updating a property on the default network should trigger |
| 296 // a default network change. |
| 297 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 298 dbus::ObjectPath(wifi1), |
| 299 flimflam::kSecurityProperty, base::StringValue("TestSecurity"), |
| 300 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 301 message_loop_.RunUntilIdle(); |
| 302 EXPECT_EQ(3u, test_observer_->default_network_change_count()); |
| 303 |
| 304 // No default network updates for signal strength changes. |
| 305 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 306 dbus::ObjectPath(wifi1), |
| 307 flimflam::kSignalStrengthProperty, base::FundamentalValue(32), |
| 308 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); |
| 309 message_loop_.RunUntilIdle(); |
| 310 EXPECT_EQ(3u, test_observer_->default_network_change_count()); |
285 } | 311 } |
286 | 312 |
287 } // namespace chromeos | 313 } // namespace chromeos |
OLD | NEW |