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

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

Issue 2473493002: [Autofill] Credit card signin promo: do not require a local suggestion first. (Closed)
Patch Set: added test 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #include "testing/gmock/include/gmock/gmock.h" 55 #include "testing/gmock/include/gmock/gmock.h"
56 #include "testing/gtest/include/gtest/gtest.h" 56 #include "testing/gtest/include/gtest/gtest.h"
57 #include "ui/base/l10n/l10n_util.h" 57 #include "ui/base/l10n/l10n_util.h"
58 #include "ui/gfx/geometry/rect.h" 58 #include "ui/gfx/geometry/rect.h"
59 #include "url/gurl.h" 59 #include "url/gurl.h"
60 60
61 using base::ASCIIToUTF16; 61 using base::ASCIIToUTF16;
62 using base::UTF8ToUTF16; 62 using base::UTF8ToUTF16;
63 using testing::_; 63 using testing::_;
64 using testing::AtLeast; 64 using testing::AtLeast;
65 using testing::Return;
65 using testing::SaveArg; 66 using testing::SaveArg;
66 67
67 namespace autofill { 68 namespace autofill {
68 69
69 namespace { 70 namespace {
70 71
71 const int kDefaultPageID = 137; 72 const int kDefaultPageID = 137;
72 73
73 class MockAutofillClient : public TestAutofillClient { 74 class MockAutofillClient : public TestAutofillClient {
74 public: 75 public:
(...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), 1594 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
1594 "", "", -1)); 1595 "", "", -1));
1595 1596
1596 // Clear the test credit cards and try again -- we shouldn't return a warning. 1597 // Clear the test credit cards and try again -- we shouldn't return a warning.
1597 personal_data_.ClearCreditCards(); 1598 personal_data_.ClearCreditCards();
1598 GetAutofillSuggestions(form, field); 1599 GetAutofillSuggestions(form, field);
1599 // Autocomplete suggestions are queried, but not Autofill. 1600 // Autocomplete suggestions are queried, but not Autofill.
1600 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 1601 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
1601 } 1602 }
1602 1603
1604 // Test that we will eventually return the credit card signin promo when there
1605 // are no credit card suggestions and the promo is active. See the tests in
1606 // AutofillExternalDelegateTest that test whether the promo is added.
1607 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) {
1608 // Enable the signin promo feature with no impression limit.
1609 EnableCreditCardSigninPromoFeatureWithLimit(0);
1610
1611 // Make sure there are no credit cards.
1612 personal_data_.ClearCreditCards();
1613
1614 // Set up our form data.
1615 FormData form;
1616 CreateTestCreditCardFormData(&form, true, false);
1617 std::vector<FormData> forms(1, form);
1618 FormsSeen(forms);
1619 FormFieldData field = form.fields[1];
1620
1621 ON_CALL(autofill_client_, ShouldShowSigninPromo())
1622 .WillByDefault(Return(true));
1623 EXPECT_CALL(autofill_client_, ShouldShowSigninPromo()).Times(2);
1624 EXPECT_TRUE(autofill_manager_->ShouldShowCreditCardSigninPromo(form, field));
1625
1626 // Autocomplete suggestions are not queried.
1627 MockAutocompleteHistoryManager* m = RecreateMockAutocompleteHistoryManager();
1628 EXPECT_CALL(*m, OnGetAutocompleteSuggestions(_, _, _, _)).Times(0);
1629
1630 GetAutofillSuggestions(form, field);
1631
1632 // Test that we sent no values to the external delegate. It will add the promo
1633 // before passing along the results.
1634 external_delegate_->CheckNoSuggestions(kDefaultPageID);
1635
1636 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen());
1637 }
1638
1603 // Test that we return a warning explaining that credit card profile suggestions 1639 // Test that we return a warning explaining that credit card profile suggestions
1604 // are unavailable when the page is secure, but the form action URL is valid but 1640 // are unavailable when the page is secure, but the form action URL is valid but
1605 // not secure. 1641 // not secure.
1606 TEST_F(AutofillManagerTest, 1642 TEST_F(AutofillManagerTest,
1607 GetCreditCardSuggestions_SecureContext_FormActionNotHTTPS) { 1643 GetCreditCardSuggestions_SecureContext_FormActionNotHTTPS) {
1608 // Set up our form data. 1644 // Set up our form data.
1609 FormData form; 1645 FormData form;
1610 CreateTestCreditCardFormData(&form, /* is_https= */ true, false); 1646 CreateTestCreditCardFormData(&form, /* is_https= */ true, false);
1611 // However we set the action (target URL) to be HTTP after all. 1647 // However we set the action (target URL) to be HTTP after all.
1612 form.action = GURL("http://myform.com/submit.html"); 1648 form.action = GURL("http://myform.com/submit.html");
(...skipping 3743 matching lines...) Expand 10 before | Expand all | Expand 10 after
5356 5392
5357 // The driver should always be notified. 5393 // The driver should always be notified.
5358 for (const FormFieldData& field : form.fields) { 5394 for (const FormFieldData& field : form.fields) {
5359 GetAutofillSuggestions(form, field); 5395 GetAutofillSuggestions(form, field);
5360 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); 5396 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form());
5361 autofill_driver_->ClearDidInteractWithCreditCardForm(); 5397 autofill_driver_->ClearDidInteractWithCreditCardForm();
5362 } 5398 }
5363 } 5399 }
5364 5400
5365 } // namespace autofill 5401 } // 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