| 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 <memory> | 5 #include <memory> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 base::i18n::TextDirection text_direction, | 71 base::i18n::TextDirection text_direction, |
| 72 const std::vector<Suggestion>& suggestions, | 72 const std::vector<Suggestion>& suggestions, |
| 73 base::WeakPtr<AutofillPopupDelegate> delegate)); | 73 base::WeakPtr<AutofillPopupDelegate> delegate)); |
| 74 | 74 |
| 75 MOCK_METHOD2(UpdateAutofillPopupDataListValues, | 75 MOCK_METHOD2(UpdateAutofillPopupDataListValues, |
| 76 void(const std::vector<base::string16>& values, | 76 void(const std::vector<base::string16>& values, |
| 77 const std::vector<base::string16>& lables)); | 77 const std::vector<base::string16>& lables)); |
| 78 | 78 |
| 79 MOCK_METHOD0(HideAutofillPopup, void()); | 79 MOCK_METHOD0(HideAutofillPopup, void()); |
| 80 | 80 |
| 81 MOCK_METHOD0(StartSigninFlow, void()); | 81 MOCK_METHOD1(ExecuteCommand, void(int)); |
| 82 | |
| 83 MOCK_METHOD0(ShowHttpNotSecureExplanation, void()); | |
| 84 | 82 |
| 85 private: | 83 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); | 84 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); |
| 87 }; | 85 }; |
| 88 | 86 |
| 89 class MockAutofillManager : public AutofillManager { | 87 class MockAutofillManager : public AutofillManager { |
| 90 public: | 88 public: |
| 91 MockAutofillManager(AutofillDriver* driver, MockAutofillClient* client) | 89 MockAutofillManager(AutofillDriver* driver, MockAutofillClient* client) |
| 92 // Force to use the constructor designated for unit test, but we don't | 90 // Force to use the constructor designated for unit test, but we don't |
| 93 // really need personal_data in this test so we pass a NULL pointer. | 91 // really need personal_data in this test so we pass a NULL pointer. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _)); | 253 ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _)); |
| 256 | 254 |
| 257 base::UserActionTester user_action_tester; | 255 base::UserActionTester user_action_tester; |
| 258 | 256 |
| 259 // This should call ShowAutofillPopup. | 257 // This should call ShowAutofillPopup. |
| 260 std::vector<Suggestion> items; | 258 std::vector<Suggestion> items; |
| 261 external_delegate_->OnSuggestionsReturned(kQueryId, items); | 259 external_delegate_->OnSuggestionsReturned(kQueryId, items); |
| 262 EXPECT_EQ(1, user_action_tester.GetActionCount( | 260 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 263 "Signin_Impression_FromAutofillDropdown")); | 261 "Signin_Impression_FromAutofillDropdown")); |
| 264 | 262 |
| 265 EXPECT_CALL(autofill_client_, StartSigninFlow()); | 263 EXPECT_CALL(autofill_client_, |
| 264 ExecuteCommand(autofill::POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO)); |
| 266 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 265 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 267 | 266 |
| 268 // This should trigger a call to start the signin flow and hide the popup | 267 // This should trigger a call to start the signin flow and hide the popup |
| 269 // since we've selected the sign-in promo option. | 268 // since we've selected the sign-in promo option. |
| 270 external_delegate_->DidAcceptSuggestion( | 269 external_delegate_->DidAcceptSuggestion( |
| 271 base::string16(), POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO, 0); | 270 base::string16(), POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO, 0); |
| 272 } | 271 } |
| 273 | 272 |
| 274 // Test that data list elements for a node will appear in the Autofill popup. | 273 // Test that data list elements for a node will appear in the Autofill popup. |
| 275 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { | 274 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 external_delegate_->DidAcceptSuggestion(base::string16(), | 659 external_delegate_->DidAcceptSuggestion(base::string16(), |
| 661 POPUP_ITEM_ID_CLEAR_FORM, | 660 POPUP_ITEM_ID_CLEAR_FORM, |
| 662 0); | 661 0); |
| 663 histogram.ExpectTotalCount("Autofill.ScanCreditCardPrompt", 0); | 662 histogram.ExpectTotalCount("Autofill.ScanCreditCardPrompt", 0); |
| 664 } | 663 } |
| 665 } | 664 } |
| 666 | 665 |
| 667 // Test that autofill client will start the signin flow after the user accepted | 666 // Test that autofill client will start the signin flow after the user accepted |
| 668 // the suggestion to sign in. | 667 // the suggestion to sign in. |
| 669 TEST_F(AutofillExternalDelegateUnitTest, SigninPromoMenuItem) { | 668 TEST_F(AutofillExternalDelegateUnitTest, SigninPromoMenuItem) { |
| 670 EXPECT_CALL(autofill_client_, StartSigninFlow()); | 669 EXPECT_CALL(autofill_client_, |
| 670 ExecuteCommand(autofill::POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO)); |
| 671 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 671 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 672 external_delegate_->DidAcceptSuggestion( | 672 external_delegate_->DidAcceptSuggestion( |
| 673 base::string16(), POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO, 0); | 673 base::string16(), POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO, 0); |
| 674 } | 674 } |
| 675 | 675 |
| 676 // Test that autofill client will open the security indicator help center url | 676 // Test that autofill client will open the security indicator help center url |
| 677 // after the user accepted the http warning message suggestion item. | 677 // after the user accepted the http warning message suggestion item. |
| 678 TEST_F(AutofillExternalDelegateUnitTest, HttpWarningMessageItem) { | 678 TEST_F(AutofillExternalDelegateUnitTest, HttpWarningMessageItem) { |
| 679 EXPECT_CALL(autofill_client_, ShowHttpNotSecureExplanation()); | 679 EXPECT_CALL( |
| 680 autofill_client_, |
| 681 ExecuteCommand(autofill::POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE)); |
| 680 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 682 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 681 external_delegate_->DidAcceptSuggestion( | 683 external_delegate_->DidAcceptSuggestion( |
| 682 base::string16(), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); | 684 base::string16(), POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE, 0); |
| 683 } | 685 } |
| 684 | 686 |
| 685 MATCHER_P(CreditCardMatches, card, "") { | 687 MATCHER_P(CreditCardMatches, card, "") { |
| 686 return !arg.Compare(card); | 688 return !arg.Compare(card); |
| 687 } | 689 } |
| 688 | 690 |
| 689 // Test that autofill manager will fill the credit card form after user scans a | 691 // Test that autofill manager will fill the credit card form after user scans a |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 RendererShouldFillFieldWithValue(dummy_string)); | 724 RendererShouldFillFieldWithValue(dummy_string)); |
| 723 base::HistogramTester histogram_tester; | 725 base::HistogramTester histogram_tester; |
| 724 external_delegate_->DidAcceptSuggestion(dummy_string, | 726 external_delegate_->DidAcceptSuggestion(dummy_string, |
| 725 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, | 727 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, |
| 726 0); | 728 0); |
| 727 histogram_tester.ExpectUniqueSample( | 729 histogram_tester.ExpectUniqueSample( |
| 728 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1); | 730 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1); |
| 729 } | 731 } |
| 730 | 732 |
| 731 } // namespace autofill | 733 } // namespace autofill |
| OLD | NEW |