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

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

Issue 2478043002: HTTP Bad: Add warning message to autofill dropdown for http sites (Closed)
Patch Set: add test to AutofillManagerTest 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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "components/autofill/core/browser/test_autofill_external_delegate.h" 42 #include "components/autofill/core/browser/test_autofill_external_delegate.h"
43 #include "components/autofill/core/browser/validation.h" 43 #include "components/autofill/core/browser/validation.h"
44 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 44 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
45 #include "components/autofill/core/common/autofill_pref_names.h" 45 #include "components/autofill/core/common/autofill_pref_names.h"
46 #include "components/autofill/core/common/autofill_switches.h" 46 #include "components/autofill/core/common/autofill_switches.h"
47 #include "components/autofill/core/common/autofill_util.h" 47 #include "components/autofill/core/common/autofill_util.h"
48 #include "components/autofill/core/common/form_data.h" 48 #include "components/autofill/core/common/form_data.h"
49 #include "components/autofill/core/common/form_field_data.h" 49 #include "components/autofill/core/common/form_field_data.h"
50 #include "components/prefs/pref_service.h" 50 #include "components/prefs/pref_service.h"
51 #include "components/rappor/test_rappor_service.h" 51 #include "components/rappor/test_rappor_service.h"
52 #include "components/security_state/switches.h"
52 #include "components/variations/variations_associated_data.h" 53 #include "components/variations/variations_associated_data.h"
53 #include "grit/components_strings.h" 54 #include "grit/components_strings.h"
54 #include "net/url_request/url_request_test_util.h" 55 #include "net/url_request/url_request_test_util.h"
55 #include "testing/gmock/include/gmock/gmock.h" 56 #include "testing/gmock/include/gmock/gmock.h"
56 #include "testing/gtest/include/gtest/gtest.h" 57 #include "testing/gtest/include/gtest/gtest.h"
57 #include "ui/base/l10n/l10n_util.h" 58 #include "ui/base/l10n/l10n_util.h"
58 #include "ui/gfx/geometry/rect.h" 59 #include "ui/gfx/geometry/rect.h"
59 #include "url/gurl.h" 60 #include "url/gurl.h"
60 61
61 using base::ASCIIToUTF16; 62 using base::ASCIIToUTF16;
(...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), 1595 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
1595 "", "", -1)); 1596 "", "", -1));
1596 1597
1597 // Clear the test credit cards and try again -- we shouldn't return a warning. 1598 // Clear the test credit cards and try again -- we shouldn't return a warning.
1598 personal_data_.ClearCreditCards(); 1599 personal_data_.ClearCreditCards();
1599 GetAutofillSuggestions(form, field); 1600 GetAutofillSuggestions(form, field);
1600 // Autocomplete suggestions are queried, but not Autofill. 1601 // Autocomplete suggestions are queried, but not Autofill.
1601 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); 1602 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
1602 } 1603 }
1603 1604
1605 // Test that we return an extra "Payment not secure" warning when the page and
1606 // the form target URL are not secure.
1607 TEST_F(AutofillManagerTest,
1608 GetCreditCardSuggestions_NonSecureContextWithHttpBadSwitchOn) {
1609 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1610 security_state::switches::kMarkHttpAs,
1611 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
1612
1613 // Set up our form data.
1614 FormData form;
1615 CreateTestCreditCardFormData(&form, /* is_https */ false, false);
1616 std::vector<FormData> forms(1, form);
1617 FormsSeen(forms);
1618
1619 const FormFieldData& field = form.fields[0];
1620 GetAutofillSuggestions(form, field);
1621
1622 // Test that we sent the right values to the external delegate.
1623 external_delegate_->CheckSuggestions(
1624 kDefaultPageID,
1625 Suggestion(l10n_util::GetStringUTF8(
1626 IDS_AUTOFILL_CREDIT_CARD_HTTP_WARNING_MESSAGE),
1627 "", "", -1),
1628 Suggestion(
1629 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION),
1630 "", "", -1));
1631
1632 // Clear the test credit cards and try again -- we shouldn't return a warning.
1633 personal_data_.ClearCreditCards();
1634 GetAutofillSuggestions(form, field);
1635 // Autocomplete suggestions are queried, but not Autofill.
1636 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen());
1637 }
1638
1639 // Test that we don't show the extra "Payment not secure" warning when the page
1640 // and the form target URL are secure, even when the switch is on.
1641 TEST_F(AutofillManagerTest,
1642 GetCreditCardSuggestions_SecureContextWithHttpBadSwitchOn) {
1643 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1644 security_state::switches::kMarkHttpAs,
1645 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
1646
1647 // Set up our form data.
1648 FormData form;
1649 CreateTestCreditCardFormData(&form, /* is_https */ true, false);
1650 std::vector<FormData> forms(1, form);
1651 FormsSeen(forms);
1652
1653 FormFieldData field = form.fields[1];
1654 GetAutofillSuggestions(form, field);
1655
1656 // Test that we sent the right values to the external delegate.
1657 external_delegate_->CheckSuggestions(
1658 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF"
1659 "3456",
1660 "04/99", kVisaCard,
1661 autofill_manager_->GetPackedCreditCardID(4)),
1662 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF"
1663 "8765",
1664 "10/98", kMasterCard,
1665 autofill_manager_->GetPackedCreditCardID(5)));
1666 }
1667
1604 // Test that we will eventually return the credit card signin promo when there 1668 // 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 1669 // are no credit card suggestions and the promo is active. See the tests in
1606 // AutofillExternalDelegateTest that test whether the promo is added. 1670 // AutofillExternalDelegateTest that test whether the promo is added.
1607 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { 1671 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) {
1608 // Enable the signin promo feature with no impression limit. 1672 // Enable the signin promo feature with no impression limit.
1609 EnableCreditCardSigninPromoFeatureWithLimit(0); 1673 EnableCreditCardSigninPromoFeatureWithLimit(0);
1610 1674
1611 // Make sure there are no credit cards. 1675 // Make sure there are no credit cards.
1612 personal_data_.ClearCreditCards(); 1676 personal_data_.ClearCreditCards();
1613 1677
(...skipping 3779 matching lines...) Expand 10 before | Expand all | Expand 10 after
5393 5457
5394 // The driver should always be notified. 5458 // The driver should always be notified.
5395 for (const FormFieldData& field : form.fields) { 5459 for (const FormFieldData& field : form.fields) {
5396 GetAutofillSuggestions(form, field); 5460 GetAutofillSuggestions(form, field);
5397 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); 5461 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form());
5398 autofill_driver_->ClearDidInteractWithCreditCardForm(); 5462 autofill_driver_->ClearDidInteractWithCreditCardForm();
5399 } 5463 }
5400 } 5464 }
5401 5465
5402 } // namespace autofill 5466 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698