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/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
10 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
11 #include "components/autofill/browser/autofill_manager.h" | 12 #include "components/autofill/browser/autofill_manager.h" |
12 #include "components/autofill/browser/test_autofill_external_delegate.h" | 13 #include "components/autofill/browser/test_autofill_external_delegate.h" |
13 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 14 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
14 #include "components/autofill/common/form_data.h" | 15 #include "components/autofill/common/form_data.h" |
15 #include "components/autofill/common/form_field_data.h" | 16 #include "components/autofill/common/form_field_data.h" |
| 17 #include "components/autofill/common/password_form_fill_data.h" |
16 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
20 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
21 | 23 |
22 using content::BrowserThread; | 24 using content::BrowserThread; |
23 using testing::_; | 25 using testing::_; |
24 using WebKit::WebAutofillClient; | 26 using WebKit::WebAutofillClient; |
25 | 27 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _)); | 271 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _)); |
270 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 272 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
271 | 273 |
272 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 274 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
273 external_delegate_->DidEndTextFieldEditing(); | 275 external_delegate_->DidEndTextFieldEditing(); |
274 } | 276 } |
275 | 277 |
276 // Test that the popup is marked as visible after recieving password | 278 // Test that the popup is marked as visible after recieving password |
277 // suggestions. | 279 // suggestions. |
278 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { | 280 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegatePasswordSuggestions) { |
| 281 static const base::string16 kUsername = ASCIIToUTF16("username"); |
279 std::vector<base::string16> suggestions; | 282 std::vector<base::string16> suggestions; |
280 suggestions.push_back(base::string16()); | 283 suggestions.push_back(kUsername); |
281 | 284 |
282 FormFieldData field; | 285 FormFieldData field; |
283 field.is_focusable = true; | 286 field.is_focusable = true; |
284 field.should_autocomplete = true; | 287 field.should_autocomplete = true; |
285 const gfx::RectF element_bounds; | 288 const gfx::RectF element_bounds; |
286 | 289 |
| 290 FormFieldData username_field_data; |
| 291 username_field_data.value = kUsername; |
| 292 PasswordFormFillData password_form_fill_data; |
| 293 password_form_fill_data.basic_data.fields.push_back(username_field_data); |
| 294 external_delegate_->AddPasswordFormMapping(field, password_form_fill_data); |
| 295 |
287 // The enums must be cast to ints to prevent compile errors on linux_rel. | 296 // The enums must be cast to ints to prevent compile errors on linux_rel. |
288 EXPECT_CALL(manager_delegate_, | 297 EXPECT_CALL(manager_delegate_, |
289 ShowAutofillPopup( | 298 ShowAutofillPopup( |
290 _, _, _, _, | 299 _, _, _, _, |
291 testing::ElementsAre( | 300 testing::ElementsAre( |
292 static_cast<int>( | 301 static_cast<int>( |
293 WebAutofillClient::MenuItemIDPasswordEntry)), | 302 WebAutofillClient::MenuItemIDPasswordEntry)), |
294 _)); | 303 _)); |
295 | 304 |
296 external_delegate_->OnShowPasswordSuggestions(suggestions, | 305 external_delegate_->OnShowPasswordSuggestions(suggestions, |
297 field, | 306 field, |
298 element_bounds); | 307 element_bounds); |
299 | 308 |
300 // Called by DidAutofillSuggestions, add expectation to remove warning. | |
301 EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)); | |
302 | |
303 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 309 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
304 | 310 |
305 // This should trigger a call to hide the popup since | 311 // This should trigger a call to hide the popup since |
306 // we've selected an option. | 312 // we've selected an option. |
307 external_delegate_->DidAcceptSuggestion( | 313 external_delegate_->DidAcceptSuggestion( |
308 suggestions[0], | 314 suggestions[0], |
309 WebAutofillClient::MenuItemIDPasswordEntry); | 315 WebAutofillClient::MenuItemIDPasswordEntry); |
310 } | 316 } |
311 | 317 |
312 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { | 318 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { |
(...skipping 16 matching lines...) Expand all Loading... |
329 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 335 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
330 | 336 |
331 external_delegate_->OnSuggestionsReturned(kQueryId, | 337 external_delegate_->OnSuggestionsReturned(kQueryId, |
332 autofill_items, | 338 autofill_items, |
333 autofill_items, | 339 autofill_items, |
334 autofill_items, | 340 autofill_items, |
335 autofill_ids); | 341 autofill_ids); |
336 } | 342 } |
337 | 343 |
338 } // namespace autofill | 344 } // namespace autofill |
OLD | NEW |