| 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/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/host_scan_device_prioritizer.h" |
| 14 #include "chromeos/components/tether/message_wrapper.h" | 15 #include "chromeos/components/tether/message_wrapper.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/mock_tether_host_response_recorder.h" |
| 17 #include "chromeos/components/tether/proto/tether.pb.h" | 17 #include "chromeos/components/tether/proto/tether.pb.h" |
| 18 #include "chromeos/components/tether/proto_test_util.h" | 18 #include "chromeos/components/tether/proto_test_util.h" |
| 19 #include "components/cryptauth/remote_device_test_util.h" | 19 #include "components/cryptauth/remote_device_test_util.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 using testing::_; | 22 using testing::_; |
| 23 using testing::StrictMock; | 23 using testing::StrictMock; |
| 24 | 24 |
| 25 namespace chromeos { | 25 namespace chromeos { |
| 26 | 26 |
| 27 namespace tether { | 27 namespace tether { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const char kDefaultCarrier[] = "Google Fi"; | 31 const char kDefaultCarrier[] = "Google Fi"; |
| 32 | 32 |
| 33 class TestHostScanDevicePrioritizer : public MockHostScanDevicePrioritizer { | 33 class TestHostScanDevicePrioritizer : public HostScanDevicePrioritizer { |
| 34 public: | 34 public: |
| 35 TestHostScanDevicePrioritizer() : MockHostScanDevicePrioritizer() {} | 35 TestHostScanDevicePrioritizer() : HostScanDevicePrioritizer() {} |
| 36 ~TestHostScanDevicePrioritizer() override {} | 36 ~TestHostScanDevicePrioritizer() override {} |
| 37 | 37 |
| 38 // Simply reverses the device order. | 38 // HostScanDevicePrioritizer: |
| 39 void SortByHostScanOrder( | 39 void SortByHostScanOrder( |
| 40 std::vector<cryptauth::RemoteDevice>* remote_devices) const override { | 40 std::vector<cryptauth::RemoteDevice>* remote_devices) const override { |
| 41 // Simply reverses the device order. |
| 41 for (size_t i = 0; i < remote_devices->size() / 2; ++i) { | 42 for (size_t i = 0; i < remote_devices->size() / 2; ++i) { |
| 42 std::iter_swap(remote_devices->begin() + i, | 43 std::iter_swap(remote_devices->begin() + i, |
| 43 remote_devices->end() - i - 1); | 44 remote_devices->end() - i - 1); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 void VerifyHasBeenPrioritized( | 48 void VerifyHasBeenPrioritized( |
| 48 const std::vector<cryptauth::RemoteDevice>& original, | 49 const std::vector<cryptauth::RemoteDevice>& original, |
| 49 const std::vector<cryptauth::RemoteDevice>& prioritized) { | 50 const std::vector<cryptauth::RemoteDevice>& prioritized) { |
| 50 std::vector<cryptauth::RemoteDevice> copy_of_original = original; | 51 std::vector<cryptauth::RemoteDevice> copy_of_original = original; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 CreateTetherAvailabilityRequestString()), | 102 CreateTetherAvailabilityRequestString()), |
| 102 test_devices_(cryptauth::GenerateTestRemoteDevices(5)) { | 103 test_devices_(cryptauth::GenerateTestRemoteDevices(5)) { |
| 103 // These tests are written under the assumption that there are a maximum of | 104 // These tests are written under the assumption that there are a maximum of |
| 104 // 3 connection attempts; they need to be edited if this value changes. | 105 // 3 connection attempts; they need to be edited if this value changes. |
| 105 EXPECT_EQ(3u, MessageTransferOperation::kMaxConnectionAttemptsPerDevice); | 106 EXPECT_EQ(3u, MessageTransferOperation::kMaxConnectionAttemptsPerDevice); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void SetUp() override { | 109 void SetUp() override { |
| 109 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); | 110 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); |
| 110 test_host_scan_device_prioritizer_ = | 111 test_host_scan_device_prioritizer_ = |
| 111 base::MakeUnique<StrictMock<TestHostScanDevicePrioritizer>>(); | 112 base::MakeUnique<TestHostScanDevicePrioritizer>(); |
| 112 mock_tether_host_response_recorder_ = | 113 mock_tether_host_response_recorder_ = |
| 113 base::MakeUnique<StrictMock<MockTetherHostResponseRecorder>>(); | 114 base::MakeUnique<StrictMock<MockTetherHostResponseRecorder>>(); |
| 114 test_observer_ = base::WrapUnique(new TestObserver()); | 115 test_observer_ = base::WrapUnique(new TestObserver()); |
| 115 } | 116 } |
| 116 | 117 |
| 117 void ConstructOperation( | 118 void ConstructOperation( |
| 118 const std::vector<cryptauth::RemoteDevice>& remote_devices) { | 119 const std::vector<cryptauth::RemoteDevice>& remote_devices) { |
| 119 operation_ = base::WrapUnique(new HostScannerOperation( | 120 operation_ = base::WrapUnique(new HostScannerOperation( |
| 120 remote_devices, fake_ble_connection_manager_.get(), | 121 remote_devices, fake_ble_connection_manager_.get(), |
| 121 test_host_scan_device_prioritizer_.get(), | 122 test_host_scan_device_prioritizer_.get(), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 ConstructOperation(std::vector<cryptauth::RemoteDevice>{test_devices_[0]}); | 197 ConstructOperation(std::vector<cryptauth::RemoteDevice>{test_devices_[0]}); |
| 197 SimulateDeviceAuthenticationAndVerifyMessageSent(test_devices_[0], 1u); | 198 SimulateDeviceAuthenticationAndVerifyMessageSent(test_devices_[0], 1u); |
| 198 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( | 199 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( |
| 199 test_devices_[0], response_code, std::string(kDefaultCarrier), true); | 200 test_devices_[0], response_code, std::string(kDefaultCarrier), true); |
| 200 } | 201 } |
| 201 | 202 |
| 202 const std::string tether_availability_request_string_; | 203 const std::string tether_availability_request_string_; |
| 203 const std::vector<cryptauth::RemoteDevice> test_devices_; | 204 const std::vector<cryptauth::RemoteDevice> test_devices_; |
| 204 | 205 |
| 205 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; | 206 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; |
| 206 std::unique_ptr<StrictMock<TestHostScanDevicePrioritizer>> | 207 std::unique_ptr<TestHostScanDevicePrioritizer> |
| 207 test_host_scan_device_prioritizer_; | 208 test_host_scan_device_prioritizer_; |
| 208 std::unique_ptr<StrictMock<MockTetherHostResponseRecorder>> | 209 std::unique_ptr<StrictMock<MockTetherHostResponseRecorder>> |
| 209 mock_tether_host_response_recorder_; | 210 mock_tether_host_response_recorder_; |
| 210 std::unique_ptr<TestObserver> test_observer_; | 211 std::unique_ptr<TestObserver> test_observer_; |
| 211 std::unique_ptr<HostScannerOperation> operation_; | 212 std::unique_ptr<HostScannerOperation> operation_; |
| 212 | 213 |
| 213 private: | 214 private: |
| 214 DISALLOW_COPY_AND_ASSIGN(HostScannerOperationTest); | 215 DISALLOW_COPY_AND_ASSIGN(HostScannerOperationTest); |
| 215 }; | 216 }; |
| 216 | 217 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 "noService", true /* expected_to_be_last_scan_result */); | 360 "noService", true /* expected_to_be_last_scan_result */); |
| 360 | 361 |
| 361 // The scan should be over, and still no new scan results should have come in. | 362 // The scan should be over, and still no new scan results should have come in. |
| 362 EXPECT_TRUE(test_observer_->has_final_scan_result_been_sent); | 363 EXPECT_TRUE(test_observer_->has_final_scan_result_been_sent); |
| 363 EXPECT_EQ(2u, test_observer_->scanned_devices_so_far.size()); | 364 EXPECT_EQ(2u, test_observer_->scanned_devices_so_far.size()); |
| 364 } | 365 } |
| 365 | 366 |
| 366 } // namespace tether | 367 } // namespace tether |
| 367 | 368 |
| 368 } // namespace chromeos | 369 } // namespace chromeos |
| OLD | NEW |