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

Side by Side Diff: components/password_manager/content/browser/credential_manager_impl_unittest.cc

Issue 1762603002: Switch components/password_manager code from IPC messages to Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp Created 4 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/password_manager/content/browser/credential_manager_dispatc her.h" 5 #include "components/password_manager/content/browser/credential_manager_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "components/password_manager/content/common/credential_manager_messages .h" 20 #include "components/password_manager/content/public/type_converters.h"
21 #include "components/password_manager/core/browser/credential_manager_password_f orm_manager.h" 21 #include "components/password_manager/core/browser/credential_manager_password_f orm_manager.h"
22 #include "components/password_manager/core/browser/mock_affiliated_match_helper. h" 22 #include "components/password_manager/core/browser/mock_affiliated_match_helper. h"
23 #include "components/password_manager/core/browser/password_manager.h" 23 #include "components/password_manager/core/browser/password_manager.h"
24 #include "components/password_manager/core/browser/stub_password_manager_client. h" 24 #include "components/password_manager/core/browser/stub_password_manager_client. h"
25 #include "components/password_manager/core/browser/stub_password_manager_driver. h" 25 #include "components/password_manager/core/browser/stub_password_manager_driver. h"
26 #include "components/password_manager/core/browser/test_password_store.h" 26 #include "components/password_manager/core/browser/test_password_store.h"
27 #include "components/password_manager/core/common/credential_manager_types.h" 27 #include "components/password_manager/core/common/credential_manager_types.h"
28 #include "components/password_manager/core/common/password_manager_pref_names.h" 28 #include "components/password_manager/core/common/password_manager_pref_names.h"
29 #include "components/prefs/pref_registry_simple.h" 29 #include "components/prefs/pref_registry_simple.h"
30 #include "components/prefs/testing_pref_service.h" 30 #include "components/prefs/testing_pref_service.h"
31 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
32 #include "content/public/test/mock_render_process_host.h" 32 #include "content/public/test/mock_render_process_host.h"
33 #include "content/public/test/test_renderer_host.h" 33 #include "content/public/test/test_renderer_host.h"
34 #include "mojo/common/url_type_converters.h"
34 #include "testing/gmock/include/gmock/gmock.h" 35 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 37
37 using content::BrowserContext; 38 using content::BrowserContext;
38 using content::WebContents; 39 using content::WebContents;
39 40
40 using testing::_; 41 using testing::_;
41 42
42 namespace password_manager { 43 namespace password_manager {
43 44
44 namespace { 45 namespace {
45 46
46 // Chosen by fair dice roll. Guaranteed to be random.
47 const int kRequestId = 4;
48
49 const char kTestWebOrigin[] = "https://example.com/"; 47 const char kTestWebOrigin[] = "https://example.com/";
50 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; 48 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/";
51 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; 49 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/";
52 50
53 class MockPasswordManagerClient : public StubPasswordManagerClient { 51 class MockPasswordManagerClient : public StubPasswordManagerClient {
54 public: 52 public:
55 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); 53 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool());
56 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); 54 MOCK_CONST_METHOD0(IsOffTheRecord, bool());
57 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); 55 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
58 MOCK_METHOD1(NotifyUserAutoSigninPtr, 56 MOCK_METHOD1(NotifyUserAutoSigninPtr,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 125 }
128 126
129 private: 127 private:
130 TestingPrefServiceSimple prefs_; 128 TestingPrefServiceSimple prefs_;
131 PasswordStore* store_; 129 PasswordStore* store_;
132 scoped_ptr<PasswordFormManager> manager_; 130 scoped_ptr<PasswordFormManager> manager_;
133 131
134 DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient); 132 DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient);
135 }; 133 };
136 134
137 class TestCredentialManagerDispatcher : public CredentialManagerDispatcher { 135 class TestCredentialManagerImpl : public CredentialManagerImpl {
138 public: 136 public:
139 TestCredentialManagerDispatcher(content::WebContents* web_contents, 137 TestCredentialManagerImpl(content::WebContents* web_contents,
140 PasswordManagerClient* client, 138 PasswordManagerClient* client,
141 PasswordManagerDriver* driver); 139 PasswordManagerDriver* driver);
142 140
143 private: 141 private:
144 base::WeakPtr<PasswordManagerDriver> GetDriver() override; 142 base::WeakPtr<PasswordManagerDriver> GetDriver() override;
145 143
146 base::WeakPtr<PasswordManagerDriver> driver_; 144 base::WeakPtr<PasswordManagerDriver> driver_;
147 }; 145 };
148 146
149 TestCredentialManagerDispatcher::TestCredentialManagerDispatcher( 147 TestCredentialManagerImpl::TestCredentialManagerImpl(
150 content::WebContents* web_contents, 148 content::WebContents* web_contents,
151 PasswordManagerClient* client, 149 PasswordManagerClient* client,
152 PasswordManagerDriver* driver) 150 PasswordManagerDriver* driver)
153 : CredentialManagerDispatcher(web_contents, client), 151 : CredentialManagerImpl(web_contents, client),
154 driver_(driver->AsWeakPtr()) {} 152 driver_(driver->AsWeakPtr()) {}
155 153
156 base::WeakPtr<PasswordManagerDriver> 154 base::WeakPtr<PasswordManagerDriver> TestCredentialManagerImpl::GetDriver() {
157 TestCredentialManagerDispatcher::GetDriver() {
158 return driver_; 155 return driver_;
159 } 156 }
160 157
161 void RunAllPendingTasks() { 158 void RunAllPendingTasks() {
162 base::RunLoop run_loop; 159 base::RunLoop run_loop;
163 base::MessageLoop::current()->PostTask( 160 base::MessageLoop::current()->PostTask(
164 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 161 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
165 run_loop.Run(); 162 run_loop.Run();
166 } 163 }
167 164
168 class SlightlyLessStubbyPasswordManagerDriver 165 class SlightlyLessStubbyPasswordManagerDriver
169 : public StubPasswordManagerDriver { 166 : public StubPasswordManagerDriver {
170 public: 167 public:
171 explicit SlightlyLessStubbyPasswordManagerDriver( 168 explicit SlightlyLessStubbyPasswordManagerDriver(
172 PasswordManagerClient* client) 169 PasswordManagerClient* client)
173 : password_manager_(client) {} 170 : password_manager_(client) {}
174 171
175 PasswordManager* GetPasswordManager() override { return &password_manager_; } 172 PasswordManager* GetPasswordManager() override { return &password_manager_; }
176 173
177 private: 174 private:
178 PasswordManager password_manager_; 175 PasswordManager password_manager_;
179 }; 176 };
180 177
178 // Callbacks from CredentialManagerImpl methods
179
180 void RespondCallback(bool* called) {
181 *called = true;
182 }
183
184 void GetCredentialCallback(bool* called,
185 mojom::CredentialManagerError* out_error,
186 mojom::CredentialInfoPtr* out_info,
187 mojom::CredentialManagerError error,
188 mojom::CredentialInfoPtr info) {
189 *called = true;
190 *out_error = error;
191 *out_info = std::move(info);
192 }
193
181 } // namespace 194 } // namespace
182 195
183 class CredentialManagerDispatcherTest 196 class CredentialManagerImplTest : public content::RenderViewHostTestHarness {
184 : public content::RenderViewHostTestHarness {
185 public: 197 public:
186 CredentialManagerDispatcherTest() {} 198 CredentialManagerImplTest() {}
187 199
188 void SetUp() override { 200 void SetUp() override {
189 content::RenderViewHostTestHarness::SetUp(); 201 content::RenderViewHostTestHarness::SetUp();
190 store_ = new TestPasswordStore; 202 store_ = new TestPasswordStore;
191 client_.reset( 203 client_.reset(
192 new testing::NiceMock<MockPasswordManagerClient>(store_.get())); 204 new testing::NiceMock<MockPasswordManagerClient>(store_.get()));
193 stub_driver_.reset( 205 stub_driver_.reset(
194 new SlightlyLessStubbyPasswordManagerDriver(client_.get())); 206 new SlightlyLessStubbyPasswordManagerDriver(client_.get()));
195 dispatcher_.reset(new TestCredentialManagerDispatcher( 207 cm_service_impl_.reset(new TestCredentialManagerImpl(
196 web_contents(), client_.get(), stub_driver_.get())); 208 web_contents(), client_.get(), stub_driver_.get()));
209
Anand Mistry (off Chromium) 2016/03/18 01:24:13 Don't introduce new whitespace unnecessarily.
leonhsl(Using Gerrit) 2016/03/18 10:02:16 Done.
197 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) 210 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage())
198 .WillByDefault(testing::Return(true)); 211 .WillByDefault(testing::Return(true));
199 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); 212 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false));
200 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) 213 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors())
201 .WillByDefault(testing::Return(false)); 214 .WillByDefault(testing::Return(false));
202 215
203 NavigateAndCommit(GURL("https://example.com/test.html")); 216 NavigateAndCommit(GURL("https://example.com/test.html"));
204 217
205 form_.username_value = base::ASCIIToUTF16("Username"); 218 form_.username_value = base::ASCIIToUTF16("Username");
206 form_.display_name = base::ASCIIToUTF16("Display Name"); 219 form_.display_name = base::ASCIIToUTF16("Display Name");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 cross_origin_form_.origin = GURL("https://example.net/"); 256 cross_origin_form_.origin = GURL("https://example.net/");
244 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); 257 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec();
245 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; 258 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML;
246 cross_origin_form_.skip_zero_click = false; 259 cross_origin_form_.skip_zero_click = false;
247 260
248 store_->Clear(); 261 store_->Clear();
249 EXPECT_TRUE(store_->IsEmpty()); 262 EXPECT_TRUE(store_->IsEmpty());
250 } 263 }
251 264
252 void TearDown() override { 265 void TearDown() override {
266 cm_service_impl_.reset();
267
253 store_->ShutdownOnUIThread(); 268 store_->ShutdownOnUIThread();
254 content::RenderViewHostTestHarness::TearDown(); 269 content::RenderViewHostTestHarness::TearDown();
255 } 270 }
256 271
257 void ExpectZeroClickSignInFailure() { 272 void ExpectZeroClickSignInFailure(bool zero_click_only,
273 bool include_passwords,
274 const std::vector<GURL>& federations) {
275 bool called = false;
276 mojom::CredentialManagerError error;
277 mojom::CredentialInfoPtr credential;
278 CallGet(zero_click_only, include_passwords, federations,
279 base::Bind(&GetCredentialCallback, &called, &error, &credential));
280
258 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 281 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
259 .Times(testing::Exactly(0)); 282 .Times(testing::Exactly(0));
260 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)) 283 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_))
261 .Times(testing::Exactly(0)); 284 .Times(testing::Exactly(0));
262 285
263 RunAllPendingTasks(); 286 RunAllPendingTasks();
264 287
265 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; 288 EXPECT_TRUE(called);
266 const IPC::Message* message = 289 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
267 process()->sink().GetFirstMessageMatching(kMsgID); 290 EXPECT_EQ(mojom::CredentialType::EMPTY, credential->type);
268 ASSERT_TRUE(message);
269 CredentialManagerMsg_SendCredential::Param send_param;
270 CredentialManagerMsg_SendCredential::Read(message, &send_param);
271
272 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY,
273 std::get<1>(send_param).type);
274 } 291 }
275 292
276 void ExpectZeroClickSignInSuccess(CredentialType type) { 293 void ExpectZeroClickSignInSuccess(bool zero_click_only,
294 bool include_passwords,
295 const std::vector<GURL>& federations,
296 mojom::CredentialType type) {
297 bool called = false;
298 mojom::CredentialManagerError error;
299 mojom::CredentialInfoPtr credential;
300 CallGet(zero_click_only, include_passwords, federations,
301 base::Bind(&GetCredentialCallback, &called, &error, &credential));
302
277 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 303 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
278 .Times(testing::Exactly(0)); 304 .Times(testing::Exactly(0));
279 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)) 305 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_))
280 .Times(testing::Exactly(1)); 306 .Times(testing::Exactly(1));
281 307
282 RunAllPendingTasks(); 308 RunAllPendingTasks();
283 309
284 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; 310 EXPECT_TRUE(called);
285 const IPC::Message* message = 311 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
286 process()->sink().GetFirstMessageMatching(kMsgID); 312 EXPECT_EQ(type, credential->type);
287 ASSERT_TRUE(message);
288 CredentialManagerMsg_SendCredential::Param send_param;
289 CredentialManagerMsg_SendCredential::Read(message, &send_param);
290
291 EXPECT_EQ(type, std::get<1>(send_param).type);
292 } 313 }
293 314
294 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } 315 void ExpectCredentialType(bool zero_click_only,
316 bool include_passwords,
317 const std::vector<GURL>& federations,
318 mojom::CredentialType type) {
319 bool called = false;
320 mojom::CredentialManagerError error;
321 mojom::CredentialInfoPtr credential;
322 CallGet(zero_click_only, include_passwords, federations,
323 base::Bind(&GetCredentialCallback, &called, &error, &credential));
324
325 RunAllPendingTasks();
326
327 EXPECT_TRUE(called);
328 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
329 EXPECT_EQ(type, credential->type);
330 }
331
332 CredentialManagerImpl* cm_service_impl() { return cm_service_impl_.get(); }
333
334 // Helpers for testing CredentialManagerImpl methods.
335 void CallStore(const CredentialInfo& info,
336 const CredentialManagerImpl::StoreCallback& callback) {
337 mojom::CredentialInfoPtr credential = mojom::CredentialInfo::From(info);
338 cm_service_impl_->Store(std::move(credential), callback);
339 }
340
341 void CallRequireUserMediation(
342 const CredentialManagerImpl::RequireUserMediationCallback& callback) {
343 cm_service_impl_->RequireUserMediation(callback);
344 }
345
346 void CallGet(bool zero_click_only,
347 bool include_passwords,
348 const std::vector<GURL>& federations,
349 const CredentialManagerImpl::GetCallback& callback) {
350 cm_service_impl_->Get(zero_click_only, include_passwords,
351 mojo::Array<mojo::String>::From(federations),
352 callback);
353 }
295 354
296 protected: 355 protected:
297 autofill::PasswordForm form_; 356 autofill::PasswordForm form_;
298 autofill::PasswordForm affiliated_form1_; 357 autofill::PasswordForm affiliated_form1_;
299 autofill::PasswordForm affiliated_form2_; 358 autofill::PasswordForm affiliated_form2_;
300 autofill::PasswordForm origin_path_form_; 359 autofill::PasswordForm origin_path_form_;
301 autofill::PasswordForm cross_origin_form_; 360 autofill::PasswordForm cross_origin_form_;
302 scoped_refptr<TestPasswordStore> store_; 361 scoped_refptr<TestPasswordStore> store_;
303 scoped_ptr<testing::NiceMock<MockPasswordManagerClient>> client_; 362 scoped_ptr<testing::NiceMock<MockPasswordManagerClient>> client_;
304 scoped_ptr<SlightlyLessStubbyPasswordManagerDriver> stub_driver_; 363 scoped_ptr<SlightlyLessStubbyPasswordManagerDriver> stub_driver_;
305 scoped_ptr<CredentialManagerDispatcher> dispatcher_; 364
365 scoped_ptr<CredentialManagerImpl> cm_service_impl_;
306 }; 366 };
307 367
308 TEST_F(CredentialManagerDispatcherTest, IsZeroClickAllowed) { 368 TEST_F(CredentialManagerImplTest, IsZeroClickAllowed) {
309 // IsZeroClickAllowed is uneffected by the first-run status. 369 // IsZeroClickAllowed is uneffected by the first-run status.
310 client_->set_zero_click_enabled(true); 370 client_->set_zero_click_enabled(true);
311 client_->set_first_run_seen(true); 371 client_->set_first_run_seen(true);
312 EXPECT_TRUE(dispatcher()->IsZeroClickAllowed()); 372 EXPECT_TRUE(cm_service_impl()->IsZeroClickAllowed());
313 373
314 client_->set_zero_click_enabled(true); 374 client_->set_zero_click_enabled(true);
315 client_->set_first_run_seen(false); 375 client_->set_first_run_seen(false);
316 EXPECT_TRUE(dispatcher()->IsZeroClickAllowed()); 376 EXPECT_TRUE(cm_service_impl()->IsZeroClickAllowed());
317 377
318 client_->set_zero_click_enabled(false); 378 client_->set_zero_click_enabled(false);
319 client_->set_first_run_seen(true); 379 client_->set_first_run_seen(true);
320 EXPECT_FALSE(dispatcher()->IsZeroClickAllowed()); 380 EXPECT_FALSE(cm_service_impl()->IsZeroClickAllowed());
321 381
322 client_->set_zero_click_enabled(false); 382 client_->set_zero_click_enabled(false);
323 client_->set_first_run_seen(false); 383 client_->set_first_run_seen(false);
324 EXPECT_FALSE(dispatcher()->IsZeroClickAllowed()); 384 EXPECT_FALSE(cm_service_impl()->IsZeroClickAllowed());
325 } 385 }
326 386
327 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnStore) { 387 TEST_F(CredentialManagerImplTest, CredentialManagerOnStore) {
328 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 388 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
329 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 389 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
330 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) 390 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
331 .Times(testing::Exactly(1)); 391 .Times(testing::Exactly(1));
332 392
333 dispatcher()->OnStore(kRequestId, info); 393 bool called = false;
334 394 CallStore(info, base::Bind(&RespondCallback, &called));
335 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID;
336 const IPC::Message* message =
337 process()->sink().GetFirstMessageMatching(kMsgID);
338 EXPECT_TRUE(message);
339 process()->sink().ClearMessages();
340 395
341 // Allow the PasswordFormManager to talk to the password store, determine 396 // Allow the PasswordFormManager to talk to the password store, determine
342 // that the form is new, and set it as pending. 397 // that the form is new, and set it as pending.
343 RunAllPendingTasks(); 398 RunAllPendingTasks();
344 399
400 EXPECT_TRUE(called);
401
345 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); 402 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching());
346 403
347 autofill::PasswordForm new_form = 404 autofill::PasswordForm new_form =
348 client_->pending_manager()->pending_credentials(); 405 client_->pending_manager()->pending_credentials();
349 EXPECT_EQ(form_.username_value, new_form.username_value); 406 EXPECT_EQ(form_.username_value, new_form.username_value);
350 EXPECT_EQ(form_.display_name, new_form.display_name); 407 EXPECT_EQ(form_.display_name, new_form.display_name);
351 EXPECT_EQ(form_.password_value, new_form.password_value); 408 EXPECT_EQ(form_.password_value, new_form.password_value);
352 EXPECT_EQ(form_.origin, new_form.origin); 409 EXPECT_EQ(form_.origin, new_form.origin);
353 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); 410 EXPECT_EQ(form_.signon_realm, new_form.signon_realm);
354 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); 411 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme);
355 } 412 }
356 413
357 TEST_F(CredentialManagerDispatcherTest, CredentialManagerStoreOverwrite) { 414 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) {
358 // Populate the PasswordStore with a form. 415 // Populate the PasswordStore with a form.
359 store_->AddLogin(form_); 416 store_->AddLogin(form_);
360 RunAllPendingTasks(); 417 RunAllPendingTasks();
361 418
362 // Calling 'OnStore' with a credential that matches |form_| should update 419 // Calling 'Store' with a credential that matches |form_| should update
363 // the password without prompting the user. 420 // the password without prompting the user.
364 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 421 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
365 info.password = base::ASCIIToUTF16("Totally new password."); 422 info.password = base::ASCIIToUTF16("Totally new password.");
366 dispatcher()->OnStore(kRequestId, info); 423 bool called = false;
424 CallStore(info, base::Bind(&RespondCallback, &called));
367 425
368 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 426 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
369 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) 427 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
370 .Times(testing::Exactly(0)); 428 .Times(testing::Exactly(0));
371 429
372 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID;
373 const IPC::Message* message =
374 process()->sink().GetFirstMessageMatching(kMsgID);
375 EXPECT_TRUE(message);
376 process()->sink().ClearMessages();
377
378 // Allow the PasswordFormManager to talk to the password store, determine 430 // Allow the PasswordFormManager to talk to the password store, determine
379 // the form is a match for an existing form, and update the PasswordStore. 431 // the form is a match for an existing form, and update the PasswordStore.
380 RunAllPendingTasks(); 432 RunAllPendingTasks();
381 433
434 EXPECT_TRUE(called);
435
382 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 436 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
383 EXPECT_EQ(1U, passwords.size()); 437 EXPECT_EQ(1U, passwords.size());
384 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 438 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
385 EXPECT_EQ(base::ASCIIToUTF16("Totally new password."), 439 EXPECT_EQ(base::ASCIIToUTF16("Totally new password."),
386 passwords[form_.signon_realm][0].password_value); 440 passwords[form_.signon_realm][0].password_value);
387 } 441 }
388 442
389 TEST_F(CredentialManagerDispatcherTest, 443 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) {
390 CredentialManagerStoreOverwriteZeroClick) {
391 // Set the global zero click flag on, and populate the PasswordStore with a 444 // Set the global zero click flag on, and populate the PasswordStore with a
392 // form that's set to skip zero click. 445 // form that's set to skip zero click.
393 client_->set_zero_click_enabled(true); 446 client_->set_zero_click_enabled(true);
394 form_.skip_zero_click = true; 447 form_.skip_zero_click = true;
395 store_->AddLogin(form_); 448 store_->AddLogin(form_);
396 RunAllPendingTasks(); 449 RunAllPendingTasks();
397 450
398 // Calling 'OnStore' with a credential that matches |form_| should update 451 // Calling 'Store' with a credential that matches |form_| should update
399 // the password without prompting the user. 452 // the password without prompting the user.
400 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 453 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
401 info.password = base::ASCIIToUTF16("Totally new password."); 454 info.password = base::ASCIIToUTF16("Totally new password.");
402 dispatcher()->OnStore(kRequestId, info); 455 bool called = false;
403 process()->sink().ClearMessages(); 456 CallStore(info, base::Bind(&RespondCallback, &called));
404 457
405 // Allow the PasswordFormManager to talk to the password store, determine 458 // Allow the PasswordFormManager to talk to the password store, determine
406 // the form is a match for an existing form, and update the PasswordStore. 459 // the form is a match for an existing form, and update the PasswordStore.
407 RunAllPendingTasks(); 460 RunAllPendingTasks();
408 461
409 // Verify that the update didn't toggle the skip_zero_click flag off. 462 // Verify that the update didn't toggle the skip_zero_click flag off.
410 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 463 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
411 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 464 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
412 } 465 }
413 466
414 TEST_F(CredentialManagerDispatcherTest, 467 TEST_F(CredentialManagerImplTest,
415 CredentialManagerSignInWithSavingDisabledForCurrentPage) { 468 CredentialManagerSignInWithSavingDisabledForCurrentPage) {
416 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); 469 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
417 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) 470 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage())
418 .WillRepeatedly(testing::Return(false)); 471 .WillRepeatedly(testing::Return(false));
419 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 472 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
420 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) 473 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
421 .Times(testing::Exactly(0)); 474 .Times(testing::Exactly(0));
422 475
423 dispatcher()->OnStore(kRequestId, info); 476 bool called = false;
424 477 CallStore(info, base::Bind(&RespondCallback, &called));
425 const uint32_t kMsgID = CredentialManagerMsg_AcknowledgeStore::ID;
426 const IPC::Message* message =
427 process()->sink().GetFirstMessageMatching(kMsgID);
428 EXPECT_TRUE(message);
429 process()->sink().ClearMessages();
430 478
431 RunAllPendingTasks(); 479 RunAllPendingTasks();
432 480
481 EXPECT_TRUE(called);
433 EXPECT_FALSE(client_->pending_manager()); 482 EXPECT_FALSE(client_->pending_manager());
434 } 483 }
435 484
436 TEST_F(CredentialManagerDispatcherTest, 485 TEST_F(CredentialManagerImplTest, CredentialManagerOnRequireUserMediation) {
437 CredentialManagerOnRequireUserMediation) {
438 store_->AddLogin(form_); 486 store_->AddLogin(form_);
439 store_->AddLogin(cross_origin_form_); 487 store_->AddLogin(cross_origin_form_);
440 RunAllPendingTasks(); 488 RunAllPendingTasks();
441 489
442 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 490 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
443 EXPECT_EQ(2U, passwords.size()); 491 EXPECT_EQ(2U, passwords.size());
444 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 492 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
445 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); 493 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size());
446 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 494 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
447 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 495 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
448 496
449 dispatcher()->OnRequireUserMediation(kRequestId); 497 bool called = false;
498 CallRequireUserMediation(base::Bind(&RespondCallback, &called));
499
450 RunAllPendingTasks(); 500 RunAllPendingTasks();
451 501
452 const uint32_t kMsgID = 502 EXPECT_TRUE(called);
453 CredentialManagerMsg_AcknowledgeRequireUserMediation::ID;
454 const IPC::Message* message =
455 process()->sink().GetFirstMessageMatching(kMsgID);
456 EXPECT_TRUE(message);
457 process()->sink().ClearMessages();
458 503
459 passwords = store_->stored_passwords(); 504 passwords = store_->stored_passwords();
460 EXPECT_EQ(2U, passwords.size()); 505 EXPECT_EQ(2U, passwords.size());
461 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 506 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
462 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); 507 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size());
463 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 508 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
464 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 509 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
465 } 510 }
466 511
467 TEST_F(CredentialManagerDispatcherTest, 512 TEST_F(CredentialManagerImplTest,
468 CredentialManagerOnRequireUserMediationIncognito) { 513 CredentialManagerOnRequireUserMediationIncognito) {
469 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); 514 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true));
470 store_->AddLogin(form_); 515 store_->AddLogin(form_);
471 RunAllPendingTasks(); 516 RunAllPendingTasks();
472 517
473 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 518 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
474 ASSERT_EQ(1U, passwords.size()); 519 ASSERT_EQ(1U, passwords.size());
475 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); 520 ASSERT_EQ(1U, passwords[form_.signon_realm].size());
476 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 521 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
477 522
478 dispatcher()->OnRequireUserMediation(kRequestId); 523 bool called = false;
524 CallRequireUserMediation(base::Bind(&RespondCallback, &called));
479 RunAllPendingTasks(); 525 RunAllPendingTasks();
480 526
481 const uint32_t kMsgID = 527 EXPECT_TRUE(called);
482 CredentialManagerMsg_AcknowledgeRequireUserMediation::ID;
483 const IPC::Message* message =
484 process()->sink().GetFirstMessageMatching(kMsgID);
485 EXPECT_TRUE(message);
486 process()->sink().ClearMessages();
487 528
488 passwords = store_->stored_passwords(); 529 passwords = store_->stored_passwords();
489 ASSERT_EQ(1U, passwords.size()); 530 ASSERT_EQ(1U, passwords.size());
490 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); 531 ASSERT_EQ(1U, passwords[form_.signon_realm].size());
491 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 532 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
492 } 533 }
493 534
494 TEST_F(CredentialManagerDispatcherTest, 535 TEST_F(CredentialManagerImplTest,
495 CredentialManagerOnRequireUserMediationWithAffiliation) { 536 CredentialManagerOnRequireUserMediationWithAffiliation) {
496 store_->AddLogin(form_); 537 store_->AddLogin(form_);
497 store_->AddLogin(cross_origin_form_); 538 store_->AddLogin(cross_origin_form_);
498 store_->AddLogin(affiliated_form1_); 539 store_->AddLogin(affiliated_form1_);
499 store_->AddLogin(affiliated_form2_); 540 store_->AddLogin(affiliated_form2_);
500 541
501 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 542 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
502 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 543 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
503 544
504 std::vector<GURL> federations; 545 std::vector<GURL> federations;
505 std::vector<std::string> affiliated_realms; 546 std::vector<std::string> affiliated_realms;
506 affiliated_realms.push_back(kTestAndroidRealm1); 547 affiliated_realms.push_back(kTestAndroidRealm1);
507 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 548 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
508 ->ExpectCallToGetAffiliatedAndroidRealms( 549 ->ExpectCallToGetAffiliatedAndroidRealms(
509 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 550 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
510 RunAllPendingTasks(); 551 RunAllPendingTasks();
511 552
512 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 553 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
513 EXPECT_EQ(4U, passwords.size()); 554 EXPECT_EQ(4U, passwords.size());
514 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 555 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
515 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 556 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
516 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); 557 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click);
517 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); 558 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click);
518 559
519 dispatcher()->OnRequireUserMediation(kRequestId); 560 bool called = false;
561 CallRequireUserMediation(base::Bind(&RespondCallback, &called));
520 RunAllPendingTasks(); 562 RunAllPendingTasks();
521 process()->sink().ClearMessages();
522 563
523 passwords = store_->stored_passwords(); 564 passwords = store_->stored_passwords();
524 EXPECT_EQ(4U, passwords.size()); 565 EXPECT_EQ(4U, passwords.size());
525 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 566 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
526 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 567 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
527 EXPECT_TRUE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); 568 EXPECT_TRUE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click);
528 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); 569 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click);
529 } 570 }
530 571
531 TEST_F(CredentialManagerDispatcherTest, 572 TEST_F(CredentialManagerImplTest,
532 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { 573 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) {
533 std::vector<GURL> federations; 574 std::vector<GURL> federations;
534 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 575 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
535 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) 576 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
536 .Times(testing::Exactly(0)); 577 .Times(testing::Exactly(0));
537 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 578 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
538 .Times(testing::Exactly(0)); 579 .Times(testing::Exactly(0));
539 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 580 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
540 581
541 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); 582 ExpectCredentialType(false, true, federations, mojom::CredentialType::EMPTY);
542
543 RunAllPendingTasks();
544
545 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID;
546 const IPC::Message* message =
547 process()->sink().GetFirstMessageMatching(kMsgID);
548 EXPECT_TRUE(message);
549 CredentialManagerMsg_SendCredential::Param param;
550 CredentialManagerMsg_SendCredential::Read(message, &param);
551 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type);
552 process()->sink().ClearMessages();
553 } 583 }
554 584
555 TEST_F(CredentialManagerDispatcherTest, 585 TEST_F(CredentialManagerImplTest,
556 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { 586 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) {
557 store_->AddLogin(cross_origin_form_); 587 store_->AddLogin(cross_origin_form_);
558 588
559 std::vector<GURL> federations; 589 std::vector<GURL> federations;
560 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 590 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
561 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) 591 _, CredentialSourceType::CREDENTIAL_SOURCE_API))
562 .Times(testing::Exactly(0)); 592 .Times(testing::Exactly(0));
563 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 593 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
564 .Times(testing::Exactly(0)); 594 .Times(testing::Exactly(0));
565 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 595 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
566 596
567 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); 597 ExpectCredentialType(false, true, federations, mojom::CredentialType::EMPTY);
568
569 RunAllPendingTasks();
570
571 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID;
572 const IPC::Message* message =
573 process()->sink().GetFirstMessageMatching(kMsgID);
574 EXPECT_TRUE(message);
575 CredentialManagerMsg_SendCredential::Param param;
576 CredentialManagerMsg_SendCredential::Read(message, &param);
577 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type);
578 process()->sink().ClearMessages();
579 } 598 }
580 599
581 TEST_F(CredentialManagerDispatcherTest, 600 TEST_F(CredentialManagerImplTest,
582 CredentialManagerOnRequestCredentialWithFullPasswordStore) { 601 CredentialManagerOnRequestCredentialWithFullPasswordStore) {
583 client_->set_zero_click_enabled(false); 602 client_->set_zero_click_enabled(false);
584 store_->AddLogin(form_); 603 store_->AddLogin(form_);
585 604
586 std::vector<GURL> federations; 605 std::vector<GURL> federations;
587 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 606 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
588 .Times(testing::Exactly(1)); 607 .Times(testing::Exactly(1));
589 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 608 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
590 609
591 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); 610 bool called = false;
611 mojom::CredentialManagerError error;
612 mojom::CredentialInfoPtr credential;
613 CallGet(false, true, federations,
614 base::Bind(&GetCredentialCallback, &called, &error, &credential));
592 615
593 RunAllPendingTasks(); 616 RunAllPendingTasks();
594 617
595 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; 618 EXPECT_TRUE(called);
596 const IPC::Message* message = 619 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
597 process()->sink().GetFirstMessageMatching(kMsgID);
598 EXPECT_TRUE(message);
599 } 620 }
600 621
601 TEST_F( 622 TEST_F(
602 CredentialManagerDispatcherTest, 623 CredentialManagerImplTest,
603 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { 624 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) {
604 std::vector<GURL> federations; 625 std::vector<GURL> federations;
605 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 626 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
606 .Times(testing::Exactly(0)); 627 .Times(testing::Exactly(0));
607 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 628 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
608 629
609 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 630 bool called = false;
631 mojom::CredentialManagerError error;
632 mojom::CredentialInfoPtr credential;
633 CallGet(true, true, federations,
634 base::Bind(&GetCredentialCallback, &called, &error, &credential));
610 635
611 RunAllPendingTasks(); 636 RunAllPendingTasks();
612 637
613 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; 638 EXPECT_TRUE(called);
614 const IPC::Message* message = 639 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
615 process()->sink().GetFirstMessageMatching(kMsgID);
616 EXPECT_TRUE(message);
617 CredentialManagerMsg_SendCredential::Param send_param;
618 CredentialManagerMsg_SendCredential::Read(message, &send_param);
619 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY,
620 std::get<1>(send_param).type);
621 } 640 }
622 641
623 TEST_F(CredentialManagerDispatcherTest, 642 TEST_F(CredentialManagerImplTest,
624 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { 643 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) {
625 store_->AddLogin(form_); 644 store_->AddLogin(form_);
626 client_->set_first_run_seen(true); 645 client_->set_first_run_seen(true);
627 646
628 std::vector<GURL> federations; 647 std::vector<GURL> federations;
629 648
630 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 649 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
631 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
632 650
633 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); 651 ExpectZeroClickSignInSuccess(true, true, federations,
652 mojom::CredentialType::PASSWORD);
634 } 653 }
635 654
636 TEST_F(CredentialManagerDispatcherTest, 655 TEST_F(CredentialManagerImplTest,
637 CredentialManagerOnRequestCredentialWithoutPasswords) { 656 CredentialManagerOnRequestCredentialWithoutPasswords) {
638 store_->AddLogin(form_); 657 store_->AddLogin(form_);
639 client_->set_first_run_seen(true); 658 client_->set_first_run_seen(true);
640 659
641 std::vector<GURL> federations; 660 std::vector<GURL> federations;
642 661
643 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 662 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
644 dispatcher()->OnRequestCredential(kRequestId, true, false, federations);
645 663
646 ExpectZeroClickSignInFailure(); 664 ExpectZeroClickSignInFailure(true, false, federations);
647 } 665 }
648 666
649 TEST_F(CredentialManagerDispatcherTest, 667 TEST_F(CredentialManagerImplTest,
650 CredentialManagerOnRequestCredentialFederatedMatch) { 668 CredentialManagerOnRequestCredentialFederatedMatch) {
651 form_.federation_origin = url::Origin(GURL("https://example.com/")); 669 form_.federation_origin = url::Origin(GURL("https://example.com/"));
652 store_->AddLogin(form_); 670 store_->AddLogin(form_);
653 client_->set_first_run_seen(true); 671 client_->set_first_run_seen(true);
654 672
655 std::vector<GURL> federations; 673 std::vector<GURL> federations;
656 federations.push_back(GURL("https://example.com/")); 674 federations.push_back(GURL("https://example.com/"));
657 675
658 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 676 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
659 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
660 677
661 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); 678 ExpectZeroClickSignInSuccess(true, true, federations,
679 mojom::CredentialType::FEDERATED);
662 } 680 }
663 681
664 TEST_F(CredentialManagerDispatcherTest, 682 TEST_F(CredentialManagerImplTest,
665 CredentialManagerOnRequestCredentialFederatedNoMatch) { 683 CredentialManagerOnRequestCredentialFederatedNoMatch) {
666 form_.federation_origin = url::Origin(GURL("https://example.com/")); 684 form_.federation_origin = url::Origin(GURL("https://example.com/"));
667 store_->AddLogin(form_); 685 store_->AddLogin(form_);
668 client_->set_first_run_seen(true); 686 client_->set_first_run_seen(true);
669 687
670 std::vector<GURL> federations; 688 std::vector<GURL> federations;
671 federations.push_back(GURL("https://not-example.com/")); 689 federations.push_back(GURL("https://not-example.com/"));
672 690
673 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 691 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
674 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
675 692
676 ExpectZeroClickSignInFailure(); 693 ExpectZeroClickSignInFailure(true, true, federations);
677 } 694 }
678 695
679 TEST_F(CredentialManagerDispatcherTest, 696 TEST_F(CredentialManagerImplTest,
680 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { 697 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) {
681 store_->AddLogin(affiliated_form1_); 698 store_->AddLogin(affiliated_form1_);
682 client_->set_first_run_seen(true); 699 client_->set_first_run_seen(true);
683 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 700 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
684 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 701 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
685 702
686 std::vector<GURL> federations; 703 std::vector<GURL> federations;
687 std::vector<std::string> affiliated_realms; 704 std::vector<std::string> affiliated_realms;
688 affiliated_realms.push_back(kTestAndroidRealm1); 705 affiliated_realms.push_back(kTestAndroidRealm1);
689 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 706 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
690 ->ExpectCallToGetAffiliatedAndroidRealms( 707 ->ExpectCallToGetAffiliatedAndroidRealms(
691 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 708 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
692 709
693 // We pass in 'true' for the 'include_passwords' argument to ensure that 710 // We pass in 'true' for the 'include_passwords' argument to ensure that
694 // password-type credentials are included as potential matches. 711 // password-type credentials are included as potential matches.
695 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 712 ExpectZeroClickSignInSuccess(true, true, federations,
696 713 mojom::CredentialType::PASSWORD);
697 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD);
698 } 714 }
699 715
700 TEST_F(CredentialManagerDispatcherTest, 716 TEST_F(CredentialManagerImplTest,
701 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { 717 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) {
702 store_->AddLogin(affiliated_form1_); 718 store_->AddLogin(affiliated_form1_);
703 client_->set_first_run_seen(true); 719 client_->set_first_run_seen(true);
704 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 720 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
705 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 721 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
706 722
707 std::vector<GURL> federations; 723 std::vector<GURL> federations;
708 std::vector<std::string> affiliated_realms; 724 std::vector<std::string> affiliated_realms;
709 affiliated_realms.push_back(kTestAndroidRealm1); 725 affiliated_realms.push_back(kTestAndroidRealm1);
710 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 726 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
711 ->ExpectCallToGetAffiliatedAndroidRealms( 727 ->ExpectCallToGetAffiliatedAndroidRealms(
712 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 728 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
713 729
714 // We pass in 'false' for the 'include_passwords' argument to ensure that 730 // We pass in 'false' for the 'include_passwords' argument to ensure that
715 // password-type credentials are excluded as potential matches. 731 // password-type credentials are excluded as potential matches.
716 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); 732 ExpectZeroClickSignInFailure(true, false, federations);
717
718 ExpectZeroClickSignInFailure();
719 } 733 }
720 734
721 TEST_F(CredentialManagerDispatcherTest, 735 TEST_F(CredentialManagerImplTest,
722 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { 736 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) {
723 affiliated_form1_.federation_origin = 737 affiliated_form1_.federation_origin =
724 url::Origin(GURL("https://example.com/")); 738 url::Origin(GURL("https://example.com/"));
725 store_->AddLogin(affiliated_form1_); 739 store_->AddLogin(affiliated_form1_);
726 client_->set_first_run_seen(true); 740 client_->set_first_run_seen(true);
727 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 741 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
728 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 742 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
729 743
730 std::vector<GURL> federations; 744 std::vector<GURL> federations;
731 federations.push_back(GURL("https://example.com/")); 745 federations.push_back(GURL("https://example.com/"));
732 746
733 std::vector<std::string> affiliated_realms; 747 std::vector<std::string> affiliated_realms;
734 affiliated_realms.push_back(kTestAndroidRealm1); 748 affiliated_realms.push_back(kTestAndroidRealm1);
735 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 749 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
736 ->ExpectCallToGetAffiliatedAndroidRealms( 750 ->ExpectCallToGetAffiliatedAndroidRealms(
737 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 751 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
738 752
739 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 753 ExpectZeroClickSignInSuccess(true, true, federations,
740 754 mojom::CredentialType::FEDERATED);
741 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED);
742 } 755 }
743 756
744 TEST_F(CredentialManagerDispatcherTest, 757 TEST_F(CredentialManagerImplTest,
745 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { 758 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) {
746 affiliated_form1_.federation_origin = 759 affiliated_form1_.federation_origin =
747 url::Origin(GURL("https://example.com/")); 760 url::Origin(GURL("https://example.com/"));
748 store_->AddLogin(affiliated_form1_); 761 store_->AddLogin(affiliated_form1_);
749 client_->set_first_run_seen(true); 762 client_->set_first_run_seen(true);
750 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 763 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
751 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 764 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
752 765
753 std::vector<GURL> federations; 766 std::vector<GURL> federations;
754 federations.push_back(GURL("https://not-example.com/")); 767 federations.push_back(GURL("https://not-example.com/"));
755 768
756 std::vector<std::string> affiliated_realms; 769 std::vector<std::string> affiliated_realms;
757 affiliated_realms.push_back(kTestAndroidRealm1); 770 affiliated_realms.push_back(kTestAndroidRealm1);
758 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 771 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
759 ->ExpectCallToGetAffiliatedAndroidRealms( 772 ->ExpectCallToGetAffiliatedAndroidRealms(
760 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 773 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
761 774
762 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 775 ExpectZeroClickSignInFailure(true, true, federations);
763
764 ExpectZeroClickSignInFailure();
765 } 776 }
766 777
767 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithoutFirstRun) { 778 TEST_F(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) {
768 client_->set_first_run_seen(false); 779 client_->set_first_run_seen(false);
769 780
770 store_->AddLogin(form_); 781 store_->AddLogin(form_);
771 782
772 std::vector<GURL> federations; 783 std::vector<GURL> federations;
773 EXPECT_CALL(*client_, 784 EXPECT_CALL(*client_,
774 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) 785 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_)))
775 .Times(1); 786 .Times(1);
776 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
777 787
778 ExpectZeroClickSignInFailure(); 788 ExpectZeroClickSignInFailure(true, true, federations);
779 } 789 }
780 790
781 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithFirstRunAndSkip) { 791 TEST_F(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) {
782 client_->set_first_run_seen(true); 792 client_->set_first_run_seen(true);
783 793
784 form_.skip_zero_click = true; 794 form_.skip_zero_click = true;
785 store_->AddLogin(form_); 795 store_->AddLogin(form_);
786 796
787 std::vector<GURL> federations; 797 std::vector<GURL> federations;
788 EXPECT_CALL(*client_, 798 EXPECT_CALL(*client_,
789 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) 799 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_)))
790 .Times(1); 800 .Times(1);
791 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
792 801
793 ExpectZeroClickSignInFailure(); 802 ExpectZeroClickSignInFailure(true, true, federations);
794 } 803 }
795 804
796 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithTLSErrors) { 805 TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) {
797 // If we encounter TLS errors, we won't return credentials. 806 // If we encounter TLS errors, we won't return credentials.
798 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) 807 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors())
799 .WillRepeatedly(testing::Return(true)); 808 .WillRepeatedly(testing::Return(true));
800 809
801 store_->AddLogin(form_); 810 store_->AddLogin(form_);
802 811
803 std::vector<GURL> federations; 812 std::vector<GURL> federations;
804 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
805 813
806 ExpectZeroClickSignInFailure(); 814 ExpectZeroClickSignInFailure(true, true, federations);
807 } 815 }
808 816
809 TEST_F(CredentialManagerDispatcherTest, 817 TEST_F(CredentialManagerImplTest,
810 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { 818 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) {
811 store_->AddLogin(form_); 819 store_->AddLogin(form_);
812 store_->AddLogin(origin_path_form_); 820 store_->AddLogin(origin_path_form_);
813 821
814 std::vector<GURL> federations; 822 std::vector<GURL> federations;
815 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 823 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
816 .Times(testing::Exactly(0)); 824 .Times(testing::Exactly(0));
817 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 825 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
818 826
819 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
820
821 RunAllPendingTasks();
822
823 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID;
824 const IPC::Message* message =
825 process()->sink().GetFirstMessageMatching(kMsgID);
826 EXPECT_TRUE(message);
827 CredentialManagerMsg_SendCredential::Param send_param;
828 CredentialManagerMsg_SendCredential::Read(message, &send_param);
829
830 // With two items in the password store, we shouldn't get credentials back. 827 // With two items in the password store, we shouldn't get credentials back.
831 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, 828 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY);
832 std::get<1>(send_param).type);
833 } 829 }
834 830
835 TEST_F(CredentialManagerDispatcherTest, 831 TEST_F(CredentialManagerImplTest,
836 OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) { 832 OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) {
837 form_.skip_zero_click = true; 833 form_.skip_zero_click = true;
838 store_->AddLogin(form_); 834 store_->AddLogin(form_);
839 store_->AddLogin(origin_path_form_); 835 store_->AddLogin(origin_path_form_);
840 836
841 std::vector<GURL> federations; 837 std::vector<GURL> federations;
842 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 838 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
843 .Times(testing::Exactly(0)); 839 .Times(testing::Exactly(0));
844 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 840 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
845 841
846 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
847
848 RunAllPendingTasks();
849
850 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID;
851 const IPC::Message* message =
852 process()->sink().GetFirstMessageMatching(kMsgID);
853 EXPECT_TRUE(message);
854 CredentialManagerMsg_SendCredential::Param send_param;
855 CredentialManagerMsg_SendCredential::Read(message, &send_param);
856
857 // With two items in the password store, we shouldn't get credentials back, 842 // With two items in the password store, we shouldn't get credentials back,
858 // even though only one item has |skip_zero_click| set |false|. 843 // even though only one item has |skip_zero_click| set |false|.
859 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, 844 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY);
860 std::get<1>(send_param).type);
861 } 845 }
862 846
863 TEST_F(CredentialManagerDispatcherTest, 847 TEST_F(CredentialManagerImplTest,
864 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { 848 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) {
865 store_->AddLogin(cross_origin_form_); 849 store_->AddLogin(cross_origin_form_);
866 850
867 form_.skip_zero_click = true; 851 form_.skip_zero_click = true;
868 store_->AddLogin(form_); 852 store_->AddLogin(form_);
869 853
870 std::vector<GURL> federations; 854 std::vector<GURL> federations;
871 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 855 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
872 .Times(testing::Exactly(0)); 856 .Times(testing::Exactly(0));
873 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 857 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
874 858
875 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
876
877 RunAllPendingTasks();
878
879 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID;
880 const IPC::Message* message =
881 process()->sink().GetFirstMessageMatching(kMsgID);
882 EXPECT_TRUE(message);
883 CredentialManagerMsg_SendCredential::Param send_param;
884 CredentialManagerMsg_SendCredential::Read(message, &send_param);
885
886 // We only have cross-origin zero-click credentials; they should not be 859 // We only have cross-origin zero-click credentials; they should not be
887 // returned. 860 // returned.
888 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, 861 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY);
889 std::get<1>(send_param).type);
890 } 862 }
891 863
892 TEST_F(CredentialManagerDispatcherTest, 864 TEST_F(CredentialManagerImplTest,
893 CredentialManagerOnRequestCredentialWhileRequestPending) { 865 CredentialManagerOnRequestCredentialWhileRequestPending) {
894 client_->set_zero_click_enabled(false); 866 client_->set_zero_click_enabled(false);
895 store_->AddLogin(form_); 867 store_->AddLogin(form_);
896 868
897 std::vector<GURL> federations; 869 std::vector<GURL> federations;
898 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 870 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
899 .Times(testing::Exactly(0)); 871 .Times(testing::Exactly(0));
900 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 872 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
901 873
902 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); 874 // 1st request.
903 dispatcher()->OnRequestCredential(kRequestId + 1, false, true, federations); 875 bool called_1 = false;
876 mojom::CredentialManagerError error_1;
877 mojom::CredentialInfoPtr credential_1;
878 CallGet(
879 false, true, federations,
880 base::Bind(&GetCredentialCallback, &called_1, &error_1, &credential_1));
881 // 2nd request.
882 bool called_2 = false;
883 mojom::CredentialManagerError error_2;
884 mojom::CredentialInfoPtr credential_2;
885 CallGet(
886 false, true, federations,
887 base::Bind(&GetCredentialCallback, &called_2, &error_2, &credential_2));
904 888
905 // Check that the second request triggered a rejection.
906 uint32_t kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID;
907 const IPC::Message* message =
908 process()->sink().GetFirstMessageMatching(kMsgID);
909 EXPECT_TRUE(message);
910
911 CredentialManagerMsg_RejectCredentialRequest::Param reject_param;
912 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param);
913 EXPECT_EQ(blink::WebCredentialManagerPendingRequestError,
914 std::get<1>(reject_param));
915 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 889 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
916 .Times(testing::Exactly(1)); 890 .Times(testing::Exactly(1));
917 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 891 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
918 892
919 process()->sink().ClearMessages();
920
921 // Execute the PasswordStore asynchronousness. 893 // Execute the PasswordStore asynchronousness.
922 RunAllPendingTasks(); 894 RunAllPendingTasks();
923 895
896 // Check that the second request triggered a rejection.
897 EXPECT_TRUE(called_2);
898 EXPECT_EQ(mojom::CredentialManagerError::PENDINGREQUEST, error_2);
899 EXPECT_TRUE(credential_2.is_null());
900
924 // Check that the first request resolves. 901 // Check that the first request resolves.
925 kMsgID = CredentialManagerMsg_SendCredential::ID; 902 EXPECT_TRUE(called_1);
926 message = process()->sink().GetFirstMessageMatching(kMsgID); 903 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error_1);
927 EXPECT_TRUE(message); 904 EXPECT_NE(mojom::CredentialType::EMPTY, credential_1->type);
928 CredentialManagerMsg_SendCredential::Param send_param;
929 CredentialManagerMsg_SendCredential::Read(message, &send_param);
930 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY,
931 std::get<1>(send_param).type);
932 process()->sink().ClearMessages();
933 } 905 }
934 906
935 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) { 907 TEST_F(CredentialManagerImplTest, ResetSkipZeroClickAfterPrompt) {
936 // Turn on the global zero-click flag, and add two credentials in separate 908 // Turn on the global zero-click flag, and add two credentials in separate
937 // origins, both set to skip zero-click. 909 // origins, both set to skip zero-click.
938 client_->set_zero_click_enabled(true); 910 client_->set_zero_click_enabled(true);
939 form_.skip_zero_click = true; 911 form_.skip_zero_click = true;
940 store_->AddLogin(form_); 912 store_->AddLogin(form_);
941 cross_origin_form_.skip_zero_click = true; 913 cross_origin_form_.skip_zero_click = true;
942 store_->AddLogin(cross_origin_form_); 914 store_->AddLogin(cross_origin_form_);
943 915
944 // Execute the PasswordStore asynchronousness to ensure everything is 916 // Execute the PasswordStore asynchronousness to ensure everything is
945 // written before proceeding. 917 // written before proceeding.
(...skipping 12 matching lines...) Expand all
958 std::vector<GURL> federations; 930 std::vector<GURL> federations;
959 // Check that the form in the database has been updated. `OnRequestCredential` 931 // Check that the form in the database has been updated. `OnRequestCredential`
960 // generates a call to prompt the user to choose a credential. 932 // generates a call to prompt the user to choose a credential.
961 // MockPasswordManagerClient mocks a user choice, and when users choose a 933 // MockPasswordManagerClient mocks a user choice, and when users choose a
962 // credential (and have the global zero-click flag enabled), we make sure that 934 // credential (and have the global zero-click flag enabled), we make sure that
963 // they'll be logged in again next time. 935 // they'll be logged in again next time.
964 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 936 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
965 .Times(testing::Exactly(1)); 937 .Times(testing::Exactly(1));
966 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 938 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
967 939
968 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); 940 bool called = false;
941 mojom::CredentialManagerError error;
942 mojom::CredentialInfoPtr credential;
943 CallGet(false, true, federations,
944 base::Bind(&GetCredentialCallback, &called, &error, &credential));
945
969 RunAllPendingTasks(); 946 RunAllPendingTasks();
970 947
971 passwords = store_->stored_passwords(); 948 passwords = store_->stored_passwords();
972 EXPECT_EQ(2U, passwords.size()); 949 EXPECT_EQ(2U, passwords.size());
973 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 950 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
974 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); 951 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size());
975 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 952 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
976 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 953 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
977 } 954 }
978 955
979 TEST_F(CredentialManagerDispatcherTest, 956 TEST_F(CredentialManagerImplTest, NoResetSkipZeroClickAfterPromptInIncognito) {
980 NoResetSkipZeroClickAfterPromptInIncognito) {
981 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); 957 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true));
982 // Turn on the global zero-click flag which should be overriden by Incognito. 958 // Turn on the global zero-click flag which should be overriden by Incognito.
983 client_->set_zero_click_enabled(true); 959 client_->set_zero_click_enabled(true);
984 form_.skip_zero_click = true; 960 form_.skip_zero_click = true;
985 store_->AddLogin(form_); 961 store_->AddLogin(form_);
986 RunAllPendingTasks(); 962 RunAllPendingTasks();
987 963
988 // Sanity check. 964 // Sanity check.
989 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 965 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
990 ASSERT_EQ(1U, passwords.size()); 966 ASSERT_EQ(1U, passwords.size());
991 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); 967 ASSERT_EQ(1U, passwords[form_.signon_realm].size());
992 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 968 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
993 969
994 // Trigger a request which should return the credential found in |form_|, and 970 // Trigger a request which should return the credential found in |form_|, and
995 // wait for it to process. 971 // wait for it to process.
996 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 972 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
997 .Times(testing::Exactly(1)); 973 .Times(testing::Exactly(1));
998 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 974 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
999 975
1000 dispatcher()->OnRequestCredential(kRequestId, false, true, 976 bool called = false;
1001 std::vector<GURL>()); 977 mojom::CredentialManagerError error;
978 mojom::CredentialInfoPtr credential;
979 CallGet(false, true, std::vector<GURL>(),
980 base::Bind(&GetCredentialCallback, &called, &error, &credential));
981
1002 RunAllPendingTasks(); 982 RunAllPendingTasks();
1003 983
1004 // The form shouldn't become a zero-click one. 984 // The form shouldn't become a zero-click one.
1005 passwords = store_->stored_passwords(); 985 passwords = store_->stored_passwords();
1006 ASSERT_EQ(1U, passwords.size()); 986 ASSERT_EQ(1U, passwords.size());
1007 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); 987 ASSERT_EQ(1U, passwords[form_.signon_realm].size());
1008 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 988 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
1009 } 989 }
1010 990
1011 TEST_F(CredentialManagerDispatcherTest, IncognitoZeroClickRequestCredential) { 991 TEST_F(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) {
1012 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); 992 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true));
1013 store_->AddLogin(form_); 993 store_->AddLogin(form_);
1014 994
1015 std::vector<GURL> federations; 995 std::vector<GURL> federations;
1016 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 996 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
1017 .Times(testing::Exactly(0)); 997 .Times(testing::Exactly(0));
1018 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 998 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
1019 999
1020 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 1000 ExpectCredentialType(true, true, federations, mojom::CredentialType::EMPTY);
1021
1022 RunAllPendingTasks();
1023
1024 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID;
1025 const IPC::Message* message =
1026 process()->sink().GetFirstMessageMatching(kMsgID);
1027 ASSERT_TRUE(message);
1028 CredentialManagerMsg_SendCredential::Param param;
1029 CredentialManagerMsg_SendCredential::Read(message, &param);
1030 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type);
1031 } 1001 }
1032 1002
1033 TEST_F(CredentialManagerDispatcherTest, 1003 TEST_F(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) {
1034 ZeroClickWithAffiliatedFormInPasswordStore) {
1035 // Insert the affiliated form into the store, and mock out the association 1004 // Insert the affiliated form into the store, and mock out the association
1036 // with the current origin. As it's the only form matching the origin, it 1005 // with the current origin. As it's the only form matching the origin, it
1037 // ought to be returned automagically. 1006 // ought to be returned automagically.
1038 store_->AddLogin(affiliated_form1_); 1007 store_->AddLogin(affiliated_form1_);
1039 1008
1040 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 1009 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
1041 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1010 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1042 1011
1043 std::vector<GURL> federations; 1012 std::vector<GURL> federations;
1044 std::vector<std::string> affiliated_realms; 1013 std::vector<std::string> affiliated_realms;
1045 affiliated_realms.push_back(kTestAndroidRealm1); 1014 affiliated_realms.push_back(kTestAndroidRealm1);
1046 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1015 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1047 ->ExpectCallToGetAffiliatedAndroidRealms( 1016 ->ExpectCallToGetAffiliatedAndroidRealms(
1048 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 1017 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1049 1018
1050 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 1019 ExpectZeroClickSignInSuccess(true, true, federations,
1051 1020 mojom::CredentialType::PASSWORD);
1052 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD);
1053 } 1021 }
1054 1022
1055 TEST_F(CredentialManagerDispatcherTest, 1023 TEST_F(CredentialManagerImplTest,
1056 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { 1024 ZeroClickWithTwoAffiliatedFormsInPasswordStore) {
1057 // Insert two affiliated forms into the store, and mock out the association 1025 // Insert two affiliated forms into the store, and mock out the association
1058 // with the current origin. Multiple forms === no zero-click sign in. 1026 // with the current origin. Multiple forms === no zero-click sign in.
1059 store_->AddLogin(affiliated_form1_); 1027 store_->AddLogin(affiliated_form1_);
1060 store_->AddLogin(affiliated_form2_); 1028 store_->AddLogin(affiliated_form2_);
1061 1029
1062 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 1030 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
1063 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1031 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1064 1032
1065 std::vector<GURL> federations; 1033 std::vector<GURL> federations;
1066 std::vector<std::string> affiliated_realms; 1034 std::vector<std::string> affiliated_realms;
1067 affiliated_realms.push_back(kTestAndroidRealm1); 1035 affiliated_realms.push_back(kTestAndroidRealm1);
1068 affiliated_realms.push_back(kTestAndroidRealm2); 1036 affiliated_realms.push_back(kTestAndroidRealm2);
1069 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1037 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1070 ->ExpectCallToGetAffiliatedAndroidRealms( 1038 ->ExpectCallToGetAffiliatedAndroidRealms(
1071 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 1039 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1072 1040
1073 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 1041 ExpectZeroClickSignInFailure(true, true, federations);
1074
1075 ExpectZeroClickSignInFailure();
1076 } 1042 }
1077 1043
1078 TEST_F(CredentialManagerDispatcherTest, 1044 TEST_F(CredentialManagerImplTest,
1079 ZeroClickWithUnaffiliatedFormsInPasswordStore) { 1045 ZeroClickWithUnaffiliatedFormsInPasswordStore) {
1080 // Insert the affiliated form into the store, but don't mock out the 1046 // Insert the affiliated form into the store, but don't mock out the
1081 // association with the current origin. No association === no zero-click sign 1047 // association with the current origin. No association === no zero-click sign
1082 // in. 1048 // in.
1083 store_->AddLogin(affiliated_form1_); 1049 store_->AddLogin(affiliated_form1_);
1084 1050
1085 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 1051 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
1086 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1052 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1087 1053
1088 std::vector<GURL> federations; 1054 std::vector<GURL> federations;
1089 std::vector<std::string> affiliated_realms; 1055 std::vector<std::string> affiliated_realms;
1090 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1056 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1091 ->ExpectCallToGetAffiliatedAndroidRealms( 1057 ->ExpectCallToGetAffiliatedAndroidRealms(
1092 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 1058 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1093 1059
1094 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 1060 ExpectZeroClickSignInFailure(true, true, federations);
1095
1096 ExpectZeroClickSignInFailure();
1097 } 1061 }
1098 1062
1099 TEST_F(CredentialManagerDispatcherTest, 1063 TEST_F(CredentialManagerImplTest,
1100 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { 1064 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) {
1101 // Insert the affiliated form into the store, along with a real form for the 1065 // Insert the affiliated form into the store, along with a real form for the
1102 // origin, and don't mock out the association with the current origin. No 1066 // origin, and don't mock out the association with the current origin. No
1103 // association + existing form === zero-click sign in. 1067 // association + existing form === zero-click sign in.
1104 store_->AddLogin(form_); 1068 store_->AddLogin(form_);
1105 store_->AddLogin(affiliated_form1_); 1069 store_->AddLogin(affiliated_form1_);
1106 1070
1107 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 1071 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
1108 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1072 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1109 1073
1110 std::vector<GURL> federations; 1074 std::vector<GURL> federations;
1111 std::vector<std::string> affiliated_realms; 1075 std::vector<std::string> affiliated_realms;
1112 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1076 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1113 ->ExpectCallToGetAffiliatedAndroidRealms( 1077 ->ExpectCallToGetAffiliatedAndroidRealms(
1114 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); 1078 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1115 1079
1116 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 1080 ExpectZeroClickSignInSuccess(true, true, federations,
1117 1081 mojom::CredentialType::PASSWORD);
1118 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD);
1119 } 1082 }
1120 1083
1121 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { 1084 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) {
1122 autofill::PasswordForm synthesized = 1085 autofill::PasswordForm synthesized =
1123 dispatcher_->GetSynthesizedFormForOrigin(); 1086 cm_service_impl_->GetSynthesizedFormForOrigin();
1124 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); 1087 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec());
1125 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); 1088 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm);
1126 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); 1089 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme);
1127 EXPECT_TRUE(synthesized.ssl_valid); 1090 EXPECT_TRUE(synthesized.ssl_valid);
1128 } 1091 }
1129 1092
1130 } // namespace password_manager 1093 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698