summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 15:34:39 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-09 15:34:39 +0000
commit51c418ffb35b1fa51368e69f3ecad1c4039f41ab (patch)
treea0be9a109e3afc9d901ffef824a6a47a06fbece1 /chrome
parentc14a8311a11ab8a06f71cd14362498494b56cb39 (diff)
downloadchromium_src-51c418ffb35b1fa51368e69f3ecad1c4039f41ab.zip
chromium_src-51c418ffb35b1fa51368e69f3ecad1c4039f41ab.tar.gz
chromium_src-51c418ffb35b1fa51368e69f3ecad1c4039f41ab.tar.bz2
AutoFill DCHECK in RenderViewHost::AutocompleteSuggestionsReturned fails.
Fixes case where DCHECK was failing in presence of Autocomplete cancel logic. The DCHECK in this case was erroneous. The new logic handles the cancel case appropriately. BUG=none TEST=AutoFillManagerTest.GetFieldSuggestionsForAutocompleteOnly Review URL: http://codereview.chromium.org/2945003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51962 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc36
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc10
2 files changed, 45 insertions, 1 deletions
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 1549079..8aeeb25 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -599,6 +599,42 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsFormIsAutoFilled) {
EXPECT_EQ(string16(), labels[1]);
}
+TEST_F(AutoFillManagerTest, GetFieldSuggestionsForAutocompleteOnly) {
+ FormData form;
+ CreateTestFormData(&form);
+
+ // Set up our FormStructures.
+ std::vector<FormData> forms;
+ forms.push_back(form);
+ autofill_manager_->FormsSeen(forms);
+
+ // The page ID sent to the AutoFillManager from the RenderView, used to send
+ // an IPC message back to the renderer.
+ const int kPageID = 1;
+ const int kAlternatePageID = 0;
+
+ webkit_glue::FormField field;
+ autofill_unittest::CreateTestFormField(
+ "First Name", "firstname", "", "text", &field);
+ EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(kPageID, true, field));
+
+ // No suggestions provided, so send an empty vector as the results.
+ // This triggers the combined message send.
+ // In this case, we're simulating a cancel of Autocomplete with a different
+ // page ID and an empty vector of suggestions.
+ rvh()->AutocompleteSuggestionsReturned(kAlternatePageID,
+ std::vector<string16>());
+
+ // Test that we sent the right message to the renderer.
+ int page_id = 0;
+ std::vector<string16> values;
+ std::vector<string16> labels;
+ EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels));
+ EXPECT_EQ(kAlternatePageID, page_id);
+ ASSERT_EQ(0U, values.size());
+ ASSERT_EQ(0U, labels.size());
+}
+
TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) {
FormData form;
CreateTestFormData(&form);
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 28b44a3..4905ad5 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1659,7 +1659,15 @@ void RenderViewHost::AutoFillSuggestionsReturned(
void RenderViewHost::AutocompleteSuggestionsReturned(
int query_id, const std::vector<string16>& suggestions) {
- DCHECK_EQ(autofill_query_id_, query_id);
+ // When query ids match we are responding to an AutoFill and Autocomplete
+ // combined query response.
+ // Otherwise Autocomplete is cancelling, so we only send suggestions (usually
+ // an empty list).
+ if (autofill_query_id_ != query_id) {
+ // Autocomplete is cancelling.
+ autofill_values_.clear();
+ autofill_labels_.clear();
+ }
// Combine AutoFill and Autocomplete values into values and labels.
for (size_t i = 0; i < suggestions.size(); ++i) {