Chromium Code Reviews| Index: components/autofill/browser/autofill_manager_unittest.cc |
| diff --git a/components/autofill/browser/autofill_manager_unittest.cc b/components/autofill/browser/autofill_manager_unittest.cc |
| index 2ea75f11c50edf495d90bdb82d28289e61fd5698..4dd8955b998478ae8c3e65d0c0ec74a02ededc64 100644 |
| --- a/components/autofill/browser/autofill_manager_unittest.cc |
| +++ b/components/autofill/browser/autofill_manager_unittest.cc |
| @@ -480,6 +480,23 @@ void ExpectFilledCreditCardYearMonthWithYearMonth(int page_id, |
| has_address_fields, true, true); |
| } |
| +class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { |
| + public: |
| + MockAutocompleteHistoryManager(AutofillDriver* driver, |
| + AutofillManagerDelegate* delegate) |
| + : AutocompleteHistoryManager(driver, delegate), |
| + form_submissions(0) { } |
|
Ilya Sherman
2013/06/19 00:38:27
nit: No space between the curlies.
sgurun-gerrit only
2013/06/19 17:56:23
Done.
|
| + |
| + void OnFormSubmitted(const FormData& form) { |
|
Ilya Sherman
2013/06/19 00:38:27
nit: virtual, OVERRIDE
Ilya Sherman
2013/06/19 00:38:27
nit: This seems like a good function to just mock
sgurun-gerrit only
2013/06/19 17:56:23
Done.
sgurun-gerrit only
2013/06/19 17:56:23
Done.
|
| + form_submissions++; |
|
Ilya Sherman
2013/06/19 00:38:27
nit: ++form_submissions;
sgurun-gerrit only
2013/06/19 17:56:23
Done.
|
| + } |
|
Ilya Sherman
2013/06/19 00:38:27
nit: Leave a blank line below this one.
sgurun-gerrit only
2013/06/19 17:56:23
Done.
|
| + int get_form_submissions() { |
| + return form_submissions; |
| + } |
|
Ilya Sherman
2013/06/19 00:38:27
nit: Leave a blank line below this one.
sgurun-gerrit only
2013/06/19 17:56:23
Done.
|
| + private: |
| + int form_submissions; |
| +}; |
| + |
| class TestAutofillManager : public AutofillManager { |
| public: |
| TestAutofillManager(AutofillDriver* driver, |
| @@ -703,7 +720,7 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { |
| void AutocompleteSuggestionsReturned( |
| const std::vector<base::string16>& result) { |
| - autofill_manager_->autocomplete_history_manager_.SendSuggestions(&result); |
| + autofill_manager_->autocomplete_history_manager_->SendSuggestions(&result); |
| } |
| void FormsSeen(const std::vector<FormData>& forms) { |
| @@ -762,7 +779,7 @@ class AutofillManagerTest : public ChromeRenderViewHostTestHarness { |
| if (unique_ids) |
| *unique_ids = autofill_param.e; |
| - autofill_manager_->autocomplete_history_manager_.CancelPendingQuery(); |
| + autofill_manager_->autocomplete_history_manager_->CancelPendingQuery(); |
| process()->sink().ClearMessages(); |
| return true; |
| } |
| @@ -2709,6 +2726,74 @@ TEST_F(AutofillManagerTest, FormSubmitted) { |
| FormSubmitted(results); |
| } |
| +// Test that when Autocomplete is enabled and Autofill is disabled, |
| +// form submissions are still received by AutocompleteHistoryManager. |
| +TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) { |
| + TestAutofillManagerDelegate delegate; |
| + autofill_manager_.reset(new TestAutofillManager( |
| + autofill_driver_.get(), |
| + &delegate, |
| + NULL)); |
| + autofill_manager_->set_autofill_enabled(false); |
| + MockAutocompleteHistoryManager* mock_autocomplete_history_manager = |
| + new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate); |
|
Ilya Sherman
2013/06/19 00:38:27
nit: Please declare this as a scoped_ptr.
sgurun-gerrit only
2013/06/19 17:56:23
Done.
|
| + autofill_manager_->autocomplete_history_manager_.reset( |
| + mock_autocomplete_history_manager); |
| + |
| + // Set up our form data. |
| + FormData form; |
| + CreateTestAddressFormData(&form); |
| + form.method = ASCIIToUTF16("GET"); |
| + FormSubmitted(form); |
| + EXPECT_EQ(1, mock_autocomplete_history_manager->get_form_submissions()); |
| +} |
| + |
| +// Test that when Autocomplete is enabled and Autofill is disabled, |
| +// Autocomplete suggestions are still received. |
| +TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { |
| + TestAutofillManagerDelegate delegate; |
| + autofill_manager_.reset(new TestAutofillManager( |
| + autofill_driver_.get(), |
| + &delegate, |
| + NULL)); |
| + autofill_manager_->set_autofill_enabled(false); |
| + |
| + // Set up our form data. |
| + FormData form; |
| + CreateTestAddressFormData(&form); |
| + form.method = ASCIIToUTF16("GET"); |
| + std::vector<FormData> forms(1, form); |
| + FormsSeen(forms); |
| + const FormFieldData& field = form.fields[0]; |
| + GetAutofillSuggestions(form, field); |
| + |
| + // Add some Autocomplete suggestions. We should return the autocomplete |
| + // suggestions, these will be culled by the renderer. |
| + std::vector<base::string16> suggestions; |
| + suggestions.push_back(ASCIIToUTF16("Jay")); |
| + suggestions.push_back(ASCIIToUTF16("Jason")); |
| + AutocompleteSuggestionsReturned(suggestions); |
| + |
| + int page_id = 0; |
| + std::vector<base::string16> values; |
| + std::vector<base::string16> labels; |
| + std::vector<base::string16> icons; |
| + std::vector<int> unique_ids; |
| + EXPECT_TRUE(GetAutofillSuggestionsMessage(&page_id, &values, &labels, &icons, |
| + &unique_ids)); |
| + |
| + base::string16 expected_values[] = { |
| + ASCIIToUTF16("Jay"), |
| + ASCIIToUTF16("Jason") |
| + }; |
| + base::string16 expected_labels[] = { base::string16(), base::string16()}; |
| + base::string16 expected_icons[] = { base::string16(), base::string16()}; |
| + int expected_unique_ids[] = {0, 0}; |
| + ExpectSuggestions(page_id, values, labels, icons, unique_ids, |
| + kDefaultPageID, arraysize(expected_values), expected_values, |
| + expected_labels, expected_icons, expected_unique_ids); |
| +} |
| + |
| // Test that we are able to save form data when forms are submitted and we only |
| // have server data for the field types. |
| TEST_F(AutofillManagerTest, FormSubmittedServerTypes) { |