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

Side by Side Diff: chromeos/components/tether/tether_connector_unittest.cc

Issue 2819303002: Changed wifi arcs to mobile bars for Tether network. (Closed)
Patch Set: khorimoto@ comments Created 3 years, 7 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/components/tether/tether_connector.h" 5 #include "chromeos/components/tether/tether_connector.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "chromeos/components/tether/connect_tethering_operation.h" 9 #include "chromeos/components/tether/connect_tethering_operation.h"
10 #include "chromeos/components/tether/device_id_tether_network_guid_map.h" 10 #include "chromeos/components/tether/device_id_tether_network_guid_map.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 "TetherNetworkName2", "TetherNetworkCarrier2", 190 "TetherNetworkName2", "TetherNetworkCarrier2",
191 90 /* battery_percentage */, 50 /* signal_strength */, 191 90 /* battery_percentage */, 50 /* signal_strength */,
192 true /* has_connected_to_host */); 192 true /* has_connected_to_host */);
193 } 193 }
194 194
195 void SuccessfullyJoinWifiNetwork() { 195 void SuccessfullyJoinWifiNetwork() {
196 ConfigureService(CreateWifiConfigurationJsonString()); 196 ConfigureService(CreateWifiConfigurationJsonString());
197 fake_wifi_hotspot_connector_->CallMostRecentCallback(kWifiNetworkGuid); 197 fake_wifi_hotspot_connector_->CallMostRecentCallback(kWifiNetworkGuid);
198 } 198 }
199 199
200 void VerifyTetherAndWifiNetworkAssociation(
201 const std::string& tether_network_guid) {
202 const NetworkState* tether_network_state =
203 network_state_handler()->GetNetworkStateFromGuid(tether_network_guid);
204 EXPECT_TRUE(tether_network_state);
205 EXPECT_EQ(kWifiNetworkGuid, tether_network_state->tether_guid());
206
207 const NetworkState* wifi_network_state =
208 network_state_handler()->GetNetworkStateFromGuid(kWifiNetworkGuid);
209 EXPECT_TRUE(wifi_network_state);
210 EXPECT_EQ(tether_network_guid, wifi_network_state->tether_guid());
211 }
212
213 void SuccessCallback() { result_ = kSuccessResult; } 200 void SuccessCallback() { result_ = kSuccessResult; }
214 201
215 void ErrorCallback(const std::string& error_name, 202 void ErrorCallback(const std::string& error_name,
216 std::unique_ptr<base::DictionaryValue> error_data) { 203 std::unique_ptr<base::DictionaryValue> error_data) {
217 result_ = error_name; 204 result_ = error_name;
218 } 205 }
219 206
220 void CallTetherDelegate(const std::string& tether_network_guid) { 207 void CallTetherDelegate(const std::string& tether_network_guid) {
221 test_network_connection_handler_->CallTetherDelegate( 208 test_network_connection_handler_->CallTetherDelegate(
222 tether_network_guid, 209 tether_network_guid,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse( 306 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse(
320 kSsid, kPassword); 307 kSsid, kPassword);
321 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, 308 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
322 fake_active_host_->GetActiveHostStatus()); 309 fake_active_host_->GetActiveHostStatus());
323 310
324 // |fake_wifi_hotspot_connector_| should have received the SSID and password 311 // |fake_wifi_hotspot_connector_| should have received the SSID and password
325 // above. Verify this, then return an empty string, signaling a failure to 312 // above. Verify this, then return an empty string, signaling a failure to
326 // connect. 313 // connect.
327 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); 314 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid());
328 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); 315 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password());
316 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(),
317 fake_wifi_hotspot_connector_->most_recent_tether_network_guid());
329 fake_wifi_hotspot_connector_->CallMostRecentCallback(""); 318 fake_wifi_hotspot_connector_->CallMostRecentCallback("");
330 319
331 // The failure should have resulted in the host being disconnected. 320 // The failure should have resulted in the host being disconnected.
332 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED, 321 EXPECT_EQ(ActiveHost::ActiveHostStatus::DISCONNECTED,
333 fake_active_host_->GetActiveHostStatus()); 322 fake_active_host_->GetActiveHostStatus());
334 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset()); 323 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset());
335 } 324 }
336 325
337 TEST_F(TetherConnectorTest, TestSuccessfulConnection) { 326 TEST_F(TetherConnectorTest, TestSuccessfulConnection) {
338 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); 327 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
(...skipping 12 matching lines...) Expand all
351 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse( 340 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse(
352 kSsid, kPassword); 341 kSsid, kPassword);
353 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, 342 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
354 fake_active_host_->GetActiveHostStatus()); 343 fake_active_host_->GetActiveHostStatus());
355 344
356 // |fake_wifi_hotspot_connector_| should have received the SSID and password 345 // |fake_wifi_hotspot_connector_| should have received the SSID and password
357 // above. Verify this, then return the GUID corresponding to the connected 346 // above. Verify this, then return the GUID corresponding to the connected
358 // Wi-Fi network. 347 // Wi-Fi network.
359 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); 348 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid());
360 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); 349 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password());
350 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(),
351 fake_wifi_hotspot_connector_->most_recent_tether_network_guid());
361 SuccessfullyJoinWifiNetwork(); 352 SuccessfullyJoinWifiNetwork();
362 353
363 // The active host should now be connected, and the tether and Wi-Fi networks 354 // The active host should now be connected.
364 // should be associated.
365 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTED, 355 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTED,
366 fake_active_host_->GetActiveHostStatus()); 356 fake_active_host_->GetActiveHostStatus());
367 EXPECT_EQ(test_devices_[0].GetDeviceId(), 357 EXPECT_EQ(test_devices_[0].GetDeviceId(),
368 fake_active_host_->GetActiveHostDeviceId()); 358 fake_active_host_->GetActiveHostDeviceId());
369 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()), 359 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()),
370 fake_active_host_->GetTetherNetworkGuid()); 360 fake_active_host_->GetTetherNetworkGuid());
371 EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid()); 361 EXPECT_EQ(kWifiNetworkGuid, fake_active_host_->GetWifiNetworkGuid());
372 VerifyTetherAndWifiNetworkAssociation( 362
373 GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
374 EXPECT_EQ(kSuccessResult, GetResultAndReset()); 363 EXPECT_EQ(kSuccessResult, GetResultAndReset());
375 } 364 }
376 365
377 TEST_F(TetherConnectorTest, 366 TEST_F(TetherConnectorTest,
378 TestNewConnectionAttemptDuringFetch_DifferentDevice) { 367 TestNewConnectionAttemptDuringFetch_DifferentDevice) {
379 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); 368 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
380 369
381 // Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|, 370 // Instead of invoking the pending callbacks on |fake_tether_host_fetcher_|,
382 // attempt another connection attempt, this time to another device. 371 // attempt another connection attempt, this time to another device.
383 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); 372 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 fake_active_host_->GetActiveHostDeviceId()); 415 fake_active_host_->GetActiveHostDeviceId());
427 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), 416 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()),
428 fake_active_host_->GetTetherNetworkGuid()); 417 fake_active_host_->GetTetherNetworkGuid());
429 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); 418 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty());
430 419
431 // A second operation should have been created. 420 // A second operation should have been created.
432 EXPECT_EQ(2u, fake_operation_factory_->created_operations().size()); 421 EXPECT_EQ(2u, fake_operation_factory_->created_operations().size());
433 422
434 // No connection should have been started. 423 // No connection should have been started.
435 EXPECT_TRUE(fake_wifi_hotspot_connector_->most_recent_ssid().empty()); 424 EXPECT_TRUE(fake_wifi_hotspot_connector_->most_recent_ssid().empty());
436 EXPECT_TRUE(fake_wifi_hotspot_connector_->most_recent_password().empty()); 425 EXPECT_TRUE(fake_wifi_hotspot_connector_->most_recent_password().empty());
Kyle Horimoto 2017/05/03 22:47:28 Also check that tether GUID is empty.
lesliewatkins 2017/05/04 01:40:16 Done.
437 426
438 // The second operation replies successfully, and this response should 427 // The second operation replies successfully, and this response should
439 // result in a Wi-Fi connection attempt. 428 // result in a Wi-Fi connection attempt.
440 fake_operation_factory_->created_operations()[1]->SendSuccessfulResponse( 429 fake_operation_factory_->created_operations()[1]->SendSuccessfulResponse(
441 kSsid, kPassword); 430 kSsid, kPassword);
442 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); 431 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid());
443 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); 432 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password());
433 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(),
434 fake_wifi_hotspot_connector_->most_recent_tether_network_guid());
444 } 435 }
445 436
446 TEST_F(TetherConnectorTest, 437 TEST_F(TetherConnectorTest,
447 TestNewConnectionAttemptDuringWifiConnection_DifferentDevice) { 438 TestNewConnectionAttemptDuringWifiConnection_DifferentDevice) {
448 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[0].GetDeviceId())); 439 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
449 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, 440 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
450 fake_active_host_->GetActiveHostStatus()); 441 fake_active_host_->GetActiveHostStatus());
451 EXPECT_EQ(test_devices_[0].GetDeviceId(), 442 EXPECT_EQ(test_devices_[0].GetDeviceId(),
452 fake_active_host_->GetActiveHostDeviceId()); 443 fake_active_host_->GetActiveHostDeviceId());
453 444
454 fake_tether_host_fetcher_->InvokePendingCallbacks(); 445 fake_tether_host_fetcher_->InvokePendingCallbacks();
455 446
456 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size()); 447 EXPECT_EQ(1u, fake_operation_factory_->created_operations().size());
457 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse( 448 fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse(
458 kSsid, kPassword); 449 kSsid, kPassword);
459 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, 450 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
460 fake_active_host_->GetActiveHostStatus()); 451 fake_active_host_->GetActiveHostStatus());
461 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid()); 452 EXPECT_EQ(kSsid, fake_wifi_hotspot_connector_->most_recent_ssid());
462 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password()); 453 EXPECT_EQ(kPassword, fake_wifi_hotspot_connector_->most_recent_password());
454 EXPECT_EQ(fake_active_host_->GetTetherNetworkGuid(),
455 fake_wifi_hotspot_connector_->most_recent_tether_network_guid());
463 456
464 // While the connection to the Wi-Fi network is in progress, start a new 457 // While the connection to the Wi-Fi network is in progress, start a new
465 // connection attempt. 458 // connection attempt.
466 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[1].GetDeviceId())); 459 CallTetherDelegate(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()));
467 // The first connection attempt should have resulted in a connect canceled 460 // The first connection attempt should have resulted in a connect canceled
468 // error. 461 // error.
469 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled, 462 EXPECT_EQ(NetworkConnectionHandler::kErrorConnectCanceled,
470 GetResultAndReset()); 463 GetResultAndReset());
471 fake_tether_host_fetcher_->InvokePendingCallbacks(); 464 fake_tether_host_fetcher_->InvokePendingCallbacks();
472 465
473 // Connect successfully to the first Wi-Fi network. Even though a temporary 466 // Connect successfully to the first Wi-Fi network. Even though a temporary
474 // connection has succeeded, the active host should be CONNECTING to device 1. 467 // connection has succeeded, the active host should be CONNECTING to device 1.
475 SuccessfullyJoinWifiNetwork(); 468 SuccessfullyJoinWifiNetwork();
476 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING, 469 EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
477 fake_active_host_->GetActiveHostStatus()); 470 fake_active_host_->GetActiveHostStatus());
478 EXPECT_EQ(test_devices_[1].GetDeviceId(), 471 EXPECT_EQ(test_devices_[1].GetDeviceId(),
479 fake_active_host_->GetActiveHostDeviceId()); 472 fake_active_host_->GetActiveHostDeviceId());
480 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), 473 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()),
481 fake_active_host_->GetTetherNetworkGuid()); 474 fake_active_host_->GetTetherNetworkGuid());
482 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); 475 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty());
483 } 476 }
484 477
485 } // namespace tether 478 } // namespace tether
486 479
487 } // namespace chromeos 480 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698