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

Unified Diff: chromeos/components/tether/tether_host_response_recorder_unittest.cc

Issue 2844973002: [CrOS Tether] Create TetherHostResponseRecorder, which records ConnectTetheringResponses and Tether… (Closed)
Patch Set: Changed "Connectable" wording to "Connected". 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/components/tether/tether_host_response_recorder.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/components/tether/tether_host_response_recorder_unittest.cc
diff --git a/chromeos/components/tether/tether_host_response_recorder_unittest.cc b/chromeos/components/tether/tether_host_response_recorder_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e2208042355ca6795126177b5c658825d4ba2996
--- /dev/null
+++ b/chromeos/components/tether/tether_host_response_recorder_unittest.cc
@@ -0,0 +1,125 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/components/tether/tether_host_response_recorder.h"
+
+#include "components/cryptauth/remote_device_test_util.h"
+#include "components/prefs/testing_pref_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+namespace tether {
+
+class TetherHostResponseRecorderTest : public testing::Test {
+ protected:
+ TetherHostResponseRecorderTest()
+ : test_devices_(cryptauth::GenerateTestRemoteDevices(10)) {}
+
+ void SetUp() override {
+ pref_service_ = base::MakeUnique<TestingPrefServiceSimple>();
+ TetherHostResponseRecorder::RegisterPrefs(pref_service_->registry());
+
+ recorder_ =
+ base::MakeUnique<TetherHostResponseRecorder>(pref_service_.get());
+ }
+
+ const std::vector<cryptauth::RemoteDevice> test_devices_;
+
+ std::unique_ptr<TestingPrefServiceSimple> pref_service_;
+ std::unique_ptr<TetherHostResponseRecorder> recorder_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TetherHostResponseRecorderTest);
+};
+
+TEST_F(TetherHostResponseRecorderTest, TestTetherAvailabilityResponses) {
+ // Receive TetherAvailabilityResponses from devices in the following order:
+ // 0, 2, 4, 6, 8, 1, 3, 5, 7, 9
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[2]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[4]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[6]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[8]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[3]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[5]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[7]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[9]);
+
+ // The order, from most recent to least recent, should be:
+ // 9, 7, 5, 3, 1, 8, 6, 4, 2, 0
+ EXPECT_EQ(
+ (std::vector<std::string>{
+ test_devices_[9].GetDeviceId(), test_devices_[7].GetDeviceId(),
+ test_devices_[5].GetDeviceId(), test_devices_[3].GetDeviceId(),
+ test_devices_[1].GetDeviceId(), test_devices_[8].GetDeviceId(),
+ test_devices_[6].GetDeviceId(), test_devices_[4].GetDeviceId(),
+ test_devices_[2].GetDeviceId(), test_devices_[0].GetDeviceId()}),
+ recorder_->GetPreviouslyAvailableHostIds());
+}
+
+TEST_F(TetherHostResponseRecorderTest, TestConnectTetheringResponses) {
+ // Receive TetherAvailabilityResponses from devices in the following order:
+ // 0, 2, 4, 6, 8, 1, 3, 5, 7, 9
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[0]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[2]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[4]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[6]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[8]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[1]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[3]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[5]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[7]);
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[9]);
+
+ // The order, from most recent to least recent, should be:
+ // 9, 7, 5, 3, 1, 8, 6, 4, 2, 0
+ EXPECT_EQ(
+ (std::vector<std::string>{
+ test_devices_[9].GetDeviceId(), test_devices_[7].GetDeviceId(),
+ test_devices_[5].GetDeviceId(), test_devices_[3].GetDeviceId(),
+ test_devices_[1].GetDeviceId(), test_devices_[8].GetDeviceId(),
+ test_devices_[6].GetDeviceId(), test_devices_[4].GetDeviceId(),
+ test_devices_[2].GetDeviceId(), test_devices_[0].GetDeviceId()}),
+ recorder_->GetPreviouslyConnectedHostIds());
+}
+
+TEST_F(TetherHostResponseRecorderTest, TestBothResponseTypes) {
+ // Receive TetherAvailabilityResponses from devices 0, 1, and 2.
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[2]);
+
+ // Receive a ConnectTetheringResponse from device 2.
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[2]);
+
+ // Receive TetherAvailabilityResponses from devices 0, 1, and 3.
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[0]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[1]);
+ recorder_->RecordSuccessfulTetherAvailabilityResponse(test_devices_[3]);
+
+ // Receive a ConnectTetheringResponse from device 0.
+ recorder_->RecordSuccessfulConnectTetheringResponse(test_devices_[0]);
+
+ // The order for TetherAvailabilityResponses, from most recent to least
+ // recent, should be:
+ // 3, 1, 0, 2
+ EXPECT_EQ(
+ (std::vector<std::string>{
+ test_devices_[3].GetDeviceId(), test_devices_[1].GetDeviceId(),
+ test_devices_[0].GetDeviceId(), test_devices_[2].GetDeviceId()}),
+ recorder_->GetPreviouslyAvailableHostIds());
+
+ // The order for ConnectTetheringResponses, from most recent to least
+ // recent, should be:
+ // 0, 2
+ EXPECT_EQ((std::vector<std::string>{test_devices_[0].GetDeviceId(),
+ test_devices_[2].GetDeviceId()}),
+ recorder_->GetPreviouslyConnectedHostIds());
+}
+
+} // namespace tether
+
+} // namespace cryptauth
« no previous file with comments | « chromeos/components/tether/tether_host_response_recorder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698