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

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: stevenjb@ comment. 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
« no previous file with comments | « chromeos/components/tether/host_scanner.cc ('k') | chromeos/components/tether/initializer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
24 #include "chromeos/network/network_type_pattern.h"
23 #include "components/cryptauth/remote_device_test_util.h" 25 #include "components/cryptauth/remote_device_test_util.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 27
26 namespace chromeos { 28 namespace chromeos {
27 29
28 namespace tether { 30 namespace tether {
29 31
30 namespace { 32 namespace {
31 33
32 class FakeHostScanDevicePrioritizer : public HostScanDevicePrioritizer { 34 class FakeHostScanDevicePrioritizer : public HostScanDevicePrioritizer {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 DBusThreadManager::Initialize(); 140 DBusThreadManager::Initialize();
139 NetworkStateTest::SetUp(); 141 NetworkStateTest::SetUp();
140 142
141 scanned_device_infos_so_far_.clear(); 143 scanned_device_infos_so_far_.clear();
142 144
143 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>( 145 fake_tether_host_fetcher_ = base::MakeUnique<FakeTetherHostFetcher>(
144 test_devices_, false /* synchronously_reply_with_results */); 146 test_devices_, false /* synchronously_reply_with_results */);
145 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); 147 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>();
146 fake_host_scan_device_prioritizer_ = 148 fake_host_scan_device_prioritizer_ =
147 base::MakeUnique<FakeHostScanDevicePrioritizer>(); 149 base::MakeUnique<FakeHostScanDevicePrioritizer>();
150 fake_notification_presenter_ =
151 base::MakeUnique<FakeNotificationPresenter>();
152 device_id_tether_network_guid_map_ =
153 base::MakeUnique<DeviceIdTetherNetworkGuidMap>();
148 154
149 fake_host_scanner_operation_factory_ = 155 fake_host_scanner_operation_factory_ =
150 base::WrapUnique(new FakeHostScannerOperationFactory(test_devices_)); 156 base::WrapUnique(new FakeHostScannerOperationFactory(test_devices_));
151 HostScannerOperation::Factory::SetInstanceForTesting( 157 HostScannerOperation::Factory::SetInstanceForTesting(
152 fake_host_scanner_operation_factory_.get()); 158 fake_host_scanner_operation_factory_.get());
153 159
154 fake_notification_presenter_ =
155 base::MakeUnique<FakeNotificationPresenter>();
156
157 host_scanner_ = base::WrapUnique(new HostScanner( 160 host_scanner_ = base::WrapUnique(new HostScanner(
158 fake_tether_host_fetcher_.get(), fake_ble_connection_manager_.get(), 161 fake_tether_host_fetcher_.get(), fake_ble_connection_manager_.get(),
159 fake_host_scan_device_prioritizer_.get(), network_state_handler(), 162 fake_host_scan_device_prioritizer_.get(), network_state_handler(),
160 fake_notification_presenter_.get())); 163 fake_notification_presenter_.get(),
164 device_id_tether_network_guid_map_.get()));
161 } 165 }
162 166
163 void TearDown() override { 167 void TearDown() override {
164 ShutdownNetworkState(); 168 ShutdownNetworkState();
165 NetworkStateTest::TearDown(); 169 NetworkStateTest::TearDown();
166 DBusThreadManager::Shutdown(); 170 DBusThreadManager::Shutdown();
167 171
168 HostScannerOperation::Factory::SetInstanceForTesting(nullptr); 172 HostScannerOperation::Factory::SetInstanceForTesting(nullptr);
169 } 173 }
170 174
171 // Causes |fake_operation| to receive the scan result in 175 // Causes |fake_operation| to receive the scan result in
172 // |test_scanned_device_infos| vector at the index |test_device_index| with 176 // |test_scanned_device_infos| vector at the index |test_device_index| with
173 // the "final result" value of |is_final_scan_result|. 177 // the "final result" value of |is_final_scan_result|.
174 void ReceiveScanResultAndVerifySuccess( 178 void ReceiveScanResultAndVerifySuccess(
175 FakeHostScannerOperation* fake_operation, 179 FakeHostScannerOperation* fake_operation,
176 size_t test_device_index, 180 size_t test_device_index,
177 bool is_final_scan_result) { 181 bool is_final_scan_result) {
178 scanned_device_infos_so_far_.push_back( 182 scanned_device_infos_so_far_.push_back(
179 test_scanned_device_infos[test_device_index]); 183 test_scanned_device_infos[test_device_index]);
180 fake_operation->SendScannedDeviceListUpdate(scanned_device_infos_so_far_, 184 fake_operation->SendScannedDeviceListUpdate(scanned_device_infos_so_far_,
181 is_final_scan_result); 185 is_final_scan_result);
182 EXPECT_EQ(scanned_device_infos_so_far_, 186 EXPECT_EQ(scanned_device_infos_so_far_,
183 host_scanner_->most_recent_scan_results()); 187 host_scanner_->most_recent_scan_results());
184 188
185 NetworkStateHandler::NetworkStateList tether_networks; 189 NetworkStateHandler::NetworkStateList tether_networks;
186 network_state_handler()->GetTetherNetworkList(0 /* no limit */, 190 network_state_handler()->GetVisibleNetworkListByType(
187 &tether_networks); 191 NetworkTypePattern::Tether(), &tether_networks);
188 EXPECT_EQ(scanned_device_infos_so_far_.size(), tether_networks.size()); 192 EXPECT_EQ(scanned_device_infos_so_far_.size(), tether_networks.size());
189 for (auto& scanned_device_info : scanned_device_infos_so_far_) { 193 for (auto& scanned_device_info : scanned_device_infos_so_far_) {
190 cryptauth::RemoteDevice remote_device = scanned_device_info.remote_device; 194 cryptauth::RemoteDevice remote_device = scanned_device_info.remote_device;
191 const NetworkState* tether_network = 195 const NetworkState* tether_network =
192 network_state_handler()->GetNetworkStateFromGuid( 196 network_state_handler()->GetNetworkStateFromGuid(
193 remote_device.GetDeviceId()); 197 remote_device.GetDeviceId());
194 ASSERT_TRUE(tether_network); 198 ASSERT_TRUE(tether_network);
195 EXPECT_EQ(remote_device.name, tether_network->name()); 199 EXPECT_EQ(remote_device.name, tether_network->name());
196 } 200 }
197 201
(...skipping 10 matching lines...) Expand all
208 212
209 base::test::ScopedTaskEnvironment scoped_task_environment_; 213 base::test::ScopedTaskEnvironment scoped_task_environment_;
210 214
211 const std::vector<cryptauth::RemoteDevice> test_devices_; 215 const std::vector<cryptauth::RemoteDevice> test_devices_;
212 const std::vector<HostScannerOperation::ScannedDeviceInfo> 216 const std::vector<HostScannerOperation::ScannedDeviceInfo>
213 test_scanned_device_infos; 217 test_scanned_device_infos;
214 218
215 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_; 219 std::unique_ptr<FakeTetherHostFetcher> fake_tether_host_fetcher_;
216 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; 220 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_;
217 std::unique_ptr<HostScanDevicePrioritizer> fake_host_scan_device_prioritizer_; 221 std::unique_ptr<HostScanDevicePrioritizer> fake_host_scan_device_prioritizer_;
222 std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_;
223 // TODO(hansberry): Use a fake for this when a real mapping scheme is created.
224 std::unique_ptr<DeviceIdTetherNetworkGuidMap>
225 device_id_tether_network_guid_map_;
218 226
219 std::unique_ptr<FakeHostScannerOperationFactory> 227 std::unique_ptr<FakeHostScannerOperationFactory>
220 fake_host_scanner_operation_factory_; 228 fake_host_scanner_operation_factory_;
221 229
222 std::vector<HostScannerOperation::ScannedDeviceInfo> 230 std::vector<HostScannerOperation::ScannedDeviceInfo>
223 scanned_device_infos_so_far_; 231 scanned_device_infos_so_far_;
224 232
225 std::unique_ptr<HostScanner> host_scanner_; 233 std::unique_ptr<HostScanner> host_scanner_;
226 234
227 std::unique_ptr<FakeNotificationPresenter> fake_notification_presenter_;
228
229 private: 235 private:
230 DISALLOW_COPY_AND_ASSIGN(HostScannerTest); 236 DISALLOW_COPY_AND_ASSIGN(HostScannerTest);
231 }; 237 };
232 238
233 TEST_F(HostScannerTest, TestScan_ResultsFromAllDevices) { 239 TEST_F(HostScannerTest, TestScan_ResultsFromAllDevices) {
234 EXPECT_FALSE(host_scanner_->IsScanActive()); 240 EXPECT_FALSE(host_scanner_->IsScanActive());
235 host_scanner_->StartScan(); 241 host_scanner_->StartScan();
236 EXPECT_TRUE(host_scanner_->IsScanActive()); 242 EXPECT_TRUE(host_scanner_->IsScanActive());
237 243
238 fake_tether_host_fetcher_->InvokePendingCallbacks(); 244 fake_tether_host_fetcher_->InvokePendingCallbacks();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 ->SendScannedDeviceListUpdate(scanned_device_infos_so_far_, 358 ->SendScannedDeviceListUpdate(scanned_device_infos_so_far_,
353 true /* is_final_scan_result */); 359 true /* is_final_scan_result */);
354 EXPECT_EQ(scanned_device_infos_so_far_, 360 EXPECT_EQ(scanned_device_infos_so_far_,
355 host_scanner_->most_recent_scan_results()); 361 host_scanner_->most_recent_scan_results());
356 EXPECT_FALSE(host_scanner_->IsScanActive()); 362 EXPECT_FALSE(host_scanner_->IsScanActive());
357 } 363 }
358 364
359 } // namespace tether 365 } // namespace tether
360 366
361 } // namespace chromeos 367 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/components/tether/host_scanner.cc ('k') | chromeos/components/tether/initializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698