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

Side by Side Diff: components/proximity_auth/cryptauth/cryptauth_enrollment_manager_unittest.cc

Issue 1548203002: Convert Pass()→std::move() in //components/[n-z]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bad headers Created 4 years, 12 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 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_enrollment_manager.h" 5 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h"
6 6
7 #include <utility>
8
7 #include "base/base64url.h" 9 #include "base/base64url.h"
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
10 #include "base/prefs/testing_pref_service.h" 12 #include "base/prefs/testing_pref_service.h"
11 #include "base/test/simple_test_clock.h" 13 #include "base/test/simple_test_clock.h"
12 #include "base/time/clock.h" 14 #include "base/time/clock.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "components/proximity_auth/cryptauth/cryptauth_enroller.h" 16 #include "components/proximity_auth/cryptauth/cryptauth_enroller.h"
15 #include "components/proximity_auth/cryptauth/fake_cryptauth_gcm_manager.h" 17 #include "components/proximity_auth/cryptauth/fake_cryptauth_gcm_manager.h"
16 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h" 18 #include "components/proximity_auth/cryptauth/fake_secure_message_delegate.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // Creates MockCryptAuthEnroller instances, and allows expecations to be set 70 // Creates MockCryptAuthEnroller instances, and allows expecations to be set
69 // before they are returned. 71 // before they are returned.
70 class MockCryptAuthEnrollerFactory : public CryptAuthEnrollerFactory { 72 class MockCryptAuthEnrollerFactory : public CryptAuthEnrollerFactory {
71 public: 73 public:
72 MockCryptAuthEnrollerFactory() 74 MockCryptAuthEnrollerFactory()
73 : next_cryptauth_enroller_(new NiceMock<MockCryptAuthEnroller>()) {} 75 : next_cryptauth_enroller_(new NiceMock<MockCryptAuthEnroller>()) {}
74 ~MockCryptAuthEnrollerFactory() override {} 76 ~MockCryptAuthEnrollerFactory() override {}
75 77
76 // CryptAuthEnrollerFactory: 78 // CryptAuthEnrollerFactory:
77 scoped_ptr<CryptAuthEnroller> CreateInstance() override { 79 scoped_ptr<CryptAuthEnroller> CreateInstance() override {
78 auto passed_cryptauth_enroller = next_cryptauth_enroller_.Pass(); 80 auto passed_cryptauth_enroller = std::move(next_cryptauth_enroller_);
79 next_cryptauth_enroller_.reset(new NiceMock<MockCryptAuthEnroller>()); 81 next_cryptauth_enroller_.reset(new NiceMock<MockCryptAuthEnroller>());
80 return passed_cryptauth_enroller.Pass(); 82 return std::move(passed_cryptauth_enroller);
81 } 83 }
82 84
83 MockCryptAuthEnroller* next_cryptauth_enroller() { 85 MockCryptAuthEnroller* next_cryptauth_enroller() {
84 return next_cryptauth_enroller_.get(); 86 return next_cryptauth_enroller_.get();
85 } 87 }
86 88
87 private: 89 private:
88 // Stores the next CryptAuthEnroller to be created. 90 // Stores the next CryptAuthEnroller to be created.
89 // Ownership is passed to the caller of |CreateInstance()|. 91 // Ownership is passed to the caller of |CreateInstance()|.
90 scoped_ptr<MockCryptAuthEnroller> next_cryptauth_enroller_; 92 scoped_ptr<MockCryptAuthEnroller> next_cryptauth_enroller_;
91 93
92 DISALLOW_COPY_AND_ASSIGN(MockCryptAuthEnrollerFactory); 94 DISALLOW_COPY_AND_ASSIGN(MockCryptAuthEnrollerFactory);
93 }; 95 };
94 96
95 // Harness for testing CryptAuthEnrollmentManager. 97 // Harness for testing CryptAuthEnrollmentManager.
96 class TestCryptAuthEnrollmentManager : public CryptAuthEnrollmentManager { 98 class TestCryptAuthEnrollmentManager : public CryptAuthEnrollmentManager {
97 public: 99 public:
98 TestCryptAuthEnrollmentManager( 100 TestCryptAuthEnrollmentManager(
99 scoped_ptr<base::Clock> clock, 101 scoped_ptr<base::Clock> clock,
100 scoped_ptr<CryptAuthEnrollerFactory> enroller_factory, 102 scoped_ptr<CryptAuthEnrollerFactory> enroller_factory,
101 scoped_ptr<SecureMessageDelegate> secure_message_delegate, 103 scoped_ptr<SecureMessageDelegate> secure_message_delegate,
102 const cryptauth::GcmDeviceInfo& device_info, 104 const cryptauth::GcmDeviceInfo& device_info,
103 CryptAuthGCMManager* gcm_manager, 105 CryptAuthGCMManager* gcm_manager,
104 PrefService* pref_service) 106 PrefService* pref_service)
105 : CryptAuthEnrollmentManager(clock.Pass(), 107 : CryptAuthEnrollmentManager(std::move(clock),
106 enroller_factory.Pass(), 108 std::move(enroller_factory),
107 secure_message_delegate.Pass(), 109 std::move(secure_message_delegate),
108 device_info, 110 device_info,
109 gcm_manager, 111 gcm_manager,
110 pref_service), 112 pref_service),
111 scoped_sync_scheduler_(new NiceMock<MockSyncScheduler>()), 113 scoped_sync_scheduler_(new NiceMock<MockSyncScheduler>()),
112 weak_sync_scheduler_factory_(scoped_sync_scheduler_.get()) {} 114 weak_sync_scheduler_factory_(scoped_sync_scheduler_.get()) {}
113 115
114 ~TestCryptAuthEnrollmentManager() override {} 116 ~TestCryptAuthEnrollmentManager() override {}
115 117
116 scoped_ptr<SyncScheduler> CreateSyncScheduler() override { 118 scoped_ptr<SyncScheduler> CreateSyncScheduler() override {
117 EXPECT_TRUE(scoped_sync_scheduler_); 119 EXPECT_TRUE(scoped_sync_scheduler_);
118 return scoped_sync_scheduler_.Pass(); 120 return std::move(scoped_sync_scheduler_);
119 } 121 }
120 122
121 base::WeakPtr<MockSyncScheduler> GetSyncScheduler() { 123 base::WeakPtr<MockSyncScheduler> GetSyncScheduler() {
122 return weak_sync_scheduler_factory_.GetWeakPtr(); 124 return weak_sync_scheduler_factory_.GetWeakPtr();
123 } 125 }
124 126
125 private: 127 private:
126 // Ownership is passed to |CryptAuthEnrollmentManager| super class when 128 // Ownership is passed to |CryptAuthEnrollmentManager| super class when
127 // |CreateSyncScheduler()| is called. 129 // |CreateSyncScheduler()| is called.
128 scoped_ptr<MockSyncScheduler> scoped_sync_scheduler_; 130 scoped_ptr<MockSyncScheduler> scoped_sync_scheduler_;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 *next_cryptauth_enroller(), 219 *next_cryptauth_enroller(),
218 Enroll(public_key_, private_key_, _, expected_invocation_reason, _)) 220 Enroll(public_key_, private_key_, _, expected_invocation_reason, _))
219 .WillOnce(SaveArg<4>(&completion_callback)); 221 .WillOnce(SaveArg<4>(&completion_callback));
220 222
221 auto sync_request = make_scoped_ptr( 223 auto sync_request = make_scoped_ptr(
222 new SyncScheduler::SyncRequest(enrollment_manager_.GetSyncScheduler())); 224 new SyncScheduler::SyncRequest(enrollment_manager_.GetSyncScheduler()));
223 EXPECT_CALL(*this, OnEnrollmentStartedProxy()); 225 EXPECT_CALL(*this, OnEnrollmentStartedProxy());
224 226
225 SyncScheduler::Delegate* delegate = 227 SyncScheduler::Delegate* delegate =
226 static_cast<SyncScheduler::Delegate*>(&enrollment_manager_); 228 static_cast<SyncScheduler::Delegate*>(&enrollment_manager_);
227 delegate->OnSyncRequested(sync_request.Pass()); 229 delegate->OnSyncRequested(std::move(sync_request));
228 230
229 return completion_callback; 231 return completion_callback;
230 } 232 }
231 233
232 MockSyncScheduler* sync_scheduler() { 234 MockSyncScheduler* sync_scheduler() {
233 return enrollment_manager_.GetSyncScheduler().get(); 235 return enrollment_manager_.GetSyncScheduler().get();
234 } 236 }
235 237
236 MockCryptAuthEnroller* next_cryptauth_enroller() { 238 MockCryptAuthEnroller* next_cryptauth_enroller() {
237 return enroller_factory_->next_cryptauth_enroller(); 239 return enroller_factory_->next_cryptauth_enroller();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 300
299 TEST_F(ProximityAuthCryptAuthEnrollmentManagerTest, InitWithDefaultPrefs) { 301 TEST_F(ProximityAuthCryptAuthEnrollmentManagerTest, InitWithDefaultPrefs) {
300 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock()); 302 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock());
301 clock->SetNow(base::Time::FromDoubleT(kInitialTimeNowSeconds)); 303 clock->SetNow(base::Time::FromDoubleT(kInitialTimeNowSeconds));
302 base::TimeDelta elapsed_time = clock->Now() - base::Time::FromDoubleT(0); 304 base::TimeDelta elapsed_time = clock->Now() - base::Time::FromDoubleT(0);
303 305
304 TestingPrefServiceSimple pref_service; 306 TestingPrefServiceSimple pref_service;
305 CryptAuthEnrollmentManager::RegisterPrefs(pref_service.registry()); 307 CryptAuthEnrollmentManager::RegisterPrefs(pref_service.registry());
306 308
307 TestCryptAuthEnrollmentManager enrollment_manager( 309 TestCryptAuthEnrollmentManager enrollment_manager(
308 clock.Pass(), make_scoped_ptr(new MockCryptAuthEnrollerFactory()), 310 std::move(clock), make_scoped_ptr(new MockCryptAuthEnrollerFactory()),
309 make_scoped_ptr(new FakeSecureMessageDelegate()), device_info_, 311 make_scoped_ptr(new FakeSecureMessageDelegate()), device_info_,
310 &gcm_manager_, &pref_service); 312 &gcm_manager_, &pref_service);
311 313
312 EXPECT_CALL( 314 EXPECT_CALL(
313 *enrollment_manager.GetSyncScheduler(), 315 *enrollment_manager.GetSyncScheduler(),
314 Start(elapsed_time, SyncScheduler::Strategy::AGGRESSIVE_RECOVERY)); 316 Start(elapsed_time, SyncScheduler::Strategy::AGGRESSIVE_RECOVERY));
315 enrollment_manager.Start(); 317 enrollment_manager.Start();
316 318
317 EXPECT_FALSE(enrollment_manager.IsEnrollmentValid()); 319 EXPECT_FALSE(enrollment_manager.IsEnrollmentValid());
318 EXPECT_TRUE(enrollment_manager.GetLastEnrollmentTime().is_null()); 320 EXPECT_TRUE(enrollment_manager.GetLastEnrollmentTime().is_null());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 pref_service_.ClearPref(prefs::kCryptAuthEnrollmentUserPrivateKey); 404 pref_service_.ClearPref(prefs::kCryptAuthEnrollmentUserPrivateKey);
403 pref_service_.ClearPref(prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds); 405 pref_service_.ClearPref(prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds);
404 enrollment_manager_.Start(); 406 enrollment_manager_.Start();
405 EXPECT_FALSE(enrollment_manager_.IsEnrollmentValid()); 407 EXPECT_FALSE(enrollment_manager_.IsEnrollmentValid());
406 408
407 // Trigger a sync request. 409 // Trigger a sync request.
408 EXPECT_CALL(*this, OnEnrollmentStartedProxy()); 410 EXPECT_CALL(*this, OnEnrollmentStartedProxy());
409 auto sync_request = make_scoped_ptr( 411 auto sync_request = make_scoped_ptr(
410 new SyncScheduler::SyncRequest(enrollment_manager_.GetSyncScheduler())); 412 new SyncScheduler::SyncRequest(enrollment_manager_.GetSyncScheduler()));
411 static_cast<SyncScheduler::Delegate*>(&enrollment_manager_) 413 static_cast<SyncScheduler::Delegate*>(&enrollment_manager_)
412 ->OnSyncRequested(sync_request.Pass()); 414 ->OnSyncRequested(std::move(sync_request));
413 415
414 // Complete GCM registration successfully, and expect an enrollment. 416 // Complete GCM registration successfully, and expect an enrollment.
415 CryptAuthEnroller::EnrollmentFinishedCallback enrollment_callback; 417 CryptAuthEnroller::EnrollmentFinishedCallback enrollment_callback;
416 EXPECT_CALL(*next_cryptauth_enroller(), 418 EXPECT_CALL(*next_cryptauth_enroller(),
417 Enroll(public_key_, private_key_, _, 419 Enroll(public_key_, private_key_, _,
418 cryptauth::INVOCATION_REASON_INITIALIZATION, _)) 420 cryptauth::INVOCATION_REASON_INITIALIZATION, _))
419 .WillOnce(SaveArg<4>(&enrollment_callback)); 421 .WillOnce(SaveArg<4>(&enrollment_callback));
420 ASSERT_TRUE(gcm_manager_.registration_in_progress()); 422 ASSERT_TRUE(gcm_manager_.registration_in_progress());
421 gcm_manager_.CompleteRegistration(kGCMRegistrationId); 423 gcm_manager_.CompleteRegistration(kGCMRegistrationId);
422 424
(...skipping 15 matching lines...) Expand all
438 ON_CALL(*sync_scheduler(), GetStrategy()) 440 ON_CALL(*sync_scheduler(), GetStrategy())
439 .WillByDefault(Return(SyncScheduler::Strategy::PERIODIC_REFRESH)); 441 .WillByDefault(Return(SyncScheduler::Strategy::PERIODIC_REFRESH));
440 gcm_manager_.set_registration_id(std::string()); 442 gcm_manager_.set_registration_id(std::string());
441 enrollment_manager_.Start(); 443 enrollment_manager_.Start();
442 444
443 // Trigger a sync request. 445 // Trigger a sync request.
444 EXPECT_CALL(*this, OnEnrollmentStartedProxy()); 446 EXPECT_CALL(*this, OnEnrollmentStartedProxy());
445 auto sync_request = make_scoped_ptr( 447 auto sync_request = make_scoped_ptr(
446 new SyncScheduler::SyncRequest(enrollment_manager_.GetSyncScheduler())); 448 new SyncScheduler::SyncRequest(enrollment_manager_.GetSyncScheduler()));
447 static_cast<SyncScheduler::Delegate*>(&enrollment_manager_) 449 static_cast<SyncScheduler::Delegate*>(&enrollment_manager_)
448 ->OnSyncRequested(sync_request.Pass()); 450 ->OnSyncRequested(std::move(sync_request));
449 451
450 // Complete GCM registration with failure. 452 // Complete GCM registration with failure.
451 EXPECT_CALL(*this, OnEnrollmentFinishedProxy(false)); 453 EXPECT_CALL(*this, OnEnrollmentFinishedProxy(false));
452 gcm_manager_.CompleteRegistration(std::string()); 454 gcm_manager_.CompleteRegistration(std::string());
453 } 455 }
454 456
455 TEST_F(ProximityAuthCryptAuthEnrollmentManagerTest, ReenrollOnGCMPushMessage) { 457 TEST_F(ProximityAuthCryptAuthEnrollmentManagerTest, ReenrollOnGCMPushMessage) {
456 enrollment_manager_.Start(); 458 enrollment_manager_.Start();
457 459
458 // Simulate receiving a GCM push message, forcing the device to re-enroll. 460 // Simulate receiving a GCM push message, forcing the device to re-enroll.
459 gcm_manager_.PushReenrollMessage(); 461 gcm_manager_.PushReenrollMessage();
460 auto completion_callback = 462 auto completion_callback =
461 FireSchedulerForEnrollment(cryptauth::INVOCATION_REASON_SERVER_INITIATED); 463 FireSchedulerForEnrollment(cryptauth::INVOCATION_REASON_SERVER_INITIATED);
462 464
463 EXPECT_CALL(*this, OnEnrollmentFinishedProxy(true)); 465 EXPECT_CALL(*this, OnEnrollmentFinishedProxy(true));
464 completion_callback.Run(true); 466 completion_callback.Run(true);
465 } 467 }
466 468
467 } // namespace proximity_auth 469 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698