OLD | NEW |
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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 namespace { | 27 namespace { |
28 | 28 |
29 const char kTestSsid[] = "testSsid"; | 29 const char kTestSsid[] = "testSsid"; |
30 const char kTestPassword[] = "testPassword"; | 30 const char kTestPassword[] = "testPassword"; |
31 | 31 |
32 class TestObserver : public ConnectTetheringOperation::Observer { | 32 class TestObserver : public ConnectTetheringOperation::Observer { |
33 public: | 33 public: |
34 TestObserver() : has_received_failure(false) {} | 34 TestObserver() : has_received_failure(false) {} |
35 | 35 |
36 void OnSuccessfulConnectTetheringResponse( | 36 void OnSuccessfulConnectTetheringResponse( |
| 37 const cryptauth::RemoteDevice& remote_device, |
37 const std::string& ssid, | 38 const std::string& ssid, |
38 const std::string& password) override { | 39 const std::string& password) override { |
| 40 this->remote_device = remote_device; |
39 this->ssid = ssid; | 41 this->ssid = ssid; |
40 this->password = password; | 42 this->password = password; |
41 } | 43 } |
42 | 44 |
43 void OnConnectTetheringFailure( | 45 void OnConnectTetheringFailure( |
| 46 const cryptauth::RemoteDevice& remote_device, |
44 ConnectTetheringResponse_ResponseCode error_code) override { | 47 ConnectTetheringResponse_ResponseCode error_code) override { |
45 has_received_failure = true; | 48 has_received_failure = true; |
| 49 this->remote_device = remote_device; |
46 this->error_code = error_code; | 50 this->error_code = error_code; |
47 } | 51 } |
48 | 52 |
| 53 cryptauth::RemoteDevice remote_device; |
49 std::string ssid; | 54 std::string ssid; |
50 std::string password; | 55 std::string password; |
51 | 56 |
52 bool has_received_failure; | 57 bool has_received_failure; |
53 ConnectTetheringResponse_ResponseCode error_code; | 58 ConnectTetheringResponse_ResponseCode error_code; |
54 }; | 59 }; |
55 | 60 |
56 std::string CreateConnectTetheringRequestString() { | 61 std::string CreateConnectTetheringRequestString() { |
57 ConnectTetheringRequest request; | 62 ConnectTetheringRequest request; |
58 return MessageWrapper(request).ToRawMessage(); | 63 return MessageWrapper(request).ToRawMessage(); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } else if (is_success_response && !use_proto_without_ssid_and_password) { | 150 } else if (is_success_response && !use_proto_without_ssid_and_password) { |
146 expected_response_code = ConnectTetheringResponse_ResponseCode:: | 151 expected_response_code = ConnectTetheringResponse_ResponseCode:: |
147 ConnectTetheringResponse_ResponseCode_SUCCESS; | 152 ConnectTetheringResponse_ResponseCode_SUCCESS; |
148 } else { | 153 } else { |
149 expected_response_code = response_code; | 154 expected_response_code = response_code; |
150 } | 155 } |
151 | 156 |
152 if (expected_response_code == | 157 if (expected_response_code == |
153 ConnectTetheringResponse_ResponseCode:: | 158 ConnectTetheringResponse_ResponseCode:: |
154 ConnectTetheringResponse_ResponseCode_SUCCESS) { | 159 ConnectTetheringResponse_ResponseCode_SUCCESS) { |
| 160 EXPECT_EQ(test_device_, test_observer_->remote_device); |
155 EXPECT_EQ(std::string(kTestSsid), test_observer_->ssid); | 161 EXPECT_EQ(std::string(kTestSsid), test_observer_->ssid); |
156 EXPECT_EQ(std::string(kTestPassword), test_observer_->password); | 162 EXPECT_EQ(std::string(kTestPassword), test_observer_->password); |
157 } else { | 163 } else { |
158 EXPECT_TRUE(test_observer_->has_received_failure); | 164 EXPECT_TRUE(test_observer_->has_received_failure); |
159 EXPECT_EQ(expected_response_code, test_observer_->error_code); | 165 EXPECT_EQ(expected_response_code, test_observer_->error_code); |
160 } | 166 } |
161 } | 167 } |
162 | 168 |
163 const std::string connect_tethering_request_string_; | 169 const std::string connect_tethering_request_string_; |
164 const cryptauth::RemoteDevice test_device_; | 170 const cryptauth::RemoteDevice test_device_; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // The maximum number of connection failures has occurred. | 248 // The maximum number of connection failures has occurred. |
243 EXPECT_TRUE(test_observer_->has_received_failure); | 249 EXPECT_TRUE(test_observer_->has_received_failure); |
244 EXPECT_EQ(ConnectTetheringResponse_ResponseCode:: | 250 EXPECT_EQ(ConnectTetheringResponse_ResponseCode:: |
245 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, | 251 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, |
246 test_observer_->error_code); | 252 test_observer_->error_code); |
247 } | 253 } |
248 | 254 |
249 } // namespace tether | 255 } // namespace tether |
250 | 256 |
251 } // namespace cryptauth | 257 } // namespace cryptauth |
OLD | NEW |