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

Side by Side Diff: chromeos/network/network_state_handler_unittest.cc

Issue 299403012: Clean up shill fake implementations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 months 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 | Annotate | Revision Log
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 "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 13 matching lines...) Expand all
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/cros_system_api/dbus/service_constants.h" 25 #include "third_party/cros_system_api/dbus/service_constants.h"
26 26
27 namespace { 27 namespace {
28 28
29 void ErrorCallbackFunction(const std::string& error_name, 29 void ErrorCallbackFunction(const std::string& error_name,
30 const std::string& error_message) { 30 const std::string& error_message) {
31 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; 31 LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message;
32 } 32 }
33 33
34 const std::string kShillManagerClientStubDefaultService = "eth1"; 34 const std::string kShillManagerClientStubDefaultService = "/service/eth1";
35 const std::string kShillManagerClientStubDefaultWifi = "wifi1"; 35 const std::string kShillManagerClientStubDefaultWifi = "/service/wifi1";
36 const std::string kShillManagerClientStubWifi2 = "wifi2"; 36 const std::string kShillManagerClientStubWifi2 = "/service/wifi2";
37 const std::string kShillManagerClientStubCellular = "cellular1"; 37 const std::string kShillManagerClientStubCellular = "/service/cellular1";
38 38
39 using chromeos::NetworkState; 39 using chromeos::NetworkState;
40 using chromeos::NetworkStateHandler; 40 using chromeos::NetworkStateHandler;
41 41
42 class TestObserver : public chromeos::NetworkStateHandlerObserver { 42 class TestObserver : public chromeos::NetworkStateHandlerObserver {
43 public: 43 public:
44 explicit TestObserver(NetworkStateHandler* handler) 44 explicit TestObserver(NetworkStateHandler* handler)
45 : handler_(handler), 45 : handler_(handler),
46 device_list_changed_count_(0), 46 device_list_changed_count_(0),
47 device_count_(0),
47 network_count_(0), 48 network_count_(0),
48 default_network_change_count_(0), 49 default_network_change_count_(0),
49 favorite_count_(0) { 50 favorite_count_(0) {
50 } 51 }
51 52
52 virtual ~TestObserver() { 53 virtual ~TestObserver() {
53 } 54 }
54 55
55 virtual void DeviceListChanged() OVERRIDE { 56 virtual void DeviceListChanged() OVERRIDE {
57 NetworkStateHandler::DeviceStateList devices;
58 handler_->GetDeviceList(&devices);
59 device_count_ = devices.size();
56 ++device_list_changed_count_; 60 ++device_list_changed_count_;
57 } 61 }
58 62
59 virtual void NetworkListChanged() OVERRIDE { 63 virtual void NetworkListChanged() OVERRIDE {
60 NetworkStateHandler::NetworkStateList networks; 64 NetworkStateHandler::NetworkStateList networks;
61 handler_->GetNetworkList(&networks); 65 handler_->GetNetworkList(&networks);
62 network_count_ = networks.size(); 66 network_count_ = networks.size();
63 if (network_count_ == 0) { 67 if (network_count_ == 0) {
64 default_network_ = ""; 68 default_network_ = "";
65 default_network_connection_state_ = ""; 69 default_network_connection_state_ = "";
(...skipping 17 matching lines...) Expand all
83 network_connection_state_[network->path()] = network->connection_state(); 87 network_connection_state_[network->path()] = network->connection_state();
84 connection_state_changes_[network->path()]++; 88 connection_state_changes_[network->path()]++;
85 } 89 }
86 90
87 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE { 91 virtual void NetworkPropertiesUpdated(const NetworkState* network) OVERRIDE {
88 DCHECK(network); 92 DCHECK(network);
89 property_updates_[network->path()]++; 93 property_updates_[network->path()]++;
90 } 94 }
91 95
92 size_t device_list_changed_count() { return device_list_changed_count_; } 96 size_t device_list_changed_count() { return device_list_changed_count_; }
97 size_t device_count() { return device_count_; }
93 size_t network_count() { return network_count_; } 98 size_t network_count() { return network_count_; }
94 size_t default_network_change_count() { 99 size_t default_network_change_count() {
95 return default_network_change_count_; 100 return default_network_change_count_;
96 } 101 }
97 void reset_network_change_count() { 102 void reset_change_counts() {
98 DVLOG(1) << "ResetNetworkChangeCount"; 103 DVLOG(1) << "=== RESET CHANGE COUNTS ===";
99 default_network_change_count_ = 0; 104 default_network_change_count_ = 0;
105 device_list_changed_count_ = 0;
100 } 106 }
101 std::string default_network() { return default_network_; } 107 std::string default_network() { return default_network_; }
102 std::string default_network_connection_state() { 108 std::string default_network_connection_state() {
103 return default_network_connection_state_; 109 return default_network_connection_state_;
104 } 110 }
105 size_t favorite_count() { return favorite_count_; } 111 size_t favorite_count() { return favorite_count_; }
106 112
107 int PropertyUpdatesForService(const std::string& service_path) { 113 int PropertyUpdatesForService(const std::string& service_path) {
108 return property_updates_[service_path]; 114 return property_updates_[service_path];
109 } 115 }
110 116
111 int ConnectionStateChangesForService(const std::string& service_path) { 117 int ConnectionStateChangesForService(const std::string& service_path) {
112 return connection_state_changes_[service_path]; 118 return connection_state_changes_[service_path];
113 } 119 }
114 120
115 std::string NetworkConnectionStateForService( 121 std::string NetworkConnectionStateForService(
116 const std::string& service_path) { 122 const std::string& service_path) {
117 return network_connection_state_[service_path]; 123 return network_connection_state_[service_path];
118 } 124 }
119 125
120 private: 126 private:
121 NetworkStateHandler* handler_; 127 NetworkStateHandler* handler_;
122 size_t device_list_changed_count_; 128 size_t device_list_changed_count_;
129 size_t device_count_;
123 size_t network_count_; 130 size_t network_count_;
124 size_t default_network_change_count_; 131 size_t default_network_change_count_;
125 std::string default_network_; 132 std::string default_network_;
126 std::string default_network_connection_state_; 133 std::string default_network_connection_state_;
127 size_t favorite_count_; 134 size_t favorite_count_;
128 std::map<std::string, int> property_updates_; 135 std::map<std::string, int> property_updates_;
129 std::map<std::string, int> connection_state_changes_; 136 std::map<std::string, int> connection_state_changes_;
130 std::map<std::string, std::string> network_connection_state_; 137 std::map<std::string, std::string> network_connection_state_;
131 138
132 DISALLOW_COPY_AND_ASSIGN(TestObserver); 139 DISALLOW_COPY_AND_ASSIGN(TestObserver);
133 }; 140 };
134 141
135 } // namespace 142 } // namespace
136 143
137 namespace chromeos { 144 namespace chromeos {
138 145
139 class NetworkStateHandlerTest : public testing::Test { 146 class NetworkStateHandlerTest : public testing::Test {
140 public: 147 public:
141 NetworkStateHandlerTest() 148 NetworkStateHandlerTest()
142 : device_test_(NULL), 149 : device_test_(NULL),
143 manager_test_(NULL), 150 manager_test_(NULL),
144 profile_test_(NULL), 151 profile_test_(NULL),
145 service_test_(NULL) {} 152 service_test_(NULL) {}
146 virtual ~NetworkStateHandlerTest() {} 153 virtual ~NetworkStateHandlerTest() {}
147 154
148 virtual void SetUp() OVERRIDE { 155 virtual void SetUp() OVERRIDE {
149 // Initialize DBusThreadManager with a stub implementation. 156 // Initialize DBusThreadManager with a stub implementation.
150 DBusThreadManager::InitializeWithStub(); 157 DBusThreadManager::InitializeWithStub();
151 SetupNetworkStateHandler(); 158 SetupDefaultShillState();
159 network_state_handler_.reset(new NetworkStateHandler);
160 test_observer_.reset(new TestObserver(network_state_handler_.get()));
161 network_state_handler_->AddObserver(test_observer_.get(), FROM_HERE);
162 network_state_handler_->InitShillPropertyHandler();
152 message_loop_.RunUntilIdle(); 163 message_loop_.RunUntilIdle();
164 test_observer_->reset_change_counts();
153 } 165 }
154 166
155 virtual void TearDown() OVERRIDE { 167 virtual void TearDown() OVERRIDE {
156 network_state_handler_->RemoveObserver(test_observer_.get(), FROM_HERE); 168 network_state_handler_->RemoveObserver(test_observer_.get(), FROM_HERE);
157 test_observer_.reset(); 169 test_observer_.reset();
158 network_state_handler_.reset(); 170 network_state_handler_.reset();
159 DBusThreadManager::Shutdown(); 171 DBusThreadManager::Shutdown();
160 } 172 }
161 173
162 void SetupNetworkStateHandler() {
163 SetupDefaultShillState();
164 network_state_handler_.reset(new NetworkStateHandler);
165 test_observer_.reset(new TestObserver(network_state_handler_.get()));
166 network_state_handler_->AddObserver(test_observer_.get(), FROM_HERE);
167 network_state_handler_->InitShillPropertyHandler();
168 }
169
170 protected: 174 protected:
171 void AddService(const std::string& service_path, 175 void AddService(const std::string& service_path,
172 const std::string& name, 176 const std::string& name,
173 const std::string& type, 177 const std::string& type,
174 const std::string& state) { 178 const std::string& state) {
175 service_test_->AddService(service_path, name, type, state, 179 service_test_->AddService(service_path, name, type, state,
176 true /* add_to_visible */, 180 true /* add_to_visible */);
177 true /* add_to_watchlist */);
178 } 181 }
179 182
180 void SetupDefaultShillState() { 183 void SetupDefaultShillState() {
181 message_loop_.RunUntilIdle(); // Process any pending updates 184 message_loop_.RunUntilIdle(); // Process any pending updates
182 device_test_ = 185 device_test_ =
183 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); 186 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
184 ASSERT_TRUE(device_test_); 187 ASSERT_TRUE(device_test_);
185 device_test_->ClearDevices(); 188 device_test_->ClearDevices();
186 device_test_->AddDevice( 189 device_test_->AddDevice(
187 "/device/stub_wifi_device1", shill::kTypeWifi, "stub_wifi_device1"); 190 "/device/stub_wifi_device1", shill::kTypeWifi, "stub_wifi_device1");
188 device_test_->AddDevice("/device/stub_cellular_device1", 191 device_test_->AddDevice("/device/stub_cellular_device1",
189 shill::kTypeCellular, 192 shill::kTypeCellular,
190 "stub_cellular_device1"); 193 "stub_cellular_device1");
191 194
192 manager_test_ = 195 manager_test_ =
193 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); 196 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
194 ASSERT_TRUE(manager_test_); 197 ASSERT_TRUE(manager_test_);
195 198
196 profile_test_ = 199 profile_test_ =
197 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); 200 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
198 ASSERT_TRUE(profile_test_); 201 ASSERT_TRUE(profile_test_);
199 profile_test_->ClearProfiles(); 202 profile_test_->ClearProfiles();
200 203
201 service_test_ = 204 service_test_ =
202 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 205 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
203 ASSERT_TRUE(service_test_); 206 ASSERT_TRUE(service_test_);
204 service_test_->ClearServices(); 207 service_test_->ClearServices();
205 AddService(kShillManagerClientStubDefaultService, 208 AddService(kShillManagerClientStubDefaultService,
206 kShillManagerClientStubDefaultService, 209 "eth1",
207 shill::kTypeEthernet, 210 shill::kTypeEthernet,
208 shill::kStateOnline); 211 shill::kStateOnline);
209 AddService(kShillManagerClientStubDefaultWifi, 212 AddService(kShillManagerClientStubDefaultWifi,
210 kShillManagerClientStubDefaultWifi, 213 "wifi1",
211 shill::kTypeWifi, 214 shill::kTypeWifi,
212 shill::kStateOnline); 215 shill::kStateOnline);
213 AddService(kShillManagerClientStubWifi2, 216 AddService(kShillManagerClientStubWifi2,
214 kShillManagerClientStubWifi2, 217 "wifi2",
215 shill::kTypeWifi, 218 shill::kTypeWifi,
216 shill::kStateIdle); 219 shill::kStateIdle);
217 AddService(kShillManagerClientStubCellular, 220 AddService(kShillManagerClientStubCellular,
218 kShillManagerClientStubCellular, 221 "cellular1",
219 shill::kTypeCellular, 222 shill::kTypeCellular,
220 shill::kStateIdle); 223 shill::kStateIdle);
221 } 224 }
222 225
223 void UpdateManagerProperties() { 226 void UpdateManagerProperties() {
224 message_loop_.RunUntilIdle(); 227 message_loop_.RunUntilIdle();
225 network_state_handler_->UpdateManagerProperties(); 228 network_state_handler_->UpdateManagerProperties();
226 message_loop_.RunUntilIdle(); 229 message_loop_.RunUntilIdle();
227 } 230 }
228 231
229 base::MessageLoopForUI message_loop_; 232 base::MessageLoopForUI message_loop_;
230 scoped_ptr<NetworkStateHandler> network_state_handler_; 233 scoped_ptr<NetworkStateHandler> network_state_handler_;
231 scoped_ptr<TestObserver> test_observer_; 234 scoped_ptr<TestObserver> test_observer_;
232 ShillDeviceClient::TestInterface* device_test_; 235 ShillDeviceClient::TestInterface* device_test_;
233 ShillManagerClient::TestInterface* manager_test_; 236 ShillManagerClient::TestInterface* manager_test_;
234 ShillProfileClient::TestInterface* profile_test_; 237 ShillProfileClient::TestInterface* profile_test_;
235 ShillServiceClient::TestInterface* service_test_; 238 ShillServiceClient::TestInterface* service_test_;
236 239
237 private: 240 private:
238 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandlerTest); 241 DISALLOW_COPY_AND_ASSIGN(NetworkStateHandlerTest);
239 }; 242 };
240 243
241 TEST_F(NetworkStateHandlerTest, NetworkStateHandlerStub) { 244 TEST_F(NetworkStateHandlerTest, NetworkStateHandlerStub) {
242 // Ensure that the network list is the expected size. 245 // Ensure that the device and network list are the expected size.
246 const size_t kNumShillManagerClientStubImplDevices = 2;
247 EXPECT_EQ(kNumShillManagerClientStubImplDevices,
248 test_observer_->device_count());
243 const size_t kNumShillManagerClientStubImplServices = 4; 249 const size_t kNumShillManagerClientStubImplServices = 4;
244 EXPECT_EQ(kNumShillManagerClientStubImplServices, 250 EXPECT_EQ(kNumShillManagerClientStubImplServices,
245 test_observer_->network_count()); 251 test_observer_->network_count());
246 // Ensure that the first stub network is the default network. 252 // Ensure that the first stub network is the default network.
247 EXPECT_EQ(kShillManagerClientStubDefaultService, 253 EXPECT_EQ(kShillManagerClientStubDefaultService,
248 test_observer_->default_network()); 254 test_observer_->default_network());
255 ASSERT_TRUE(network_state_handler_->DefaultNetwork());
249 EXPECT_EQ(kShillManagerClientStubDefaultService, 256 EXPECT_EQ(kShillManagerClientStubDefaultService,
250 network_state_handler_->ConnectedNetworkByType( 257 network_state_handler_->DefaultNetwork()->path());
251 NetworkTypePattern::Default())->path());
252 EXPECT_EQ(kShillManagerClientStubDefaultService, 258 EXPECT_EQ(kShillManagerClientStubDefaultService,
253 network_state_handler_->ConnectedNetworkByType( 259 network_state_handler_->ConnectedNetworkByType(
254 NetworkTypePattern::Ethernet())->path()); 260 NetworkTypePattern::Ethernet())->path());
255 EXPECT_EQ(kShillManagerClientStubDefaultWifi, 261 EXPECT_EQ(kShillManagerClientStubDefaultWifi,
256 network_state_handler_->ConnectedNetworkByType( 262 network_state_handler_->ConnectedNetworkByType(
257 NetworkTypePattern::WiFi())->path()); 263 NetworkTypePattern::WiFi())->path());
258 EXPECT_EQ(kShillManagerClientStubCellular, 264 EXPECT_EQ(kShillManagerClientStubCellular,
259 network_state_handler_->FirstNetworkByType( 265 network_state_handler_->FirstNetworkByType(
260 NetworkTypePattern::Mobile())->path()); 266 NetworkTypePattern::Mobile())->path());
261 EXPECT_EQ( 267 EXPECT_EQ(
262 kShillManagerClientStubCellular, 268 kShillManagerClientStubCellular,
263 network_state_handler_->FirstNetworkByType(NetworkTypePattern::Cellular()) 269 network_state_handler_->FirstNetworkByType(NetworkTypePattern::Cellular())
264 ->path()); 270 ->path());
265 EXPECT_EQ(shill::kStateOnline, 271 EXPECT_EQ(shill::kStateOnline,
266 test_observer_->default_network_connection_state()); 272 test_observer_->default_network_connection_state());
267 } 273 }
268 274
269 TEST_F(NetworkStateHandlerTest, TechnologyChanged) { 275 TEST_F(NetworkStateHandlerTest, TechnologyChanged) {
270 // There may be several manager changes during initialization. 276 // Disable a technology. Will immediately set the state to AVAILABLE and
271 size_t initial_changed_count = test_observer_->device_list_changed_count(); 277 // notify observers.
272 // Disable a technology.
273 network_state_handler_->SetTechnologyEnabled( 278 network_state_handler_->SetTechnologyEnabled(
274 NetworkTypePattern::Wimax(), false, network_handler::ErrorCallback()); 279 NetworkTypePattern::WiFi(), false, network_handler::ErrorCallback());
275 EXPECT_NE( 280 EXPECT_EQ(1u, test_observer_->device_list_changed_count());
276 NetworkStateHandler::TECHNOLOGY_ENABLED, 281 EXPECT_EQ(
277 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax())); 282 NetworkStateHandler::TECHNOLOGY_AVAILABLE,
278 EXPECT_EQ(initial_changed_count + 1, 283 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi()));
279 test_observer_->device_list_changed_count()); 284
280 // Enable a technology. 285 // Run the message loop. An additional notification will be received when
286 // Shill updates the enabled technologies. The state should remain AVAILABLE.
287 test_observer_->reset_change_counts();
288 message_loop_.RunUntilIdle();
289 EXPECT_EQ(1u, test_observer_->device_list_changed_count());
290 EXPECT_EQ(
291 NetworkStateHandler::TECHNOLOGY_AVAILABLE,
292 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi()));
293
294 // Enable a technology. Will immediately set the state to ENABLING and
295 // notify observers.
296 test_observer_->reset_change_counts();
281 network_state_handler_->SetTechnologyEnabled( 297 network_state_handler_->SetTechnologyEnabled(
282 NetworkTypePattern::Wimax(), true, network_handler::ErrorCallback()); 298 NetworkTypePattern::WiFi(), true, network_handler::ErrorCallback());
283 // The technology state should immediately change to ENABLING and we should 299 EXPECT_EQ(1u, test_observer_->device_list_changed_count());
284 // receive a manager changed callback.
285 EXPECT_EQ(initial_changed_count + 2,
286 test_observer_->device_list_changed_count());
287 EXPECT_EQ( 300 EXPECT_EQ(
288 NetworkStateHandler::TECHNOLOGY_ENABLING, 301 NetworkStateHandler::TECHNOLOGY_ENABLING,
289 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax())); 302 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi()));
303
304 // Run the message loop. State should change to ENABLED.
305 test_observer_->reset_change_counts();
290 message_loop_.RunUntilIdle(); 306 message_loop_.RunUntilIdle();
291 // Ensure we receive 2 manager changed callbacks when the technology becomes 307 EXPECT_EQ(1u, test_observer_->device_list_changed_count());
292 // avalable and enabled.
293 EXPECT_EQ(initial_changed_count + 4,
294 test_observer_->device_list_changed_count());
295 EXPECT_EQ( 308 EXPECT_EQ(
296 NetworkStateHandler::TECHNOLOGY_ENABLED, 309 NetworkStateHandler::TECHNOLOGY_ENABLED,
297 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax())); 310 network_state_handler_->GetTechnologyState(NetworkTypePattern::WiFi()));
298 } 311 }
299 312
300 TEST_F(NetworkStateHandlerTest, TechnologyState) { 313 TEST_F(NetworkStateHandlerTest, TechnologyState) {
301 manager_test_->RemoveTechnology(shill::kTypeWimax); 314 manager_test_->RemoveTechnology(shill::kTypeWimax);
302 message_loop_.RunUntilIdle(); 315 message_loop_.RunUntilIdle();
303 EXPECT_EQ( 316 EXPECT_EQ(
304 NetworkStateHandler::TECHNOLOGY_UNAVAILABLE, 317 NetworkStateHandler::TECHNOLOGY_UNAVAILABLE,
305 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax())); 318 network_state_handler_->GetTechnologyState(NetworkTypePattern::Wimax()));
306 319
307 manager_test_->AddTechnology(shill::kTypeWimax, false); 320 manager_test_->AddTechnology(shill::kTypeWimax, false);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 connection_state_idle_value); 420 connection_state_idle_value);
408 message_loop_.RunUntilIdle(); 421 message_loop_.RunUntilIdle();
409 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1)); 422 EXPECT_EQ(2, test_observer_->ConnectionStateChangesForService(eth1));
410 } 423 }
411 424
412 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) { 425 TEST_F(NetworkStateHandlerTest, DefaultServiceDisconnected) {
413 const std::string eth1 = kShillManagerClientStubDefaultService; 426 const std::string eth1 = kShillManagerClientStubDefaultService;
414 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 427 const std::string wifi1 = kShillManagerClientStubDefaultWifi;
415 428
416 // Disconnect ethernet. 429 // Disconnect ethernet.
417 test_observer_->reset_network_change_count();
418 base::StringValue connection_state_idle_value(shill::kStateIdle); 430 base::StringValue connection_state_idle_value(shill::kStateIdle);
419 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 431 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
420 connection_state_idle_value); 432 connection_state_idle_value);
421 message_loop_.RunUntilIdle(); 433 message_loop_.RunUntilIdle();
422 // Expect two changes: first when eth1 becomes disconnected, second when 434 // Expect two changes: first when eth1 becomes disconnected, second when
423 // wifi1 becomes the default. 435 // wifi1 becomes the default.
424 EXPECT_EQ(2u, test_observer_->default_network_change_count()); 436 EXPECT_EQ(2u, test_observer_->default_network_change_count());
425 EXPECT_EQ(wifi1, test_observer_->default_network()); 437 EXPECT_EQ(wifi1, test_observer_->default_network());
426 438
427 // Disconnect wifi. 439 // Disconnect wifi.
428 test_observer_->reset_network_change_count(); 440 test_observer_->reset_change_counts();
429 service_test_->SetServiceProperty(wifi1, shill::kStateProperty, 441 service_test_->SetServiceProperty(wifi1, shill::kStateProperty,
430 connection_state_idle_value); 442 connection_state_idle_value);
431 message_loop_.RunUntilIdle(); 443 message_loop_.RunUntilIdle();
432 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 444 EXPECT_EQ(1u, test_observer_->default_network_change_count());
433 EXPECT_EQ("", test_observer_->default_network()); 445 EXPECT_EQ("", test_observer_->default_network());
434 } 446 }
435 447
436 TEST_F(NetworkStateHandlerTest, DefaultServiceConnected) { 448 TEST_F(NetworkStateHandlerTest, DefaultServiceConnected) {
437 const std::string eth1 = kShillManagerClientStubDefaultService; 449 const std::string eth1 = kShillManagerClientStubDefaultService;
438 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 450 const std::string wifi1 = kShillManagerClientStubDefaultWifi;
439 451
440 // Disconnect ethernet and wifi. 452 // Disconnect ethernet and wifi.
441 base::StringValue connection_state_idle_value(shill::kStateIdle); 453 base::StringValue connection_state_idle_value(shill::kStateIdle);
442 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 454 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
443 connection_state_idle_value); 455 connection_state_idle_value);
444 service_test_->SetServiceProperty(wifi1, shill::kStateProperty, 456 service_test_->SetServiceProperty(wifi1, shill::kStateProperty,
445 connection_state_idle_value); 457 connection_state_idle_value);
446 message_loop_.RunUntilIdle(); 458 message_loop_.RunUntilIdle();
447 EXPECT_EQ(std::string(), test_observer_->default_network()); 459 EXPECT_EQ(std::string(), test_observer_->default_network());
448 460
449 // Connect ethernet, should become the default network. 461 // Connect ethernet, should become the default network.
450 test_observer_->reset_network_change_count(); 462 test_observer_->reset_change_counts();
451 base::StringValue connection_state_ready_value(shill::kStateReady); 463 base::StringValue connection_state_ready_value(shill::kStateReady);
452 service_test_->SetServiceProperty(eth1, shill::kStateProperty, 464 service_test_->SetServiceProperty(eth1, shill::kStateProperty,
453 connection_state_ready_value); 465 connection_state_ready_value);
454 message_loop_.RunUntilIdle(); 466 message_loop_.RunUntilIdle();
455 EXPECT_EQ(eth1, test_observer_->default_network()); 467 EXPECT_EQ(eth1, test_observer_->default_network());
456 EXPECT_EQ(shill::kStateReady, 468 EXPECT_EQ(shill::kStateReady,
457 test_observer_->default_network_connection_state()); 469 test_observer_->default_network_connection_state());
458 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 470 EXPECT_EQ(1u, test_observer_->default_network_change_count());
459 } 471 }
460 472
461 TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) { 473 TEST_F(NetworkStateHandlerTest, DefaultServiceChanged) {
462 const std::string eth1 = kShillManagerClientStubDefaultService; 474 const std::string eth1 = kShillManagerClientStubDefaultService;
463 // The default service should be eth1. 475 // The default service should be eth1.
464 EXPECT_EQ(eth1, test_observer_->default_network()); 476 EXPECT_EQ(eth1, test_observer_->default_network());
465 477
466 // Change the default network by changing Manager.DefaultService. 478 // Change the default network by changing Manager.DefaultService.
467 test_observer_->reset_network_change_count();
468 const std::string wifi1 = kShillManagerClientStubDefaultWifi; 479 const std::string wifi1 = kShillManagerClientStubDefaultWifi;
469 base::StringValue wifi1_value(wifi1); 480 base::StringValue wifi1_value(wifi1);
470 manager_test_->SetManagerProperty( 481 manager_test_->SetManagerProperty(
471 shill::kDefaultServiceProperty, wifi1_value); 482 shill::kDefaultServiceProperty, wifi1_value);
472 message_loop_.RunUntilIdle(); 483 message_loop_.RunUntilIdle();
473 EXPECT_EQ(wifi1, test_observer_->default_network()); 484 EXPECT_EQ(wifi1, test_observer_->default_network());
474 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 485 EXPECT_EQ(1u, test_observer_->default_network_change_count());
475 486
476 // Change the state of the default network. 487 // Change the state of the default network.
477 test_observer_->reset_network_change_count(); 488 test_observer_->reset_change_counts();
478 base::StringValue connection_state_ready_value(shill::kStateReady); 489 base::StringValue connection_state_ready_value(shill::kStateReady);
479 service_test_->SetServiceProperty(wifi1, shill::kStateProperty, 490 service_test_->SetServiceProperty(wifi1, shill::kStateProperty,
480 connection_state_ready_value); 491 connection_state_ready_value);
481 message_loop_.RunUntilIdle(); 492 message_loop_.RunUntilIdle();
482 EXPECT_EQ(shill::kStateReady, 493 EXPECT_EQ(shill::kStateReady,
483 test_observer_->default_network_connection_state()); 494 test_observer_->default_network_connection_state());
484 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 495 EXPECT_EQ(1u, test_observer_->default_network_change_count());
485 496
486 // Updating a property on the default network should trigger 497 // Updating a property on the default network should trigger
487 // a default network change. 498 // a default network change.
488 test_observer_->reset_network_change_count(); 499 test_observer_->reset_change_counts();
489 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 500 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
490 dbus::ObjectPath(wifi1), 501 dbus::ObjectPath(wifi1),
491 shill::kSecurityProperty, base::StringValue("TestSecurity"), 502 shill::kSecurityProperty, base::StringValue("TestSecurity"),
492 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 503 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
493 message_loop_.RunUntilIdle(); 504 message_loop_.RunUntilIdle();
494 EXPECT_EQ(1u, test_observer_->default_network_change_count()); 505 EXPECT_EQ(1u, test_observer_->default_network_change_count());
495 506
496 // No default network updates for signal strength changes. 507 // No default network updates for signal strength changes.
497 test_observer_->reset_network_change_count(); 508 test_observer_->reset_change_counts();
498 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( 509 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
499 dbus::ObjectPath(wifi1), 510 dbus::ObjectPath(wifi1),
500 shill::kSignalStrengthProperty, base::FundamentalValue(32), 511 shill::kSignalStrengthProperty, base::FundamentalValue(32),
501 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction)); 512 base::Bind(&base::DoNothing), base::Bind(&ErrorCallbackFunction));
502 message_loop_.RunUntilIdle(); 513 message_loop_.RunUntilIdle();
503 EXPECT_EQ(0u, test_observer_->default_network_change_count()); 514 EXPECT_EQ(0u, test_observer_->default_network_change_count());
504 } 515 }
505 516
506 TEST_F(NetworkStateHandlerTest, RequestUpdate) { 517 TEST_F(NetworkStateHandlerTest, RequestUpdate) {
507 // Request an update for kShillManagerClientStubDefaultWifi. 518 // Request an update for kShillManagerClientStubDefaultWifi.
508 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService( 519 EXPECT_EQ(1, test_observer_->PropertyUpdatesForService(
509 kShillManagerClientStubDefaultWifi)); 520 kShillManagerClientStubDefaultWifi));
510 network_state_handler_->RequestUpdateForNetwork( 521 network_state_handler_->RequestUpdateForNetwork(
511 kShillManagerClientStubDefaultWifi); 522 kShillManagerClientStubDefaultWifi);
512 message_loop_.RunUntilIdle(); 523 message_loop_.RunUntilIdle();
513 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService( 524 EXPECT_EQ(2, test_observer_->PropertyUpdatesForService(
514 kShillManagerClientStubDefaultWifi)); 525 kShillManagerClientStubDefaultWifi));
515 } 526 }
516 527
517 TEST_F(NetworkStateHandlerTest, NetworkGuidInProfile) { 528 TEST_F(NetworkStateHandlerTest, NetworkGuidInProfile) {
518 const std::string profile = "/profile/profile1"; 529 const std::string profile = "/profile/profile1";
519 const std::string wifi_path = "wifi_with_guid"; 530 const std::string wifi_path = "/service/wifi_with_guid";
520 const std::string wifi_guid = "WIFI_GUID"; 531 const std::string wifi_guid = "WIFI_GUID";
521 const bool is_service_configured = true; 532 const bool is_service_configured = true;
522 533
523 // Add a network to the default Profile with a specified GUID. 534 // Add a network to the default Profile with a specified GUID.
524 service_test_->AddServiceWithIPConfig( 535 service_test_->AddServiceWithIPConfig(
525 wifi_path, 536 wifi_path,
526 wifi_guid, 537 wifi_guid,
527 wifi_path /* name */, 538 wifi_path /* name */,
528 shill::kTypeWifi, 539 shill::kTypeWifi,
529 shill::kStateOnline, 540 shill::kStateOnline,
530 "" /* ipconfig_path */, 541 "" /* ipconfig_path */,
531 true /* add_to_visible */, 542 true /* add_to_visible */);
532 true /* add_to_watchlist */);
533 profile_test_->AddProfile(profile, "" /* userhash */); 543 profile_test_->AddProfile(profile, "" /* userhash */);
534 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path)); 544 EXPECT_TRUE(profile_test_->AddService(profile, wifi_path));
535 UpdateManagerProperties(); 545 UpdateManagerProperties();
536 546
537 // Verify that a FavoriteState exists with a matching GUID. 547 // Verify that a FavoriteState exists with a matching GUID.
538 const FavoriteState* favorite = 548 const FavoriteState* favorite =
539 network_state_handler_->GetFavoriteStateFromServicePath( 549 network_state_handler_->GetFavoriteStateFromServicePath(
540 wifi_path, is_service_configured); 550 wifi_path, is_service_configured);
541 ASSERT_TRUE(favorite); 551 ASSERT_TRUE(favorite);
542 EXPECT_EQ(wifi_guid, favorite->guid()); 552 EXPECT_EQ(wifi_guid, favorite->guid());
(...skipping 18 matching lines...) Expand all
561 EXPECT_EQ(wifi_guid, network->guid()); 571 EXPECT_EQ(wifi_guid, network->guid());
562 572
563 // Also verify FavoriteState (mostly to test the stub behavior). 573 // Also verify FavoriteState (mostly to test the stub behavior).
564 favorite = network_state_handler_->GetFavoriteStateFromServicePath( 574 favorite = network_state_handler_->GetFavoriteStateFromServicePath(
565 wifi_path, is_service_configured); 575 wifi_path, is_service_configured);
566 ASSERT_TRUE(favorite); 576 ASSERT_TRUE(favorite);
567 EXPECT_EQ(wifi_guid, favorite->guid()); 577 EXPECT_EQ(wifi_guid, favorite->guid());
568 } 578 }
569 579
570 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) { 580 TEST_F(NetworkStateHandlerTest, NetworkGuidNotInProfile) {
571 const std::string wifi_path = "wifi_with_guid"; 581 const std::string wifi_path = "/service/wifi_with_guid";
572 const bool is_service_configured = false; 582 const bool is_service_configured = false;
573 583
574 // Add a network without adding it to a profile. 584 // Add a network without adding it to a profile.
575 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline); 585 AddService(wifi_path, wifi_path, shill::kTypeWifi, shill::kStateOnline);
576 UpdateManagerProperties(); 586 UpdateManagerProperties();
577 587
578 // Verify that a FavoriteState exists with an assigned GUID. 588 // Verify that a FavoriteState exists with an assigned GUID.
579 const FavoriteState* favorite = 589 const FavoriteState* favorite =
580 network_state_handler_->GetFavoriteStateFromServicePath( 590 network_state_handler_->GetFavoriteStateFromServicePath(
581 wifi_path, is_service_configured); 591 wifi_path, is_service_configured);
(...skipping 21 matching lines...) Expand all
603 EXPECT_EQ(wifi_guid, network->guid()); 613 EXPECT_EQ(wifi_guid, network->guid());
604 614
605 // Also verify FavoriteState (mostly to test the stub behavior). 615 // Also verify FavoriteState (mostly to test the stub behavior).
606 favorite = network_state_handler_->GetFavoriteStateFromServicePath( 616 favorite = network_state_handler_->GetFavoriteStateFromServicePath(
607 wifi_path, is_service_configured); 617 wifi_path, is_service_configured);
608 ASSERT_TRUE(favorite); 618 ASSERT_TRUE(favorite);
609 EXPECT_EQ(wifi_guid, favorite->guid()); 619 EXPECT_EQ(wifi_guid, favorite->guid());
610 } 620 }
611 621
612 } // namespace chromeos 622 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698