| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 class MockAutofillDriver : public TestAutofillDriver { | 41 class MockAutofillDriver : public TestAutofillDriver { |
| 42 public: | 42 public: |
| 43 MockAutofillDriver() {} | 43 MockAutofillDriver() {} |
| 44 // Mock methods to enable testability. | 44 // Mock methods to enable testability. |
| 45 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion, | 45 MOCK_METHOD1(RendererShouldAcceptDataListSuggestion, |
| 46 void(const base::string16&)); | 46 void(const base::string16&)); |
| 47 MOCK_METHOD0(RendererShouldClearFilledForm, void()); | 47 MOCK_METHOD0(RendererShouldClearFilledForm, void()); |
| 48 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); | 48 MOCK_METHOD0(RendererShouldClearPreviewedForm, void()); |
| 49 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&)); | 49 MOCK_METHOD1(RendererShouldFillFieldWithValue, void(const base::string16&)); |
| 50 MOCK_METHOD1(RendererShouldPreviewFieldWithValue, | 50 MOCK_METHOD2(RendererShouldPreviewFieldWithValue, |
| 51 void(const base::string16&)); | 51 void(const base::string16&, size_t)); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); | 54 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class MockAutofillClient : public autofill::TestAutofillClient { | 57 class MockAutofillClient : public autofill::TestAutofillClient { |
| 58 public: | 58 public: |
| 59 MockAutofillClient() {} | 59 MockAutofillClient() {} |
| 60 | 60 |
| 61 MOCK_METHOD1(ScanCreditCard, | 61 MOCK_METHOD1(ScanCreditCard, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 std::vector<Suggestion> autofill_item; | 312 std::vector<Suggestion> autofill_item; |
| 313 autofill_item.push_back(Suggestion()); | 313 autofill_item.push_back(Suggestion()); |
| 314 autofill_item[0].frontend_id = POPUP_ITEM_ID_WARNING_MESSAGE; | 314 autofill_item[0].frontend_id = POPUP_ITEM_ID_WARNING_MESSAGE; |
| 315 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); | 315 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
| 316 } | 316 } |
| 317 | 317 |
| 318 // Test that the Autofill delegate doesn't try and fill a form with a | 318 // Test that the Autofill delegate doesn't try and fill a form with a |
| 319 // negative unique id. | 319 // negative unique id. |
| 320 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { | 320 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
| 321 // Ensure it doesn't try to preview the negative id. | 321 // Ensure it doesn't try to preview the negative id. |
| 322 size_t match_start = 0; |
| 322 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); | 323 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); |
| 323 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 324 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 324 external_delegate_->DidSelectSuggestion(base::string16(), -1); | 325 external_delegate_->DidSelectSuggestion(base::string16(), -1, match_start); |
| 325 | 326 |
| 326 // Ensure it doesn't try to fill the form in with the negative id. | 327 // Ensure it doesn't try to fill the form in with the negative id. |
| 327 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 328 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 328 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); | 329 EXPECT_CALL(*autofill_manager_, FillOrPreviewForm(_, _, _, _, _)).Times(0); |
| 329 external_delegate_->DidAcceptSuggestion(base::string16(), -1, 0); | 330 external_delegate_->DidAcceptSuggestion(base::string16(), -1, 0); |
| 330 } | 331 } |
| 331 | 332 |
| 332 // Test that the ClearPreview call is only sent if the form was being previewed | 333 // Test that the ClearPreview call is only sent if the form was being previewed |
| 333 // (i.e. it isn't autofilling a password). | 334 // (i.e. it isn't autofilling a password). |
| 334 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { | 335 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { |
| 335 // Ensure selecting a new password entries or Autofill entries will | 336 // Ensure selecting a new password entries or Autofill entries will |
| 336 // cause any previews to get cleared. | 337 // cause any previews to get cleared. |
| 338 size_t match_start = 0; |
| 337 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 339 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 338 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), | 340 external_delegate_->DidSelectSuggestion( |
| 339 POPUP_ITEM_ID_PASSWORD_ENTRY); | 341 ASCIIToUTF16("baz foo"), POPUP_ITEM_ID_PASSWORD_ENTRY, match_start); |
| 340 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 342 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 341 EXPECT_CALL(*autofill_manager_, | 343 EXPECT_CALL(*autofill_manager_, |
| 342 FillOrPreviewForm( | 344 FillOrPreviewForm( |
| 343 AutofillDriver::FORM_DATA_ACTION_PREVIEW, _, _, _, _)); | 345 AutofillDriver::FORM_DATA_ACTION_PREVIEW, _, _, _, _)); |
| 344 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), 1); | 346 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), 1, |
| 347 match_start); |
| 345 | 348 |
| 346 // Ensure selecting an autocomplete entry will cause any previews to | 349 // Ensure selecting an autocomplete entry will cause any previews to |
| 347 // get cleared. | 350 // get cleared. |
| 348 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); | 351 EXPECT_CALL(*autofill_driver_, RendererShouldClearPreviewedForm()).Times(1); |
| 349 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue( | 352 EXPECT_CALL(*autofill_driver_, RendererShouldPreviewFieldWithValue( |
| 350 ASCIIToUTF16("baz foo"))); | 353 ASCIIToUTF16("baz foo"), match_start)); |
| 351 external_delegate_->DidSelectSuggestion(ASCIIToUTF16("baz foo"), | 354 external_delegate_->DidSelectSuggestion( |
| 352 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); | 355 ASCIIToUTF16("baz foo"), POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, match_start); |
| 353 } | 356 } |
| 354 | 357 |
| 355 // Test that the popup is hidden once we are done editing the autofill field. | 358 // Test that the popup is hidden once we are done editing the autofill field. |
| 356 TEST_F(AutofillExternalDelegateUnitTest, | 359 TEST_F(AutofillExternalDelegateUnitTest, |
| 357 ExternalDelegateHidePopupAfterEditing) { | 360 ExternalDelegateHidePopupAfterEditing) { |
| 358 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)); | 361 EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)); |
| 359 autofill::GenerateTestAutofillPopup(external_delegate_.get()); | 362 autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
| 360 | 363 |
| 361 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 364 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 362 external_delegate_->DidEndTextFieldEditing(); | 365 external_delegate_->DidEndTextFieldEditing(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 516 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 514 base::string16 dummy_string(ASCIIToUTF16("baz foo")); | 517 base::string16 dummy_string(ASCIIToUTF16("baz foo")); |
| 515 EXPECT_CALL(*autofill_driver_, | 518 EXPECT_CALL(*autofill_driver_, |
| 516 RendererShouldFillFieldWithValue(dummy_string)); | 519 RendererShouldFillFieldWithValue(dummy_string)); |
| 517 external_delegate_->DidAcceptSuggestion(dummy_string, | 520 external_delegate_->DidAcceptSuggestion(dummy_string, |
| 518 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, | 521 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, |
| 519 0); | 522 0); |
| 520 } | 523 } |
| 521 | 524 |
| 522 } // namespace autofill | 525 } // namespace autofill |
| OLD | NEW |