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

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

Issue 2844973002: [CrOS Tether] Create TetherHostResponseRecorder, which records ConnectTetheringResponses and Tether… (Closed)
Patch Set: Changed "Connectable" wording to "Connected". 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"
11 #include "chromeos/components/tether/fake_active_host.h" 11 #include "chromeos/components/tether/fake_active_host.h"
12 #include "chromeos/components/tether/fake_ble_connection_manager.h" 12 #include "chromeos/components/tether/fake_ble_connection_manager.h"
13 #include "chromeos/components/tether/fake_tether_host_fetcher.h" 13 #include "chromeos/components/tether/fake_tether_host_fetcher.h"
14 #include "chromeos/components/tether/fake_wifi_hotspot_connector.h" 14 #include "chromeos/components/tether/fake_wifi_hotspot_connector.h"
15 #include "chromeos/components/tether/mock_host_scan_device_prioritizer.h" 15 #include "chromeos/components/tether/mock_tether_host_response_recorder.h"
16 #include "chromeos/components/tether/tether_connector.h" 16 #include "chromeos/components/tether/tether_connector.h"
17 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/network/network_connection_handler.h" 18 #include "chromeos/network/network_connection_handler.h"
19 #include "chromeos/network/network_state.h" 19 #include "chromeos/network/network_state.h"
20 #include "chromeos/network/network_state_handler.h" 20 #include "chromeos/network/network_state_handler.h"
21 #include "chromeos/network/network_state_test.h" 21 #include "chromeos/network/network_state_test.h"
22 #include "components/cryptauth/remote_device.h" 22 #include "components/cryptauth/remote_device.h"
23 #include "components/cryptauth/remote_device_test_util.h" 23 #include "components/cryptauth/remote_device_test_util.h"
24 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 InitiateTetherNetworkConnection(tether_network_guid, success_callback, 60 InitiateTetherNetworkConnection(tether_network_guid, success_callback,
61 error_callback); 61 error_callback);
62 } 62 }
63 }; 63 };
64 64
65 class FakeConnectTetheringOperation : public ConnectTetheringOperation { 65 class FakeConnectTetheringOperation : public ConnectTetheringOperation {
66 public: 66 public:
67 FakeConnectTetheringOperation( 67 FakeConnectTetheringOperation(
68 const cryptauth::RemoteDevice& device_to_connect, 68 const cryptauth::RemoteDevice& device_to_connect,
69 BleConnectionManager* connection_manager, 69 BleConnectionManager* connection_manager,
70 HostScanDevicePrioritizer* host_scan_device_prioritizer) 70 TetherHostResponseRecorder* tether_host_response_recorder)
71 : ConnectTetheringOperation(device_to_connect, 71 : ConnectTetheringOperation(device_to_connect,
72 connection_manager, 72 connection_manager,
73 host_scan_device_prioritizer) {} 73 tether_host_response_recorder) {}
74 74
75 ~FakeConnectTetheringOperation() override {} 75 ~FakeConnectTetheringOperation() override {}
76 76
77 void SendSuccessfulResponse(const std::string& ssid, 77 void SendSuccessfulResponse(const std::string& ssid,
78 const std::string& password) { 78 const std::string& password) {
79 NotifyObserversOfSuccessfulResponse(ssid, password); 79 NotifyObserversOfSuccessfulResponse(ssid, password);
80 } 80 }
81 81
82 void SendFailedResponse(ConnectTetheringResponse_ResponseCode error_code) { 82 void SendFailedResponse(ConnectTetheringResponse_ResponseCode error_code) {
83 NotifyObserversOfConnectionFailure(error_code); 83 NotifyObserversOfConnectionFailure(error_code);
(...skipping 13 matching lines...) Expand all
97 97
98 std::vector<FakeConnectTetheringOperation*>& created_operations() { 98 std::vector<FakeConnectTetheringOperation*>& created_operations() {
99 return created_operations_; 99 return created_operations_;
100 } 100 }
101 101
102 protected: 102 protected:
103 // ConnectTetheringOperation::Factory: 103 // ConnectTetheringOperation::Factory:
104 std::unique_ptr<ConnectTetheringOperation> BuildInstance( 104 std::unique_ptr<ConnectTetheringOperation> BuildInstance(
105 const cryptauth::RemoteDevice& device_to_connect, 105 const cryptauth::RemoteDevice& device_to_connect,
106 BleConnectionManager* connection_manager, 106 BleConnectionManager* connection_manager,
107 HostScanDevicePrioritizer* host_scan_device_prioritizer) override { 107 TetherHostResponseRecorder* tether_host_response_recorder) override {
108 FakeConnectTetheringOperation* operation = 108 FakeConnectTetheringOperation* operation =
109 new FakeConnectTetheringOperation(device_to_connect, connection_manager, 109 new FakeConnectTetheringOperation(device_to_connect, connection_manager,
110 host_scan_device_prioritizer); 110 tether_host_response_recorder);
111 created_operations_.push_back(operation); 111 created_operations_.push_back(operation);
112 return base::WrapUnique(operation); 112 return base::WrapUnique(operation);
113 } 113 }
114 114
115 private: 115 private:
116 std::vector<FakeConnectTetheringOperation*> created_operations_; 116 std::vector<FakeConnectTetheringOperation*> created_operations_;
117 }; 117 };
118 118
119 } // namespace 119 } // namespace
120 120
(...skipping 15 matching lines...) Expand all
136 fake_operation_factory_.get()); 136 fake_operation_factory_.get());
137 137
138 test_network_connection_handler_ = 138 test_network_connection_handler_ =
139 base::WrapUnique(new TestNetworkConnectionHandler()); 139 base::WrapUnique(new TestNetworkConnectionHandler());
140 fake_wifi_hotspot_connector_ = 140 fake_wifi_hotspot_connector_ =
141 base::MakeUnique<FakeWifiHotspotConnector>(network_state_handler()); 141 base::MakeUnique<FakeWifiHotspotConnector>(network_state_handler());
142 fake_active_host_ = base::MakeUnique<FakeActiveHost>(); 142 fake_active_host_ = base::MakeUnique<FakeActiveHost>();
143 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>( 143 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>(
144 test_devices_, false /* synchronously_reply_with_results */); 144 test_devices_, false /* synchronously_reply_with_results */);
145 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); 145 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>();
146 mock_host_scan_device_prioritizer_ = 146 mock_tether_host_response_recorder_ =
147 base::MakeUnique<MockHostScanDevicePrioritizer>(); 147 base::MakeUnique<MockTetherHostResponseRecorder>();
148 device_id_tether_network_guid_map_ = 148 device_id_tether_network_guid_map_ =
149 base::MakeUnique<DeviceIdTetherNetworkGuidMap>(); 149 base::MakeUnique<DeviceIdTetherNetworkGuidMap>();
150 150
151 result_.clear(); 151 result_.clear();
152 152
153 tether_connector_ = base::WrapUnique(new TetherConnector( 153 tether_connector_ = base::WrapUnique(new TetherConnector(
154 test_network_connection_handler_.get(), network_state_handler(), 154 test_network_connection_handler_.get(), network_state_handler(),
155 fake_wifi_hotspot_connector_.get(), fake_active_host_.get(), 155 fake_wifi_hotspot_connector_.get(), fake_active_host_.get(),
156 fake_tether_host_fetcher_.get(), fake_ble_connection_manager_.get(), 156 fake_tether_host_fetcher_.get(), fake_ble_connection_manager_.get(),
157 mock_host_scan_device_prioritizer_.get(), 157 mock_tether_host_response_recorder_.get(),
158 device_id_tether_network_guid_map_.get())); 158 device_id_tether_network_guid_map_.get()));
159 159
160 SetUpTetherNetworks(); 160 SetUpTetherNetworks();
161 } 161 }
162 162
163 void TearDown() override { 163 void TearDown() override {
164 // Must delete |fake_wifi_hotspot_connector_| before NetworkStateHandler is 164 // Must delete |fake_wifi_hotspot_connector_| before NetworkStateHandler is
165 // destroyed to ensure that NetworkStateHandler has zero observers by the 165 // destroyed to ensure that NetworkStateHandler has zero observers by the
166 // time it reaches its destructor. 166 // time it reaches its destructor.
167 fake_wifi_hotspot_connector_.reset(); 167 fake_wifi_hotspot_connector_.reset();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 const std::vector<cryptauth::RemoteDevice> test_devices_; 233 const std::vector<cryptauth::RemoteDevice> test_devices_;
234 const base::MessageLoop message_loop_; 234 const base::MessageLoop message_loop_;
235 235
236 std::unique_ptr<FakeConnectTetheringOperationFactory> fake_operation_factory_; 236 std::unique_ptr<FakeConnectTetheringOperationFactory> fake_operation_factory_;
237 std::unique_ptr<TestNetworkConnectionHandler> 237 std::unique_ptr<TestNetworkConnectionHandler>
238 test_network_connection_handler_; 238 test_network_connection_handler_;
239 std::unique_ptr<FakeWifiHotspotConnector> fake_wifi_hotspot_connector_; 239 std::unique_ptr<FakeWifiHotspotConnector> fake_wifi_hotspot_connector_;
240 std::unique_ptr<FakeActiveHost> fake_active_host_; 240 std::unique_ptr<FakeActiveHost> fake_active_host_;
241 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; 241 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_;
242 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; 242 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_;
243 std::unique_ptr<MockHostScanDevicePrioritizer> 243 std::unique_ptr<MockTetherHostResponseRecorder>
244 mock_host_scan_device_prioritizer_; 244 mock_tether_host_response_recorder_;
245 // TODO(hansberry): Use a fake for this when a real mapping scheme is created. 245 // TODO(hansberry): Use a fake for this when a real mapping scheme is created.
246 std::unique_ptr<DeviceIdTetherNetworkGuidMap> 246 std::unique_ptr<DeviceIdTetherNetworkGuidMap>
247 device_id_tether_network_guid_map_; 247 device_id_tether_network_guid_map_;
248 248
249 std::string result_; 249 std::string result_;
250 250
251 std::unique_ptr<TetherConnector> tether_connector_; 251 std::unique_ptr<TetherConnector> tether_connector_;
252 252
253 private: 253 private:
254 DISALLOW_COPY_AND_ASSIGN(TetherConnectorTest); 254 DISALLOW_COPY_AND_ASSIGN(TetherConnectorTest);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 EXPECT_EQ(test_devices_[1].GetDeviceId(), 476 EXPECT_EQ(test_devices_[1].GetDeviceId(),
477 fake_active_host_->GetActiveHostDeviceId()); 477 fake_active_host_->GetActiveHostDeviceId());
478 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()), 478 EXPECT_EQ(GetTetherNetworkGuid(test_devices_[1].GetDeviceId()),
479 fake_active_host_->GetTetherNetworkGuid()); 479 fake_active_host_->GetTetherNetworkGuid());
480 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty()); 480 EXPECT_TRUE(fake_active_host_->GetWifiNetworkGuid().empty());
481 } 481 }
482 482
483 } // namespace tether 483 } // namespace tether
484 484
485 } // namespace chromeos 485 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/components/tether/tether_connector.cc ('k') | chromeos/components/tether/tether_host_response_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698