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

Side by Side Diff: chrome/browser/autocomplete_history_manager_unittest.cc

Issue 8353025: External autofill delegates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase against TOT Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <vector> 5 #include <vector>
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/task.h" 9 #include "base/task.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autocomplete_history_manager.h" 11 #include "chrome/browser/autocomplete_history_manager.h"
12 #include "chrome/browser/autofill/autofill_external_delegate.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "chrome/browser/webdata/web_data_service.h" 14 #include "chrome/browser/webdata/web_data_service.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "chrome/test/base/testing_browser_process.h" 16 #include "chrome/test/base/testing_browser_process.h"
15 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
16 #include "content/browser/tab_contents/test_tab_contents.h" 18 #include "content/browser/tab_contents/test_tab_contents.h"
17 #include "content/test/test_browser_thread.h" 19 #include "content/test/test_browser_thread.h"
18 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 #include "webkit/glue/form_data.h" 22 #include "webkit/glue/form_data.h"
21 23
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 webkit_glue::FormField search_field; 127 webkit_glue::FormField search_field;
126 search_field.label = ASCIIToUTF16("Search"); 128 search_field.label = ASCIIToUTF16("Search");
127 search_field.name = ASCIIToUTF16("search"); 129 search_field.name = ASCIIToUTF16("search");
128 search_field.value = ASCIIToUTF16("my favorite query"); 130 search_field.value = ASCIIToUTF16("my favorite query");
129 search_field.form_control_type = ASCIIToUTF16("search"); 131 search_field.form_control_type = ASCIIToUTF16("search");
130 form.fields.push_back(search_field); 132 form.fields.push_back(search_field);
131 133
132 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); 134 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1);
133 autocomplete_manager_->OnFormSubmitted(form); 135 autocomplete_manager_->OnFormSubmitted(form);
134 } 136 }
137
138 namespace {
139
140 class MockAutofillExternalDelegate : public AutofillExternalDelegate {
141 public:
142 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper)
143 : AutofillExternalDelegate(wrapper) {}
144 virtual ~MockAutofillExternalDelegate() {}
145
146 virtual void OnQuery(int query_id,
147 const webkit_glue::FormData& form,
148 const webkit_glue::FormField& field) {}
149 MOCK_METHOD5(OnSuggestionsReturned,
150 void(int query_id,
151 const std::vector<string16>& autofill_values,
152 const std::vector<string16>& autofill_labels,
153 const std::vector<string16>& autofill_icons,
154 const std::vector<int>& autofill_unique_ids));
155
156 private:
157 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
158 };
159
160 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager {
161 public:
162 explicit AutocompleteHistoryManagerStubSend(TabContents* tab_contents,
163 Profile* profile,
164 WebDataService* wds)
165 : AutocompleteHistoryManager(tab_contents, profile, wds) {}
166
167 virtual bool Send(IPC::Message* message) { return true; } // intentional nop
168 };
169
170 } // namespace
171
172 // Make sure our external delegate is called at the right time.
173 TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) {
174 // Local version with a stubbed out Send()
175 AutocompleteHistoryManagerStubSend autocomplete_history_manager(
176 contents(),
177 &profile_, web_data_service_);
178
179 MockAutofillExternalDelegate external_delegate(
180 TabContentsWrapper::GetCurrentWrapperForContents(contents()));
181 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _));
182 autocomplete_history_manager.SetExternalDelegate(&external_delegate);
183
184 // Should trigger a call to OnSuggestionsReturned, verified by the mock.
185 autocomplete_history_manager.SendSuggestions(NULL);
186 }
187
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698