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

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

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

Powered by Google App Engine
This is Rietveld 408576698