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

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

Issue 2819383002: [CrOS Tether] Update NetworkState to include tether properties and integrate into NetworkStateHandl… (Closed)
Patch Set: Fix comments, add style change, change a LOG to a DCHECK. Created 3 years, 8 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/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/device_id_tether_network_guid_map.h"
14 #include "chromeos/components/tether/fake_ble_connection_manager.h" 15 #include "chromeos/components/tether/fake_ble_connection_manager.h"
15 #include "chromeos/components/tether/fake_notification_presenter.h" 16 #include "chromeos/components/tether/fake_notification_presenter.h"
16 #include "chromeos/components/tether/fake_tether_host_fetcher.h" 17 #include "chromeos/components/tether/fake_tether_host_fetcher.h"
17 #include "chromeos/components/tether/host_scan_device_prioritizer.h" 18 #include "chromeos/components/tether/host_scan_device_prioritizer.h"
18 #include "chromeos/components/tether/host_scanner.h" 19 #include "chromeos/components/tether/host_scanner.h"
19 #include "chromeos/dbus/dbus_thread_manager.h" 20 #include "chromeos/dbus/dbus_thread_manager.h"
20 #include "chromeos/network/network_state.h" 21 #include "chromeos/network/network_state.h"
21 #include "chromeos/network/network_state_handler.h" 22 #include "chromeos/network/network_state_handler.h"
22 #include "chromeos/network/network_state_test.h" 23 #include "chromeos/network/network_state_test.h"
23 #include "components/cryptauth/remote_device_test_util.h" 24 #include "components/cryptauth/remote_device_test_util.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 DBusThreadManager::Initialize(); 139 DBusThreadManager::Initialize();
139 NetworkStateTest::SetUp(); 140 NetworkStateTest::SetUp();
140 141
141 scanned_device_infos_so_far_.clear(); 142 scanned_device_infos_so_far_.clear();
142 143
143 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>( 144 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>(
144 test_devices_, false /* synchronously_reply_with_results */); 145 test_devices_, false /* synchronously_reply_with_results */);
145 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); 146 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>();
146 fake_host_scan_device_prioritizer_ = 147 fake_host_scan_device_prioritizer_ =
147 base::MakeUnique<FakeHostScanDevicePrioritizer>(); 148 base::MakeUnique<FakeHostScanDevicePrioritizer>();
149 fake_notification_presenter_ =
150 base::MakeUnique<FakeNotificationPresenter>();
151 device_id_tether_network_guid_map_ =
152 base::MakeUnique<DeviceIdTetherNetworkGuidMap>();
148 153
149 fake_host_scanner_operation_factory_ = 154 fake_host_scanner_operation_factory_ =
150 base::WrapUnique(new FakeHostScannerOperationFactory(test_devices_)); 155 base::WrapUnique(new FakeHostScannerOperationFactory(test_devices_));
151 HostScannerOperation::Factory::SetInstanceForTesting( 156 HostScannerOperation::Factory::SetInstanceForTesting(
152 fake_host_scanner_operation_factory_.get()); 157 fake_host_scanner_operation_factory_.get());
153 158
154 fake_notification_presenter_ =
155 base::MakeUnique<FakeNotificationPresenter>();
156
157 host_scanner_ = base::WrapUnique(new HostScanner( 159 host_scanner_ = base::WrapUnique(new HostScanner(
158 fake_tether_host_fetcher_.get(), fake_ble_connection_manager_.get(), 160 fake_tether_host_fetcher_.get(), fake_ble_connection_manager_.get(),
159 fake_host_scan_device_prioritizer_.get(), network_state_handler(), 161 fake_host_scan_device_prioritizer_.get(), network_state_handler(),
160 fake_notification_presenter_.get())); 162 fake_notification_presenter_.get(),
163 device_id_tether_network_guid_map_.get()));
161 } 164 }
162 165
163 void TearDown() override { 166 void TearDown() override {
164 ShutdownNetworkState(); 167 ShutdownNetworkState();
165 NetworkStateTest::TearDown(); 168 NetworkStateTest::TearDown();
166 DBusThreadManager::Shutdown(); 169 DBusThreadManager::Shutdown();
167 170
168 HostScannerOperation::Factory::SetInstanceForTesting(nullptr); 171 HostScannerOperation::Factory::SetInstanceForTesting(nullptr);
169 } 172 }
170 173
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 211
209 base::test::ScopedTaskEnvironment scoped_task_environment_; 212 base::test::ScopedTaskEnvironment scoped_task_environment_;
210 213
211 const std::vector<cryptauth::RemoteDevice> test_devices_; 214 const std::vector<cryptauth::RemoteDevice> test_devices_;
212 const std::vector<HostScannerOperation::ScannedDeviceInfo> 215 const std::vector<HostScannerOperation::ScannedDeviceInfo>
213 test_scanned_device_infos; 216 test_scanned_device_infos;
214 217
215 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; 218 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_;
216 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; 219 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_;
217 std::unique_ptr<HostScanDevicePrioritizer> fake_host_scan_device_prioritizer_; 220 std::unique_ptr<HostScanDevicePrioritizer> fake_host_scan_device_prioritizer_;
221 std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_;
222 // TODO(hansberry): Use a fake for this when a real mapping scheme is created.
223 std::unique_ptr<DeviceIdTetherNetworkGuidMap>
224 device_id_tether_network_guid_map_;
218 225
219 std::unique_ptr<FakeHostScannerOperationFactory> 226 std::unique_ptr<FakeHostScannerOperationFactory>
220 fake_host_scanner_operation_factory_; 227 fake_host_scanner_operation_factory_;
221 228
222 std::vector<HostScannerOperation::ScannedDeviceInfo> 229 std::vector<HostScannerOperation::ScannedDeviceInfo>
223 scanned_device_infos_so_far_; 230 scanned_device_infos_so_far_;
224 231
225 std::unique_ptr<HostScanner> host_scanner_; 232 std::unique_ptr<HostScanner> host_scanner_;
226 233
227 std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_;
228
229 private: 234 private:
230 DISALLOW_COPY_AND_ASSIGN(HostScannerTest); 235 DISALLOW_COPY_AND_ASSIGN(HostScannerTest);
231 }; 236 };
232 237
233 TEST_F(HostScannerTest, TestScan_ResultsFromAllDevices) { 238 TEST_F(HostScannerTest, TestScan_ResultsFromAllDevices) {
234 EXPECT_FALSE(host_scanner_->IsScanActive()); 239 EXPECT_FALSE(host_scanner_->IsScanActive());
235 host_scanner_->StartScan(); 240 host_scanner_->StartScan();
236 EXPECT_TRUE(host_scanner_->IsScanActive()); 241 EXPECT_TRUE(host_scanner_->IsScanActive());
237 242
238 fake_tether_host_fetcher_->InvokePendingCallbacks(); 243 fake_tether_host_fetcher_->InvokePendingCallbacks();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 ->SendScannedDeviceListUpdate(scanned_device_infos_so_far_, 357 ->SendScannedDeviceListUpdate(scanned_device_infos_so_far_,
353 true /* is_final_scan_result */); 358 true /* is_final_scan_result */);
354 EXPECT_EQ(scanned_device_infos_so_far_, 359 EXPECT_EQ(scanned_device_infos_so_far_,
355 host_scanner_->most_recent_scan_results()); 360 host_scanner_->most_recent_scan_results());
356 EXPECT_FALSE(host_scanner_->IsScanActive()); 361 EXPECT_FALSE(host_scanner_->IsScanActive());
357 } 362 }
358 363
359 } // namespace tether 364 } // namespace tether
360 365
361 } // namespace chromeos 366 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698