Chromium Code Reviews| Index: chrome/browser/autofill/autofill_external_delegate_unittest.cc |
| diff --git a/chrome/browser/autofill/autofill_external_delegate_unittest.cc b/chrome/browser/autofill/autofill_external_delegate_unittest.cc |
| index 44e21e88b61b09cfb463041e33209a720972a540..1c2d9b6258dbdf76242590bfb8025d084339a240 100644 |
| --- a/chrome/browser/autofill/autofill_external_delegate_unittest.cc |
| +++ b/chrome/browser/autofill/autofill_external_delegate_unittest.cc |
| @@ -27,6 +27,12 @@ using WebKit::WebAutofillClient; |
| namespace { |
| +// A constant value to use as the Autofill query Id. |
|
Ilya Sherman
2012/06/07 22:56:05
nit: "Id" -> either "id" or "ID"
csharp
2012/06/08 14:44:54
Done.
|
| +const int kQueryId = 5; |
| + |
| +// A constant vale to use as an Autofill profile Id. |
|
Ilya Sherman
2012/06/07 22:56:05
nit: "vale" -> "value"
csharp
2012/06/08 14:44:54
Done.
|
| +const int kAutofillProfileId = 1; |
| + |
| class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| public: |
| MockAutofillExternalDelegate(TabContentsWrapper* wrapper, |
| @@ -88,6 +94,22 @@ class AutofillExternalDelegateUnitTest : public TabContentsWrapperTestHarness { |
| } |
| protected: |
| + // Set up the expectation for a platform specific OnQuery call and then |
| + // execute it with the given QueryId. |
| + void IssueOnQuery(int query_id) { |
| + const FormData form; |
| + FormField field; |
| + field.is_focusable = true; |
| + field.should_autocomplete = true; |
| + const gfx::Rect bounds; |
| + |
| + EXPECT_CALL(*external_delegate_, |
| + OnQueryPlatformSpecific(query_id, form, field, bounds)); |
| + |
| + // This should call OnQueryPlatform specific. |
| + external_delegate_->OnQuery(query_id, form, field, bounds, false); |
| + } |
| + |
| scoped_refptr<MockAutofillManager> autofill_manager_; |
| scoped_ptr<MockAutofillExternalDelegate> external_delegate_; |
| @@ -99,26 +121,19 @@ class AutofillExternalDelegateUnitTest : public TabContentsWrapperTestHarness { |
| // Test that our external delegate called the virtual methods at the right time. |
| TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
| - const int kQueryId = 5; |
| - const FormData form; |
| - FormField field; |
| - field.is_focusable = true; |
| - field.should_autocomplete = true; |
| - const gfx::Rect bounds; |
| + IssueOnQuery(kQueryId); |
| EXPECT_CALL(*external_delegate_, |
| - OnQueryPlatformSpecific(kQueryId, form, field, bounds)); |
| - |
| - // This should call OnQueryPlatform specific. |
| - external_delegate_->OnQuery(kQueryId, form, field, bounds, false); |
| - |
| - EXPECT_CALL(*external_delegate_, ApplyAutofillSuggestions(_, _, _, _)); |
| + ApplyAutofillSuggestions(_, _, _, testing::ElementsAre( |
| + kAutofillProfileId, |
| + WebAutofillClient::MenuItemIDSeparator, |
| + WebAutofillClient::MenuItemIDAutofillOptions))); |
| // This should call ApplyAutofillSuggestions. |
| std::vector<string16> autofill_item; |
| autofill_item.push_back(string16()); |
| std::vector<int> autofill_ids; |
| - autofill_ids.push_back(1); |
| + autofill_ids.push_back(kAutofillProfileId); |
| external_delegate_->OnSuggestionsReturned(kQueryId, |
| autofill_item, |
| autofill_item, |
| @@ -137,11 +152,62 @@ TEST_F(AutofillExternalDelegateUnitTest, TestExternalDelegateVirtualCalls) { |
| autofill_ids[0], 0); |
| } |
| +// Test that data list elements for a node will appear in the Autofill popup. |
| +TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateDataList) { |
| + IssueOnQuery(kQueryId); |
| + |
| + std::vector<string16> data_list_items; |
| + data_list_items.push_back(string16()); |
| + std::vector<int> data_list_ids; |
| + data_list_ids.push_back(WebAutofillClient::MenuItemIDDataListEntry); |
| + |
| + external_delegate_->SetCurrentDataListValues(data_list_items, |
| + data_list_items, |
| + data_list_items, |
| + data_list_ids); |
| + |
| + EXPECT_CALL(*external_delegate_, |
| + ApplyAutofillSuggestions( |
| + _, _, _, testing::ElementsAre( |
| + WebAutofillClient::MenuItemIDDataListEntry, |
| + WebAutofillClient::MenuItemIDSeparator, |
| + kAutofillProfileId, |
| + WebAutofillClient::MenuItemIDSeparator, |
| + WebAutofillClient::MenuItemIDAutofillOptions))); |
| + |
| + // This should call ApplyAutofillSuggestions. |
| + std::vector<string16> autofill_item; |
| + autofill_item.push_back(string16()); |
| + std::vector<int> autofill_ids; |
| + autofill_ids.push_back(kAutofillProfileId); |
| + external_delegate_->OnSuggestionsReturned(kQueryId, |
| + autofill_item, |
| + autofill_item, |
| + autofill_item, |
| + autofill_ids); |
| + |
| + // Try calling OnSuggestionsReturned with no Autofill values and ensure |
| + // the datalist items are still shown. |
| + EXPECT_CALL(*external_delegate_, |
| + ApplyAutofillSuggestions( |
| + _, _, _, testing::ElementsAre( |
| + WebAutofillClient::MenuItemIDDataListEntry))); |
| + |
| + autofill_item = std::vector<string16>(); |
| + autofill_ids = std::vector<int>(); |
| + external_delegate_->OnSuggestionsReturned(kQueryId, |
| + autofill_item, |
| + autofill_item, |
| + autofill_item, |
| + autofill_ids); |
| +} |
| + |
| // Test that the Autofill delegate doesn't try and fill a form with a |
| // negative unique id. |
| TEST_F(AutofillExternalDelegateUnitTest, ExternalDelegateInvalidUniqueId) { |
| // Ensure it doesn't try to preview the negative id. |
| EXPECT_CALL(*autofill_manager_, OnFillAutofillFormData(_, _, _, _)).Times(0); |
| + EXPECT_CALL(*external_delegate_, ClearPreviewedForm()).Times(1); |
| external_delegate_->SelectAutofillSuggestionAtIndex(-1); |
| // Ensure it doesn't try to fill the form in with the negative id. |