OLD | NEW |
(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/tether_host_response_recorder.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 TetherHostResponseRecorderTest : public testing::Test { |
| 16 protected: |
| 17 TetherHostResponseRecorderTest() |
| 18 : test_devices_(cryptauth::GenerateTestRemoteDevices(10)) {} |
| 19 |
| 20 void SetUp() override { |
| 21 pref_service_ = base::MakeUnique<TestingPrefServiceSimple>(); |
| 22 TetherHostResponseRecorder::RegisterPrefs(pref_service_->registry()); |
| 23 |
| 24 recorder_ = |
| 25 base::MakeUnique<TetherHostResponseRecorder>(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<TetherHostResponseRecorder> recorder_; |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(TetherHostResponseRecorderTest); |
| 35 }; |
| 36 |
| 37 TEST_F(TetherHostResponseRecorderTest, TestTetherAvailabilityResponses) { |
| 38 // Receive TetherAvailabilityResponses from devices in the following order: |
| 39 // 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 |
| 40 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]); |
| 41 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[2]); |
| 42 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[4]); |
| 43 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[6]); |
| 44 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[8]); |
| 45 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]); |
| 46 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[3]); |
| 47 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[5]); |
| 48 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[7]); |
| 49 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[9]); |
| 50 |
| 51 // The order, from most recent to least recent, should be: |
| 52 // 9, 7, 5, 3, 1, 8, 6, 4, 2, 0 |
| 53 EXPECT_EQ( |
| 54 (std::vector<std::string>{ |
| 55 test_devices_[9].GetDeviceId(), test_devices_[7].GetDeviceId(), |
| 56 test_devices_[5].GetDeviceId(), test_devices_[3].GetDeviceId(), |
| 57 test_devices_[1].GetDeviceId(), test_devices_[8].GetDeviceId(), |
| 58 test_devices_[6].GetDeviceId(), test_devices_[4].GetDeviceId(), |
| 59 test_devices_[2].GetDeviceId(), test_devices_[0].GetDeviceId()}), |
| 60 recorder_->GetPreviouslyAvailableHostIds()); |
| 61 } |
| 62 |
| 63 TEST_F(TetherHostResponseRecorderTest, TestConnectTetheringResponses) { |
| 64 // Receive TetherAvailabilityResponses from devices in the following order: |
| 65 // 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 |
| 66 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[0]); |
| 67 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[2]); |
| 68 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[4]); |
| 69 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[6]); |
| 70 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[8]); |
| 71 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[1]); |
| 72 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[3]); |
| 73 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[5]); |
| 74 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[7]); |
| 75 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[9]); |
| 76 |
| 77 // The order, from most recent to least recent, should be: |
| 78 // 9, 7, 5, 3, 1, 8, 6, 4, 2, 0 |
| 79 EXPECT_EQ( |
| 80 (std::vector<std::string>{ |
| 81 test_devices_[9].GetDeviceId(), test_devices_[7].GetDeviceId(), |
| 82 test_devices_[5].GetDeviceId(), test_devices_[3].GetDeviceId(), |
| 83 test_devices_[1].GetDeviceId(), test_devices_[8].GetDeviceId(), |
| 84 test_devices_[6].GetDeviceId(), test_devices_[4].GetDeviceId(), |
| 85 test_devices_[2].GetDeviceId(), test_devices_[0].GetDeviceId()}), |
| 86 recorder_->GetPreviouslyConnectedHostIds()); |
| 87 } |
| 88 |
| 89 TEST_F(TetherHostResponseRecorderTest, TestBothResponseTypes) { |
| 90 // Receive TetherAvailabilityResponses from devices 0, 1, and 2. |
| 91 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]); |
| 92 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]); |
| 93 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[2]); |
| 94 |
| 95 // Receive a ConnectTetheringResponse from device 2. |
| 96 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[2]); |
| 97 |
| 98 // Receive TetherAvailabilityResponses from devices 0, 1, and 3. |
| 99 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]); |
| 100 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]); |
| 101 recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[3]); |
| 102 |
| 103 // Receive a ConnectTetheringResponse from device 0. |
| 104 recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[0]); |
| 105 |
| 106 // The order for TetherAvailabilityResponses, from most recent to least |
| 107 // recent, should be: |
| 108 // 3, 1, 0, 2 |
| 109 EXPECT_EQ( |
| 110 (std::vector<std::string>{ |
| 111 test_devices_[3].GetDeviceId(), test_devices_[1].GetDeviceId(), |
| 112 test_devices_[0].GetDeviceId(), test_devices_[2].GetDeviceId()}), |
| 113 recorder_->GetPreviouslyAvailableHostIds()); |
| 114 |
| 115 // The order for ConnectTetheringResponses, from most recent to least |
| 116 // recent, should be: |
| 117 // 0, 2 |
| 118 EXPECT_EQ((std::vector<std::string>{test_devices_[0].GetDeviceId(), |
| 119 test_devices_[2].GetDeviceId()}), |
| 120 recorder_->GetPreviouslyConnectedHostIds()); |
| 121 } |
| 122 |
| 123 } // namespace tether |
| 124 |
| 125 } // namespace cryptauth |
OLD | NEW |