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

Unified Diff: components/autofill/browser/autofill_manager_unittest.cc

Issue 15097004: Enable Autocomplete feature for chromium webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@setSaveFormData2
Patch Set: address nits Created 7 years, 6 months 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 side-by-side diff with in-line comments
Download patch
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..7ba78354eeffe10a95fd33dc8affd1c21b27132d 100644
--- a/components/autofill/browser/autofill_manager_unittest.cc
+++ b/components/autofill/browser/autofill_manager_unittest.cc
@@ -480,6 +480,18 @@ void ExpectFilledCreditCardYearMonthWithYearMonth(int page_id,
has_address_fields, true, true);
}
+class MockAutocompleteHistoryManager : public AutocompleteHistoryManager {
+ public:
+ MockAutocompleteHistoryManager(AutofillDriver* driver,
+ AutofillManagerDelegate* delegate)
+ : AutocompleteHistoryManager(driver, delegate) {}
+
+ MOCK_METHOD1(OnFormSubmitted, void(const FormData& form));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager);
+};
+
class TestAutofillManager : public AutofillManager {
public:
TestAutofillManager(AutofillDriver* driver,
@@ -703,7 +715,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 +774,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 +2721,76 @@ 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);
+ scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager;
+ autocomplete_history_manager.reset(
+ new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate));
+ autofill_manager_->autocomplete_history_manager_.reset(
+ autocomplete_history_manager.get());
Ilya Sherman 2013/06/19 23:19:55 Pretty sure this needs to be .Pass(), or else you'
sgurun-gerrit only 2013/06/20 15:18:44 You are right. thanks. On 2013/06/19 23:19:55, Il
+
+ // Set up our form data.
+ FormData form;
+ CreateTestAddressFormData(&form);
+ form.method = ASCIIToUTF16("GET");
+ FormSubmitted(form);
+ EXPECT_CALL(*(autocomplete_history_manager.get()),
+ OnFormSubmitted(_)).Times(1);
Ilya Sherman 2013/06/19 23:19:55 I'm pretty sure this is supposed to go *before* th
sgurun-gerrit only 2013/06/20 15:18:44 Done.
+}
+
+// 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) {
« no previous file with comments | « components/autofill/browser/autofill_manager_delegate.h ('k') | components/autofill/browser/test_autofill_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698