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

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

Issue 2801353002: [CrOS Tether] Fill out the Initializer class. Tether will now initialize fully once the flag is ena… (Closed)
Patch Set: hansberry@ comments, DEPS change. 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 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/tether_host_fetcher.h" 5 #include "chromeos/components/tether/tether_host_fetcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 std::vector<cryptauth::ExternalDeviceInfo> device_infos; 83 std::vector<cryptauth::ExternalDeviceInfo> device_infos;
84 for (const auto& remote_device : remote_devices) { 84 for (const auto& remote_device : remote_devices) {
85 // Add an ExternalDeviceInfo with the same public key as the RemoteDevice. 85 // Add an ExternalDeviceInfo with the same public key as the RemoteDevice.
86 cryptauth::ExternalDeviceInfo info; 86 cryptauth::ExternalDeviceInfo info;
87 info.set_public_key(remote_device.public_key); 87 info.set_public_key(remote_device.public_key);
88 device_infos.push_back(info); 88 device_infos.push_back(info);
89 } 89 }
90 return device_infos; 90 return device_infos;
91 } 91 }
92 92
93 class TestTetherHostFetcher : public TetherHostFetcher {
94 public:
95 TestTetherHostFetcher(const std::string& user_id,
96 const std::string& user_private_key,
97 cryptauth::CryptAuthService* cryptauth_service,
98 cryptauth::CryptAuthDeviceManager* device_manager)
99 : TetherHostFetcher(user_id,
100 user_private_key,
101 cryptauth_service,
102 device_manager) {}
103 };
104
93 } // namespace 105 } // namespace
94 106
95 class TetherHostFetcherTest : public testing::Test { 107 class TetherHostFetcherTest : public testing::Test {
96 public: 108 public:
97 class TestRemoteDeviceLoaderFactory 109 class TestRemoteDeviceLoaderFactory
98 : public cryptauth::RemoteDeviceLoader::Factory { 110 : public cryptauth::RemoteDeviceLoader::Factory {
99 public: 111 public:
100 TestRemoteDeviceLoaderFactory(TetherHostFetcherTest* test) : test_(test) {} 112 explicit TestRemoteDeviceLoaderFactory(TetherHostFetcherTest* test)
113 : test_(test) {}
101 114
102 std::unique_ptr<cryptauth::RemoteDeviceLoader> BuildInstance( 115 std::unique_ptr<cryptauth::RemoteDeviceLoader> BuildInstance(
103 const std::vector<cryptauth::ExternalDeviceInfo>& device_info_list, 116 const std::vector<cryptauth::ExternalDeviceInfo>& device_info_list,
104 const std::string& user_id, 117 const std::string& user_id,
105 const std::string& user_private_key, 118 const std::string& user_private_key,
106 std::unique_ptr<cryptauth::SecureMessageDelegate> 119 std::unique_ptr<cryptauth::SecureMessageDelegate>
107 secure_message_delegate) override { 120 secure_message_delegate) override {
108 EXPECT_EQ(test_->test_device_infos_.size(), device_info_list.size()); 121 EXPECT_EQ(test_->test_device_infos_.size(), device_info_list.size());
109 EXPECT_EQ(std::string(kTestUserId), user_id); 122 EXPECT_EQ(std::string(kTestUserId), user_id);
110 EXPECT_EQ(std::string(kTestUserPrivateKey), user_private_key); 123 EXPECT_EQ(std::string(kTestUserPrivateKey), user_private_key);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 163
151 mock_device_manager_ = base::WrapUnique(new NiceMock<MockDeviceManager>()); 164 mock_device_manager_ = base::WrapUnique(new NiceMock<MockDeviceManager>());
152 ON_CALL(*mock_device_manager_, GetTetherHosts()) 165 ON_CALL(*mock_device_manager_, GetTetherHosts())
153 .WillByDefault(Return(test_device_infos_)); 166 .WillByDefault(Return(test_device_infos_));
154 167
155 test_device_loader_factory_ = 168 test_device_loader_factory_ =
156 base::WrapUnique(new TestRemoteDeviceLoaderFactory(this)); 169 base::WrapUnique(new TestRemoteDeviceLoaderFactory(this));
157 cryptauth::RemoteDeviceLoader::Factory::SetInstanceForTesting( 170 cryptauth::RemoteDeviceLoader::Factory::SetInstanceForTesting(
158 test_device_loader_factory_.get()); 171 test_device_loader_factory_.get());
159 172
160 tether_host_fetcher_ = base::MakeUnique<TetherHostFetcher>( 173 tether_host_fetcher_ = base::WrapUnique(new TestTetherHostFetcher(
161 std::string(kTestUserId), std::string(kTestUserPrivateKey), 174 std::string(kTestUserId), std::string(kTestUserPrivateKey),
162 fake_cryptauth_service_.get(), mock_device_manager_.get()); 175 fake_cryptauth_service_.get(), mock_device_manager_.get()));
163 } 176 }
164 177
165 void OnTetherHostListFetched(const cryptauth::RemoteDeviceList& device_list) { 178 void OnTetherHostListFetched(const cryptauth::RemoteDeviceList& device_list) {
166 device_list_list_.push_back(device_list); 179 device_list_list_.push_back(device_list);
167 } 180 }
168 181
169 void OnSingleTetherHostFetched( 182 void OnSingleTetherHostFetched(
170 std::unique_ptr<cryptauth::RemoteDevice> device) { 183 std::unique_ptr<cryptauth::RemoteDevice> device) {
171 single_device_list_.push_back(std::move(device)); 184 single_device_list_.push_back(std::move(device));
172 } 185 }
173 186
174 const std::vector<cryptauth::RemoteDevice> test_devices_; 187 const std::vector<cryptauth::RemoteDevice> test_devices_;
175 const std::vector<cryptauth::ExternalDeviceInfo> test_device_infos_; 188 const std::vector<cryptauth::ExternalDeviceInfo> test_device_infos_;
176 189
177 std::vector<cryptauth::RemoteDeviceList> device_list_list_; 190 std::vector<cryptauth::RemoteDeviceList> device_list_list_;
178 std::vector<std::shared_ptr<cryptauth::RemoteDevice>> single_device_list_; 191 std::vector<std::shared_ptr<cryptauth::RemoteDevice>> single_device_list_;
179 192
180 std::unique_ptr<FakeCryptAuthServiceWithTracking> fake_cryptauth_service_; 193 std::unique_ptr<FakeCryptAuthServiceWithTracking> fake_cryptauth_service_;
181 std::unique_ptr<NiceMock<MockDeviceManager>> mock_device_manager_; 194 std::unique_ptr<NiceMock<MockDeviceManager>> mock_device_manager_;
182 std::unique_ptr<TestRemoteDeviceLoaderFactory> test_device_loader_factory_; 195 std::unique_ptr<TestRemoteDeviceLoaderFactory> test_device_loader_factory_;
183 196
184 std::unique_ptr<TetherHostFetcher> tether_host_fetcher_; 197 std::unique_ptr<TestTetherHostFetcher> tether_host_fetcher_;
185 198
186 private: 199 private:
187 DISALLOW_COPY_AND_ASSIGN(TetherHostFetcherTest); 200 DISALLOW_COPY_AND_ASSIGN(TetherHostFetcherTest);
188 }; 201 };
189 202
190 TEST_F(TetherHostFetcherTest, TestFetchAllTetherHosts) { 203 TEST_F(TetherHostFetcherTest, TestFetchAllTetherHosts) {
191 tether_host_fetcher_->FetchAllTetherHosts(base::Bind( 204 tether_host_fetcher_->FetchAllTetherHosts(base::Bind(
192 &TetherHostFetcherTest::OnTetherHostListFetched, base::Unretained(this))); 205 &TetherHostFetcherTest::OnTetherHostListFetched, base::Unretained(this)));
193 206
194 // Nothing should load until the callback is invoked. 207 // Nothing should load until the callback is invoked.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 271
259 EXPECT_EQ(1u, device_list_list_.size()); 272 EXPECT_EQ(1u, device_list_list_.size());
260 EXPECT_EQ(test_devices_, device_list_list_[0]); 273 EXPECT_EQ(test_devices_, device_list_list_[0]);
261 EXPECT_EQ(2u, single_device_list_.size()); 274 EXPECT_EQ(2u, single_device_list_.size());
262 EXPECT_EQ(test_devices_[0], *single_device_list_[0]); 275 EXPECT_EQ(test_devices_[0], *single_device_list_[0]);
263 EXPECT_EQ(nullptr, single_device_list_[1]); 276 EXPECT_EQ(nullptr, single_device_list_[1]);
264 } 277 }
265 278
266 } // namespace tether 279 } // namespace tether
267 280
268 } // namespace cryptauth 281 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698