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

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 2478013004: [Merge M55] [Autofill] Credit card signin promo: do not require a local suggestion (Closed)
Patch Set: Created 4 years, 1 month 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/autofill/core/browser/autofill_manager.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "testing/gmock/include/gmock/gmock.h" 54 #include "testing/gmock/include/gmock/gmock.h"
55 #include "testing/gtest/include/gtest/gtest.h" 55 #include "testing/gtest/include/gtest/gtest.h"
56 #include "ui/base/l10n/l10n_util.h" 56 #include "ui/base/l10n/l10n_util.h"
57 #include "ui/gfx/geometry/rect.h" 57 #include "ui/gfx/geometry/rect.h"
58 #include "url/gurl.h" 58 #include "url/gurl.h"
59 59
60 using base::ASCIIToUTF16; 60 using base::ASCIIToUTF16;
61 using base::UTF8ToUTF16; 61 using base::UTF8ToUTF16;
62 using testing::_; 62 using testing::_;
63 using testing::AtLeast; 63 using testing::AtLeast;
64 using testing::Return;
64 using testing::SaveArg; 65 using testing::SaveArg;
65 66
66 namespace autofill { 67 namespace autofill {
67 68
68 namespace { 69 namespace {
69 70
70 const int kDefaultPageID = 137; 71 const int kDefaultPageID = 137;
71 72
72 class MockAutofillClient : public TestAutofillClient { 73 class MockAutofillClient : public TestAutofillClient {
73 public: 74 public:
(...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), 1573 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
1573 "", "", -1)); 1574 "", "", -1));
1574 1575
1575 // Clear the test credit cards and try again -- we shouldn't return a warning. 1576 // Clear the test credit cards and try again -- we shouldn't return a warning.
1576 personal_data_.ClearCreditCards(); 1577 personal_data_.ClearCreditCards();
1577 GetAutofillSuggestions(form, field); 1578 GetAutofillSuggestions(form, field);
1578 // Autocomplete suggestions are queried, but not Autofill. 1579 // Autocomplete suggestions are queried, but not Autofill.
1579 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 1580 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
1580 } 1581 }
1581 1582
1583 // Test that we will eventually return the credit card signin promo when there
1584 // are no credit card suggestions and the promo is active. See the tests in
1585 // AutofillExternalDelegateTest that test whether the promo is added.
1586 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) {
1587 // Enable the signin promo feature with no impression limit.
1588 EnableCreditCardSigninPromoFeatureWithLimit(0);
1589
1590 // Make sure there are no credit cards.
1591 personal_data_.ClearCreditCards();
1592
1593 // Set up our form data.
1594 FormData form;
1595 CreateTestCreditCardFormData(&form, true, false);
1596 std::vector<FormData> forms(1, form);
1597 FormsSeen(forms);
1598 FormFieldData field = form.fields[1];
1599
1600 ON_CALL(autofill_client_, ShouldShowSigninPromo())
1601 .WillByDefault(Return(true));
1602 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo()).Times(2);
1603 EXPECT_TRUE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field));
1604
1605 // Autocomplete suggestions are not queried.
1606 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager();
1607 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0);
1608
1609 GetAutofillSuggestions(form, field);
1610
1611 // Test that we sent no values to the external delegate. It will add the promo
1612 // before passing along the results.
1613 external_delegate_->CheckNoSuggestions(kDefaultPageID);
1614
1615 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
1616 }
1617
1582 // Test that we return all credit card suggestions in the case that two cards 1618 // Test that we return all credit card suggestions in the case that two cards
1583 // have the same obfuscated number. 1619 // have the same obfuscated number.
1584 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) { 1620 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_RepeatedObfuscatedNumber) {
1585 // Add a credit card with the same obfuscated number as Elvis's. 1621 // Add a credit card with the same obfuscated number as Elvis's.
1586 // |credit_card| will be owned by the mock PersonalDataManager. 1622 // |credit_card| will be owned by the mock PersonalDataManager.
1587 CreditCard* credit_card = new CreditCard; 1623 CreditCard* credit_card = new CreditCard;
1588 test::SetCreditCardInfo(credit_card, "Elvis Presley", 1624 test::SetCreditCardInfo(credit_card, "Elvis Presley",
1589 "5231567890123456", // Mastercard 1625 "5231567890123456", // Mastercard
1590 "05", "2999"); 1626 "05", "2999");
1591 credit_card->set_guid("00000000-0000-0000-0000-000000000007"); 1627 credit_card->set_guid("00000000-0000-0000-0000-000000000007");
(...skipping 3622 matching lines...) Expand 10 before | Expand all | Expand 10 after
5214 FormsSeen(mixed_forms); 5250 FormsSeen(mixed_forms);
5215 5251
5216 // Suggestions should always be displayed. 5252 // Suggestions should always be displayed.
5217 for (const FormFieldData& field : mixed_form.fields) { 5253 for (const FormFieldData& field : mixed_form.fields) {
5218 GetAutofillSuggestions(mixed_form, field); 5254 GetAutofillSuggestions(mixed_form, field);
5219 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); 5255 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
5220 } 5256 }
5221 } 5257 }
5222 5258
5223 } // namespace autofill 5259 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698