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

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

Issue 2803913002: [CrOS Tether] Update TetherHostFetcher to use CryptAuthService instead of a Delegate. (Closed)
Patch Set: Rebased. 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
« no previous file with comments | « chromeos/components/tether/tether_host_fetcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "components/cryptauth/cryptauth_device_manager.h" 12 #include "components/cryptauth/cryptauth_device_manager.h"
13 #include "components/cryptauth/fake_cryptauth_service.h"
13 #include "components/cryptauth/fake_secure_message_delegate.h" 14 #include "components/cryptauth/fake_secure_message_delegate.h"
14 #include "components/cryptauth/proto/cryptauth_api.pb.h" 15 #include "components/cryptauth/proto/cryptauth_api.pb.h"
15 #include "components/cryptauth/remote_device_loader.h" 16 #include "components/cryptauth/remote_device_loader.h"
16 #include "components/cryptauth/remote_device_test_util.h" 17 #include "components/cryptauth/remote_device_test_util.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using testing::_; 21 using testing::_;
21 using testing::Invoke; 22 using testing::Invoke;
22 using testing::NiceMock; 23 using testing::NiceMock;
23 using testing::Return; 24 using testing::Return;
24 25
25 namespace chromeos { 26 namespace chromeos {
26 27
27 namespace tether { 28 namespace tether {
28 29
29 namespace { 30 namespace {
30 31
31 const char kTestUserId[] = "testUserId"; 32 const char kTestUserId[] = "testUserId";
32 const char kTestUserPrivateKey[] = "kTestUserPrivateKey"; 33 const char kTestUserPrivateKey[] = "kTestUserPrivateKey";
33 34
34 class TestDelegate : public TetherHostFetcher::Delegate { 35 class FakeCryptAuthServiceWithTracking
36 : public cryptauth::FakeCryptAuthService {
35 public: 37 public:
38 // FakeCryptAuthService:
36 std::unique_ptr<cryptauth::SecureMessageDelegate> 39 std::unique_ptr<cryptauth::SecureMessageDelegate>
37 CreateSecureMessageDelegate() override { 40 CreateSecureMessageDelegate() override {
38 cryptauth::FakeSecureMessageDelegate* delegate = 41 cryptauth::FakeSecureMessageDelegate* delegate =
39 new cryptauth::FakeSecureMessageDelegate(); 42 new cryptauth::FakeSecureMessageDelegate();
40 created_delegates_.push_back(delegate); 43 created_delegates_.push_back(delegate);
41 return base::WrapUnique(delegate); 44 return base::WrapUnique(delegate);
42 } 45 }
43 46
44 void VerifySecureMessageDelegateCreatedByFactory( 47 void VerifySecureMessageDelegateCreatedByFactory(
45 cryptauth::FakeSecureMessageDelegate* delegate) { 48 cryptauth::FakeSecureMessageDelegate* delegate) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 101
99 std::unique_ptr<cryptauth::RemoteDeviceLoader> BuildInstance( 102 std::unique_ptr<cryptauth::RemoteDeviceLoader> BuildInstance(
100 const std::vector<cryptauth::ExternalDeviceInfo>& device_info_list, 103 const std::vector<cryptauth::ExternalDeviceInfo>& device_info_list,
101 const std::string& user_id, 104 const std::string& user_id,
102 const std::string& user_private_key, 105 const std::string& user_private_key,
103 std::unique_ptr<cryptauth::SecureMessageDelegate> 106 std::unique_ptr<cryptauth::SecureMessageDelegate>
104 secure_message_delegate) override { 107 secure_message_delegate) override {
105 EXPECT_EQ(test_->test_device_infos_.size(), device_info_list.size()); 108 EXPECT_EQ(test_->test_device_infos_.size(), device_info_list.size());
106 EXPECT_EQ(std::string(kTestUserId), user_id); 109 EXPECT_EQ(std::string(kTestUserId), user_id);
107 EXPECT_EQ(std::string(kTestUserPrivateKey), user_private_key); 110 EXPECT_EQ(std::string(kTestUserPrivateKey), user_private_key);
108 test_->test_delegate_->VerifySecureMessageDelegateCreatedByFactory( 111 test_->fake_cryptauth_service_
109 static_cast<cryptauth::FakeSecureMessageDelegate*>( 112 ->VerifySecureMessageDelegateCreatedByFactory(
110 secure_message_delegate.get())); 113 static_cast<cryptauth::FakeSecureMessageDelegate*>(
114 secure_message_delegate.get()));
111 115
112 std::unique_ptr<MockDeviceLoader> device_loader = 116 std::unique_ptr<MockDeviceLoader> device_loader =
113 base::WrapUnique(new NiceMock<MockDeviceLoader>()); 117 base::WrapUnique(new NiceMock<MockDeviceLoader>());
114 ON_CALL(*device_loader, Load(_)) 118 ON_CALL(*device_loader, Load(_))
115 .WillByDefault( 119 .WillByDefault(
116 Invoke(this, &TestRemoteDeviceLoaderFactory::MockLoadImpl)); 120 Invoke(this, &TestRemoteDeviceLoaderFactory::MockLoadImpl));
117 return std::move(device_loader); 121 return std::move(device_loader);
118 } 122 }
119 123
120 void MockLoadImpl( 124 void MockLoadImpl(
(...skipping 13 matching lines...) Expand all
134 138
135 TetherHostFetcherTest() 139 TetherHostFetcherTest()
136 : test_devices_(cryptauth::GenerateTestRemoteDevices(5)), 140 : test_devices_(cryptauth::GenerateTestRemoteDevices(5)),
137 test_device_infos_( 141 test_device_infos_(
138 CreateTetherExternalDeviceInfosForRemoteDevices(test_devices_)) {} 142 CreateTetherExternalDeviceInfosForRemoteDevices(test_devices_)) {}
139 143
140 void SetUp() override { 144 void SetUp() override {
141 device_list_list_.clear(); 145 device_list_list_.clear();
142 single_device_list_.clear(); 146 single_device_list_.clear();
143 147
144 std::unique_ptr<TestDelegate> test_delegate = 148 fake_cryptauth_service_ =
145 base::WrapUnique(new TestDelegate()); 149 base::WrapUnique(new FakeCryptAuthServiceWithTracking());
146 test_delegate_ = test_delegate.get();
147 150
148 mock_device_manager_ = base::WrapUnique(new NiceMock<MockDeviceManager>()); 151 mock_device_manager_ = base::WrapUnique(new NiceMock<MockDeviceManager>());
149 ON_CALL(*mock_device_manager_, GetTetherHosts()) 152 ON_CALL(*mock_device_manager_, GetTetherHosts())
150 .WillByDefault(Return(test_device_infos_)); 153 .WillByDefault(Return(test_device_infos_));
151 154
152 test_device_loader_factory_ = 155 test_device_loader_factory_ =
153 base::WrapUnique(new TestRemoteDeviceLoaderFactory(this)); 156 base::WrapUnique(new TestRemoteDeviceLoaderFactory(this));
154 cryptauth::RemoteDeviceLoader::Factory::SetInstanceForTesting( 157 cryptauth::RemoteDeviceLoader::Factory::SetInstanceForTesting(
155 test_device_loader_factory_.get()); 158 test_device_loader_factory_.get());
156 159
157 tether_host_fetcher_ = base::MakeUnique<TetherHostFetcher>( 160 tether_host_fetcher_ = base::MakeUnique<TetherHostFetcher>(
158 std::string(kTestUserId), std::string(kTestUserPrivateKey), 161 std::string(kTestUserId), std::string(kTestUserPrivateKey),
159 std::move(test_delegate), mock_device_manager_.get()); 162 fake_cryptauth_service_.get(), mock_device_manager_.get());
160 } 163 }
161 164
162 void OnTetherHostListFetched(const cryptauth::RemoteDeviceList& device_list) { 165 void OnTetherHostListFetched(const cryptauth::RemoteDeviceList& device_list) {
163 device_list_list_.push_back(device_list); 166 device_list_list_.push_back(device_list);
164 } 167 }
165 168
166 void OnSingleTetherHostFetched( 169 void OnSingleTetherHostFetched(
167 std::unique_ptr<cryptauth::RemoteDevice> device) { 170 std::unique_ptr<cryptauth::RemoteDevice> device) {
168 single_device_list_.push_back(std::move(device)); 171 single_device_list_.push_back(std::move(device));
169 } 172 }
170 173
171 const std::vector<cryptauth::RemoteDevice> test_devices_; 174 const std::vector<cryptauth::RemoteDevice> test_devices_;
172 const std::vector<cryptauth::ExternalDeviceInfo> test_device_infos_; 175 const std::vector<cryptauth::ExternalDeviceInfo> test_device_infos_;
173 176
174 std::vector<cryptauth::RemoteDeviceList> device_list_list_; 177 std::vector<cryptauth::RemoteDeviceList> device_list_list_;
175 std::vector<std::shared_ptr<cryptauth::RemoteDevice>> single_device_list_; 178 std::vector<std::shared_ptr<cryptauth::RemoteDevice>> single_device_list_;
176 179
177 TestDelegate* test_delegate_; 180 std::unique_ptr<FakeCryptAuthServiceWithTracking> fake_cryptauth_service_;
178 std::unique_ptr<NiceMock<MockDeviceManager>> mock_device_manager_; 181 std::unique_ptr<NiceMock<MockDeviceManager>> mock_device_manager_;
179 std::unique_ptr<TestRemoteDeviceLoaderFactory> test_device_loader_factory_; 182 std::unique_ptr<TestRemoteDeviceLoaderFactory> test_device_loader_factory_;
180 183
181 std::unique_ptr<TetherHostFetcher> tether_host_fetcher_; 184 std::unique_ptr<TetherHostFetcher> tether_host_fetcher_;
182 185
183 private: 186 private:
184 DISALLOW_COPY_AND_ASSIGN(TetherHostFetcherTest); 187 DISALLOW_COPY_AND_ASSIGN(TetherHostFetcherTest);
185 }; 188 };
186 189
187 TEST_F(TetherHostFetcherTest, TestFetchAllTetherHosts) { 190 TEST_F(TetherHostFetcherTest, TestFetchAllTetherHosts) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 EXPECT_EQ(1u, device_list_list_.size()); 259 EXPECT_EQ(1u, device_list_list_.size());
257 EXPECT_EQ(test_devices_, device_list_list_[0]); 260 EXPECT_EQ(test_devices_, device_list_list_[0]);
258 EXPECT_EQ(2u, single_device_list_.size()); 261 EXPECT_EQ(2u, single_device_list_.size());
259 EXPECT_EQ(test_devices_[0], *single_device_list_[0]); 262 EXPECT_EQ(test_devices_[0], *single_device_list_[0]);
260 EXPECT_EQ(nullptr, single_device_list_[1]); 263 EXPECT_EQ(nullptr, single_device_list_[1]);
261 } 264 }
262 265
263 } // namespace tether 266 } // namespace tether
264 267
265 } // namespace cryptauth 268 } // namespace cryptauth
OLDNEW
« no previous file with comments | « chromeos/components/tether/tether_host_fetcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698