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

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

Issue 1377313002: Revert of Hook up ProximityAuthSystem in EasyUnlockService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth_connection
Patch Set: 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(Connection* connection) : connection_(connection) {} 89 FakeAuthenticator() {}
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 }
96 91
97 void OnAuthenticationResult(Authenticator::Result result) { 92 void OnAuthenticationResult(Authenticator::Result result) {
98 ASSERT_FALSE(callback_.is_null()); 93 ASSERT_FALSE(callback_.is_null());
99 scoped_ptr<SecureContext> secure_context; 94 scoped_ptr<SecureContext> secure_context;
100 if (result == Authenticator::Result::SUCCESS) 95 if (result == Authenticator::Result::SUCCESS)
101 secure_context.reset(new StubSecureContext()); 96 secure_context.reset(new StubSecureContext());
102 callback_.Run(result, secure_context.Pass()); 97 callback_.Run(result, secure_context.Pass());
103 } 98 }
104 99
105 private: 100 private:
106 // Authenticator: 101 // Authenticator:
107 void Authenticate(const AuthenticationCallback& callback) override { 102 void Authenticate(const AuthenticationCallback& callback) override {
108 ASSERT_TRUE(callback_.is_null()); 103 ASSERT_TRUE(callback_.is_null());
109 callback_ = callback; 104 callback_ = callback;
110 } 105 }
111 106
112 Connection* connection_;
113
114 AuthenticationCallback callback_; 107 AuthenticationCallback callback_;
115 108
116 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator); 109 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator);
117 }; 110 };
118 111
119 // Subclass of RemoteDeviceLifeCycleImpl to make it testable. 112 // Subclass of RemoteDeviceLifeCycleImpl to make it testable.
120 class TestableRemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycleImpl { 113 class TestableRemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycleImpl {
121 public: 114 public:
122 TestableRemoteDeviceLifeCycleImpl(const RemoteDevice& remote_device) 115 TestableRemoteDeviceLifeCycleImpl(const RemoteDevice& remote_device)
123 : RemoteDeviceLifeCycleImpl(remote_device, nullptr), 116 : RemoteDeviceLifeCycleImpl(remote_device, nullptr),
124 remote_device_(remote_device) {} 117 remote_device_(remote_device) {}
125 118
126 ~TestableRemoteDeviceLifeCycleImpl() override {} 119 ~TestableRemoteDeviceLifeCycleImpl() override {}
127 120
128 FakeConnectionFinder* connection_finder() { return connection_finder_; } 121 FakeConnectionFinder* connection_finder() { return connection_finder_; }
129 FakeAuthenticator* authenticator() { return authenticator_; } 122 FakeAuthenticator* authenticator() { return authenticator_; }
130 123
131 private: 124 private:
132 scoped_ptr<ConnectionFinder> CreateConnectionFinder() override { 125 scoped_ptr<ConnectionFinder> CreateConnectionFinder() override {
133 scoped_ptr<FakeConnectionFinder> scoped_connection_finder( 126 scoped_ptr<FakeConnectionFinder> scoped_connection_finder(
134 new FakeConnectionFinder(remote_device_)); 127 new FakeConnectionFinder(remote_device_));
135 connection_finder_ = scoped_connection_finder.get(); 128 connection_finder_ = scoped_connection_finder.get();
136 return scoped_connection_finder.Pass(); 129 return scoped_connection_finder.Pass();
137 } 130 }
138 131
139 scoped_ptr<Authenticator> CreateAuthenticator() override { 132 scoped_ptr<Authenticator> CreateAuthenticator() override {
140 EXPECT_TRUE(connection_finder_); 133 scoped_ptr<FakeAuthenticator> scoped_authenticator(new FakeAuthenticator());
141 scoped_ptr<FakeAuthenticator> scoped_authenticator(
142 new FakeAuthenticator(connection_finder_->connection()));
143 authenticator_ = scoped_authenticator.get(); 134 authenticator_ = scoped_authenticator.get();
144 return scoped_authenticator.Pass(); 135 return scoped_authenticator.Pass();
145 } 136 }
146 137
147 const RemoteDevice remote_device_; 138 const RemoteDevice remote_device_;
148 FakeConnectionFinder* connection_finder_; 139 FakeConnectionFinder* connection_finder_;
149 FakeAuthenticator* authenticator_; 140 FakeAuthenticator* authenticator_;
150 141
151 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl); 142 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl);
152 }; 143 };
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 278
288 // Authentication succeeds on second pass. 279 // Authentication succeeds on second pass.
289 Connection* connection = OnConnectionFound(); 280 Connection* connection = OnConnectionFound();
290 Authenticate(Authenticator::Result::SUCCESS); 281 Authenticate(Authenticator::Result::SUCCESS);
291 EXPECT_TRUE(life_cycle_.GetMessenger()); 282 EXPECT_TRUE(life_cycle_.GetMessenger());
292 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _)); 283 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _));
293 connection->Disconnect(); 284 connection->Disconnect();
294 } 285 }
295 286
296 } // namespace proximity_auth 287 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/remote_device_life_cycle_impl.cc ('k') | components/proximity_auth/screenlock_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698