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

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

Issue 2945643002: [CrOS Tether] Sort Tether network lists. (Closed)
Patch Set: Cleanup - now ready for review. Created 3 years, 6 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_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 "base/test/scoped_task_environment.h"
Ryan Hansberry 2017/06/19 19:17:48 It's a shame that this and host_scanner's test nee
Kyle Horimoto 2017/06/20 23:44:54 You're right - done.
12 #include "chromeos/components/tether/ble_constants.h" 13 #include "chromeos/components/tether/ble_constants.h"
13 #include "chromeos/components/tether/fake_ble_connection_manager.h" 14 #include "chromeos/components/tether/fake_ble_connection_manager.h"
15 #include "chromeos/components/tether/host_scan_device_prioritizer.h"
14 #include "chromeos/components/tether/message_wrapper.h" 16 #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" 17 #include "chromeos/components/tether/mock_tether_host_response_recorder.h"
17 #include "chromeos/components/tether/proto/tether.pb.h" 18 #include "chromeos/components/tether/proto/tether.pb.h"
18 #include "chromeos/components/tether/proto_test_util.h" 19 #include "chromeos/components/tether/proto_test_util.h"
20 #include "chromeos/dbus/dbus_thread_manager.h"
21 #include "chromeos/network/network_state_test.h"
19 #include "components/cryptauth/remote_device_test_util.h" 22 #include "components/cryptauth/remote_device_test_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
21 24
22 using testing::_; 25 using testing::_;
23 using testing::StrictMock; 26 using testing::StrictMock;
24 27
25 namespace chromeos { 28 namespace chromeos {
26 29
27 namespace tether { 30 namespace tether {
28 31
29 namespace { 32 namespace {
30 33
31 const char kDefaultCarrier[] = "Google Fi"; 34 const char kDefaultCarrier[] = "Google Fi";
32 35
33 class TestHostScanDevicePrioritizer : public MockHostScanDevicePrioritizer { 36 class TestHostScanDevicePrioritizer : public HostScanDevicePrioritizer {
34 public: 37 public:
35 TestHostScanDevicePrioritizer() : MockHostScanDevicePrioritizer() {} 38 TestHostScanDevicePrioritizer(NetworkStateHandler* network_state_handler)
39 : HostScanDevicePrioritizer(
40 network_state_handler,
41 nullptr /* tether_host_response_recorder */,
42 nullptr /* device_id_tether_network_guid_map */) {}
36 ~TestHostScanDevicePrioritizer() override {} 43 ~TestHostScanDevicePrioritizer() override {}
37 44
38 // Simply reverses the device order. 45 // HostScanDevicePrioritizer:
39 void SortByHostScanOrder( 46 void SortByHostScanOrder(
40 std::vector<cryptauth::RemoteDevice>* remote_devices) const override { 47 std::vector<cryptauth::RemoteDevice>* remote_devices) const override {
48 // Simply reverses the device order.
41 for (size_t i = 0; i < remote_devices->size() / 2; ++i) { 49 for (size_t i = 0; i < remote_devices->size() / 2; ++i) {
42 std::iter_swap(remote_devices->begin() + i, 50 std::iter_swap(remote_devices->begin() + i,
43 remote_devices->end() - i - 1); 51 remote_devices->end() - i - 1);
44 } 52 }
45 } 53 }
46 54
47 void VerifyHasBeenPrioritized( 55 void VerifyHasBeenPrioritized(
48 const std::vector<cryptauth::RemoteDevice>& original, 56 const std::vector<cryptauth::RemoteDevice>& original,
49 const std::vector<cryptauth::RemoteDevice>& prioritized) { 57 const std::vector<cryptauth::RemoteDevice>& prioritized) {
50 std::vector<cryptauth::RemoteDevice> copy_of_original = original; 58 std::vector<cryptauth::RemoteDevice> copy_of_original = original;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 const std::string& cell_provider_name) { 95 const std::string& cell_provider_name) {
88 TetherAvailabilityResponse response; 96 TetherAvailabilityResponse response;
89 response.set_response_code(response_code); 97 response.set_response_code(response_code);
90 response.mutable_device_status()->CopyFrom( 98 response.mutable_device_status()->CopyFrom(
91 CreateFakeDeviceStatus(cell_provider_name)); 99 CreateFakeDeviceStatus(cell_provider_name));
92 return MessageWrapper(response).ToRawMessage(); 100 return MessageWrapper(response).ToRawMessage();
93 } 101 }
94 102
95 } // namespace 103 } // namespace
96 104
97 class HostScannerOperationTest : public testing::Test { 105 class HostScannerOperationTest : public NetworkStateTest {
98 protected: 106 protected:
99 HostScannerOperationTest() 107 HostScannerOperationTest()
100 : tether_availability_request_string_( 108 : tether_availability_request_string_(
101 CreateTetherAvailabilityRequestString()), 109 CreateTetherAvailabilityRequestString()),
102 test_devices_(cryptauth::GenerateTestRemoteDevices(5)) { 110 test_devices_(cryptauth::GenerateTestRemoteDevices(5)) {
103 // These tests are written under the assumption that there are a maximum of 111 // 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. 112 // 3 connection attempts; they need to be edited if this value changes.
105 EXPECT_EQ(3u, MessageTransferOperation::kMaxConnectionAttemptsPerDevice); 113 EXPECT_EQ(3u, MessageTransferOperation::kMaxConnectionAttemptsPerDevice);
106 } 114 }
107 115
108 void SetUp() override { 116 void SetUp() override {
117 DBusThreadManager::Initialize();
118 NetworkStateTest::SetUp();
119
109 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>(); 120 fake_ble_connection_manager_ = base::MakeUnique<FakeBleConnectionManager>();
110 test_host_scan_device_prioritizer_ = 121 test_host_scan_device_prioritizer_ =
111 base::MakeUnique<StrictMock<TestHostScanDevicePrioritizer>>(); 122 base::MakeUnique<TestHostScanDevicePrioritizer>(
123 network_state_handler());
112 mock_tether_host_response_recorder_ = 124 mock_tether_host_response_recorder_ =
113 base::MakeUnique<StrictMock<MockTetherHostResponseRecorder>>(); 125 base::MakeUnique<StrictMock<MockTetherHostResponseRecorder>>();
114 test_observer_ = base::WrapUnique(new TestObserver()); 126 test_observer_ = base::WrapUnique(new TestObserver());
115 } 127 }
116 128
129 void TearDown() override {
130 test_host_scan_device_prioritizer_.reset();
131 ShutdownNetworkState();
132 NetworkStateTest::TearDown();
133 DBusThreadManager::Shutdown();
134 }
135
117 void ConstructOperation( 136 void ConstructOperation(
118 const std::vector<cryptauth::RemoteDevice>& remote_devices) { 137 const std::vector<cryptauth::RemoteDevice>& remote_devices) {
119 operation_ = base::WrapUnique(new HostScannerOperation( 138 operation_ = base::WrapUnique(new HostScannerOperation(
120 remote_devices, fake_ble_connection_manager_.get(), 139 remote_devices, fake_ble_connection_manager_.get(),
121 test_host_scan_device_prioritizer_.get(), 140 test_host_scan_device_prioritizer_.get(),
122 mock_tether_host_response_recorder_.get())); 141 mock_tether_host_response_recorder_.get()));
123 operation_->AddObserver(test_observer_.get()); 142 operation_->AddObserver(test_observer_.get());
124 143
125 // Verify that the devices have been correctly prioritized. 144 // Verify that the devices have been correctly prioritized.
126 test_host_scan_device_prioritizer_->VerifyHasBeenPrioritized( 145 test_host_scan_device_prioritizer_->VerifyHasBeenPrioritized(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 211 }
193 212
194 void TestOperationWithOneDevice( 213 void TestOperationWithOneDevice(
195 TetherAvailabilityResponse_ResponseCode response_code) { 214 TetherAvailabilityResponse_ResponseCode response_code) {
196 ConstructOperation(std::vector<cryptauth::RemoteDevice>{test_devices_[0]}); 215 ConstructOperation(std::vector<cryptauth::RemoteDevice>{test_devices_[0]});
197 SimulateDeviceAuthenticationAndVerifyMessageSent(test_devices_[0], 1u); 216 SimulateDeviceAuthenticationAndVerifyMessageSent(test_devices_[0], 1u);
198 SimulateResponseReceivedAndVerifyObserverCallbackInvoked( 217 SimulateResponseReceivedAndVerifyObserverCallbackInvoked(
199 test_devices_[0], response_code, std::string(kDefaultCarrier), true); 218 test_devices_[0], response_code, std::string(kDefaultCarrier), true);
200 } 219 }
201 220
221 const base::test::ScopedTaskEnvironment scoped_task_environment_;
202 const std::string tether_availability_request_string_; 222 const std::string tether_availability_request_string_;
203 const std::vector<cryptauth::RemoteDevice> test_devices_; 223 const std::vector<cryptauth::RemoteDevice> test_devices_;
204 224
205 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_; 225 std::unique_ptr<FakeBleConnectionManager> fake_ble_connection_manager_;
206 std::unique_ptr<StrictMock<TestHostScanDevicePrioritizer>> 226 std::unique_ptr<TestHostScanDevicePrioritizer>
207 test_host_scan_device_prioritizer_; 227 test_host_scan_device_prioritizer_;
208 std::unique_ptr<StrictMock<MockTetherHostResponseRecorder>> 228 std::unique_ptr<StrictMock<MockTetherHostResponseRecorder>>
209 mock_tether_host_response_recorder_; 229 mock_tether_host_response_recorder_;
210 std::unique_ptr<TestObserver> test_observer_; 230 std::unique_ptr<TestObserver> test_observer_;
211 std::unique_ptr<HostScannerOperation> operation_; 231 std::unique_ptr<HostScannerOperation> operation_;
212 232
213 private: 233 private:
214 DISALLOW_COPY_AND_ASSIGN(HostScannerOperationTest); 234 DISALLOW_COPY_AND_ASSIGN(HostScannerOperationTest);
215 }; 235 };
216 236
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 "noService", true /* expected_to_be_last_scan_result */); 379 "noService", true /* expected_to_be_last_scan_result */);
360 380
361 // The scan should be over, and still no new scan results should have come in. 381 // 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); 382 EXPECT_TRUE(test_observer_->has_final_scan_result_been_sent);
363 EXPECT_EQ(2u, test_observer_->scanned_devices_so_far.size()); 383 EXPECT_EQ(2u, test_observer_->scanned_devices_so_far.size());
364 } 384 }
365 385
366 } // namespace tether 386 } // namespace tether
367 387
368 } // namespace chromeos 388 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698