| OLD | NEW |
| 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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const int kAutofillProfileId = 1; | 35 const int kAutofillProfileId = 1; |
| 36 | 36 |
| 37 class MockAutofillDriver : public TestAutofillDriver { | 37 class MockAutofillDriver : public TestAutofillDriver { |
| 38 public: | 38 public: |
| 39 MockAutofillDriver() {} | 39 MockAutofillDriver() {} |
| 40 // Mock methods to enable testability. | 40 // Mock methods to enable testability. |
| 41 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion, | 41 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion, |
| 42 void(const base::string16&)); | 42 void(const base::string16&)); |
| 43 MOCK_METHOD0(RendererShouldClearFilledForm, void()); | 43 MOCK_METHOD0(RendererShouldClearFilledForm, void()); |
| 44 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); | 44 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); |
| 45 MOCK_METHOD1(RendererShouldSetNodeText, void(const base::string16&)); | 45 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&)); |
| 46 MOCK_METHOD1(RendererShouldPreviewFieldWithValue, |
| 47 void(const base::string16&)); |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); | 50 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 class MockAutofillManagerDelegate | 53 class MockAutofillManagerDelegate |
| 52 : public autofill::TestAutofillManagerDelegate { | 54 : public autofill::TestAutofillManagerDelegate { |
| 53 public: | 55 public: |
| 54 MockAutofillManagerDelegate() {} | 56 MockAutofillManagerDelegate() {} |
| 55 | 57 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 autofill_item, | 350 autofill_item, |
| 349 autofill_ids); | 351 autofill_ids); |
| 350 } | 352 } |
| 351 | 353 |
| 352 // Test that the Autofill delegate doesn't try and fill a form with a | 354 // Test that the Autofill delegate doesn't try and fill a form with a |
| 353 // negative unique id. | 355 // negative unique id. |
| 354 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 356 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
| 355 // Ensure it doesn't try to preview the negative id. | 357 // Ensure it doesn't try to preview the negative id. |
| 356 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); | 358 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); |
| 357 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 359 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 358 external_delegate_->DidSelectSuggestion(-1); | 360 external_delegate_->DidSelectSuggestion(base::string16(), -1); |
| 359 | 361 |
| 360 // Ensure it doesn't try to fill the form in with the negative id. | 362 // Ensure it doesn't try to fill the form in with the negative id. |
| 361 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 363 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 362 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); | 364 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); |
| 363 external_delegate_->DidAcceptSuggestion(base::string16(), -1); | 365 external_delegate_->DidAcceptSuggestion(base::string16(), -1); |
| 364 } | 366 } |
| 365 | 367 |
| 366 // Test that the ClearPreview call is only sent if the form was being previewed | 368 // Test that the ClearPreview call is only sent if the form was being previewed |
| 367 // (i.e. it isn't autofilling a password). | 369 // (i.e. it isn't autofilling a password). |
| 368 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { | 370 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { |
| 369 // Ensure selecting a new password entries or Autofill entries will | 371 // Ensure selecting a new password entries or Autofill entries will |
| 370 // cause any previews to get cleared. | 372 // cause any previews to get cleared. |
| 371 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 373 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 372 external_delegate_->DidSelectSuggestion(POPUP_ITEM_ID_PASSWORD_ENTRY); | 374 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), |
| 375 POPUP_ITEM_ID_PASSWORD_ENTRY); |
| 373 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 376 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 374 EXPECT_CALL(*autofill_manager_, | 377 EXPECT_CALL(*autofill_manager_, |
| 375 FillOrPreviewForm( | 378 FillOrPreviewForm( |
| 376 AutofillDriver::FORM_DATA_ACTION_PREVIEW, _, _, _, _)); | 379 AutofillDriver::FORM_DATA_ACTION_PREVIEW, _, _, _, _)); |
| 377 external_delegate_->DidSelectSuggestion(1); | 380 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), 1); |
| 381 |
| 382 // Ensure selecting an autocomplete entry will cause any previews to |
| 383 // get cleared. |
| 384 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 385 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue( |
| 386 ASCIIToUTF16("baz foo"))); |
| 387 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), |
| 388 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
| 378 } | 389 } |
| 379 | 390 |
| 380 // Test that the popup is hidden once we are done editing the autofill field. | 391 // Test that the popup is hidden once we are done editing the autofill field. |
| 381 TEST_F(AutofillExternalDelegateUnitTest, | 392 TEST_F(AutofillExternalDelegateUnitTest, |
| 382 ExternalDelegateHidePopupAfterEditing) { | 393 ExternalDelegateHidePopupAfterEditing) { |
| 383 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); | 394 EXPECT_CALL(manager_delegate_, ShowAutofillPopup(_, _, _, _, _, _, _)); |
| 384 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 395 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 385 | 396 |
| 386 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 397 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 387 external_delegate_->DidEndTextFieldEditing(); | 398 external_delegate_->DidEndTextFieldEditing(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // anything. | 484 // anything. |
| 474 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 485 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 475 | 486 |
| 476 external_delegate_->OnSuggestionsReturned(kQueryId, | 487 external_delegate_->OnSuggestionsReturned(kQueryId, |
| 477 autofill_items, | 488 autofill_items, |
| 478 autofill_items, | 489 autofill_items, |
| 479 autofill_items, | 490 autofill_items, |
| 480 autofill_ids); | 491 autofill_ids); |
| 481 } | 492 } |
| 482 | 493 |
| 483 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateSetNodeText) { | 494 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) { |
| 484 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); | 495 EXPECT_CALL(manager_delegate_, HideAutofillPopup()); |
| 485 base::string16 dummy_string(ASCIIToUTF16("baz foo")); | 496 base::string16 dummy_string(ASCIIToUTF16("baz foo")); |
| 486 EXPECT_CALL(*autofill_driver_, | 497 EXPECT_CALL(*autofill_driver_, |
| 487 RendererShouldSetNodeText(dummy_string)); | 498 RendererShouldFillFieldWithValue(dummy_string)); |
| 488 external_delegate_->DidAcceptSuggestion(dummy_string, | 499 external_delegate_->DidAcceptSuggestion(dummy_string, |
| 489 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); | 500 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
| 490 } | 501 } |
| 491 | 502 |
| 492 } // namespace autofill | 503 } // namespace autofill |
| OLD | NEW |