| 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.h" | 5 #include "chromeos/components/tether/host_scanner.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/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/scoped_task_environment.h" | 13 #include "base/test/scoped_task_environment.h" |
| 14 #include "chromeos/components/tether/fake_ble_connection_manager.h" | 14 #include "chromeos/components/tether/fake_ble_connection_manager.h" |
| 15 #include "chromeos/components/tether/fake_notification_presenter.h" | 15 #include "chromeos/components/tether/fake_notification_presenter.h" |
| 16 #include "chromeos/components/tether/fake_tether_host_fetcher.h" | 16 #include "chromeos/components/tether/fake_tether_host_fetcher.h" |
| 17 #include "chromeos/components/tether/host_scan_device_prioritizer.h" | 17 #include "chromeos/components/tether/host_scan_device_prioritizer.h" |
| 18 #include "chromeos/components/tether/host_scanner.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chromeos/network/network_state.h" | 20 #include "chromeos/network/network_state.h" |
| 20 #include "chromeos/network/network_state_handler.h" | 21 #include "chromeos/network/network_state_handler.h" |
| 21 #include "chromeos/network/network_state_test.h" | 22 #include "chromeos/network/network_state_test.h" |
| 22 #include "components/cryptauth/remote_device_test_util.h" | 23 #include "components/cryptauth/remote_device_test_util.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 | 27 |
| 27 namespace tether { | 28 namespace tether { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 base::MakeUnique<FakeHostScanDevicePrioritizer>(); | 147 base::MakeUnique<FakeHostScanDevicePrioritizer>(); |
| 147 | 148 |
| 148 fake_host_scanner_operation_factory_ = | 149 fake_host_scanner_operation_factory_ = |
| 149 base::WrapUnique(new FakeHostScannerOperationFactory(test_devices_)); | 150 base::WrapUnique(new FakeHostScannerOperationFactory(test_devices_)); |
| 150 HostScannerOperation::Factory::SetInstanceForTesting( | 151 HostScannerOperation::Factory::SetInstanceForTesting( |
| 151 fake_host_scanner_operation_factory_.get()); | 152 fake_host_scanner_operation_factory_.get()); |
| 152 | 153 |
| 153 fake_notification_presenter_ = | 154 fake_notification_presenter_ = |
| 154 base::MakeUnique<FakeNotificationPresenter>(); | 155 base::MakeUnique<FakeNotificationPresenter>(); |
| 155 | 156 |
| 156 host_scanner_ = base::MakeUnique<HostScanner>( | 157 host_scanner_ = base::WrapUnique(new HostScanner( |
| 157 fake_tether_host_fetcher_.get(), fake_ble_connection_manager_.get(), | 158 fake_tether_host_fetcher_.get(), fake_ble_connection_manager_.get(), |
| 158 fake_host_scan_device_prioritizer_.get(), network_state_handler(), | 159 fake_host_scan_device_prioritizer_.get(), network_state_handler(), |
| 159 fake_notification_presenter_.get()); | 160 fake_notification_presenter_.get())); |
| 160 } | 161 } |
| 161 | 162 |
| 162 void TearDown() override { | 163 void TearDown() override { |
| 163 ShutdownNetworkState(); | 164 ShutdownNetworkState(); |
| 164 NetworkStateTest::TearDown(); | 165 NetworkStateTest::TearDown(); |
| 165 DBusThreadManager::Shutdown(); | 166 DBusThreadManager::Shutdown(); |
| 167 |
| 168 HostScannerOperation::Factory::SetInstanceForTesting(nullptr); |
| 166 } | 169 } |
| 167 | 170 |
| 168 // Causes |fake_operation| to receive the scan result in | 171 // Causes |fake_operation| to receive the scan result in |
| 169 // |test_scanned_device_infos| vector at the index |test_device_index| with | 172 // |test_scanned_device_infos| vector at the index |test_device_index| with |
| 170 // the "final result" value of |is_final_scan_result|. | 173 // the "final result" value of |is_final_scan_result|. |
| 171 void ReceiveScanResultAndVerifySuccess( | 174 void ReceiveScanResultAndVerifySuccess( |
| 172 FakeHostScannerOperation* fake_operation, | 175 FakeHostScannerOperation* fake_operation, |
| 173 size_t test_device_index, | 176 size_t test_device_index, |
| 174 bool is_final_scan_result) { | 177 bool is_final_scan_result) { |
| 175 scanned_device_infos_so_far_.push_back( | 178 scanned_device_infos_so_far_.push_back( |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 fake_host_scanner_operation_factory_->created_operations()[0] | 351 fake_host_scanner_operation_factory_->created_operations()[0] |
| 349 ->SendScannedDeviceListUpdate(scanned_device_infos_so_far_, | 352 ->SendScannedDeviceListUpdate(scanned_device_infos_so_far_, |
| 350 true /* is_final_scan_result */); | 353 true /* is_final_scan_result */); |
| 351 EXPECT_EQ(scanned_device_infos_so_far_, | 354 EXPECT_EQ(scanned_device_infos_so_far_, |
| 352 host_scanner_->most_recent_scan_results()); | 355 host_scanner_->most_recent_scan_results()); |
| 353 EXPECT_FALSE(host_scanner_->IsScanActive()); | 356 EXPECT_FALSE(host_scanner_->IsScanActive()); |
| 354 } | 357 } |
| 355 | 358 |
| 356 } // namespace tether | 359 } // namespace tether |
| 357 | 360 |
| 358 } // namespace cryptauth | 361 } // namespace chromeos |
| OLD | NEW |