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

Side by Side Diff: components/autofill/core/browser/autofill_external_delegate_unittest.cc

Issue 306053008: Rename AutofillManagerDelegate to AutofillClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "components/autofill/core/browser/autofill_manager.h" 11 #include "components/autofill/core/browser/autofill_manager.h"
12 #include "components/autofill/core/browser/popup_item_ids.h" 12 #include "components/autofill/core/browser/popup_item_ids.h"
13 #include "components/autofill/core/browser/test_autofill_client.h"
13 #include "components/autofill/core/browser/test_autofill_driver.h" 14 #include "components/autofill/core/browser/test_autofill_driver.h"
14 #include "components/autofill/core/browser/test_autofill_external_delegate.h" 15 #include "components/autofill/core/browser/test_autofill_external_delegate.h"
15 #include "components/autofill/core/browser/test_autofill_manager_delegate.h"
16 #include "components/autofill/core/common/form_data.h" 16 #include "components/autofill/core/common/form_data.h"
17 #include "components/autofill/core/common/form_field_data.h" 17 #include "components/autofill/core/common/form_field_data.h"
18 #include "components/autofill/core/common/password_form_fill_data.h" 18 #include "components/autofill/core/common/password_form_fill_data.h"
19 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/gfx/rect.h" 21 #include "ui/gfx/rect.h"
22 22
23 using base::ASCIIToUTF16; 23 using base::ASCIIToUTF16;
24 using testing::_; 24 using testing::_;
25 25
(...skipping 16 matching lines...) Expand all
42 MOCK_METHOD0(RendererShouldClearFilledForm, void()); 42 MOCK_METHOD0(RendererShouldClearFilledForm, void());
43 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); 43 MOCK_METHOD0(RendererShouldClearPreviewedForm, void());
44 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&)); 44 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&));
45 MOCK_METHOD1(RendererShouldPreviewFieldWithValue, 45 MOCK_METHOD1(RendererShouldPreviewFieldWithValue,
46 void(const base::string16&)); 46 void(const base::string16&));
47 47
48 private: 48 private:
49 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); 49 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
50 }; 50 };
51 51
52 class MockAutofillManagerDelegate 52 class MockAutofillClient : public autofill::TestAutofillClient {
53 : public autofill::TestAutofillManagerDelegate {
54 public: 53 public:
55 MockAutofillManagerDelegate() {} 54 MockAutofillClient() {}
56 55
57 MOCK_METHOD7(ShowAutofillPopup, 56 MOCK_METHOD7(ShowAutofillPopup,
58 void(const gfx::RectF& element_bounds, 57 void(const gfx::RectF& element_bounds,
59 base::i18n::TextDirection text_direction, 58 base::i18n::TextDirection text_direction,
60 const std::vector<base::string16>& values, 59 const std::vector<base::string16>& values,
61 const std::vector<base::string16>& labels, 60 const std::vector<base::string16>& labels,
62 const std::vector<base::string16>& icons, 61 const std::vector<base::string16>& icons,
63 const std::vector<int>& identifiers, 62 const std::vector<int>& identifiers,
64 base::WeakPtr<AutofillPopupDelegate> delegate)); 63 base::WeakPtr<AutofillPopupDelegate> delegate));
65 64
66 MOCK_METHOD2(UpdateAutofillPopupDataListValues, 65 MOCK_METHOD2(UpdateAutofillPopupDataListValues,
67 void(const std::vector<base::string16>& values, 66 void(const std::vector<base::string16>& values,
68 const std::vector<base::string16>& lables)); 67 const std::vector<base::string16>& lables));
69 68
70 MOCK_METHOD0(HideAutofillPopup, void()); 69 MOCK_METHOD0(HideAutofillPopup, void());
71 70
72 private: 71 private:
73 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 72 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient);
74 }; 73 };
75 74
76 class MockAutofillManager : public AutofillManager { 75 class MockAutofillManager : public AutofillManager {
77 public: 76 public:
78 MockAutofillManager(AutofillDriver* driver, 77 MockAutofillManager(AutofillDriver* driver, MockAutofillClient* client)
79 MockAutofillManagerDelegate* delegate)
80 // Force to use the constructor designated for unit test, but we don't 78 // Force to use the constructor designated for unit test, but we don't
81 // really need personal_data in this test so we pass a NULL pointer. 79 // really need personal_data in this test so we pass a NULL pointer.
82 : AutofillManager(driver, delegate, NULL) { 80 : AutofillManager(driver, client, NULL) {}
83 }
84 virtual ~MockAutofillManager() {} 81 virtual ~MockAutofillManager() {}
85 82
86 MOCK_METHOD5(FillOrPreviewForm, 83 MOCK_METHOD5(FillOrPreviewForm,
87 void(AutofillDriver::RendererFormDataAction action, 84 void(AutofillDriver::RendererFormDataAction action,
88 int query_id, 85 int query_id,
89 const FormData& form, 86 const FormData& form,
90 const FormFieldData& field, 87 const FormFieldData& field,
91 int unique_id)); 88 int unique_id));
92 89
93 private: 90 private:
94 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager); 91 DISALLOW_COPY_AND_ASSIGN(MockAutofillManager);
95 }; 92 };
96 93
97 } // namespace 94 } // namespace
98 95
99 class AutofillExternalDelegateUnitTest : public testing::Test { 96 class AutofillExternalDelegateUnitTest : public testing::Test {
100 protected: 97 protected:
101 virtual void SetUp() OVERRIDE { 98 virtual void SetUp() OVERRIDE {
102 autofill_driver_.reset(new MockAutofillDriver()); 99 autofill_driver_.reset(new MockAutofillDriver());
103 autofill_manager_.reset( 100 autofill_manager_.reset(
104 new MockAutofillManager(autofill_driver_.get(), 101 new MockAutofillManager(autofill_driver_.get(), &autofill_client_));
105 &manager_delegate_));
106 external_delegate_.reset( 102 external_delegate_.reset(
107 new AutofillExternalDelegate( 103 new AutofillExternalDelegate(
108 autofill_manager_.get(), autofill_driver_.get())); 104 autofill_manager_.get(), autofill_driver_.get()));
109 } 105 }
110 106
111 virtual void TearDown() OVERRIDE { 107 virtual void TearDown() OVERRIDE {
112 // Order of destruction is important as AutofillManager relies on 108 // Order of destruction is important as AutofillManager relies on
113 // PersonalDataManager to be around when it gets destroyed. 109 // PersonalDataManager to be around when it gets destroyed.
114 autofill_manager_.reset(); 110 autofill_manager_.reset();
115 external_delegate_.reset(); 111 external_delegate_.reset();
116 autofill_driver_.reset(); 112 autofill_driver_.reset();
117 } 113 }
118 114
119 // Issue an OnQuery call with the given |query_id|. 115 // Issue an OnQuery call with the given |query_id|.
120 void IssueOnQuery(int query_id) { 116 void IssueOnQuery(int query_id) {
121 const FormData form; 117 const FormData form;
122 FormFieldData field; 118 FormFieldData field;
123 field.is_focusable = true; 119 field.is_focusable = true;
124 field.should_autocomplete = true; 120 field.should_autocomplete = true;
125 const gfx::RectF element_bounds; 121 const gfx::RectF element_bounds;
126 122
127 external_delegate_->OnQuery(query_id, form, field, element_bounds, true); 123 external_delegate_->OnQuery(query_id, form, field, element_bounds, true);
128 } 124 }
129 125
130 MockAutofillManagerDelegate manager_delegate_; 126 MockAutofillClient autofill_client_;
131 scoped_ptr<MockAutofillDriver> autofill_driver_; 127 scoped_ptr<MockAutofillDriver> autofill_driver_;
132 scoped_ptr<MockAutofillManager> autofill_manager_; 128 scoped_ptr<MockAutofillManager> autofill_manager_;
133 scoped_ptr<AutofillExternalDelegate> external_delegate_; 129 scoped_ptr<AutofillExternalDelegate> external_delegate_;
134 130
135 base::MessageLoop message_loop_; 131 base::MessageLoop message_loop_;
136 }; 132 };
137 133
138 // Test that our external delegate called the virtual methods at the right time. 134 // Test that our external delegate called the virtual methods at the right time.
139 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { 135 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) {
140 IssueOnQuery(kQueryId); 136 IssueOnQuery(kQueryId);
141 137
142 // The enums must be cast to ints to prevent compile errors on linux_rel. 138 // The enums must be cast to ints to prevent compile errors on linux_rel.
143 EXPECT_CALL( 139 EXPECT_CALL(
144 manager_delegate_, 140 autofill_client_,
145 ShowAutofillPopup(_, 141 ShowAutofillPopup(_,
146 _, 142 _,
147 _, 143 _,
148 _, 144 _,
149 _, 145 _,
150 testing::ElementsAre( 146 testing::ElementsAre(
151 kAutofillProfileId, 147 kAutofillProfileId,
152 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 148 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
153 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), 149 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)),
154 _)); 150 _));
155 151
156 // This should call ShowAutofillPopup. 152 // This should call ShowAutofillPopup.
157 std::vector<base::string16> autofill_item; 153 std::vector<base::string16> autofill_item;
158 autofill_item.push_back(base::string16()); 154 autofill_item.push_back(base::string16());
159 std::vector<int> autofill_ids; 155 std::vector<int> autofill_ids;
160 autofill_ids.push_back(kAutofillProfileId); 156 autofill_ids.push_back(kAutofillProfileId);
161 external_delegate_->OnSuggestionsReturned(kQueryId, 157 external_delegate_->OnSuggestionsReturned(kQueryId,
162 autofill_item, 158 autofill_item,
163 autofill_item, 159 autofill_item,
164 autofill_item, 160 autofill_item,
165 autofill_ids); 161 autofill_ids);
166 162
167 EXPECT_CALL(*autofill_manager_, 163 EXPECT_CALL(*autofill_manager_,
168 FillOrPreviewForm( 164 FillOrPreviewForm(
169 AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); 165 AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _));
170 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 166 EXPECT_CALL(autofill_client_, HideAutofillPopup());
171 167
172 // This should trigger a call to hide the popup since we've selected an 168 // This should trigger a call to hide the popup since we've selected an
173 // option. 169 // option.
174 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]); 170 external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]);
175 } 171 }
176 172
177 // Test that data list elements for a node will appear in the Autofill popup. 173 // Test that data list elements for a node will appear in the Autofill popup.
178 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { 174 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) {
179 IssueOnQuery(kQueryId); 175 IssueOnQuery(kQueryId);
180 176
181 std::vector<base::string16> data_list_items; 177 std::vector<base::string16> data_list_items;
182 data_list_items.push_back(base::string16()); 178 data_list_items.push_back(base::string16());
183 179
184 external_delegate_->SetCurrentDataListValues(data_list_items, 180 external_delegate_->SetCurrentDataListValues(data_list_items,
185 data_list_items); 181 data_list_items);
186 182
187 // The enums must be cast to ints to prevent compile errors on linux_rel. 183 // The enums must be cast to ints to prevent compile errors on linux_rel.
188 EXPECT_CALL( 184 EXPECT_CALL(
189 manager_delegate_, 185 autofill_client_,
190 ShowAutofillPopup(_, 186 ShowAutofillPopup(_,
191 _, 187 _,
192 _, 188 _,
193 _, 189 _,
194 _, 190 _,
195 testing::ElementsAre( 191 testing::ElementsAre(
196 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), 192 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
197 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 193 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
198 kAutofillProfileId, 194 kAutofillProfileId,
199 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 195 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
200 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), 196 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)),
201 _)); 197 _));
202 198
203 // This should call ShowAutofillPopup. 199 // This should call ShowAutofillPopup.
204 std::vector<base::string16> autofill_item; 200 std::vector<base::string16> autofill_item;
205 autofill_item.push_back(base::string16()); 201 autofill_item.push_back(base::string16());
206 std::vector<int> autofill_ids; 202 std::vector<int> autofill_ids;
207 autofill_ids.push_back(kAutofillProfileId); 203 autofill_ids.push_back(kAutofillProfileId);
208 external_delegate_->OnSuggestionsReturned(kQueryId, 204 external_delegate_->OnSuggestionsReturned(kQueryId,
209 autofill_item, 205 autofill_item,
210 autofill_item, 206 autofill_item,
211 autofill_item, 207 autofill_item,
212 autofill_ids); 208 autofill_ids);
213 209
214 // Try calling OnSuggestionsReturned with no Autofill values and ensure 210 // Try calling OnSuggestionsReturned with no Autofill values and ensure
215 // the datalist items are still shown. 211 // the datalist items are still shown.
216 // The enum must be cast to an int to prevent compile errors on linux_rel. 212 // The enum must be cast to an int to prevent compile errors on linux_rel.
217 EXPECT_CALL( 213 EXPECT_CALL(
218 manager_delegate_, 214 autofill_client_,
219 ShowAutofillPopup( 215 ShowAutofillPopup(
220 _, 216 _,
221 _, 217 _,
222 _, 218 _,
223 _, 219 _,
224 _, 220 _,
225 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY)), 221 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY)),
226 _)); 222 _));
227 223
228 autofill_item = std::vector<base::string16>(); 224 autofill_item = std::vector<base::string16>();
229 autofill_ids = std::vector<int>(); 225 autofill_ids = std::vector<int>();
230 external_delegate_->OnSuggestionsReturned(kQueryId, 226 external_delegate_->OnSuggestionsReturned(kQueryId,
231 autofill_item, 227 autofill_item,
232 autofill_item, 228 autofill_item,
233 autofill_item, 229 autofill_item,
234 autofill_ids); 230 autofill_ids);
235 } 231 }
236 232
237 // Test that datalist values can get updated while a popup is showing. 233 // Test that datalist values can get updated while a popup is showing.
238 TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) { 234 TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) {
239 IssueOnQuery(kQueryId); 235 IssueOnQuery(kQueryId);
240 236
241 EXPECT_CALL(manager_delegate_, 237 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _))
242 ShowAutofillPopup(_, _, _, _, _, _, _)).Times(0); 238 .Times(0);
243 239
244 // Make sure just setting the data list values doesn't cause the popup to 240 // Make sure just setting the data list values doesn't cause the popup to
245 // appear. 241 // appear.
246 std::vector<base::string16> data_list_items; 242 std::vector<base::string16> data_list_items;
247 data_list_items.push_back(base::string16()); 243 data_list_items.push_back(base::string16());
248 244
249 external_delegate_->SetCurrentDataListValues(data_list_items, 245 external_delegate_->SetCurrentDataListValues(data_list_items,
250 data_list_items); 246 data_list_items);
251 247
252 // The enums must be cast to ints to prevent compile errors on linux_rel. 248 // The enums must be cast to ints to prevent compile errors on linux_rel.
253 EXPECT_CALL( 249 EXPECT_CALL(
254 manager_delegate_, 250 autofill_client_,
255 ShowAutofillPopup(_, 251 ShowAutofillPopup(_,
256 _, 252 _,
257 _, 253 _,
258 _, 254 _,
259 _, 255 _,
260 testing::ElementsAre( 256 testing::ElementsAre(
261 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), 257 static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY),
262 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 258 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
263 kAutofillProfileId, 259 kAutofillProfileId,
264 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), 260 static_cast<int>(POPUP_ITEM_ID_SEPARATOR),
(...skipping 12 matching lines...) Expand all
277 autofill_ids); 273 autofill_ids);
278 274
279 // This would normally get called from ShowAutofillPopup, but it is mocked so 275 // This would normally get called from ShowAutofillPopup, but it is mocked so
280 // we need to call OnPopupShown ourselves. 276 // we need to call OnPopupShown ourselves.
281 external_delegate_->OnPopupShown(); 277 external_delegate_->OnPopupShown();
282 278
283 // Update the current data list and ensure the popup is updated. 279 // Update the current data list and ensure the popup is updated.
284 data_list_items.push_back(base::string16()); 280 data_list_items.push_back(base::string16());
285 281
286 // The enums must be cast to ints to prevent compile errors on linux_rel. 282 // The enums must be cast to ints to prevent compile errors on linux_rel.
287 EXPECT_CALL(manager_delegate_, 283 EXPECT_CALL(
288 UpdateAutofillPopupDataListValues(data_list_items, 284 autofill_client_,
289 data_list_items)); 285 UpdateAutofillPopupDataListValues(data_list_items, data_list_items));
290 286
291 external_delegate_->SetCurrentDataListValues(data_list_items, 287 external_delegate_->SetCurrentDataListValues(data_list_items,
292 data_list_items); 288 data_list_items);
293 } 289 }
294 290
295 // Test that the Autofill popup is able to display warnings explaining why 291 // Test that the Autofill popup is able to display warnings explaining why
296 // Autofill is disabled for a website. 292 // Autofill is disabled for a website.
297 // Regression test for http://crbug.com/247880 293 // Regression test for http://crbug.com/247880
298 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { 294 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) {
299 IssueOnQuery(kQueryId); 295 IssueOnQuery(kQueryId);
300 296
301 // The enums must be cast to ints to prevent compile errors on linux_rel. 297 // The enums must be cast to ints to prevent compile errors on linux_rel.
302 EXPECT_CALL( 298 EXPECT_CALL(
303 manager_delegate_, 299 autofill_client_,
304 ShowAutofillPopup( 300 ShowAutofillPopup(
305 _, 301 _,
306 _, 302 _,
307 _, 303 _,
308 _, 304 _,
309 _, 305 _,
310 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE)), 306 testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE)),
311 _)); 307 _));
312 308
313 // This should call ShowAutofillPopup. 309 // This should call ShowAutofillPopup.
(...skipping 13 matching lines...) Expand all
327 // Regression test for http://crbug.com/105636 323 // Regression test for http://crbug.com/105636
328 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { 324 TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) {
329 const FormData form; 325 const FormData form;
330 FormFieldData field; 326 FormFieldData field;
331 field.is_focusable = true; 327 field.is_focusable = true;
332 field.should_autocomplete = false; 328 field.should_autocomplete = false;
333 const gfx::RectF element_bounds; 329 const gfx::RectF element_bounds;
334 330
335 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); 331 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true);
336 332
337 EXPECT_CALL(manager_delegate_, 333 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _))
338 ShowAutofillPopup(_, _, _, _, _, _, _)).Times(0); 334 .Times(0);
339 EXPECT_CALL(manager_delegate_, HideAutofillPopup()).Times(1); 335 EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(1);
340 336
341 // This should not call ShowAutofillPopup. 337 // This should not call ShowAutofillPopup.
342 std::vector<base::string16> autofill_item; 338 std::vector<base::string16> autofill_item;
343 autofill_item.push_back(base::string16()); 339 autofill_item.push_back(base::string16());
344 std::vector<int> autofill_ids; 340 std::vector<int> autofill_ids;
345 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 341 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
346 external_delegate_->OnSuggestionsReturned(kQueryId, 342 external_delegate_->OnSuggestionsReturned(kQueryId,
347 autofill_item, 343 autofill_item,
348 autofill_item, 344 autofill_item,
349 autofill_item, 345 autofill_item,
350 autofill_ids); 346 autofill_ids);
351 } 347 }
352 348
353 // Test that the Autofill delegate doesn't try and fill a form with a 349 // Test that the Autofill delegate doesn't try and fill a form with a
354 // negative unique id. 350 // negative unique id.
355 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { 351 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) {
356 // Ensure it doesn't try to preview the negative id. 352 // Ensure it doesn't try to preview the negative id.
357 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); 353 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0);
358 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 354 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
359 external_delegate_->DidSelectSuggestion(base::string16(), -1); 355 external_delegate_->DidSelectSuggestion(base::string16(), -1);
360 356
361 // Ensure it doesn't try to fill the form in with the negative id. 357 // Ensure it doesn't try to fill the form in with the negative id.
362 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 358 EXPECT_CALL(autofill_client_, HideAutofillPopup());
363 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); 359 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0);
364 external_delegate_->DidAcceptSuggestion(base::string16(), -1); 360 external_delegate_->DidAcceptSuggestion(base::string16(), -1);
365 } 361 }
366 362
367 // Test that the ClearPreview call is only sent if the form was being previewed 363 // Test that the ClearPreview call is only sent if the form was being previewed
368 // (i.e. it isn't autofilling a password). 364 // (i.e. it isn't autofilling a password).
369 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { 365 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) {
370 // Ensure selecting a new password entries or Autofill entries will 366 // Ensure selecting a new password entries or Autofill entries will
371 // cause any previews to get cleared. 367 // cause any previews to get cleared.
372 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 368 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
(...skipping 10 matching lines...) Expand all
383 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); 379 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1);
384 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue( 380 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue(
385 ASCIIToUTF16("baz foo"))); 381 ASCIIToUTF16("baz foo")));
386 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), 382 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"),
387 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 383 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
388 } 384 }
389 385
390 // Test that the popup is hidden once we are done editing the autofill field. 386 // Test that the popup is hidden once we are done editing the autofill field.
391 TEST_F(AutofillExternalDelegateUnitTest, 387 TEST_F(AutofillExternalDelegateUnitTest,
392 ExternalDelegateHidePopupAfterEditing) { 388 ExternalDelegateHidePopupAfterEditing) {
393 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); 389 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _));
394 autofill::GenerateTestAutofillPopup(external_delegate_.get()); 390 autofill::GenerateTestAutofillPopup(external_delegate_.get());
395 391
396 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 392 EXPECT_CALL(autofill_client_, HideAutofillPopup());
397 external_delegate_->DidEndTextFieldEditing(); 393 external_delegate_->DidEndTextFieldEditing();
398 } 394 }
399 395
400 // Test that the driver is directed to accept the data list after being notified 396 // Test that the driver is directed to accept the data list after being notified
401 // that the user accepted the data list suggestion. 397 // that the user accepted the data list suggestion.
402 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateAcceptSuggestion) { 398 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateAcceptSuggestion) {
403 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 399 EXPECT_CALL(autofill_client_, HideAutofillPopup());
404 base::string16 dummy_string(ASCIIToUTF16("baz qux")); 400 base::string16 dummy_string(ASCIIToUTF16("baz qux"));
405 EXPECT_CALL(*autofill_driver_, 401 EXPECT_CALL(*autofill_driver_,
406 RendererShouldAcceptDataListSuggestion(dummy_string)); 402 RendererShouldAcceptDataListSuggestion(dummy_string));
407 external_delegate_->DidAcceptSuggestion(dummy_string, 403 external_delegate_->DidAcceptSuggestion(dummy_string,
408 POPUP_ITEM_ID_DATALIST_ENTRY); 404 POPUP_ITEM_ID_DATALIST_ENTRY);
409 } 405 }
410 406
411 // Test that the driver is directed to clear the form after being notified that 407 // Test that the driver is directed to clear the form after being notified that
412 // the user accepted the suggestion to clear the form. 408 // the user accepted the suggestion to clear the form.
413 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearForm) { 409 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearForm) {
414 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 410 EXPECT_CALL(autofill_client_, HideAutofillPopup());
415 EXPECT_CALL(*autofill_driver_, RendererShouldClearFilledForm()); 411 EXPECT_CALL(*autofill_driver_, RendererShouldClearFilledForm());
416 412
417 external_delegate_->DidAcceptSuggestion(base::string16(), 413 external_delegate_->DidAcceptSuggestion(base::string16(),
418 POPUP_ITEM_ID_CLEAR_FORM); 414 POPUP_ITEM_ID_CLEAR_FORM);
419 } 415 }
420 416
421 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { 417 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) {
422 // Set up a field that shouldn't get autocompleted or display warnings. 418 // Set up a field that shouldn't get autocompleted or display warnings.
423 const FormData form; 419 const FormData form;
424 FormFieldData field; 420 FormFieldData field;
425 field.is_focusable = true; 421 field.is_focusable = true;
426 field.should_autocomplete = false; 422 field.should_autocomplete = false;
427 const gfx::RectF element_bounds; 423 const gfx::RectF element_bounds;
428 424
429 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); 425 external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false);
430 426
431 std::vector<base::string16> autofill_items; 427 std::vector<base::string16> autofill_items;
432 autofill_items.push_back(base::string16()); 428 autofill_items.push_back(base::string16());
433 std::vector<int> autofill_ids; 429 std::vector<int> autofill_ids;
434 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 430 autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
435 431
436 // Ensure the popup tries to hide itself, since it is not allowed to show 432 // Ensure the popup tries to hide itself, since it is not allowed to show
437 // anything. 433 // anything.
438 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 434 EXPECT_CALL(autofill_client_, HideAutofillPopup());
439 435
440 external_delegate_->OnSuggestionsReturned(kQueryId, 436 external_delegate_->OnSuggestionsReturned(kQueryId,
441 autofill_items, 437 autofill_items,
442 autofill_items, 438 autofill_items,
443 autofill_items, 439 autofill_items,
444 autofill_ids); 440 autofill_ids);
445 } 441 }
446 442
447 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) { 443 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) {
448 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); 444 EXPECT_CALL(autofill_client_, HideAutofillPopup());
449 base::string16 dummy_string(ASCIIToUTF16("baz foo")); 445 base::string16 dummy_string(ASCIIToUTF16("baz foo"));
450 EXPECT_CALL(*autofill_driver_, 446 EXPECT_CALL(*autofill_driver_,
451 RendererShouldFillFieldWithValue(dummy_string)); 447 RendererShouldFillFieldWithValue(dummy_string));
452 external_delegate_->DidAcceptSuggestion(dummy_string, 448 external_delegate_->DidAcceptSuggestion(dummy_string,
453 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); 449 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY);
454 } 450 }
455 451
456 } // namespace autofill 452 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_external_delegate.cc ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698