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

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

Issue 896803003: Credential Manager: Respect the 'skip_zero_click' flag for 'request()'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rename
Patch Set: Created 5 years, 10 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
« no previous file with comments | « components/password_manager/content/browser/credential_manager_dispatcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_dispatc her.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 web_contents(), client_.get(), &stub_driver_)); 160 web_contents(), client_.get(), &stub_driver_));
161 161
162 NavigateAndCommit(GURL("https://example.com/test.html")); 162 NavigateAndCommit(GURL("https://example.com/test.html"));
163 163
164 form_.username_value = base::ASCIIToUTF16("Username"); 164 form_.username_value = base::ASCIIToUTF16("Username");
165 form_.display_name = base::ASCIIToUTF16("Display Name"); 165 form_.display_name = base::ASCIIToUTF16("Display Name");
166 form_.password_value = base::ASCIIToUTF16("Password"); 166 form_.password_value = base::ASCIIToUTF16("Password");
167 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); 167 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin();
168 form_.signon_realm = form_.origin.spec(); 168 form_.signon_realm = form_.origin.spec();
169 form_.scheme = autofill::PasswordForm::SCHEME_HTML; 169 form_.scheme = autofill::PasswordForm::SCHEME_HTML;
170 form_.skip_zero_click = false;
170 171
171 form2_.username_value = base::ASCIIToUTF16("Username 2"); 172 form2_.username_value = base::ASCIIToUTF16("Username 2");
172 form2_.display_name = base::ASCIIToUTF16("Display Name 2"); 173 form2_.display_name = base::ASCIIToUTF16("Display Name 2");
173 form2_.password_value = base::ASCIIToUTF16("Password 2"); 174 form2_.password_value = base::ASCIIToUTF16("Password 2");
174 form2_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); 175 form2_.origin = web_contents()->GetLastCommittedURL().GetOrigin();
175 form2_.signon_realm = form_.origin.spec(); 176 form2_.signon_realm = form2_.origin.spec();
176 form2_.scheme = autofill::PasswordForm::SCHEME_HTML; 177 form2_.scheme = autofill::PasswordForm::SCHEME_HTML;
178 form2_.skip_zero_click = false;
177 179
178 cross_origin_form_.username_value = base::ASCIIToUTF16("Username"); 180 cross_origin_form_.username_value = base::ASCIIToUTF16("Username");
179 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name"); 181 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name");
180 cross_origin_form_.password_value = base::ASCIIToUTF16("Password"); 182 cross_origin_form_.password_value = base::ASCIIToUTF16("Password");
181 cross_origin_form_.origin = GURL("https://example.net/"); 183 cross_origin_form_.origin = GURL("https://example.net/");
182 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); 184 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec();
183 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; 185 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML;
186 cross_origin_form_.skip_zero_click = false;
184 187
185 store_->Clear(); 188 store_->Clear();
186 EXPECT_TRUE(store_->IsEmpty()); 189 EXPECT_TRUE(store_->IsEmpty());
187 } 190 }
188 191
189 void TearDown() override { 192 void TearDown() override {
190 store_->Shutdown(); 193 store_->Shutdown();
191 content::RenderViewHostTestHarness::TearDown(); 194 content::RenderViewHostTestHarness::TearDown();
192 } 195 }
193 196
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 EXPECT_TRUE(message); 400 EXPECT_TRUE(message);
398 EXPECT_FALSE(client_->did_prompt_user_to_choose()); 401 EXPECT_FALSE(client_->did_prompt_user_to_choose());
399 CredentialManagerMsg_SendCredential::Param send_param; 402 CredentialManagerMsg_SendCredential::Param send_param;
400 CredentialManagerMsg_SendCredential::Read(message, &send_param); 403 CredentialManagerMsg_SendCredential::Read(message, &send_param);
401 404
402 // With two items in the password store, we shouldn't get credentials back. 405 // With two items in the password store, we shouldn't get credentials back.
403 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); 406 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type);
404 } 407 }
405 408
406 TEST_F(CredentialManagerDispatcherTest, 409 TEST_F(CredentialManagerDispatcherTest,
410 OnRequestCredentialWithZeroClickOnlyOnePasswordStore) {
411 form_.skip_zero_click = true;
412 store_->AddLogin(form_);
413 store_->AddLogin(form2_);
414
415 std::vector<GURL> federations;
416 dispatcher()->OnRequestCredential(kRequestId, true, federations);
417
418 RunAllPendingTasks();
419
420 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
421 const IPC::Message* message =
422 process()->sink().GetFirstMessageMatching(kMsgID);
423 EXPECT_TRUE(message);
424 EXPECT_FALSE(client_->did_prompt_user_to_choose());
425 CredentialManagerMsg_SendCredential::Param send_param;
426 CredentialManagerMsg_SendCredential::Read(message, &send_param);
427
428 // We should get |form_| back, as |form2_| is marked as skipping zero-click.
vasilii 2015/02/09 10:44:07 Actually |form_| is marked as skipping zero-click.
Mike West 2015/02/09 10:51:49 Good eye, thanks!
429 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type);
vabr (Chromium) 2015/02/09 10:31:13 Should you also check, e.g., the .name field to ve
vasilii 2015/02/09 10:44:07 Acknowledged.
Mike West 2015/02/09 10:51:49 Done.
430 }
431
432 TEST_F(CredentialManagerDispatcherTest,
433 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) {
434 store_->AddLogin(cross_origin_form_);
435
436 form_.skip_zero_click = true;
437 store_->AddLogin(form_);
438
439 std::vector<GURL> federations;
440 dispatcher()->OnRequestCredential(kRequestId, true, federations);
441
442 RunAllPendingTasks();
443
444 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
445 const IPC::Message* message =
446 process()->sink().GetFirstMessageMatching(kMsgID);
447 EXPECT_TRUE(message);
448 EXPECT_FALSE(client_->did_prompt_user_to_choose());
449 CredentialManagerMsg_SendCredential::Param send_param;
450 CredentialManagerMsg_SendCredential::Read(message, &send_param);
451
452 // We only have cross-origin zero-click credentials; they should not be
453 // returned.
454 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type);
455 }
456
457 TEST_F(CredentialManagerDispatcherTest,
407 CredentialManagerOnRequestCredentialWhileRequestPending) { 458 CredentialManagerOnRequestCredentialWhileRequestPending) {
408 client_->set_zero_click_enabled(false); 459 client_->set_zero_click_enabled(false);
409 store_->AddLogin(form_); 460 store_->AddLogin(form_);
410 461
411 std::vector<GURL> federations; 462 std::vector<GURL> federations;
412 dispatcher()->OnRequestCredential(kRequestId, false, federations); 463 dispatcher()->OnRequestCredential(kRequestId, false, federations);
413 dispatcher()->OnRequestCredential(kRequestId, false, federations); 464 dispatcher()->OnRequestCredential(kRequestId, false, federations);
414 465
415 // Check that the second request triggered a rejection. 466 // Check that the second request triggered a rejection.
416 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; 467 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 const IPC::Message* message = 503 const IPC::Message* message =
453 process()->sink().GetFirstMessageMatching(kMsgID); 504 process()->sink().GetFirstMessageMatching(kMsgID);
454 ASSERT_TRUE(message); 505 ASSERT_TRUE(message);
455 CredentialManagerMsg_SendCredential::Param param; 506 CredentialManagerMsg_SendCredential::Param param;
456 CredentialManagerMsg_SendCredential::Read(message, &param); 507 CredentialManagerMsg_SendCredential::Read(message, &param);
457 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); 508 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type);
458 EXPECT_FALSE(client_->did_prompt_user_to_choose()); 509 EXPECT_FALSE(client_->did_prompt_user_to_choose());
459 } 510 }
460 511
461 } // namespace password_manager 512 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/password_manager/content/browser/credential_manager_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698