OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/cryptauth/cryptauth_enroller_impl.h" | 5 #include "components/proximity_auth/cryptauth/cryptauth_enroller_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" |
9 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h" | 10 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h" |
10 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" | 11 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" |
11 #include "components/proximity_auth/cryptauth/mock_cryptauth_client.h" | 12 #include "components/proximity_auth/cryptauth/mock_cryptauth_client.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 using ::testing::_; | 15 using ::testing::_; |
15 using ::testing::Return; | 16 using ::testing::Return; |
16 | 17 |
17 namespace proximity_auth { | 18 namespace proximity_auth { |
18 | 19 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } // namespace | 99 } // namespace |
99 | 100 |
100 class ProximityAuthCryptAuthEnrollerTest | 101 class ProximityAuthCryptAuthEnrollerTest |
101 : public testing::Test, | 102 : public testing::Test, |
102 public MockCryptAuthClientFactory::Observer { | 103 public MockCryptAuthClientFactory::Observer { |
103 public: | 104 public: |
104 ProximityAuthCryptAuthEnrollerTest() | 105 ProximityAuthCryptAuthEnrollerTest() |
105 : client_factory_(new MockCryptAuthClientFactory( | 106 : client_factory_(new MockCryptAuthClientFactory( |
106 MockCryptAuthClientFactory::MockType::MAKE_NICE_MOCKS)), | 107 MockCryptAuthClientFactory::MockType::MAKE_NICE_MOCKS)), |
107 secure_message_delegate_(new FakeSecureMessageDelegate()), | 108 secure_message_delegate_(new FakeSecureMessageDelegate()), |
108 enroller_(make_scoped_ptr(client_factory_), | 109 enroller_(base::WrapUnique(client_factory_), |
109 make_scoped_ptr(secure_message_delegate_)) { | 110 base::WrapUnique(secure_message_delegate_)) { |
110 client_factory_->AddObserver(this); | 111 client_factory_->AddObserver(this); |
111 | 112 |
112 // This call is actually synchronous. | 113 // This call is actually synchronous. |
113 secure_message_delegate_->GenerateKeyPair( | 114 secure_message_delegate_->GenerateKeyPair( |
114 base::Bind(&ProximityAuthCryptAuthEnrollerTest::OnKeyPairGenerated, | 115 base::Bind(&ProximityAuthCryptAuthEnrollerTest::OnKeyPairGenerated, |
115 base::Unretained(this))); | 116 base::Unretained(this))); |
116 } | 117 } |
117 | 118 |
118 // Starts the enroller. | 119 // Starts the enroller. |
119 void StartEnroller(const cryptauth::GcmDeviceInfo& device_info) { | 120 void StartEnroller(const cryptauth::GcmDeviceInfo& device_info) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 std::string user_private_key_; | 243 std::string user_private_key_; |
243 | 244 |
244 // Owned by |enroller_|. | 245 // Owned by |enroller_|. |
245 MockCryptAuthClientFactory* client_factory_; | 246 MockCryptAuthClientFactory* client_factory_; |
246 // Owned by |enroller_|. | 247 // Owned by |enroller_|. |
247 FakeSecureMessageDelegate* secure_message_delegate_; | 248 FakeSecureMessageDelegate* secure_message_delegate_; |
248 // The CryptAuthEnroller under test. | 249 // The CryptAuthEnroller under test. |
249 CryptAuthEnrollerImpl enroller_; | 250 CryptAuthEnrollerImpl enroller_; |
250 | 251 |
251 // Stores the result of running |enroller_|. | 252 // Stores the result of running |enroller_|. |
252 scoped_ptr<bool> enroller_result_; | 253 std::unique_ptr<bool> enroller_result_; |
253 | 254 |
254 // Stored callbacks and requests for SetupEnrollment and FinishEnrollment. | 255 // Stored callbacks and requests for SetupEnrollment and FinishEnrollment. |
255 scoped_ptr<cryptauth::SetupEnrollmentRequest> setup_request_; | 256 std::unique_ptr<cryptauth::SetupEnrollmentRequest> setup_request_; |
256 scoped_ptr<cryptauth::FinishEnrollmentRequest> finish_request_; | 257 std::unique_ptr<cryptauth::FinishEnrollmentRequest> finish_request_; |
257 CryptAuthClient::SetupEnrollmentCallback setup_callback_; | 258 CryptAuthClient::SetupEnrollmentCallback setup_callback_; |
258 CryptAuthClient::FinishEnrollmentCallback finish_callback_; | 259 CryptAuthClient::FinishEnrollmentCallback finish_callback_; |
259 CryptAuthClient::ErrorCallback error_callback_; | 260 CryptAuthClient::ErrorCallback error_callback_; |
260 | 261 |
261 DISALLOW_COPY_AND_ASSIGN(ProximityAuthCryptAuthEnrollerTest); | 262 DISALLOW_COPY_AND_ASSIGN(ProximityAuthCryptAuthEnrollerTest); |
262 }; | 263 }; |
263 | 264 |
264 TEST_F(ProximityAuthCryptAuthEnrollerTest, EnrollmentSucceeds) { | 265 TEST_F(ProximityAuthCryptAuthEnrollerTest, EnrollmentSucceeds) { |
265 StartEnroller(GetDeviceInfo()); | 266 StartEnroller(GetDeviceInfo()); |
266 | 267 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 EXPECT_FALSE(*enroller_result_); | 350 EXPECT_FALSE(*enroller_result_); |
350 } | 351 } |
351 | 352 |
352 TEST_F(ProximityAuthCryptAuthEnrollerTest, IncompleteDeviceInfo) { | 353 TEST_F(ProximityAuthCryptAuthEnrollerTest, IncompleteDeviceInfo) { |
353 StartEnroller(cryptauth::GcmDeviceInfo()); | 354 StartEnroller(cryptauth::GcmDeviceInfo()); |
354 ASSERT_TRUE(enroller_result_.get()); | 355 ASSERT_TRUE(enroller_result_.get()); |
355 EXPECT_FALSE(*enroller_result_); | 356 EXPECT_FALSE(*enroller_result_); |
356 } | 357 } |
357 | 358 |
358 } // namespace proximity_auth | 359 } // namespace proximity_auth |
OLD | NEW |