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

Side by Side Diff: components/proximity_auth/remote_device_life_cycle_impl_unittest.cc

Issue 1372283002: Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: fix msan tests Created 5 years, 2 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/remote_device_life_cycle_impl.h" 5 #include "components/proximity_auth/remote_device_life_cycle_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/test/test_simple_task_runner.h" 9 #include "base/test/test_simple_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 FakeConnection* connection_; 80 FakeConnection* connection_;
81 81
82 ConnectionCallback connection_callback_; 82 ConnectionCallback connection_callback_;
83 83
84 DISALLOW_COPY_AND_ASSIGN(FakeConnectionFinder); 84 DISALLOW_COPY_AND_ASSIGN(FakeConnectionFinder);
85 }; 85 };
86 86
87 class FakeAuthenticator : public Authenticator { 87 class FakeAuthenticator : public Authenticator {
88 public: 88 public:
89 FakeAuthenticator() {} 89 FakeAuthenticator(Connection* connection) : connection_(connection) {}
90 ~FakeAuthenticator() override {} 90 ~FakeAuthenticator() override {
91 // This object should be destroyed immediately after authentication is
92 // complete in order not to outlive the underlying connection.
93 EXPECT_FALSE(callback_.is_null());
94 EXPECT_EQ(std::string(), connection_->remote_device().public_key);
95 }
91 96
92 void OnAuthenticationResult(Authenticator::Result result) { 97 void OnAuthenticationResult(Authenticator::Result result) {
93 ASSERT_FALSE(callback_.is_null()); 98 ASSERT_FALSE(callback_.is_null());
94 scoped_ptr<SecureContext> secure_context; 99 scoped_ptr<SecureContext> secure_context;
95 if (result == Authenticator::Result::SUCCESS) 100 if (result == Authenticator::Result::SUCCESS)
96 secure_context.reset(new StubSecureContext()); 101 secure_context.reset(new StubSecureContext());
97 callback_.Run(result, secure_context.Pass()); 102 callback_.Run(result, secure_context.Pass());
98 } 103 }
99 104
100 private: 105 private:
101 // Authenticator: 106 // Authenticator:
102 void Authenticate(const AuthenticationCallback& callback) override { 107 void Authenticate(const AuthenticationCallback& callback) override {
103 ASSERT_TRUE(callback_.is_null()); 108 ASSERT_TRUE(callback_.is_null());
104 callback_ = callback; 109 callback_ = callback;
105 } 110 }
106 111
112 Connection* connection_;
113
107 AuthenticationCallback callback_; 114 AuthenticationCallback callback_;
108 115
109 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator); 116 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator);
110 }; 117 };
111 118
112 // Subclass of RemoteDeviceLifeCycleImpl to make it testable. 119 // Subclass of RemoteDeviceLifeCycleImpl to make it testable.
113 class TestableRemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycleImpl { 120 class TestableRemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycleImpl {
114 public: 121 public:
115 TestableRemoteDeviceLifeCycleImpl(const RemoteDevice& remote_device) 122 TestableRemoteDeviceLifeCycleImpl(const RemoteDevice& remote_device)
116 : RemoteDeviceLifeCycleImpl(remote_device, nullptr), 123 : RemoteDeviceLifeCycleImpl(remote_device, nullptr),
117 remote_device_(remote_device) {} 124 remote_device_(remote_device) {}
118 125
119 ~TestableRemoteDeviceLifeCycleImpl() override {} 126 ~TestableRemoteDeviceLifeCycleImpl() override {}
120 127
121 FakeConnectionFinder* connection_finder() { return connection_finder_; } 128 FakeConnectionFinder* connection_finder() { return connection_finder_; }
122 FakeAuthenticator* authenticator() { return authenticator_; } 129 FakeAuthenticator* authenticator() { return authenticator_; }
123 130
124 private: 131 private:
125 scoped_ptr<ConnectionFinder> CreateConnectionFinder() override { 132 scoped_ptr<ConnectionFinder> CreateConnectionFinder() override {
126 scoped_ptr<FakeConnectionFinder> scoped_connection_finder( 133 scoped_ptr<FakeConnectionFinder> scoped_connection_finder(
127 new FakeConnectionFinder(remote_device_)); 134 new FakeConnectionFinder(remote_device_));
128 connection_finder_ = scoped_connection_finder.get(); 135 connection_finder_ = scoped_connection_finder.get();
129 return scoped_connection_finder.Pass(); 136 return scoped_connection_finder.Pass();
130 } 137 }
131 138
132 scoped_ptr<Authenticator> CreateAuthenticator() override { 139 scoped_ptr<Authenticator> CreateAuthenticator() override {
133 scoped_ptr<FakeAuthenticator> scoped_authenticator(new FakeAuthenticator()); 140 EXPECT_TRUE(connection_finder_);
141 scoped_ptr<FakeAuthenticator> scoped_authenticator(
142 new FakeAuthenticator(connection_finder_->connection()));
134 authenticator_ = scoped_authenticator.get(); 143 authenticator_ = scoped_authenticator.get();
135 return scoped_authenticator.Pass(); 144 return scoped_authenticator.Pass();
136 } 145 }
137 146
138 const RemoteDevice remote_device_; 147 const RemoteDevice remote_device_;
139 FakeConnectionFinder* connection_finder_; 148 FakeConnectionFinder* connection_finder_;
140 FakeAuthenticator* authenticator_; 149 FakeAuthenticator* authenticator_;
141 150
142 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl); 151 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl);
143 }; 152 };
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 287
279 // Authentication succeeds on second pass. 288 // Authentication succeeds on second pass.
280 Connection* connection = OnConnectionFound(); 289 Connection* connection = OnConnectionFound();
281 Authenticate(Authenticator::Result::SUCCESS); 290 Authenticate(Authenticator::Result::SUCCESS);
282 EXPECT_TRUE(life_cycle_.GetMessenger()); 291 EXPECT_TRUE(life_cycle_.GetMessenger());
283 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _)); 292 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _));
284 connection->Disconnect(); 293 connection->Disconnect();
285 } 294 }
286 295
287 } // namespace proximity_auth 296 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698