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

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

Issue 2713073002: [CrOS Tether] Create HostScanDevicePrioritizer, a class which prioritizes the order of connection a… (Closed)
Patch Set: hansberry@ comments. Created 3 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromeos/components/tether/host_scan_device_prioritizer.h"
6
7 #include "components/cryptauth/remote_device_test_util.h"
8 #include "components/prefs/testing_pref_service.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace chromeos {
12
13 namespace tether {
14
15 class HostScanDevicePrioritizerTest : public testing::Test {
16 protected:
17 HostScanDevicePrioritizerTest()
18 : test_devices_(cryptauth::GenerateTestRemoteDevices(10)) {}
19
20 void SetUp() override {
21 pref_service_ = base::MakeUnique<TestingPrefServiceSimple>();
22 HostScanDevicePrioritizer::RegisterPrefs(pref_service_->registry());
23
24 prioritizer_ =
25 base::MakeUnique<HostScanDevicePrioritizer>(pref_service_.get());
26 }
27
28 const std::vector<cryptauth::RemoteDevice> test_devices_;
29
30 std::unique_ptr<TestingPrefServiceSimple> pref_service_;
31 std::unique_ptr<HostScanDevicePrioritizer> prioritizer_;
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(HostScanDevicePrioritizerTest);
35 };
36
37 TEST_F(HostScanDevicePrioritizerTest, TestOnlyTetherAvailabilityResponses) {
38 // Receive TetherAvailabilityResponses from devices 0-4.
39 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]);
40 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]);
41 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[2]);
42 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[3]);
43 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[4]);
44
45 // Do not receive a ConnectTetheringResponse.
46
47 std::vector<cryptauth::RemoteDevice> test_vector =
48 std::vector<cryptauth::RemoteDevice>{test_devices_[6], test_devices_[5],
49 test_devices_[4], test_devices_[3],
50 test_devices_[2], test_devices_[1],
51 test_devices_[0]};
52
53 prioritizer_->PrioritizeHostScanDeviceOrder(test_vector);
54 EXPECT_EQ((std::vector<cryptauth::RemoteDevice>{
55 test_devices_[4], test_devices_[3], test_devices_[2],
56 test_devices_[1], test_devices_[0], test_devices_[6],
57 test_devices_[5]}),
58 test_vector);
59 }
60
61 TEST_F(HostScanDevicePrioritizerTest, TestBothTypesOfResponses) {
62 // Receive TetherAvailabilityResponses from devices 0-4.
63 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]);
64 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]);
65 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[2]);
66 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[3]);
67 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[4]);
68
69 // Receive ConnectTetheringResponse from device 0.
70 prioritizer_->RecordSuccessfulConnectTetheringResponse(test_devices_[0]);
71
72 std::vector<cryptauth::RemoteDevice> test_vector =
73 std::vector<cryptauth::RemoteDevice>{test_devices_[6], test_devices_[5],
74 test_devices_[4], test_devices_[3],
75 test_devices_[2], test_devices_[1],
76 test_devices_[0]};
77
78 prioritizer_->PrioritizeHostScanDeviceOrder(test_vector);
79 EXPECT_EQ((std::vector<cryptauth::RemoteDevice>{
80 test_devices_[0], test_devices_[4], test_devices_[3],
81 test_devices_[2], test_devices_[1], test_devices_[6],
82 test_devices_[5]}),
83 test_vector);
84 }
85
86 TEST_F(HostScanDevicePrioritizerTest, TestBothTypesOfResponses_DifferentOrder) {
87 // Receive different order.
88 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]);
89 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[2]);
90 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]);
91 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[4]);
92 prioritizer_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[3]);
93
94 // Receive ConnectTetheringResponse from device 1.
95 prioritizer_->RecordSuccessfulConnectTetheringResponse(test_devices_[1]);
96
97 std::vector<cryptauth::RemoteDevice> test_vector =
98 std::vector<cryptauth::RemoteDevice>{test_devices_[9], test_devices_[8],
99 test_devices_[7], test_devices_[6],
100 test_devices_[5], test_devices_[4],
101 test_devices_[3], test_devices_[2],
102 test_devices_[1], test_devices_[0]};
103
104 prioritizer_->PrioritizeHostScanDeviceOrder(test_vector);
105 EXPECT_EQ((std::vector<cryptauth::RemoteDevice>{
106 test_devices_[1], test_devices_[3], test_devices_[4],
107 test_devices_[2], test_devices_[0], test_devices_[9],
108 test_devices_[8], test_devices_[7], test_devices_[6],
109 test_devices_[5]}),
110 test_vector);
111 }
112
113 } // namespace tether
114
115 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698