| 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> |
| 11 #include <utility> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/feature_list.h" | 15 #include "base/feature_list.h" |
| 15 #include "base/format_macros.h" | 16 #include "base/format_macros.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/scoped_vector.h" | 20 #include "base/memory/scoped_vector.h" |
| 20 #include "base/metrics/field_trial.h" | 21 #include "base/metrics/field_trial.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 45 #include "components/autofill/core/common/autofill_pref_names.h" | 46 #include "components/autofill/core/common/autofill_pref_names.h" |
| 46 #include "components/autofill/core/common/autofill_switches.h" | 47 #include "components/autofill/core/common/autofill_switches.h" |
| 47 #include "components/autofill/core/common/autofill_util.h" | 48 #include "components/autofill/core/common/autofill_util.h" |
| 48 #include "components/autofill/core/common/form_data.h" | 49 #include "components/autofill/core/common/form_data.h" |
| 49 #include "components/autofill/core/common/form_field_data.h" | 50 #include "components/autofill/core/common/form_field_data.h" |
| 50 #include "components/prefs/pref_service.h" | 51 #include "components/prefs/pref_service.h" |
| 51 #include "components/rappor/test_rappor_service.h" | 52 #include "components/rappor/test_rappor_service.h" |
| 52 #include "components/security_state/core/security_state.h" | 53 #include "components/security_state/core/security_state.h" |
| 53 #include "components/strings/grit/components_strings.h" | 54 #include "components/strings/grit/components_strings.h" |
| 54 #include "components/variations/variations_associated_data.h" | 55 #include "components/variations/variations_associated_data.h" |
| 56 #include "net/base/url_util.h" |
| 55 #include "net/url_request/url_request_test_util.h" | 57 #include "net/url_request/url_request_test_util.h" |
| 56 #include "testing/gmock/include/gmock/gmock.h" | 58 #include "testing/gmock/include/gmock/gmock.h" |
| 57 #include "testing/gtest/include/gtest/gtest.h" | 59 #include "testing/gtest/include/gtest/gtest.h" |
| 58 #include "ui/base/l10n/l10n_util.h" | 60 #include "ui/base/l10n/l10n_util.h" |
| 59 #include "ui/gfx/geometry/rect.h" | 61 #include "ui/gfx/geometry/rect.h" |
| 60 #include "url/gurl.h" | 62 #include "url/gurl.h" |
| 61 | 63 |
| 62 using base::ASCIIToUTF16; | 64 using base::ASCIIToUTF16; |
| 63 using base::UTF8ToUTF16; | 65 using base::UTF8ToUTF16; |
| 64 using testing::_; | 66 using testing::_; |
| (...skipping 5576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5641 EXPECT_FALSE(autofill_driver_->did_interact_with_credit_card_form()); | 5643 EXPECT_FALSE(autofill_driver_->did_interact_with_credit_card_form()); |
| 5642 | 5644 |
| 5643 // The driver should always be notified. | 5645 // The driver should always be notified. |
| 5644 for (const FormFieldData& field : form.fields) { | 5646 for (const FormFieldData& field : form.fields) { |
| 5645 GetAutofillSuggestions(form, field); | 5647 GetAutofillSuggestions(form, field); |
| 5646 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); | 5648 EXPECT_TRUE(autofill_driver_->did_interact_with_credit_card_form()); |
| 5647 autofill_driver_->ClearDidInteractWithCreditCardForm(); | 5649 autofill_driver_->ClearDidInteractWithCreditCardForm(); |
| 5648 } | 5650 } |
| 5649 } | 5651 } |
| 5650 | 5652 |
| 5653 // Tests that a form with server only types is still autofillable if the form |
| 5654 // gets updated in cache. |
| 5655 TEST_F(AutofillManagerTest, DisplaySuggestionsForUpdatedServerTypedForm) { |
| 5656 // Create a form with unknown heuristic fields. |
| 5657 FormData form; |
| 5658 form.name = ASCIIToUTF16("MyForm"); |
| 5659 form.origin = GURL("http://myform.com/form.html"); |
| 5660 form.action = GURL("http://myform.com/submit.html"); |
| 5661 |
| 5662 FormFieldData field; |
| 5663 test::CreateTestFormField("Field 1", "field1", "", "text", &field); |
| 5664 form.fields.push_back(field); |
| 5665 test::CreateTestFormField("Field 2", "field2", "", "text", &field); |
| 5666 form.fields.push_back(field); |
| 5667 test::CreateTestFormField("Field 3", "field3", "", "text", &field); |
| 5668 form.fields.push_back(field); |
| 5669 |
| 5670 auto form_structure = base::MakeUnique<TestFormStructure>(form); |
| 5671 form_structure->DetermineHeuristicTypes(); |
| 5672 // Make sure the form can not be autofilled now. |
| 5673 ASSERT_EQ(0u, form_structure->autofill_count()); |
| 5674 for (size_t idx = 0; idx < form_structure->field_count(); ++idx) { |
| 5675 ASSERT_EQ(UNKNOWN_TYPE, form_structure->field(idx)->heuristic_type()); |
| 5676 } |
| 5677 |
| 5678 // Prepare and set known server fields. |
| 5679 const std::vector<ServerFieldType> heuristic_types(form.fields.size(), |
| 5680 UNKNOWN_TYPE); |
| 5681 const std::vector<ServerFieldType> server_types{NAME_FIRST, NAME_MIDDLE, |
| 5682 NAME_LAST}; |
| 5683 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 5684 autofill_manager_->AddSeenForm(std::move(form_structure)); |
| 5685 |
| 5686 // Make sure the form can be autofilled. |
| 5687 for (const FormFieldData& field : form.fields) { |
| 5688 GetAutofillSuggestions(form, field); |
| 5689 ASSERT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5690 } |
| 5691 |
| 5692 // Modify one of the fields in the original form. |
| 5693 form.fields[0].css_classes += ASCIIToUTF16("a"); |
| 5694 |
| 5695 // Expect the form still can be autofilled. |
| 5696 for (const FormFieldData& field : form.fields) { |
| 5697 GetAutofillSuggestions(form, field); |
| 5698 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5699 } |
| 5700 |
| 5701 // Modify form action URL. This can happen on in-page navitaion if the form |
| 5702 // doesn't have an actual action (attribute is empty). |
| 5703 form.action = net::AppendQueryParameter(form.action, "arg", "value"); |
| 5704 |
| 5705 // Expect the form still can be autofilled. |
| 5706 for (const FormFieldData& field : form.fields) { |
| 5707 GetAutofillSuggestions(form, field); |
| 5708 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5709 } |
| 5710 } |
| 5711 |
| 5712 // Tests that a form with <select> field is accepted if <option> value (not |
| 5713 // content) is quite long. Some websites use value to propagate long JSON to |
| 5714 // JS-backed logic. |
| 5715 TEST_F(AutofillManagerTest, FormWithLongOptionValuesIsAcceptable) { |
| 5716 FormData form; |
| 5717 form.name = ASCIIToUTF16("MyForm"); |
| 5718 form.origin = GURL("http://myform.com/form.html"); |
| 5719 form.action = GURL("http://myform.com/submit.html"); |
| 5720 |
| 5721 FormFieldData field; |
| 5722 test::CreateTestFormField("First name", "firstname", "", "text", &field); |
| 5723 form.fields.push_back(field); |
| 5724 test::CreateTestFormField("Last name", "lastname", "", "text", &field); |
| 5725 form.fields.push_back(field); |
| 5726 |
| 5727 // Prepare <select> field with long <option> values. |
| 5728 const size_t kOptionValueLength = 10240; |
| 5729 const std::string long_string(kOptionValueLength, 'a'); |
| 5730 const std::vector<const char*> values(3, long_string.c_str()); |
| 5731 const std::vector<const char*> contents{"A", "B", "C"}; |
| 5732 test::CreateTestSelectField("Country", "country", "", values, contents, |
| 5733 values.size(), &field); |
| 5734 form.fields.push_back(field); |
| 5735 |
| 5736 FormsSeen({form}); |
| 5737 |
| 5738 // Suggestions should be displayed. |
| 5739 for (const FormFieldData& field : form.fields) { |
| 5740 GetAutofillSuggestions(form, field); |
| 5741 EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| 5742 } |
| 5743 } |
| 5744 |
| 5651 } // namespace autofill | 5745 } // namespace autofill |
| OLD | NEW |