Index: components/autofill/core/browser/autofill_external_delegate_unittest.cc |
diff --git a/components/autofill/core/browser/autofill_external_delegate_unittest.cc b/components/autofill/core/browser/autofill_external_delegate_unittest.cc |
index 7b078a6a2c2d67a94af6a924b39ebe841ef8abab..6890162dfad2dc89d4d1404691678e8be4c90137 100644 |
--- a/components/autofill/core/browser/autofill_external_delegate_unittest.cc |
+++ b/components/autofill/core/browser/autofill_external_delegate_unittest.cc |
@@ -12,6 +12,7 @@ |
#include "base/test/histogram_tester.h" |
#include "components/autofill/core/browser/autofill_manager.h" |
#include "components/autofill/core/browser/popup_item_ids.h" |
+#include "components/autofill/core/browser/suggestion_test_helpers.h" |
#include "components/autofill/core/browser/test_autofill_client.h" |
#include "components/autofill/core/browser/test_autofill_driver.h" |
#include "components/autofill/core/browser/test_autofill_external_delegate.h" |
@@ -59,13 +60,10 @@ class MockAutofillClient : public autofill::TestAutofillClient { |
MOCK_METHOD1(ScanCreditCard, |
void(const CreditCardScanCallback& callbacK)); |
- MOCK_METHOD7(ShowAutofillPopup, |
+ MOCK_METHOD4(ShowAutofillPopup, |
void(const gfx::RectF& element_bounds, |
base::i18n::TextDirection text_direction, |
- const std::vector<base::string16>& values, |
- const std::vector<base::string16>& labels, |
- const std::vector<base::string16>& icons, |
- const std::vector<int>& identifiers, |
+ const std::vector<Suggestion>& suggestions, |
base::WeakPtr<AutofillPopupDelegate> delegate)); |
MOCK_METHOD2(UpdateAutofillPopupDataListValues, |
@@ -139,12 +137,10 @@ class AutofillExternalDelegateUnitTest : public testing::Test { |
} |
void IssueOnSuggestionsReturned() { |
- std::vector<base::string16> autofill_item; |
- autofill_item.push_back(base::string16()); |
- std::vector<int> autofill_ids; |
- autofill_ids.push_back(kAutofillProfileId); |
- external_delegate_->OnSuggestionsReturned( |
- kQueryId, autofill_item, autofill_item, autofill_item, autofill_ids); |
+ std::vector<Suggestion> suggestions; |
+ suggestions.push_back(Suggestion()); |
+ suggestions[0].frontend_id = kAutofillProfileId; |
+ external_delegate_->OnSuggestionsReturned(kQueryId, suggestions); |
} |
testing::NiceMock<MockAutofillClient> autofill_client_; |
@@ -164,25 +160,17 @@ TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
autofill_client_, |
ShowAutofillPopup(_, |
_, |
- _, |
- _, |
- _, |
- testing::ElementsAre( |
+ SuggestionVectorIdsAre(testing::ElementsAre( |
kAutofillProfileId, |
static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
- static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), |
+ static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))), |
_)); |
// This should call ShowAutofillPopup. |
- std::vector<base::string16> autofill_item; |
- autofill_item.push_back(base::string16()); |
- std::vector<int> autofill_ids; |
- autofill_ids.push_back(kAutofillProfileId); |
- external_delegate_->OnSuggestionsReturned(kQueryId, |
- autofill_item, |
- autofill_item, |
- autofill_item, |
- autofill_ids); |
+ std::vector<Suggestion> autofill_item; |
+ autofill_item.push_back(Suggestion()); |
+ autofill_item[0].frontend_id = kAutofillProfileId; |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
EXPECT_CALL(*autofill_manager_, |
FillOrPreviewForm( |
@@ -191,7 +179,8 @@ TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
// This should trigger a call to hide the popup since we've selected an |
// option. |
- external_delegate_->DidAcceptSuggestion(autofill_item[0], autofill_ids[0]); |
+ external_delegate_->DidAcceptSuggestion(autofill_item[0].value, |
+ autofill_item[0].frontend_id); |
} |
// Test that data list elements for a node will appear in the Autofill popup. |
@@ -213,27 +202,19 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
autofill_client_, |
ShowAutofillPopup(_, |
_, |
- _, |
- _, |
- _, |
- testing::ElementsAre( |
+ SuggestionVectorIdsAre(testing::ElementsAre( |
static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
kAutofillProfileId, |
static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
- static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), |
+ static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))), |
_)); |
// This should call ShowAutofillPopup. |
- std::vector<base::string16> autofill_item; |
- autofill_item.push_back(base::string16()); |
- std::vector<int> autofill_ids; |
- autofill_ids.push_back(kAutofillProfileId); |
- external_delegate_->OnSuggestionsReturned(kQueryId, |
- autofill_item, |
- autofill_item, |
- autofill_item, |
- autofill_ids); |
+ std::vector<Suggestion> autofill_item; |
+ autofill_item.push_back(Suggestion()); |
+ autofill_item[0].frontend_id = kAutofillProfileId; |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
// Try calling OnSuggestionsReturned with no Autofill values and ensure |
// the datalist items are still shown. |
@@ -243,26 +224,19 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
ShowAutofillPopup( |
_, |
_, |
- _, |
- _, |
- _, |
- testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY)), |
+ SuggestionVectorIdsAre(testing::ElementsAre( |
+ static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY))), |
_)); |
- autofill_item = std::vector<base::string16>(); |
- autofill_ids = std::vector<int>(); |
- external_delegate_->OnSuggestionsReturned(kQueryId, |
- autofill_item, |
- autofill_item, |
- autofill_item, |
- autofill_ids); |
+ autofill_item.clear(); |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
} |
// Test that datalist values can get updated while a popup is showing. |
TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) { |
IssueOnQuery(kQueryId); |
- EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)) |
+ EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)) |
.Times(0); |
// Make sure just setting the data list values doesn't cause the popup to |
@@ -282,27 +256,19 @@ TEST_F(AutofillExternalDelegateUnitTest, UpdateDataListWhileShowingPopup) { |
autofill_client_, |
ShowAutofillPopup(_, |
_, |
- _, |
- _, |
- _, |
- testing::ElementsAre( |
+ SuggestionVectorIdsAre(testing::ElementsAre( |
static_cast<int>(POPUP_ITEM_ID_DATALIST_ENTRY), |
static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
kAutofillProfileId, |
static_cast<int>(POPUP_ITEM_ID_SEPARATOR), |
- static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS)), |
+ static_cast<int>(POPUP_ITEM_ID_AUTOFILL_OPTIONS))), |
_)); |
// Ensure the popup is displayed. |
- std::vector<base::string16> autofill_item; |
- autofill_item.push_back(base::string16()); |
- std::vector<int> autofill_ids; |
- autofill_ids.push_back(kAutofillProfileId); |
- external_delegate_->OnSuggestionsReturned(kQueryId, |
- autofill_item, |
- autofill_item, |
- autofill_item, |
- autofill_ids); |
+ std::vector<Suggestion> autofill_item; |
+ autofill_item.push_back(Suggestion()); |
+ autofill_item[0].frontend_id = kAutofillProfileId; |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
// This would normally get called from ShowAutofillPopup, but it is mocked so |
// we need to call OnPopupShown ourselves. |
@@ -332,22 +298,15 @@ TEST_F(AutofillExternalDelegateUnitTest, AutofillWarnings) { |
ShowAutofillPopup( |
_, |
_, |
- _, |
- _, |
- _, |
- testing::ElementsAre(static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE)), |
+ SuggestionVectorIdsAre(testing::ElementsAre( |
+ static_cast<int>(POPUP_ITEM_ID_WARNING_MESSAGE))), |
_)); |
// This should call ShowAutofillPopup. |
- std::vector<base::string16> autofill_item; |
- autofill_item.push_back(base::string16()); |
- std::vector<int> autofill_ids; |
- autofill_ids.push_back(POPUP_ITEM_ID_WARNING_MESSAGE); |
- external_delegate_->OnSuggestionsReturned(kQueryId, |
- autofill_item, |
- autofill_item, |
- autofill_item, |
- autofill_ids); |
+ std::vector<Suggestion> autofill_item; |
+ autofill_item.push_back(Suggestion()); |
+ autofill_item[0].frontend_id = POPUP_ITEM_ID_WARNING_MESSAGE; |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
} |
// Test that the Autofill popup doesn't display a warning explaining why |
@@ -367,20 +326,15 @@ TEST_F(AutofillExternalDelegateUnitTest, NoAutofillWarningsWithoutSuggestions) { |
external_delegate_->OnQuery(kQueryId, form, field, element_bounds, true); |
- EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)) |
+ EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)) |
.Times(0); |
EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(1); |
// This should not call ShowAutofillPopup. |
- std::vector<base::string16> autofill_item; |
- autofill_item.push_back(base::string16()); |
- std::vector<int> autofill_ids; |
- autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
- external_delegate_->OnSuggestionsReturned(kQueryId, |
- autofill_item, |
- autofill_item, |
- autofill_item, |
- autofill_ids); |
+ std::vector<Suggestion> autofill_item; |
+ autofill_item.push_back(Suggestion()); |
+ autofill_item[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_item); |
} |
// Test that the Autofill delegate doesn't try and fill a form with a |
@@ -423,7 +377,7 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateClearPreviewedForm) { |
// Test that the popup is hidden once we are done editing the autofill field. |
TEST_F(AutofillExternalDelegateUnitTest, |
ExternalDelegateHidePopupAfterEditing) { |
- EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)); |
+ EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)); |
autofill::GenerateTestAutofillPopup(external_delegate_.get()); |
EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
@@ -546,20 +500,15 @@ TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateHideWarning) { |
external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); |
- std::vector<base::string16> autofill_items; |
- autofill_items.push_back(base::string16()); |
- std::vector<int> autofill_ids; |
- autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
+ std::vector<Suggestion> autofill_items; |
+ autofill_items.push_back(Suggestion()); |
+ autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
// Ensure the popup tries to hide itself, since it is not allowed to show |
// anything. |
EXPECT_CALL(autofill_client_, HideAutofillPopup()); |
- external_delegate_->OnSuggestionsReturned(kQueryId, |
- autofill_items, |
- autofill_items, |
- autofill_items, |
- autofill_ids); |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items); |
} |
TEST_F(AutofillExternalDelegateUnitTest, IgnoreAutocompleteOffForAutofill) { |
@@ -571,20 +520,15 @@ TEST_F(AutofillExternalDelegateUnitTest, IgnoreAutocompleteOffForAutofill) { |
external_delegate_->OnQuery(kQueryId, form, field, element_bounds, false); |
- std::vector<base::string16> autofill_items; |
- autofill_items.push_back(base::string16()); |
- std::vector<int> autofill_ids; |
- autofill_ids.push_back(POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY); |
+ std::vector<Suggestion> autofill_items; |
+ autofill_items.push_back(Suggestion()); |
+ autofill_items[0].frontend_id = POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY; |
// Ensure the popup tries to show itself, despite autocomplete="off". |
- EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _, _, _, _)); |
+ EXPECT_CALL(autofill_client_, ShowAutofillPopup(_, _, _, _)); |
EXPECT_CALL(autofill_client_, HideAutofillPopup()).Times(0); |
- external_delegate_->OnSuggestionsReturned(kQueryId, |
- autofill_items, |
- autofill_items, |
- autofill_items, |
- autofill_ids); |
+ external_delegate_->OnSuggestionsReturned(kQueryId, autofill_items); |
} |
TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateFillFieldWithValue) { |