Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 return manager; | 1004 return manager; |
| 1004 } | 1005 } |
| 1005 | 1006 |
| 1006 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate. | 1007 // Convenience method to cast the FullCardRequest into a CardUnmaskDelegate. |
| 1007 CardUnmaskDelegate* full_card_unmask_delegate() { | 1008 CardUnmaskDelegate* full_card_unmask_delegate() { |
| 1008 DCHECK(autofill_manager_->full_card_request_); | 1009 DCHECK(autofill_manager_->full_card_request_); |
| 1009 return static_cast<CardUnmaskDelegate*>( | 1010 return static_cast<CardUnmaskDelegate*>( |
| 1010 autofill_manager_->full_card_request_.get()); | 1011 autofill_manager_->full_card_request_.get()); |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1014 void set_http_warning_enabled() { | |
|
Mathieu
2016/11/08 17:26:17
Use CamelCaseNaming()
lshang
2016/11/08 23:39:06
Done.
| |
| 1015 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 1016 security_state::switches::kMarkHttpAs, | |
| 1017 security_state::switches:: | |
| 1018 kMarkHttpWithPasswordsOrCcWithChipAndFormWarning); | |
| 1019 } | |
| 1020 | |
| 1013 protected: | 1021 protected: |
| 1014 base::MessageLoop message_loop_; | 1022 base::MessageLoop message_loop_; |
| 1015 MockAutofillClient autofill_client_; | 1023 MockAutofillClient autofill_client_; |
| 1016 std::unique_ptr<MockAutofillDriver> autofill_driver_; | 1024 std::unique_ptr<MockAutofillDriver> autofill_driver_; |
| 1017 std::unique_ptr<TestAutofillManager> autofill_manager_; | 1025 std::unique_ptr<TestAutofillManager> autofill_manager_; |
| 1018 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; | 1026 std::unique_ptr<TestAutofillExternalDelegate> external_delegate_; |
| 1019 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 1027 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
| 1020 TestPaymentsClient* payments_client_; | 1028 TestPaymentsClient* payments_client_; |
| 1021 TestAutofillDownloadManager* download_manager_; | 1029 TestAutofillDownloadManager* download_manager_; |
| 1022 TestPersonalDataManager personal_data_; | 1030 TestPersonalDataManager personal_data_; |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1594 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | 1602 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), |
| 1595 "", "", -1)); | 1603 "", "", -1)); |
| 1596 | 1604 |
| 1597 // Clear the test credit cards and try again -- we shouldn't return a warning. | 1605 // Clear the test credit cards and try again -- we shouldn't return a warning. |
| 1598 personal_data_.ClearCreditCards(); | 1606 personal_data_.ClearCreditCards(); |
| 1599 GetAutofillSuggestions(form, field); | 1607 GetAutofillSuggestions(form, field); |
| 1600 // Autocomplete suggestions are queried, but not Autofill. | 1608 // Autocomplete suggestions are queried, but not Autofill. |
| 1601 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | 1609 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| 1602 } | 1610 } |
| 1603 | 1611 |
| 1612 // Test that we return an extra "Payment not secure" warning when the page and | |
| 1613 // the form target URL are not secure. | |
| 1614 TEST_F(AutofillManagerTest, | |
| 1615 GetCreditCardSuggestions_NonSecureContextWithHttpBadSwitchOn) { | |
| 1616 set_http_warning_enabled(); | |
| 1617 | |
| 1618 // Set up our form data. | |
|
Mathieu
2016/11/08 17:26:17
indent is off here
lshang
2016/11/08 23:39:06
Done. Don't know why this weird indent happens, pr
| |
| 1619 FormData form; | |
| 1620 CreateTestCreditCardFormData(&form, /* is_https */ false, false); | |
| 1621 std::vector<FormData> forms(1, form); | |
| 1622 FormsSeen(forms); | |
| 1623 | |
| 1624 const FormFieldData& field = form.fields[0]; | |
| 1625 GetAutofillSuggestions(form, field); | |
| 1626 | |
| 1627 // Test that we sent the right values to the external delegate. | |
| 1628 external_delegate_->CheckSuggestions( | |
| 1629 kDefaultPageID, | |
| 1630 Suggestion(l10n_util::GetStringUTF8( | |
| 1631 IDS_AUTOFILL_CREDIT_CARD_HTTP_WARNING_MESSAGE), | |
| 1632 "", "", -1), | |
| 1633 Suggestion( | |
| 1634 l10n_util::GetStringUTF8(IDS_AUTOFILL_WARNING_INSECURE_CONNECTION), | |
| 1635 "", "", -1)); | |
| 1636 | |
| 1637 // Clear the test credit cards and try again -- we shouldn't return a warning. | |
| 1638 personal_data_.ClearCreditCards(); | |
| 1639 GetAutofillSuggestions(form, field); | |
| 1640 // Autocomplete suggestions are queried, but not Autofill. | |
| 1641 EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); | |
| 1642 } | |
| 1643 | |
| 1644 // Test that we don't show the extra "Payment not secure" warning when the page | |
| 1645 // and the form target URL are secure, even when the switch is on. | |
| 1646 TEST_F(AutofillManagerTest, | |
| 1647 GetCreditCardSuggestions_SecureContextWithHttpBadSwitchOn) { | |
| 1648 set_http_warning_enabled(); | |
| 1649 | |
| 1650 // Set up our form data. | |
| 1651 FormData form; | |
| 1652 CreateTestCreditCardFormData(&form, /* is_https */ true, false); | |
| 1653 std::vector<FormData> forms(1, form); | |
| 1654 FormsSeen(forms); | |
| 1655 | |
| 1656 FormFieldData field = form.fields[1]; | |
| 1657 GetAutofillSuggestions(form, field); | |
| 1658 | |
| 1659 // Test that we sent the right values to the external delegate. | |
| 1660 external_delegate_->CheckSuggestions( | |
| 1661 kDefaultPageID, Suggestion("Visa\xC2\xA0\xE2\x8B\xAF" | |
| 1662 "3456", | |
| 1663 "04/99", kVisaCard, | |
| 1664 autofill_manager_->GetPackedCreditCardID(4)), | |
| 1665 Suggestion("MasterCard\xC2\xA0\xE2\x8B\xAF" | |
| 1666 "8765", | |
| 1667 "10/98", kMasterCard, | |
| 1668 autofill_manager_->GetPackedCreditCardID(5))); | |
| 1669 } | |
| 1670 | |
| 1604 // Test that we will eventually return the credit card signin promo when there | 1671 // 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 | 1672 // are no credit card suggestions and the promo is active. See the tests in |
| 1606 // AutofillExternalDelegateTest that test whether the promo is added. | 1673 // AutofillExternalDelegateTest that test whether the promo is added. |
| 1607 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { | 1674 TEST_F(AutofillManagerTest, GetCreditCardSuggestions_OnlySigninPromo) { |
| 1608 // Enable the signin promo feature with no impression limit. | 1675 // Enable the signin promo feature with no impression limit. |
| 1609 EnableCreditCardSigninPromoFeatureWithLimit(0); | 1676 EnableCreditCardSigninPromoFeatureWithLimit(0); |
| 1610 | 1677 |
| 1611 // Make sure there are no credit cards. | 1678 // Make sure there are no credit cards. |
| 1612 personal_data_.ClearCreditCards(); | 1679 personal_data_.ClearCreditCards(); |
| 1613 | 1680 |
| (...skipping 3779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5393 | 5460 |
| 5394 // The driver should always be notified. | 5461 // The driver should always be notified. |
| 5395 for (const FormFieldData& field : form.fields) { | 5462 for (const FormFieldData& field : form.fields) { |
| 5396 GetAutofillSuggestions(form, field); | 5463 GetAutofillSuggestions(form, field); |
| 5397 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); | 5464 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); |
| 5398 autofill_driver_->ClearDidInteractWithCreditCardForm(); | 5465 autofill_driver_->ClearDidInteractWithCreditCardForm(); |
| 5399 } | 5466 } |
| 5400 } | 5467 } |
| 5401 | 5468 |
| 5402 } // namespace autofill | 5469 } // namespace autofill |
| OLD | NEW |