OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 } | 654 } |
655 | 655 |
656 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { | 656 void AutocompleteSuggestionsReturned(const std::vector<string16>& result) { |
657 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); | 657 autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); |
658 } | 658 } |
659 | 659 |
660 void FormsSeen(const std::vector<FormData>& forms) { | 660 void FormsSeen(const std::vector<FormData>& forms) { |
661 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); | 661 autofill_manager_->OnFormsSeen(forms, base::TimeTicks()); |
662 } | 662 } |
663 | 663 |
| 664 void LoadServerPredictions(const std::string& response_xml) { |
| 665 autofill_manager_->OnLoadedServerPredictions(response_xml); |
| 666 } |
| 667 |
664 void FormSubmitted(const FormData& form) { | 668 void FormSubmitted(const FormData& form) { |
665 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) | 669 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) |
666 autofill_manager_->WaitForAsyncFormSubmit(); | 670 autofill_manager_->WaitForAsyncFormSubmit(); |
667 } | 671 } |
668 | 672 |
669 void FillAutofillFormData(int query_id, | 673 void FillAutofillFormData(int query_id, |
670 const FormData& form, | 674 const FormData& form, |
671 const FormFieldData& field, | 675 const FormFieldData& field, |
672 int unique_id) { | 676 int unique_id) { |
673 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); | 677 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); |
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 GUIDPair empty(std::string(), 0); | 1807 GUIDPair empty(std::string(), 0); |
1804 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), | 1808 FillAutofillFormData(kDefaultPageID, form, *form.fields.begin(), |
1805 PackGUIDs(guid, empty)); | 1809 PackGUIDs(guid, empty)); |
1806 | 1810 |
1807 int page_id = 0; | 1811 int page_id = 0; |
1808 FormData results; | 1812 FormData results; |
1809 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); | 1813 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
1810 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false); | 1814 ExpectFilledCreditCardFormElvis(page_id, results, kDefaultPageID, false); |
1811 } | 1815 } |
1812 | 1816 |
| 1817 TEST_F(AutofillManagerTest, FillCheckableElements) { |
| 1818 FormData form; |
| 1819 CreateTestAddressFormData(&form); |
| 1820 |
| 1821 // Add a checkbox field. |
| 1822 FormFieldData field; |
| 1823 autofill_test::CreateTestFormField( |
| 1824 "Checkbox", "checkbx", "fill-me", "checkbox", &field); |
| 1825 field.is_checkable = true; |
| 1826 form.fields.push_back(field); |
| 1827 autofill_test::CreateTestFormField( |
| 1828 "Checkbox", "checkbx", "fill-me", "checkbox", &field); |
| 1829 field.is_checkable = true; |
| 1830 form.fields.push_back(field); |
| 1831 |
| 1832 std::vector<FormData> forms(1, form); |
| 1833 FormsSeen(forms); |
| 1834 |
| 1835 // Replicate server response with XML. |
| 1836 const std::string response_xml = |
| 1837 "<autofillqueryresponse>" |
| 1838 "<field autofilltype=\"0\"/>" |
| 1839 "<field autofilltype=\"0\"/>" |
| 1840 "<field autofilltype=\"0\"/>" |
| 1841 "<field autofilltype=\"0\"/>" |
| 1842 "<field autofilltype=\"0\"/>" |
| 1843 "<field autofilltype=\"0\"/>" |
| 1844 "<field autofilltype=\"0\"/>" |
| 1845 "<field autofilltype=\"0\"/>" |
| 1846 "<field autofilltype=\"0\"/>" |
| 1847 "<field autofilltype=\"0\"/>" |
| 1848 "<field autofilltype=\"0\"/>" |
| 1849 "<field autofilltype=\"61\" defaultvalue=\"fill-me\"/>" |
| 1850 "<field autofilltype=\"61\" defaultvalue=\"dont-fill-me\"/>" |
| 1851 "</autofillqueryresponse>"; |
| 1852 LoadServerPredictions(response_xml); |
| 1853 |
| 1854 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 1855 GUIDPair empty(std::string(), 0); |
| 1856 FillAutofillFormData(kDefaultPageID, form, form.fields[0], |
| 1857 PackGUIDs(empty, guid)); |
| 1858 int page_id = 0; |
| 1859 FormData results; |
| 1860 EXPECT_TRUE(GetAutofillFormDataFilledMessage(&page_id, &results)); |
| 1861 // Second to last field should be checked. |
| 1862 EXPECT_TRUE(results.fields[results.fields.size()-2].is_checked); |
| 1863 // Last field shouldn't be checked as values are not same. |
| 1864 EXPECT_FALSE(results.fields[results.fields.size()-1].is_checked); |
| 1865 } |
| 1866 |
1813 // Test that we correctly fill a credit card form with month input type. | 1867 // Test that we correctly fill a credit card form with month input type. |
1814 // 1. year empty, month empty | 1868 // 1. year empty, month empty |
1815 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { | 1869 TEST_F(AutofillManagerTest, FillCreditCardFormNoYearNoMonth) { |
1816 // Same as the SetUp(), but generate 4 credit cards with year month | 1870 // Same as the SetUp(), but generate 4 credit cards with year month |
1817 // combination. | 1871 // combination. |
1818 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); | 1872 personal_data_.CreateTestCreditCardsYearAndMonth("", ""); |
1819 // Set up our form data. | 1873 // Set up our form data. |
1820 FormData form; | 1874 FormData form; |
1821 CreateTestCreditCardFormData(&form, true, true); | 1875 CreateTestCreditCardFormData(&form, true, true); |
1822 std::vector<FormData> forms(1, form); | 1876 std::vector<FormData> forms(1, form); |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3155 | 3209 |
3156 FormData form; | 3210 FormData form; |
3157 CreateTestAddressFormData(&form); | 3211 CreateTestAddressFormData(&form); |
3158 std::vector<FormData> forms(1, form); | 3212 std::vector<FormData> forms(1, form); |
3159 FormsSeen(forms); | 3213 FormsSeen(forms); |
3160 const FormFieldData& field = form.fields[0]; | 3214 const FormFieldData& field = form.fields[0]; |
3161 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3215 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3162 | 3216 |
3163 autofill_manager_->SetExternalDelegate(NULL); | 3217 autofill_manager_->SetExternalDelegate(NULL); |
3164 } | 3218 } |
OLD | NEW |