OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 private: | 46 private: |
47 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 47 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
48 }; | 48 }; |
49 | 49 |
50 class MockAutofillManagerDelegate | 50 class MockAutofillManagerDelegate |
51 : public autofill::TestAutofillManagerDelegate { | 51 : public autofill::TestAutofillManagerDelegate { |
52 public: | 52 public: |
53 MockAutofillManagerDelegate() {} | 53 MockAutofillManagerDelegate() {} |
54 | 54 |
55 MOCK_METHOD6(ShowAutofillPopup, | 55 MOCK_METHOD7(ShowAutofillPopup, |
56 void(const gfx::RectF& element_bounds, | 56 void(const gfx::RectF& element_bounds, |
| 57 base::i18n::TextDirection text_direction, |
57 const std::vector<base::string16>& values, | 58 const std::vector<base::string16>& values, |
58 const std::vector<base::string16>& labels, | 59 const std::vector<base::string16>& labels, |
59 const std::vector<base::string16>& icons, | 60 const std::vector<base::string16>& icons, |
60 const std::vector<int>& identifiers, | 61 const std::vector<int>& identifiers, |
61 base::WeakPtr<AutofillPopupDelegate> delegate)); | 62 base::WeakPtr<AutofillPopupDelegate> delegate)); |
62 | 63 |
63 MOCK_METHOD0(HideAutofillPopup, void()); | 64 MOCK_METHOD0(HideAutofillPopup, void()); |
64 | 65 |
65 private: | 66 private: |
66 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 67 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 external_delegate_; | 129 external_delegate_; |
129 }; | 130 }; |
130 | 131 |
131 // Test that our external delegate called the virtual methods at the right time. | 132 // Test that our external delegate called the virtual methods at the right time. |
132 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { | 133 TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
133 IssueOnQuery(kQueryId); | 134 IssueOnQuery(kQueryId); |
134 | 135 |
135 // The enums must be cast to ints to prevent compile errors on linux_rel. | 136 // The enums must be cast to ints to prevent compile errors on linux_rel. |
136 EXPECT_CALL(manager_delegate_, | 137 EXPECT_CALL(manager_delegate_, |
137 ShowAutofillPopup( | 138 ShowAutofillPopup( |
138 _, _, _, _, | 139 _, _, _, _, _, |
139 testing::ElementsAre( | 140 testing::ElementsAre( |
140 kAutofillProfileId, | 141 kAutofillProfileId, |
141 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 142 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
142 static_cast<int>( | 143 static_cast<int>( |
143 WebAutofillClient::MenuItemIDAutofillOptions)), | 144 WebAutofillClient::MenuItemIDAutofillOptions)), |
144 _)); | 145 _)); |
145 | 146 |
146 // This should call ShowAutofillPopup. | 147 // This should call ShowAutofillPopup. |
147 std::vector<base::string16> autofill_item; | 148 std::vector<base::string16> autofill_item; |
148 autofill_item.push_back(base::string16()); | 149 autofill_item.push_back(base::string16()); |
(...skipping 25 matching lines...) Expand all Loading... |
174 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); | 175 data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); |
175 | 176 |
176 external_delegate_->SetCurrentDataListValues(data_list_items, | 177 external_delegate_->SetCurrentDataListValues(data_list_items, |
177 data_list_items, | 178 data_list_items, |
178 data_list_items, | 179 data_list_items, |
179 data_list_ids); | 180 data_list_ids); |
180 | 181 |
181 // The enums must be cast to ints to prevent compile errors on linux_rel. | 182 // The enums must be cast to ints to prevent compile errors on linux_rel. |
182 EXPECT_CALL(manager_delegate_, | 183 EXPECT_CALL(manager_delegate_, |
183 ShowAutofillPopup( | 184 ShowAutofillPopup( |
184 _, _, _, _, | 185 _, _, _, _, _, |
185 testing::ElementsAre( | 186 testing::ElementsAre( |
186 static_cast<int>( | 187 static_cast<int>( |
187 WebAutofillClient::MenuItemIDDataListEntry), | 188 WebAutofillClient::MenuItemIDDataListEntry), |
188 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 189 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
189 kAutofillProfileId, | 190 kAutofillProfileId, |
190 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), | 191 static_cast<int>(WebAutofillClient::MenuItemIDSeparator), |
191 static_cast<int>( | 192 static_cast<int>( |
192 WebAutofillClient::MenuItemIDAutofillOptions)), | 193 WebAutofillClient::MenuItemIDAutofillOptions)), |
193 _)); | 194 _)); |
194 | 195 |
195 // This should call ShowAutofillPopup. | 196 // This should call ShowAutofillPopup. |
196 std::vector<base::string16> autofill_item; | 197 std::vector<base::string16> autofill_item; |
197 autofill_item.push_back(base::string16()); | 198 autofill_item.push_back(base::string16()); |
198 std::vector<int> autofill_ids; | 199 std::vector<int> autofill_ids; |
199 autofill_ids.push_back(kAutofillProfileId); | 200 autofill_ids.push_back(kAutofillProfileId); |
200 external_delegate_->OnSuggestionsReturned(kQueryId, | 201 external_delegate_->OnSuggestionsReturned(kQueryId, |
201 autofill_item, | 202 autofill_item, |
202 autofill_item, | 203 autofill_item, |
203 autofill_item, | 204 autofill_item, |
204 autofill_ids); | 205 autofill_ids); |
205 | 206 |
206 // Try calling OnSuggestionsReturned with no Autofill values and ensure | 207 // Try calling OnSuggestionsReturned with no Autofill values and ensure |
207 // the datalist items are still shown. | 208 // the datalist items are still shown. |
208 // The enum must be cast to an int to prevent compile errors on linux_rel. | 209 // The enum must be cast to an int to prevent compile errors on linux_rel. |
209 EXPECT_CALL(manager_delegate_, | 210 EXPECT_CALL(manager_delegate_, |
210 ShowAutofillPopup( | 211 ShowAutofillPopup( |
211 _, _, _, _, | 212 _, _, _, _, _, |
212 testing::ElementsAre( | 213 testing::ElementsAre( |
213 static_cast<int>( | 214 static_cast<int>( |
214 WebAutofillClient::MenuItemIDDataListEntry)), | 215 WebAutofillClient::MenuItemIDDataListEntry)), |
215 _)); | 216 _)); |
216 | 217 |
217 autofill_item = std::vector<base::string16>(); | 218 autofill_item = std::vector<base::string16>(); |
218 autofill_ids = std::vector<int>(); | 219 autofill_ids = std::vector<int>(); |
219 external_delegate_->OnSuggestionsReturned(kQueryId, | 220 external_delegate_->OnSuggestionsReturned(kQueryId, |
220 autofill_item, | 221 autofill_item, |
221 autofill_item, | 222 autofill_item, |
222 autofill_item, | 223 autofill_item, |
223 autofill_ids); | 224 autofill_ids); |
224 } | 225 } |
225 | 226 |
226 // Test that the Autofill popup is able to display warnings explaining why | 227 // Test that the Autofill popup is able to display warnings explaining why |
227 // Autofill is disabled for a website. | 228 // Autofill is disabled for a website. |
228 // Regression test for http://crbug.com/247880 | 229 // Regression test for http://crbug.com/247880 |
229 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { | 230 TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { |
230 IssueOnQuery(kQueryId); | 231 IssueOnQuery(kQueryId); |
231 | 232 |
232 // The enums must be cast to ints to prevent compile errors on linux_rel. | 233 // The enums must be cast to ints to prevent compile errors on linux_rel. |
233 EXPECT_CALL(manager_delegate_, | 234 EXPECT_CALL(manager_delegate_, |
234 ShowAutofillPopup( | 235 ShowAutofillPopup( |
235 _, _, _, _, | 236 _, _, _, _, _, |
236 testing::ElementsAre( | 237 testing::ElementsAre( |
237 static_cast<int>( | 238 static_cast<int>( |
238 WebAutofillClient::MenuItemIDWarningMessage)), | 239 WebAutofillClient::MenuItemIDWarningMessage)), |
239 _)); | 240 _)); |
240 | 241 |
241 // This should call ShowAutofillPopup. | 242 // This should call ShowAutofillPopup. |
242 std::vector<base::string16> autofill_item; | 243 std::vector<base::string16> autofill_item; |
243 autofill_item.push_back(base::string16()); | 244 autofill_item.push_back(base::string16()); |
244 std::vector<int> autofill_ids; | 245 std::vector<int> autofill_ids; |
245 autofill_ids.push_back(WebAutofillClient::MenuItemIDWarningMessage); | 246 autofill_ids.push_back(WebAutofillClient::MenuItemIDWarningMessage); |
(...skipping 30 matching lines...) Expand all Loading... |
276 external_delegate_->DidSelectSuggestion( | 277 external_delegate_->DidSelectSuggestion( |
277 WebAutofillClient::MenuItemIDPasswordEntry); | 278 WebAutofillClient::MenuItemIDPasswordEntry); |
278 | 279 |
279 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); | 280 EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
280 external_delegate_->DidSelectSuggestion(1); | 281 external_delegate_->DidSelectSuggestion(1); |
281 } | 282 } |
282 | 283 |
283 // Test that the popup is hidden once we are done editing the autofill field. | 284 // Test that the popup is hidden once we are done editing the autofill field. |
284 TEST_F(AutofillExternalDelegateUnitTest, | 285 TEST_F(AutofillExternalDelegateUnitTest, |
285 ExternalDelegateHidePopupAfterEditing) { | 286 ExternalDelegateHidePopupAfterEditing) { |
286 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _)); | 287 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); |
287 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 288 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
288 | 289 |
289 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 290 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
290 external_delegate_->DidEndTextFieldEditing(); | 291 external_delegate_->DidEndTextFieldEditing(); |
291 } | 292 } |
292 | 293 |
293 // Test that the popup is marked as visible after recieving password | 294 // Test that the popup is marked as visible after recieving password |
294 // suggestions. | 295 // suggestions. |
295 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { | 296 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { |
296 static const base::string16 kUsername = ASCIIToUTF16("username"); | 297 static const base::string16 kUsername = ASCIIToUTF16("username"); |
297 std::vector<base::string16> suggestions; | 298 std::vector<base::string16> suggestions; |
298 suggestions.push_back(kUsername); | 299 suggestions.push_back(kUsername); |
299 | 300 |
300 FormFieldData field; | 301 FormFieldData field; |
301 field.is_focusable = true; | 302 field.is_focusable = true; |
302 field.should_autocomplete = true; | 303 field.should_autocomplete = true; |
303 const gfx::RectF element_bounds; | 304 const gfx::RectF element_bounds; |
304 | 305 |
305 FormFieldData username_field_data; | 306 FormFieldData username_field_data; |
306 username_field_data.value = kUsername; | 307 username_field_data.value = kUsername; |
307 PasswordFormFillData password_form_fill_data; | 308 PasswordFormFillData password_form_fill_data; |
308 password_form_fill_data.basic_data.fields.push_back(username_field_data); | 309 password_form_fill_data.basic_data.fields.push_back(username_field_data); |
309 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data); | 310 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data); |
310 | 311 |
311 // The enums must be cast to ints to prevent compile errors on linux_rel. | 312 // The enums must be cast to ints to prevent compile errors on linux_rel. |
312 EXPECT_CALL(manager_delegate_, | 313 EXPECT_CALL(manager_delegate_, |
313 ShowAutofillPopup( | 314 ShowAutofillPopup( |
314 _, _, _, _, | 315 _, _, _, _, _, |
315 testing::ElementsAre( | 316 testing::ElementsAre( |
316 static_cast<int>( | 317 static_cast<int>( |
317 WebAutofillClient::MenuItemIDPasswordEntry)), | 318 WebAutofillClient::MenuItemIDPasswordEntry)), |
318 _)); | 319 _)); |
319 | 320 |
320 external_delegate_->OnShowPasswordSuggestions(suggestions, | 321 external_delegate_->OnShowPasswordSuggestions(suggestions, |
321 field, | 322 field, |
322 element_bounds); | 323 element_bounds); |
323 | 324 |
324 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 325 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
(...skipping 25 matching lines...) Expand all Loading... |
350 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 351 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
351 | 352 |
352 external_delegate_->OnSuggestionsReturned(kQueryId, | 353 external_delegate_->OnSuggestionsReturned(kQueryId, |
353 autofill_items, | 354 autofill_items, |
354 autofill_items, | 355 autofill_items, |
355 autofill_items, | 356 autofill_items, |
356 autofill_ids); | 357 autofill_ids); |
357 } | 358 } |
358 | 359 |
359 } // namespace autofill | 360 } // namespace autofill |
OLD | NEW |