| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 base::i18n::TextDirection text_direction, | 69 base::i18n::TextDirection text_direction, |
| 70 const std::vector<Suggestion>& suggestions, | 70 const std::vector<Suggestion>& suggestions, |
| 71 base::WeakPtr<AutofillPopupDelegate> delegate)); | 71 base::WeakPtr<AutofillPopupDelegate> delegate)); |
| 72 | 72 |
| 73 MOCK_METHOD2(UpdateAutofillPopupDataListValues, | 73 MOCK_METHOD2(UpdateAutofillPopupDataListValues, |
| 74 void(const std::vector<base::string16>& values, | 74 void(const std::vector<base::string16>& values, |
| 75 const std::vector<base::string16>& lables)); | 75 const std::vector<base::string16>& lables)); |
| 76 | 76 |
| 77 MOCK_METHOD0(HideAutofillPopup, void()); | 77 MOCK_METHOD0(HideAutofillPopup, void()); |
| 78 | 78 |
| 79 MOCK_METHOD0(StartSigninFlow, void()); |
| 80 |
| 79 private: | 81 private: |
| 80 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); | 82 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 class MockAutofillManager : public AutofillManager { | 85 class MockAutofillManager : public AutofillManager { |
| 84 public: | 86 public: |
| 85 MockAutofillManager(AutofillDriver* driver, MockAutofillClient* client) | 87 MockAutofillManager(AutofillDriver* driver, MockAutofillClient* client) |
| 86 // Force to use the constructor designated for unit test, but we don't | 88 // Force to use the constructor designated for unit test, but we don't |
| 87 // really need personal_data in this test so we pass a NULL pointer. | 89 // really need personal_data in this test so we pass a NULL pointer. |
| 88 : AutofillManager(driver, client, NULL) {} | 90 : AutofillManager(driver, client, NULL) {} |
| 89 virtual ~MockAutofillManager() {} | 91 virtual ~MockAutofillManager() {} |
| 90 | 92 |
| 91 MOCK_METHOD2(ShouldShowScanCreditCard, | 93 MOCK_METHOD2(ShouldShowScanCreditCard, |
| 92 bool(const FormData& form, const FormFieldData& field)); | 94 bool(const FormData& form, const FormFieldData& field)); |
| 93 | 95 |
| 96 MOCK_METHOD2(ShouldShowCreditCardSigninPromo, |
| 97 bool(const FormData& form, const FormFieldData& field)); |
| 98 |
| 94 MOCK_METHOD5(FillOrPreviewForm, | 99 MOCK_METHOD5(FillOrPreviewForm, |
| 95 void(AutofillDriver::RendererFormDataAction action, | 100 void(AutofillDriver::RendererFormDataAction action, |
| 96 int query_id, | 101 int query_id, |
| 97 const FormData& form, | 102 const FormData& form, |
| 98 const FormFieldData& field, | 103 const FormFieldData& field, |
| 99 int unique_id)); | 104 int unique_id)); |
| 100 | 105 |
| 101 MOCK_METHOD5(FillCreditCardForm, | 106 MOCK_METHOD5(FillCreditCardForm, |
| 102 void(int query_id, | 107 void(int query_id, |
| 103 const FormData& form, | 108 const FormData& form, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); | 186 AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); |
| 182 EXPECT_CALL(autofill_client_, HideAutofillPopup()); | 187 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 183 | 188 |
| 184 // This should trigger a call to hide the popup since we've selected an | 189 // This should trigger a call to hide the popup since we've selected an |
| 185 // option. | 190 // option. |
| 186 external_delegate_->DidAcceptSuggestion(autofill_item[0].value, | 191 external_delegate_->DidAcceptSuggestion(autofill_item[0].value, |
| 187 autofill_item[0].frontend_id, | 192 autofill_item[0].frontend_id, |
| 188 0); | 193 0); |
| 189 } | 194 } |
| 190 | 195 |
| 196 // Test that our external delegate properly adds the signin promo and its |
| 197 // separator in the popup items. |
| 198 TEST_F(AutofillExternalDelegateUnitTest, TestSigninPromoIsAdded) { |
| 199 EXPECT_CALL(*autofill_manager_, ShouldShowCreditCardSigninPromo(_, _)) |
| 200 .WillOnce(testing::Return(true)); |
| 201 |
| 202 IssueOnQuery(kQueryId); |
| 203 |
| 204 // The enums must be cast to ints to prevent compile errors on linux_rel. |
| 205 auto element_ids = testing::ElementsAre( |
| 206 kAutofillProfileId, |
| 207 #if !defined(OS_ANDROID) |
| 208 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 209 #endif |
| 210 static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS), |
| 211 #if !defined(OS_ANDROID) |
| 212 static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
| 213 #endif |
| 214 static_cast<int>(POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO)); |
| 215 |
| 216 EXPECT_CALL(autofill_client_, |
| 217 ShowAutofillPopup(_, _, SuggestionVectorIdsAre(element_ids), _)); |
| 218 |
| 219 // This should call ShowAutofillPopup. |
| 220 std::vector<Suggestion> autofill_item; |
| 221 autofill_item.push_back(Suggestion()); |
| 222 autofill_item[0].frontend_id = kAutofillProfileId; |
| 223 external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
| 224 |
| 225 EXPECT_CALL( |
| 226 *autofill_manager_, |
| 227 FillOrPreviewForm(AutofillDriver::FORM_DATA_ACTION_FILL, _, _, _, _)); |
| 228 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 229 |
| 230 // This should trigger a call to hide the popup since we've selected an |
| 231 // option. |
| 232 external_delegate_->DidAcceptSuggestion(autofill_item[0].value, |
| 233 autofill_item[0].frontend_id, 0); |
| 234 } |
| 235 |
| 191 // Test that data list elements for a node will appear in the Autofill popup. | 236 // Test that data list elements for a node will appear in the Autofill popup. |
| 192 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { | 237 TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
| 193 IssueOnQuery(kQueryId); | 238 IssueOnQuery(kQueryId); |
| 194 | 239 |
| 195 std::vector<base::string16> data_list_items; | 240 std::vector<base::string16> data_list_items; |
| 196 data_list_items.push_back(base::string16()); | 241 data_list_items.push_back(base::string16()); |
| 197 | 242 |
| 198 EXPECT_CALL( | 243 EXPECT_CALL( |
| 199 autofill_client_, | 244 autofill_client_, |
| 200 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); | 245 UpdateAutofillPopupDataListValues(data_list_items, data_list_items)); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 602 |
| 558 MATCHER_P3(CreditCardMatches, | 603 MATCHER_P3(CreditCardMatches, |
| 559 card_number, | 604 card_number, |
| 560 expiration_month, | 605 expiration_month, |
| 561 expiration_year, | 606 expiration_year, |
| 562 "") { | 607 "") { |
| 563 return !arg.Compare( | 608 return !arg.Compare( |
| 564 CreditCard(card_number, expiration_month, expiration_year)); | 609 CreditCard(card_number, expiration_month, expiration_year)); |
| 565 } | 610 } |
| 566 | 611 |
| 612 // Test that autofill client will start the sign-in flow after the user accepted |
| 613 // the suggestion to sign in. |
| 614 TEST_F(AutofillExternalDelegateUnitTest, SigninPromoMenuItem) { |
| 615 EXPECT_CALL(autofill_client_, StartSigninFlow()); |
| 616 EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
| 617 external_delegate_->DidAcceptSuggestion( |
| 618 base::string16(), POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO, 0); |
| 619 } |
| 620 |
| 567 // Test that autofill manager will fill the credit card form after user scans a | 621 // Test that autofill manager will fill the credit card form after user scans a |
| 568 // credit card. | 622 // credit card. |
| 569 TEST_F(AutofillExternalDelegateUnitTest, FillCreditCardForm) { | 623 TEST_F(AutofillExternalDelegateUnitTest, FillCreditCardForm) { |
| 570 base::string16 card_number = base::ASCIIToUTF16("test"); | 624 base::string16 card_number = base::ASCIIToUTF16("test"); |
| 571 int expiration_month = 1; | 625 int expiration_month = 1; |
| 572 int expiration_year = 3000; | 626 int expiration_year = 3000; |
| 573 EXPECT_CALL(*autofill_manager_, | 627 EXPECT_CALL(*autofill_manager_, |
| 574 FillCreditCardForm( | 628 FillCreditCardForm( |
| 575 _, _, _, CreditCardMatches(card_number, expiration_month, | 629 _, _, _, CreditCardMatches(card_number, expiration_month, |
| 576 expiration_year), | 630 expiration_year), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 605 RendererShouldFillFieldWithValue(dummy_string)); | 659 RendererShouldFillFieldWithValue(dummy_string)); |
| 606 base::HistogramTester histogram_tester; | 660 base::HistogramTester histogram_tester; |
| 607 external_delegate_->DidAcceptSuggestion(dummy_string, | 661 external_delegate_->DidAcceptSuggestion(dummy_string, |
| 608 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, | 662 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY, |
| 609 0); | 663 0); |
| 610 histogram_tester.ExpectUniqueSample( | 664 histogram_tester.ExpectUniqueSample( |
| 611 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1); | 665 "Autofill.SuggestionAcceptedIndex.Autocomplete", 0, 1); |
| 612 } | 666 } |
| 613 | 667 |
| 614 } // namespace autofill | 668 } // namespace autofill |
| OLD | NEW |