| Index: chromeos/components/tether/tether_connector_unittest.cc
|
| diff --git a/chromeos/components/tether/tether_connector_unittest.cc b/chromeos/components/tether/tether_connector_unittest.cc
|
| index df7e664dd9d904ee48d87d768f7c816ba924b27a..4910a09be5d7fe83e8b16bbfbcef49ca77cd0b87 100644
|
| --- a/chromeos/components/tether/tether_connector_unittest.cc
|
| +++ b/chromeos/components/tether/tether_connector_unittest.cc
|
| @@ -10,6 +10,8 @@
|
| #include "chromeos/components/tether/device_id_tether_network_guid_map.h"
|
| #include "chromeos/components/tether/fake_active_host.h"
|
| #include "chromeos/components/tether/fake_ble_connection_manager.h"
|
| +#include "chromeos/components/tether/fake_host_scan_cache.h"
|
| +#include "chromeos/components/tether/fake_notification_presenter.h"
|
| #include "chromeos/components/tether/fake_tether_host_fetcher.h"
|
| #include "chromeos/components/tether/fake_wifi_hotspot_connector.h"
|
| #include "chromeos/components/tether/mock_tether_host_response_recorder.h"
|
| @@ -131,6 +133,9 @@ class TetherConnectorTest : public NetworkStateTest {
|
| base::MakeUnique<MockTetherHostResponseRecorder>();
|
| device_id_tether_network_guid_map_ =
|
| base::MakeUnique<DeviceIdTetherNetworkGuidMap>();
|
| + fake_host_scan_cache_ = base::MakeUnique<FakeHostScanCache>();
|
| + fake_notification_presenter_ =
|
| + base::MakeUnique<FakeNotificationPresenter>();
|
|
|
| result_.clear();
|
|
|
| @@ -139,7 +144,8 @@ class TetherConnectorTest : public NetworkStateTest {
|
| fake_active_host_.get(), fake_tether_host_fetcher_.get(),
|
| fake_ble_connection_manager_.get(),
|
| mock_tether_host_response_recorder_.get(),
|
| - device_id_tether_network_guid_map_.get()));
|
| + device_id_tether_network_guid_map_.get(), fake_host_scan_cache_.get(),
|
| + fake_notification_presenter_.get()));
|
|
|
| SetUpTetherNetworks();
|
| }
|
| @@ -164,16 +170,31 @@ class TetherConnectorTest : public NetworkStateTest {
|
| // Add a tether network corresponding to both of the test devices. These
|
| // networks are expected to be added already before
|
| // TetherConnector::ConnectToNetwork is called.
|
| + AddTetherNetwork(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()),
|
| + "TetherNetworkName1", "TetherNetworkCarrier1",
|
| + 85 /* battery_percentage */, 75 /* signal_strength */,
|
| + true /* has_connected_to_host */,
|
| + false /* setup_required */);
|
| + AddTetherNetwork(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()),
|
| + "TetherNetworkName2", "TetherNetworkCarrier2",
|
| + 90 /* battery_percentage */, 50 /* signal_strength */,
|
| + true /* has_connected_to_host */,
|
| + true /* setup_required */);
|
| + }
|
| +
|
| + virtual void AddTetherNetwork(const std::string& tether_network_guid,
|
| + const std::string& device_name,
|
| + const std::string& carrier,
|
| + int battery_percentage,
|
| + int signal_strength,
|
| + bool has_connected_to_host,
|
| + bool setup_required) {
|
| network_state_handler()->AddTetherNetworkState(
|
| - GetTetherNetworkGuid(test_devices_[0].GetDeviceId()),
|
| - "TetherNetworkName1", "TetherNetworkCarrier1",
|
| - 85 /* battery_percentage */, 75 /* signal_strength */,
|
| - true /* has_connected_to_host */);
|
| - network_state_handler()->AddTetherNetworkState(
|
| - GetTetherNetworkGuid(test_devices_[1].GetDeviceId()),
|
| - "TetherNetworkName2", "TetherNetworkCarrier2",
|
| - 90 /* battery_percentage */, 50 /* signal_strength */,
|
| - true /* has_connected_to_host */);
|
| + tether_network_guid, device_name, carrier, battery_percentage,
|
| + signal_strength, has_connected_to_host);
|
| + fake_host_scan_cache_->SetHostScanResult(tether_network_guid, device_name,
|
| + carrier, battery_percentage,
|
| + signal_strength, setup_required);
|
| }
|
|
|
| void SuccessfullyJoinWifiNetwork() {
|
| @@ -213,6 +234,8 @@ class TetherConnectorTest : public NetworkStateTest {
|
| // TODO(hansberry): Use a fake for this when a real mapping scheme is created.
|
| std::unique_ptr<DeviceIdTetherNetworkGuidMap>
|
| device_id_tether_network_guid_map_;
|
| + std::unique_ptr<FakeHostScanCache> fake_host_scan_cache_;
|
| + std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_;
|
|
|
| std::string result_;
|
|
|
| @@ -292,6 +315,30 @@ TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails) {
|
| EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset());
|
| }
|
|
|
| +TEST_F(TetherConnectorTest, TestConnectTetheringOperationFails_SetupRequired) {
|
| + EXPECT_FALSE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()));
|
| +
|
| + EXPECT_TRUE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + fake_tether_host_fetcher_->InvokePendingCallbacks();
|
| +
|
| + EXPECT_TRUE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + fake_operation_factory_->created_operations()[0]->SendFailedResponse(
|
| + ConnectTetheringResponse_ResponseCode::
|
| + ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR);
|
| +
|
| + EXPECT_FALSE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + EXPECT_EQ(NetworkConnectionHandler::kErrorConnectFailed, GetResultAndReset());
|
| +}
|
| +
|
| TEST_F(TetherConnectorTest, TestConnectingToWifiFails) {
|
| CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
|
| EXPECT_EQ(ActiveHost::ActiveHostStatus::CONNECTING,
|
| @@ -363,6 +410,8 @@ TEST_F(TetherConnectorTest, TestSuccessfulConnection) {
|
| EXPECT_EQ(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()),
|
| fake_active_host_->GetTetherNetworkGuid());
|
| EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty());
|
| + EXPECT_FALSE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
|
|
| fake_tether_host_fetcher_->InvokePendingCallbacks();
|
|
|
| @@ -394,6 +443,34 @@ TEST_F(TetherConnectorTest, TestSuccessfulConnection) {
|
| EXPECT_EQ(kSuccessResult, GetResultAndReset());
|
| }
|
|
|
| +TEST_F(TetherConnectorTest, TestSuccessfulConnection_SetupRequired) {
|
| + EXPECT_FALSE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + CallConnect(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()));
|
| +
|
| + EXPECT_TRUE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + fake_tether_host_fetcher_->InvokePendingCallbacks();
|
| +
|
| + EXPECT_TRUE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + fake_operation_factory_->created_operations()[0]->SendSuccessfulResponse(
|
| + kSsid, kPassword);
|
| +
|
| + EXPECT_TRUE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + SuccessfullyJoinWifiNetwork();
|
| +
|
| + EXPECT_FALSE(
|
| + fake_notification_presenter_->is_setup_required_notification_shown());
|
| +
|
| + EXPECT_EQ(kSuccessResult, GetResultAndReset());
|
| +}
|
| +
|
| TEST_F(TetherConnectorTest,
|
| TestNewConnectionAttemptDuringFetch_DifferentDevice) {
|
| CallConnect(GetTetherNetworkGuid(test_devices_[0].GetDeviceId()));
|
|
|