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" |
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_tether_host_response_recorder.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 "chromeos/components/tether/proto_test_util.h" |
16 #include "components/cryptauth/remote_device_test_util.h" | 17 #include "components/cryptauth/remote_device_test_util.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.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 30 matching lines...) Expand all Loading... |
56 | 57 |
57 bool has_received_failure; | 58 bool has_received_failure; |
58 ConnectTetheringResponse_ResponseCode error_code; | 59 ConnectTetheringResponse_ResponseCode error_code; |
59 }; | 60 }; |
60 | 61 |
61 std::string CreateConnectTetheringRequestString() { | 62 std::string CreateConnectTetheringRequestString() { |
62 ConnectTetheringRequest request; | 63 ConnectTetheringRequest request; |
63 return MessageWrapper(request).ToRawMessage(); | 64 return MessageWrapper(request).ToRawMessage(); |
64 } | 65 } |
65 | 66 |
66 DeviceStatus CreateFakeDeviceStatus() { | |
67 WifiStatus wifi_status; | |
68 wifi_status.set_status_code( | |
69 WifiStatus_StatusCode::WifiStatus_StatusCode_NOT_CONNECTED); | |
70 | |
71 DeviceStatus device_status; | |
72 device_status.set_battery_percentage(75); | |
73 device_status.set_cell_provider("Google Fi"); | |
74 device_status.set_connection_strength(4); | |
75 device_status.mutable_wifi_status()->CopyFrom(wifi_status); | |
76 | |
77 return device_status; | |
78 } | |
79 | |
80 std::string CreateConnectTetheringResponseString( | 67 std::string CreateConnectTetheringResponseString( |
81 ConnectTetheringResponse_ResponseCode response_code, | 68 ConnectTetheringResponse_ResponseCode response_code, |
82 bool use_proto_without_ssid_and_password) { | 69 bool use_proto_without_ssid_and_password) { |
83 ConnectTetheringResponse response; | 70 ConnectTetheringResponse response; |
84 response.set_response_code(response_code); | 71 response.set_response_code(response_code); |
85 | 72 |
86 // Only set SSID/password if |response_code| is SUCCESS. | 73 // Only set SSID/password if |response_code| is SUCCESS. |
87 if (!use_proto_without_ssid_and_password && | 74 if (!use_proto_without_ssid_and_password && |
88 response_code == ConnectTetheringResponse_ResponseCode:: | 75 response_code == ConnectTetheringResponse_ResponseCode:: |
89 ConnectTetheringResponse_ResponseCode_SUCCESS) { | 76 ConnectTetheringResponse_ResponseCode_SUCCESS) { |
90 response.set_ssid(std::string(kTestSsid)); | 77 response.set_ssid(std::string(kTestSsid)); |
91 response.set_password(std::string(kTestPassword)); | 78 response.set_password(std::string(kTestPassword)); |
92 } | 79 } |
93 | 80 |
94 response.mutable_device_status()->CopyFrom(CreateFakeDeviceStatus()); | 81 response.mutable_device_status()->CopyFrom( |
| 82 CreateDeviceStatusWithFakeFields()); |
95 | 83 |
96 return MessageWrapper(response).ToRawMessage(); | 84 return MessageWrapper(response).ToRawMessage(); |
97 } | 85 } |
98 | 86 |
99 } // namespace | 87 } // namespace |
100 | 88 |
101 class ConnectTetheringOperationTest : public testing::Test { | 89 class ConnectTetheringOperationTest : public testing::Test { |
102 protected: | 90 protected: |
103 ConnectTetheringOperationTest() | 91 ConnectTetheringOperationTest() |
104 : connect_tethering_request_string_( | 92 : connect_tethering_request_string_( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // The maximum number of connection failures has occurred. | 236 // The maximum number of connection failures has occurred. |
249 EXPECT_TRUE(test_observer_->has_received_failure); | 237 EXPECT_TRUE(test_observer_->has_received_failure); |
250 EXPECT_EQ(ConnectTetheringResponse_ResponseCode:: | 238 EXPECT_EQ(ConnectTetheringResponse_ResponseCode:: |
251 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, | 239 ConnectTetheringResponse_ResponseCode_UNKNOWN_ERROR, |
252 test_observer_->error_code); | 240 test_observer_->error_code); |
253 } | 241 } |
254 | 242 |
255 } // namespace tether | 243 } // namespace tether |
256 | 244 |
257 } // namespace cryptauth | 245 } // namespace cryptauth |
OLD | NEW |