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

Side by Side Diff: chromeos/components/tether/host_scanner_operation_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/host_scanner_operation.h" 5 #include "chromeos/components/tether/host_scanner_operation.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "chromeos/components/tether/ble_constants.h" 12 #include "chromeos/components/tether/ble_constants.h"
13 #include "chromeos/components/tether/fake_ble_connection_manager.h" 13 #include "chromeos/components/tether/fake_ble_connection_manager.h"
14 #include "chromeos/components/tether/message_wrapper.h" 14 #include "chromeos/components/tether/message_wrapper.h"
15 #include "chromeos/components/tether/mock_host_scan_device_prioritizer.h" 15 #include "chromeos/components/tether/mock_host_scan_device_prioritizer.h"
16 #include "chromeos/components/tether/mock_tether_host_response_recorder.h"
16 #include "chromeos/components/tether/proto/tether.pb.h" 17 #include "chromeos/components/tether/proto/tether.pb.h"
17 #include "components/cryptauth/remote_device_test_util.h" 18 #include "components/cryptauth/remote_device_test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using testing::_; 21 using testing::_;
21 using testing::StrictMock; 22 using testing::StrictMock;
22 23
23 namespace chromeos { 24 namespace chromeos {
24 25
25 namespace tether { 26 namespace tether {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 test_devices_(cryptauth::GenerateTestRemoteDevices(5)) { 111 test_devices_(cryptauth::GenerateTestRemoteDevices(5)) {
111 // These tests are written under the assumption that there are a maximum of 112 // These tests are written under the assumption that there are a maximum of
112 // 3 connection attempts; they need to be edited if this value changes. 113 // 3 connection attempts; they need to be edited if this value changes.
113 EXPECT_EQ(3u, MessageTransferOperation::kMaxConnectionAttemptsPerDevice); 114 EXPECT_EQ(3u, MessageTransferOperation::kMaxConnectionAttemptsPerDevice);
114 } 115 }
115 116
116 void SetUp() override { 117 void SetUp() override {
117 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); 118 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>();
118 test_host_scan_device_prioritizer_ = 119 test_host_scan_device_prioritizer_ =
119 base::MakeUnique<StrictMock<TestHostScanDevicePrioritizer>>(); 120 base::MakeUnique<StrictMock<TestHostScanDevicePrioritizer>>();
121 mock_tether_host_response_recorder_ =
122 base::MakeUnique<StrictMock<MockTetherHostResponseRecorder>>();
120 test_observer_ = base::WrapUnique(new TestObserver()); 123 test_observer_ = base::WrapUnique(new TestObserver());
121 } 124 }
122 125
123 void ConstructOperation( 126 void ConstructOperation(
124 const std::vector<cryptauth::RemoteDevice>& remote_devices) { 127 const std::vector<cryptauth::RemoteDevice>& remote_devices) {
125 operation_ = base::WrapUnique(new HostScannerOperation( 128 operation_ = base::WrapUnique(new HostScannerOperation(
126 remote_devices, fake_ble_connection_manager_.get(), 129 remote_devices, fake_ble_connection_manager_.get(),
127 test_host_scan_device_prioritizer_.get())); 130 test_host_scan_device_prioritizer_.get(),
131 mock_tether_host_response_recorder_.get()));
128 operation_->AddObserver(test_observer_.get()); 132 operation_->AddObserver(test_observer_.get());
129 133
130 // Verify that the devices have been correctly prioritized. 134 // Verify that the devices have been correctly prioritized.
131 test_host_scan_device_prioritizer_->VerifyHasBeenPrioritized( 135 test_host_scan_device_prioritizer_->VerifyHasBeenPrioritized(
132 remote_devices, operation_->remote_devices()); 136 remote_devices, operation_->remote_devices());
133 137
134 EXPECT_FALSE(test_observer_->has_received_update); 138 EXPECT_FALSE(test_observer_->has_received_update);
135 operation_->Initialize(); 139 operation_->Initialize();
136 EXPECT_TRUE(test_observer_->has_received_update); 140 EXPECT_TRUE(test_observer_->has_received_update);
137 EXPECT_TRUE(test_observer_->scanned_devices_so_far.empty()); 141 EXPECT_TRUE(test_observer_->scanned_devices_so_far.empty());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( 207 SimulateResponseReceivedAndVerifyObserverCallbackInvoked(
204 test_devices_[0], response_code, std::string(kDefaultCarrier), true); 208 test_devices_[0], response_code, std::string(kDefaultCarrier), true);
205 } 209 }
206 210
207 const std::string tether_availability_request_string_; 211 const std::string tether_availability_request_string_;
208 const std::vector<cryptauth::RemoteDevice> test_devices_; 212 const std::vector<cryptauth::RemoteDevice> test_devices_;
209 213
210 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; 214 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_;
211 std::unique_ptr<StrictMock<TestHostScanDevicePrioritizer>> 215 std::unique_ptr<StrictMock<TestHostScanDevicePrioritizer>>
212 test_host_scan_device_prioritizer_; 216 test_host_scan_device_prioritizer_;
217 std::unique_ptr<StrictMock<MockTetherHostResponseRecorder>>
218 mock_tether_host_response_recorder_;
213 std::unique_ptr<TestObserver> test_observer_; 219 std::unique_ptr<TestObserver> test_observer_;
214 std::unique_ptr<HostScannerOperation> operation_; 220 std::unique_ptr<HostScannerOperation> operation_;
215 221
216 private: 222 private:
217 DISALLOW_COPY_AND_ASSIGN(HostScannerOperationTest); 223 DISALLOW_COPY_AND_ASSIGN(HostScannerOperationTest);
218 }; 224 };
219 225
220 TEST_F(HostScannerOperationTest, TestDevicesArePrioritizedDuringConstruction) { 226 TEST_F(HostScannerOperationTest, TestDevicesArePrioritizedDuringConstruction) {
221 // Verification of device order prioritization occurs in ConstructOperation(). 227 // Verification of device order prioritization occurs in ConstructOperation().
222 ConstructOperation(test_devices_); 228 ConstructOperation(test_devices_);
223 } 229 }
224 230
225 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_UnknownError) { 231 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_UnknownError) {
226 EXPECT_CALL(*test_host_scan_device_prioritizer_, 232 EXPECT_CALL(*mock_tether_host_response_recorder_,
227 RecordSuccessfulTetherAvailabilityResponse(_)) 233 RecordSuccessfulTetherAvailabilityResponse(_))
228 .Times(0); 234 .Times(0);
229 235
230 TestOperationWithOneDevice( 236 TestOperationWithOneDevice(
231 TetherAvailabilityResponse_ResponseCode :: 237 TetherAvailabilityResponse_ResponseCode ::
232 TetherAvailabilityResponse_ResponseCode_UNKNOWN_ERROR); 238 TetherAvailabilityResponse_ResponseCode_UNKNOWN_ERROR);
233 } 239 }
234 240
235 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_TetherAvailable) { 241 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_TetherAvailable) {
236 EXPECT_CALL(*test_host_scan_device_prioritizer_, 242 EXPECT_CALL(*mock_tether_host_response_recorder_,
237 RecordSuccessfulTetherAvailabilityResponse(test_devices_[0])); 243 RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]));
238 244
239 TestOperationWithOneDevice( 245 TestOperationWithOneDevice(
240 TetherAvailabilityResponse_ResponseCode :: 246 TetherAvailabilityResponse_ResponseCode ::
241 TetherAvailabilityResponse_ResponseCode_TETHER_AVAILABLE); 247 TetherAvailabilityResponse_ResponseCode_TETHER_AVAILABLE);
242 } 248 }
243 249
244 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_SetupNeeded) { 250 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_SetupNeeded) {
245 EXPECT_CALL(*test_host_scan_device_prioritizer_, 251 EXPECT_CALL(*mock_tether_host_response_recorder_,
246 RecordSuccessfulTetherAvailabilityResponse(test_devices_[0])); 252 RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]));
247 253
248 TestOperationWithOneDevice( 254 TestOperationWithOneDevice(
249 TetherAvailabilityResponse_ResponseCode :: 255 TetherAvailabilityResponse_ResponseCode ::
250 TetherAvailabilityResponse_ResponseCode_SETUP_NEEDED); 256 TetherAvailabilityResponse_ResponseCode_SETUP_NEEDED);
251 } 257 }
252 258
253 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_NoReception) { 259 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_NoReception) {
254 EXPECT_CALL(*test_host_scan_device_prioritizer_, 260 EXPECT_CALL(*mock_tether_host_response_recorder_,
255 RecordSuccessfulTetherAvailabilityResponse(_)) 261 RecordSuccessfulTetherAvailabilityResponse(_))
256 .Times(0); 262 .Times(0);
257 263
258 TestOperationWithOneDevice( 264 TestOperationWithOneDevice(
259 TetherAvailabilityResponse_ResponseCode :: 265 TetherAvailabilityResponse_ResponseCode ::
260 TetherAvailabilityResponse_ResponseCode_NO_RECEPTION); 266 TetherAvailabilityResponse_ResponseCode_NO_RECEPTION);
261 } 267 }
262 268
263 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_NoSimCard) { 269 TEST_F(HostScannerOperationTest, TestOperation_OneDevice_NoSimCard) {
264 EXPECT_CALL(*test_host_scan_device_prioritizer_, 270 EXPECT_CALL(*mock_tether_host_response_recorder_,
265 RecordSuccessfulTetherAvailabilityResponse(_)) 271 RecordSuccessfulTetherAvailabilityResponse(_))
266 .Times(0); 272 .Times(0);
267 273
268 TestOperationWithOneDevice( 274 TestOperationWithOneDevice(
269 TetherAvailabilityResponse_ResponseCode :: 275 TetherAvailabilityResponse_ResponseCode ::
270 TetherAvailabilityResponse_ResponseCode_NO_SIM_CARD); 276 TetherAvailabilityResponse_ResponseCode_NO_SIM_CARD);
271 } 277 }
272 278
273 TEST_F(HostScannerOperationTest, 279 TEST_F(HostScannerOperationTest,
274 TestOperation_OneDevice_NotificationsDisabled) { 280 TestOperation_OneDevice_NotificationsDisabled) {
275 EXPECT_CALL(*test_host_scan_device_prioritizer_, 281 EXPECT_CALL(*mock_tether_host_response_recorder_,
276 RecordSuccessfulTetherAvailabilityResponse(_)) 282 RecordSuccessfulTetherAvailabilityResponse(_))
277 .Times(0); 283 .Times(0);
278 284
279 TestOperationWithOneDevice( 285 TestOperationWithOneDevice(
280 TetherAvailabilityResponse_ResponseCode :: 286 TetherAvailabilityResponse_ResponseCode ::
281 TetherAvailabilityResponse_ResponseCode_NOTIFICATIONS_DISABLED); 287 TetherAvailabilityResponse_ResponseCode_NOTIFICATIONS_DISABLED);
282 } 288 }
283 289
284 TEST_F(HostScannerOperationTest, TestMultipleDevices) { 290 TEST_F(HostScannerOperationTest, TestMultipleDevices) {
285 EXPECT_CALL(*test_host_scan_device_prioritizer_, 291 EXPECT_CALL(*mock_tether_host_response_recorder_,
286 RecordSuccessfulTetherAvailabilityResponse(test_devices_[0])); 292 RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]));
287 EXPECT_CALL(*test_host_scan_device_prioritizer_, 293 EXPECT_CALL(*mock_tether_host_response_recorder_,
288 RecordSuccessfulTetherAvailabilityResponse(test_devices_[1])) 294 RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]))
289 .Times(0); 295 .Times(0);
290 EXPECT_CALL(*test_host_scan_device_prioritizer_, 296 EXPECT_CALL(*mock_tether_host_response_recorder_,
291 RecordSuccessfulTetherAvailabilityResponse(test_devices_[2])); 297 RecordSuccessfulTetherAvailabilityResponse(test_devices_[2]));
292 EXPECT_CALL(*test_host_scan_device_prioritizer_, 298 EXPECT_CALL(*mock_tether_host_response_recorder_,
293 RecordSuccessfulTetherAvailabilityResponse(test_devices_[3])) 299 RecordSuccessfulTetherAvailabilityResponse(test_devices_[3]))
294 .Times(0); 300 .Times(0);
295 EXPECT_CALL(*test_host_scan_device_prioritizer_, 301 EXPECT_CALL(*mock_tether_host_response_recorder_,
296 RecordSuccessfulTetherAvailabilityResponse(test_devices_[4])) 302 RecordSuccessfulTetherAvailabilityResponse(test_devices_[4]))
297 .Times(0); 303 .Times(0);
298 304
299 ConstructOperation(test_devices_); 305 ConstructOperation(test_devices_);
300 306
301 // Simulate devices 0 and 2 authenticating successfully. Use different carrier 307 // Simulate devices 0 and 2 authenticating successfully. Use different carrier
302 // names to ensure that the DeviceStatus is being stored correctly. 308 // names to ensure that the DeviceStatus is being stored correctly.
303 SimulateDeviceAuthenticationAndVerifyMessageSent(test_devices_[0], 1u); 309 SimulateDeviceAuthenticationAndVerifyMessageSent(test_devices_[0], 1u);
304 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( 310 SimulateResponseReceivedAndVerifyObserverCallbackInvoked(
305 test_devices_[0], 311 test_devices_[0],
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 "noService", true /* expected_to_be_last_scan_result */); 368 "noService", true /* expected_to_be_last_scan_result */);
363 369
364 // The scan should be over, and still no new scan results should have come in. 370 // The scan should be over, and still no new scan results should have come in.
365 EXPECT_TRUE(test_observer_->has_final_scan_result_been_sent); 371 EXPECT_TRUE(test_observer_->has_final_scan_result_been_sent);
366 EXPECT_EQ(2u, test_observer_->scanned_devices_so_far.size()); 372 EXPECT_EQ(2u, test_observer_->scanned_devices_so_far.size());
367 } 373 }
368 374
369 } // namespace tether 375 } // namespace tether
370 376
371 } // namespace cryptauth 377 } // namespace cryptauth
OLDNEW
« no previous file with comments | « chromeos/components/tether/host_scanner_operation.cc ('k') | chromeos/components/tether/host_scanner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698