OLD | NEW |
---|---|
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" | |
12 #include "chrome/browser/webdata/web_data_service.h" | 13 #include "chrome/browser/webdata/web_data_service.h" |
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
16 #include "content/browser/tab_contents/test_tab_contents.h" | 17 #include "content/browser/tab_contents/test_tab_contents.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "webkit/glue/form_data.h" | 20 #include "webkit/glue/form_data.h" |
20 | 21 |
21 using testing::_; | 22 using testing::_; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 webkit_glue::FormField search_field; | 125 webkit_glue::FormField search_field; |
125 search_field.label = ASCIIToUTF16("Search"); | 126 search_field.label = ASCIIToUTF16("Search"); |
126 search_field.name = ASCIIToUTF16("search"); | 127 search_field.name = ASCIIToUTF16("search"); |
127 search_field.value = ASCIIToUTF16("my favorite query"); | 128 search_field.value = ASCIIToUTF16("my favorite query"); |
128 search_field.form_control_type = ASCIIToUTF16("search"); | 129 search_field.form_control_type = ASCIIToUTF16("search"); |
129 form.fields.push_back(search_field); | 130 form.fields.push_back(search_field); |
130 | 131 |
131 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); | 132 EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1); |
132 autocomplete_manager_->OnFormSubmitted(form); | 133 autocomplete_manager_->OnFormSubmitted(form); |
133 } | 134 } |
135 | |
136 namespace { | |
137 | |
138 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | |
139 public: | |
140 MockAutofillExternalDelegate() {} | |
141 virtual ~MockAutofillExternalDelegate() {} | |
142 | |
143 virtual void OnQuery(int query_id, | |
144 const webkit_glue::FormData& form, | |
145 const webkit_glue::FormField& field) {} | |
146 MOCK_METHOD5(OnSuggestionsReturned, void( | |
dhollowa
2011/10/26 16:14:22
nit: indent seems off here. What about pulling vo
| |
147 int query_id, | |
148 const std::vector<string16>& autofill_values, | |
149 const std::vector<string16>& autofill_labels, | |
150 const std::vector<string16>& autofill_icons, | |
151 const std::vector<int>& autofill_unique_ids)); | |
152 | |
153 private: | |
154 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | |
155 }; | |
156 | |
157 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager { | |
158 public: | |
159 explicit AutocompleteHistoryManagerStubSend(TabContents* tab_contents, | |
160 Profile* profile, | |
161 WebDataService* wds) | |
162 : AutocompleteHistoryManager(tab_contents, profile, wds) {} | |
163 | |
164 virtual bool Send(IPC::Message* message) { return true; } // intentional nop | |
165 }; | |
166 | |
167 } // namespace | |
168 | |
169 // Make sure our external delegate is called at the right time. | |
170 TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) { | |
171 // Local version with a stubbed out Send() | |
172 scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager( | |
173 new AutocompleteHistoryManagerStubSend(contents(), | |
174 &profile_, web_data_service_)); | |
Ilya Sherman
2011/10/26 11:09:58
nit: Can this be stack-allocated, rather than heap
| |
175 | |
176 MockAutofillExternalDelegate external_delegate; | |
177 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | |
178 autocomplete_history_manager->SetExternalDelegate(&external_delegate); | |
179 | |
180 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | |
181 autocomplete_history_manager->SendSuggestions(NULL); | |
182 } | |
183 | |
OLD | NEW |