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

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

Issue 1159553007: Move Tuple to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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_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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 dispatcher()->OnRequestCredential(kRequestId, false, federations); 326 dispatcher()->OnRequestCredential(kRequestId, false, federations);
327 327
328 RunAllPendingTasks(); 328 RunAllPendingTasks();
329 329
330 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 330 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
331 const IPC::Message* message = 331 const IPC::Message* message =
332 process()->sink().GetFirstMessageMatching(kMsgID); 332 process()->sink().GetFirstMessageMatching(kMsgID);
333 EXPECT_TRUE(message); 333 EXPECT_TRUE(message);
334 CredentialManagerMsg_SendCredential::Param param; 334 CredentialManagerMsg_SendCredential::Param param;
335 CredentialManagerMsg_SendCredential::Read(message, &param); 335 CredentialManagerMsg_SendCredential::Read(message, &param);
336 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); 336 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type);
337 process()->sink().ClearMessages(); 337 process()->sink().ClearMessages();
338 } 338 }
339 339
340 TEST_F(CredentialManagerDispatcherTest, 340 TEST_F(CredentialManagerDispatcherTest,
341 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { 341 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) {
342 store_->AddLogin(cross_origin_form_); 342 store_->AddLogin(cross_origin_form_);
343 343
344 std::vector<GURL> federations; 344 std::vector<GURL> federations;
345 EXPECT_CALL( 345 EXPECT_CALL(
346 *client_, 346 *client_,
347 PromptUserToSavePasswordPtr( 347 PromptUserToSavePasswordPtr(
348 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) 348 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API))
349 .Times(testing::Exactly(0)); 349 .Times(testing::Exactly(0));
350 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 350 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
351 .Times(testing::Exactly(0)); 351 .Times(testing::Exactly(0));
352 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 352 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
353 353
354 dispatcher()->OnRequestCredential(kRequestId, false, federations); 354 dispatcher()->OnRequestCredential(kRequestId, false, federations);
355 355
356 RunAllPendingTasks(); 356 RunAllPendingTasks();
357 357
358 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 358 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
359 const IPC::Message* message = 359 const IPC::Message* message =
360 process()->sink().GetFirstMessageMatching(kMsgID); 360 process()->sink().GetFirstMessageMatching(kMsgID);
361 EXPECT_TRUE(message); 361 EXPECT_TRUE(message);
362 CredentialManagerMsg_SendCredential::Param param; 362 CredentialManagerMsg_SendCredential::Param param;
363 CredentialManagerMsg_SendCredential::Read(message, &param); 363 CredentialManagerMsg_SendCredential::Read(message, &param);
364 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); 364 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type);
365 process()->sink().ClearMessages(); 365 process()->sink().ClearMessages();
366 } 366 }
367 367
368 TEST_F(CredentialManagerDispatcherTest, 368 TEST_F(CredentialManagerDispatcherTest,
369 CredentialManagerOnRequestCredentialWithFullPasswordStore) { 369 CredentialManagerOnRequestCredentialWithFullPasswordStore) {
370 client_->set_zero_click_enabled(false); 370 client_->set_zero_click_enabled(false);
371 store_->AddLogin(form_); 371 store_->AddLogin(form_);
372 372
373 std::vector<GURL> federations; 373 std::vector<GURL> federations;
374 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 374 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
(...skipping 21 matching lines...) Expand all
396 dispatcher()->OnRequestCredential(kRequestId, true, federations); 396 dispatcher()->OnRequestCredential(kRequestId, true, federations);
397 397
398 RunAllPendingTasks(); 398 RunAllPendingTasks();
399 399
400 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 400 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
401 const IPC::Message* message = 401 const IPC::Message* message =
402 process()->sink().GetFirstMessageMatching(kMsgID); 402 process()->sink().GetFirstMessageMatching(kMsgID);
403 EXPECT_TRUE(message); 403 EXPECT_TRUE(message);
404 CredentialManagerMsg_SendCredential::Param send_param; 404 CredentialManagerMsg_SendCredential::Param send_param;
405 CredentialManagerMsg_SendCredential::Read(message, &send_param); 405 CredentialManagerMsg_SendCredential::Read(message, &send_param);
406 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); 406 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY,
407 base::get<1>(send_param).type);
407 } 408 }
408 409
409 TEST_F(CredentialManagerDispatcherTest, 410 TEST_F(CredentialManagerDispatcherTest,
410 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { 411 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) {
411 store_->AddLogin(form_); 412 store_->AddLogin(form_);
412 413
413 std::vector<GURL> federations; 414 std::vector<GURL> federations;
414 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 415 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
415 .Times(testing::Exactly(0)); 416 .Times(testing::Exactly(0));
416 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(1)); 417 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(1));
417 418
418 dispatcher()->OnRequestCredential(kRequestId, true, federations); 419 dispatcher()->OnRequestCredential(kRequestId, true, federations);
419 420
420 RunAllPendingTasks(); 421 RunAllPendingTasks();
421 422
422 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 423 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
423 const IPC::Message* message = 424 const IPC::Message* message =
424 process()->sink().GetFirstMessageMatching(kMsgID); 425 process()->sink().GetFirstMessageMatching(kMsgID);
425 EXPECT_TRUE(message); 426 EXPECT_TRUE(message);
426 CredentialManagerMsg_SendCredential::Param send_param; 427 CredentialManagerMsg_SendCredential::Param send_param;
427 CredentialManagerMsg_SendCredential::Read(message, &send_param); 428 CredentialManagerMsg_SendCredential::Read(message, &send_param);
428 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); 429 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL,
430 base::get<1>(send_param).type);
429 } 431 }
430 432
431 TEST_F(CredentialManagerDispatcherTest, 433 TEST_F(CredentialManagerDispatcherTest,
432 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { 434 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) {
433 store_->AddLogin(form_); 435 store_->AddLogin(form_);
434 store_->AddLogin(origin_path_form_); 436 store_->AddLogin(origin_path_form_);
435 437
436 std::vector<GURL> federations; 438 std::vector<GURL> federations;
437 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 439 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
438 .Times(testing::Exactly(0)); 440 .Times(testing::Exactly(0));
439 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 441 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
440 442
441 dispatcher()->OnRequestCredential(kRequestId, true, federations); 443 dispatcher()->OnRequestCredential(kRequestId, true, federations);
442 444
443 RunAllPendingTasks(); 445 RunAllPendingTasks();
444 446
445 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 447 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
446 const IPC::Message* message = 448 const IPC::Message* message =
447 process()->sink().GetFirstMessageMatching(kMsgID); 449 process()->sink().GetFirstMessageMatching(kMsgID);
448 EXPECT_TRUE(message); 450 EXPECT_TRUE(message);
449 CredentialManagerMsg_SendCredential::Param send_param; 451 CredentialManagerMsg_SendCredential::Param send_param;
450 CredentialManagerMsg_SendCredential::Read(message, &send_param); 452 CredentialManagerMsg_SendCredential::Read(message, &send_param);
451 453
452 // With two items in the password store, we shouldn't get credentials back. 454 // With two items in the password store, we shouldn't get credentials back.
453 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); 455 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY,
456 base::get<1>(send_param).type);
454 } 457 }
455 458
456 TEST_F(CredentialManagerDispatcherTest, 459 TEST_F(CredentialManagerDispatcherTest,
457 OnRequestCredentialWithZeroClickOnlyOnePasswordStore) { 460 OnRequestCredentialWithZeroClickOnlyOnePasswordStore) {
458 form_.skip_zero_click = true; 461 form_.skip_zero_click = true;
459 store_->AddLogin(form_); 462 store_->AddLogin(form_);
460 store_->AddLogin(origin_path_form_); 463 store_->AddLogin(origin_path_form_);
461 464
462 std::vector<GURL> federations; 465 std::vector<GURL> federations;
463 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 466 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
464 .Times(testing::Exactly(0)); 467 .Times(testing::Exactly(0));
465 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(1)); 468 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(1));
466 469
467 dispatcher()->OnRequestCredential(kRequestId, true, federations); 470 dispatcher()->OnRequestCredential(kRequestId, true, federations);
468 471
469 RunAllPendingTasks(); 472 RunAllPendingTasks();
470 473
471 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 474 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
472 const IPC::Message* message = 475 const IPC::Message* message =
473 process()->sink().GetFirstMessageMatching(kMsgID); 476 process()->sink().GetFirstMessageMatching(kMsgID);
474 EXPECT_TRUE(message); 477 EXPECT_TRUE(message);
475 CredentialManagerMsg_SendCredential::Param send_param; 478 CredentialManagerMsg_SendCredential::Param send_param;
476 CredentialManagerMsg_SendCredential::Read(message, &send_param); 479 CredentialManagerMsg_SendCredential::Read(message, &send_param);
477 480
478 // We should get |origin_path_form_| back, as |form_| is marked as skipping 481 // We should get |origin_path_form_| back, as |form_| is marked as skipping
479 // zero-click. 482 // zero-click.
480 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); 483 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL,
481 EXPECT_EQ(origin_path_form_.username_value, get<1>(send_param).id); 484 base::get<1>(send_param).type);
482 EXPECT_EQ(origin_path_form_.display_name, get<1>(send_param).name); 485 EXPECT_EQ(origin_path_form_.username_value, base::get<1>(send_param).id);
483 EXPECT_EQ(origin_path_form_.password_value, get<1>(send_param).password); 486 EXPECT_EQ(origin_path_form_.display_name, base::get<1>(send_param).name);
487 EXPECT_EQ(origin_path_form_.password_value,
488 base::get<1>(send_param).password);
484 } 489 }
485 490
486 TEST_F(CredentialManagerDispatcherTest, 491 TEST_F(CredentialManagerDispatcherTest,
487 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { 492 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) {
488 store_->AddLogin(cross_origin_form_); 493 store_->AddLogin(cross_origin_form_);
489 494
490 form_.skip_zero_click = true; 495 form_.skip_zero_click = true;
491 store_->AddLogin(form_); 496 store_->AddLogin(form_);
492 497
493 std::vector<GURL> federations; 498 std::vector<GURL> federations;
494 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 499 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
495 .Times(testing::Exactly(0)); 500 .Times(testing::Exactly(0));
496 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 501 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
497 502
498 dispatcher()->OnRequestCredential(kRequestId, true, federations); 503 dispatcher()->OnRequestCredential(kRequestId, true, federations);
499 504
500 RunAllPendingTasks(); 505 RunAllPendingTasks();
501 506
502 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 507 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
503 const IPC::Message* message = 508 const IPC::Message* message =
504 process()->sink().GetFirstMessageMatching(kMsgID); 509 process()->sink().GetFirstMessageMatching(kMsgID);
505 EXPECT_TRUE(message); 510 EXPECT_TRUE(message);
506 CredentialManagerMsg_SendCredential::Param send_param; 511 CredentialManagerMsg_SendCredential::Param send_param;
507 CredentialManagerMsg_SendCredential::Read(message, &send_param); 512 CredentialManagerMsg_SendCredential::Read(message, &send_param);
508 513
509 // We only have cross-origin zero-click credentials; they should not be 514 // We only have cross-origin zero-click credentials; they should not be
510 // returned. 515 // returned.
511 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); 516 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY,
517 base::get<1>(send_param).type);
512 } 518 }
513 519
514 TEST_F(CredentialManagerDispatcherTest, 520 TEST_F(CredentialManagerDispatcherTest,
515 CredentialManagerOnRequestCredentialWhileRequestPending) { 521 CredentialManagerOnRequestCredentialWhileRequestPending) {
516 client_->set_zero_click_enabled(false); 522 client_->set_zero_click_enabled(false);
517 store_->AddLogin(form_); 523 store_->AddLogin(form_);
518 524
519 std::vector<GURL> federations; 525 std::vector<GURL> federations;
520 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 526 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
521 .Times(testing::Exactly(0)); 527 .Times(testing::Exactly(0));
522 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 528 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
523 529
524 dispatcher()->OnRequestCredential(kRequestId, false, federations); 530 dispatcher()->OnRequestCredential(kRequestId, false, federations);
525 dispatcher()->OnRequestCredential(kRequestId, false, federations); 531 dispatcher()->OnRequestCredential(kRequestId, false, federations);
526 532
527 // Check that the second request triggered a rejection. 533 // Check that the second request triggered a rejection.
528 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; 534 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID;
529 const IPC::Message* message = 535 const IPC::Message* message =
530 process()->sink().GetFirstMessageMatching(kMsgID); 536 process()->sink().GetFirstMessageMatching(kMsgID);
531 EXPECT_TRUE(message); 537 EXPECT_TRUE(message);
532 538
533 CredentialManagerMsg_RejectCredentialRequest::Param reject_param; 539 CredentialManagerMsg_RejectCredentialRequest::Param reject_param;
534 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param); 540 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param);
535 EXPECT_EQ(blink::WebCredentialManagerError::ErrorTypePendingRequest, 541 EXPECT_EQ(blink::WebCredentialManagerError::ErrorTypePendingRequest,
536 get<1>(reject_param)); 542 base::get<1>(reject_param));
537 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 543 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
538 .Times(testing::Exactly(1)); 544 .Times(testing::Exactly(1));
539 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); 545 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0));
540 546
541 process()->sink().ClearMessages(); 547 process()->sink().ClearMessages();
542 548
543 // Execute the PasswordStore asynchronousness. 549 // Execute the PasswordStore asynchronousness.
544 RunAllPendingTasks(); 550 RunAllPendingTasks();
545 551
546 // Check that the first request resolves. 552 // Check that the first request resolves.
547 kMsgID = CredentialManagerMsg_SendCredential::ID; 553 kMsgID = CredentialManagerMsg_SendCredential::ID;
548 message = process()->sink().GetFirstMessageMatching(kMsgID); 554 message = process()->sink().GetFirstMessageMatching(kMsgID);
549 EXPECT_TRUE(message); 555 EXPECT_TRUE(message);
550 CredentialManagerMsg_SendCredential::Param send_param; 556 CredentialManagerMsg_SendCredential::Param send_param;
551 CredentialManagerMsg_SendCredential::Read(message, &send_param); 557 CredentialManagerMsg_SendCredential::Read(message, &send_param);
552 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); 558 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY,
559 base::get<1>(send_param).type);
553 process()->sink().ClearMessages(); 560 process()->sink().ClearMessages();
554 } 561 }
555 562
556 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) { 563 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) {
557 // Turn on the global zero-click flag, and add two credentials in separate 564 // Turn on the global zero-click flag, and add two credentials in separate
558 // origins, both set to skip zero-click. 565 // origins, both set to skip zero-click.
559 client_->set_zero_click_enabled(true); 566 client_->set_zero_click_enabled(true);
560 form_.skip_zero_click = true; 567 form_.skip_zero_click = true;
561 store_->AddLogin(form_); 568 store_->AddLogin(form_);
562 cross_origin_form_.skip_zero_click = true; 569 cross_origin_form_.skip_zero_click = true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 dispatcher()->OnRequestCredential(kRequestId, true, federations); 616 dispatcher()->OnRequestCredential(kRequestId, true, federations);
610 617
611 RunAllPendingTasks(); 618 RunAllPendingTasks();
612 619
613 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 620 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
614 const IPC::Message* message = 621 const IPC::Message* message =
615 process()->sink().GetFirstMessageMatching(kMsgID); 622 process()->sink().GetFirstMessageMatching(kMsgID);
616 ASSERT_TRUE(message); 623 ASSERT_TRUE(message);
617 CredentialManagerMsg_SendCredential::Param param; 624 CredentialManagerMsg_SendCredential::Param param;
618 CredentialManagerMsg_SendCredential::Read(message, &param); 625 CredentialManagerMsg_SendCredential::Read(message, &param);
619 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); 626 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type);
620 } 627 }
621 628
622 } // namespace password_manager 629 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698