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

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

Issue 2844973002: [CrOS Tether] Create TetherHostResponseRecorder, which records ConnectTetheringResponses and Tether… (Closed)
Patch Set: Removed file that didn't belong in this CL, alphabetized forward declarations. 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/connect_tethering_operation.h" 5 #include "chromeos/components/tether/connect_tethering_operation.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chromeos/components/tether/ble_constants.h" 11 #include "chromeos/components/tether/ble_constants.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/message_wrapper.h" 13 #include "chromeos/components/tether/message_wrapper.h"
14 #include "chromeos/components/tether/mock_host_scan_device_prioritizer.h" 14 #include "chromeos/components/tether/mock_tether_host_response_recorder.h"
15 #include "chromeos/components/tether/proto/tether.pb.h" 15 #include "chromeos/components/tether/proto/tether.pb.h"
16 #include "components/cryptauth/remote_device_test_util.h" 16 #include "components/cryptauth/remote_device_test_util.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using testing::_; 20 using testing::_;
21 using testing::StrictMock; 21 using testing::StrictMock;
22 22
23 namespace chromeos { 23 namespace chromeos {
24 24
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 : connect_tethering_request_string_( 104 : connect_tethering_request_string_(
105 CreateConnectTetheringRequestString()), 105 CreateConnectTetheringRequestString()),
106 test_device_(cryptauth::GenerateTestRemoteDevices(1)[0]) { 106 test_device_(cryptauth::GenerateTestRemoteDevices(1)[0]) {
107 // These tests are written under the assumption that there are a maximum of 107 // These tests are written under the assumption that there are a maximum of
108 // 3 connection attempts; they need to be edited if this value changes. 108 // 3 connection attempts; they need to be edited if this value changes.
109 EXPECT_EQ(3u, MessageTransferOperation::kMaxConnectionAttemptsPerDevice); 109 EXPECT_EQ(3u, MessageTransferOperation::kMaxConnectionAttemptsPerDevice);
110 } 110 }
111 111
112 void SetUp() override { 112 void SetUp() override {
113 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); 113 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>();
114 mock_host_scan_device_prioritizer_ = 114 mock_tether_host_response_recorder_ =
115 base::MakeUnique<StrictMock<MockHostScanDevicePrioritizer>>(); 115 base::MakeUnique<StrictMock<MockTetherHostResponseRecorder>>();
116 test_observer_ = base::WrapUnique(new TestObserver()); 116 test_observer_ = base::WrapUnique(new TestObserver());
117 117
118 operation_ = base::WrapUnique(new ConnectTetheringOperation( 118 operation_ = base::WrapUnique(new ConnectTetheringOperation(
119 test_device_, fake_ble_connection_manager_.get(), 119 test_device_, fake_ble_connection_manager_.get(),
120 mock_host_scan_device_prioritizer_.get())); 120 mock_tether_host_response_recorder_.get()));
121 operation_->AddObserver(test_observer_.get()); 121 operation_->AddObserver(test_observer_.get());
122 operation_->Initialize(); 122 operation_->Initialize();
123 } 123 }
124 124
125 void SimulateDeviceAuthenticationAndVerifyMessageSent() { 125 void SimulateDeviceAuthenticationAndVerifyMessageSent() {
126 operation_->OnDeviceAuthenticated(test_device_); 126 operation_->OnDeviceAuthenticated(test_device_);
127 127
128 // Verify that the message was sent successfully. 128 // Verify that the message was sent successfully.
129 std::vector<FakeBleConnectionManager::SentMessage>& sent_messages = 129 std::vector<FakeBleConnectionManager::SentMessage>& sent_messages =
130 fake_ble_connection_manager_->sent_messages(); 130 fake_ble_connection_manager_->sent_messages();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } else { 163 } else {
164 EXPECT_TRUE(test_observer_->has_received_failure); 164 EXPECT_TRUE(test_observer_->has_received_failure);
165 EXPECT_EQ(expected_response_code, test_observer_->error_code); 165 EXPECT_EQ(expected_response_code, test_observer_->error_code);
166 } 166 }
167 } 167 }
168 168
169 const std::string connect_tethering_request_string_; 169 const std::string connect_tethering_request_string_;
170 const cryptauth::RemoteDevice test_device_; 170 const cryptauth::RemoteDevice test_device_;
171 171
172 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; 172 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_;
173 std::unique_ptr<StrictMock<MockHostScanDevicePrioritizer>> 173 std::unique_ptr<StrictMock<MockTetherHostResponseRecorder>>
174 mock_host_scan_device_prioritizer_; 174 mock_tether_host_response_recorder_;
175 std::unique_ptr<TestObserver> test_observer_; 175 std::unique_ptr<TestObserver> test_observer_;
176 std::unique_ptr<ConnectTetheringOperation> operation_; 176 std::unique_ptr<ConnectTetheringOperation> operation_;
177 177
178 private: 178 private:
179 DISALLOW_COPY_AND_ASSIGN(ConnectTetheringOperationTest); 179 DISALLOW_COPY_AND_ASSIGN(ConnectTetheringOperationTest);
180 }; 180 };
181 181
182 TEST_F(ConnectTetheringOperationTest, TestOperation_SuccessButInvalidResponse) { 182 TEST_F(ConnectTetheringOperationTest, TestOperation_SuccessButInvalidResponse) {
183 EXPECT_CALL(*mock_host_scan_device_prioritizer_, 183 EXPECT_CALL(*mock_tether_host_response_recorder_,
184 RecordSuccessfulConnectTetheringResponse(_)) 184 RecordSuccessfulConnectTetheringResponse(_))
185 .Times(0); 185 .Times(0);
186 186
187 SimulateDeviceAuthenticationAndVerifyMessageSent(); 187 SimulateDeviceAuthenticationAndVerifyMessageSent();
188 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( 188 SimulateResponseReceivedAndVerifyObserverCallbackInvoked(
189 ConnectTetheringResponse_ResponseCode:: 189 ConnectTetheringResponse_ResponseCode::
190 ConnectTetheringResponse_ResponseCode_SUCCESS, 190 ConnectTetheringResponse_ResponseCode_SUCCESS,
191 true /* use_proto_without_ssid_and_password */); 191 true /* use_proto_without_ssid_and_password */);
192 } 192 }
193 193
194 TEST_F(ConnectTetheringOperationTest, TestOperation_SuccessWithValidResponse) { 194 TEST_F(ConnectTetheringOperationTest, TestOperation_SuccessWithValidResponse) {
195 EXPECT_CALL(*mock_host_scan_device_prioritizer_, 195 EXPECT_CALL(*mock_tether_host_response_recorder_,
196 RecordSuccessfulConnectTetheringResponse(test_device_)); 196 RecordSuccessfulConnectTetheringResponse(test_device_));
197 197
198 SimulateDeviceAuthenticationAndVerifyMessageSent(); 198 SimulateDeviceAuthenticationAndVerifyMessageSent();
199 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( 199 SimulateResponseReceivedAndVerifyObserverCallbackInvoked(
200 ConnectTetheringResponse_ResponseCode:: 200 ConnectTetheringResponse_ResponseCode::
201 ConnectTetheringResponse_ResponseCode_SUCCESS, 201 ConnectTetheringResponse_ResponseCode_SUCCESS,
202 false /* use_proto_without_ssid_and_password */); 202 false /* use_proto_without_ssid_and_password */);
203 } 203 }
204 204
205 TEST_F(ConnectTetheringOperationTest, TestOperation_UnknownError) { 205 TEST_F(ConnectTetheringOperationTest, TestOperation_UnknownError) {
206 EXPECT_CALL(*mock_host_scan_device_prioritizer_, 206 EXPECT_CALL(*mock_tether_host_response_recorder_,
207 RecordSuccessfulConnectTetheringResponse(_)) 207 RecordSuccessfulConnectTetheringResponse(_))
208 .Times(0); 208 .Times(0);
209 209
210 SimulateDeviceAuthenticationAndVerifyMessageSent(); 210 SimulateDeviceAuthenticationAndVerifyMessageSent();
211 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( 211 SimulateResponseReceivedAndVerifyObserverCallbackInvoked(
212 ConnectTetheringResponse_ResponseCode:: 212 ConnectTetheringResponse_ResponseCode::
213 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, 213 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR,
214 false /* use_proto_without_ssid_and_password */); 214 false /* use_proto_without_ssid_and_password */);
215 } 215 }
216 216
217 TEST_F(ConnectTetheringOperationTest, TestOperation_ProvisioningFailed) { 217 TEST_F(ConnectTetheringOperationTest, TestOperation_ProvisioningFailed) {
218 EXPECT_CALL(*mock_host_scan_device_prioritizer_, 218 EXPECT_CALL(*mock_tether_host_response_recorder_,
219 RecordSuccessfulConnectTetheringResponse(_)) 219 RecordSuccessfulConnectTetheringResponse(_))
220 .Times(0); 220 .Times(0);
221 221
222 SimulateDeviceAuthenticationAndVerifyMessageSent(); 222 SimulateDeviceAuthenticationAndVerifyMessageSent();
223 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( 223 SimulateResponseReceivedAndVerifyObserverCallbackInvoked(
224 ConnectTetheringResponse_ResponseCode:: 224 ConnectTetheringResponse_ResponseCode::
225 ConnectTetheringResponse_ResponseCode_PROVISIONING_FAILED, 225 ConnectTetheringResponse_ResponseCode_PROVISIONING_FAILED,
226 false /* use_proto_without_ssid_and_password */); 226 false /* use_proto_without_ssid_and_password */);
227 } 227 }
228 228
229 TEST_F(ConnectTetheringOperationTest, TestCannotConnect) { 229 TEST_F(ConnectTetheringOperationTest, TestCannotConnect) {
230 EXPECT_CALL(*mock_host_scan_device_prioritizer_, 230 EXPECT_CALL(*mock_tether_host_response_recorder_,
231 RecordSuccessfulConnectTetheringResponse(_)) 231 RecordSuccessfulConnectTetheringResponse(_))
232 .Times(0); 232 .Times(0);
233 233
234 // Simulate the device failing to connect. 234 // Simulate the device failing to connect.
235 fake_ble_connection_manager_->SetDeviceStatus( 235 fake_ble_connection_manager_->SetDeviceStatus(
236 test_device_, cryptauth::SecureChannel::Status::CONNECTING); 236 test_device_, cryptauth::SecureChannel::Status::CONNECTING);
237 fake_ble_connection_manager_->SetDeviceStatus( 237 fake_ble_connection_manager_->SetDeviceStatus(
238 test_device_, cryptauth::SecureChannel::Status::DISCONNECTED); 238 test_device_, cryptauth::SecureChannel::Status::DISCONNECTED);
239 fake_ble_connection_manager_->SetDeviceStatus( 239 fake_ble_connection_manager_->SetDeviceStatus(
240 test_device_, cryptauth::SecureChannel::Status::CONNECTING); 240 test_device_, cryptauth::SecureChannel::Status::CONNECTING);
241 fake_ble_connection_manager_->SetDeviceStatus( 241 fake_ble_connection_manager_->SetDeviceStatus(
242 test_device_, cryptauth::SecureChannel::Status::DISCONNECTED); 242 test_device_, cryptauth::SecureChannel::Status::DISCONNECTED);
243 fake_ble_connection_manager_->SetDeviceStatus( 243 fake_ble_connection_manager_->SetDeviceStatus(
244 test_device_, cryptauth::SecureChannel::Status::CONNECTING); 244 test_device_, cryptauth::SecureChannel::Status::CONNECTING);
245 fake_ble_connection_manager_->SetDeviceStatus( 245 fake_ble_connection_manager_->SetDeviceStatus(
246 test_device_, cryptauth::SecureChannel::Status::DISCONNECTED); 246 test_device_, cryptauth::SecureChannel::Status::DISCONNECTED);
247 247
248 // The maximum number of connection failures has occurred. 248 // The maximum number of connection failures has occurred.
249 EXPECT_TRUE(test_observer_->has_received_failure); 249 EXPECT_TRUE(test_observer_->has_received_failure);
250 EXPECT_EQ(ConnectTetheringResponse_ResponseCode:: 250 EXPECT_EQ(ConnectTetheringResponse_ResponseCode::
251 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, 251 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR,
252 test_observer_->error_code); 252 test_observer_->error_code);
253 } 253 }
254 254
255 } // namespace tether 255 } // namespace tether
256 256
257 } // namespace cryptauth 257 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698