Chromium Code Reviews| Index: chrome/browser/autofill/autofill_popup_unittest.cc |
| diff --git a/chrome/browser/autofill/autofill_popup_unittest.cc b/chrome/browser/autofill/autofill_popup_unittest.cc |
| index 4332cd63e19ccbc24f92605a42b4d217946619ed..2409610ba21d427a15081f20d0fd12033ea331d8 100644 |
| --- a/chrome/browser/autofill/autofill_popup_unittest.cc |
| +++ b/chrome/browser/autofill/autofill_popup_unittest.cc |
| @@ -8,6 +8,9 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| +using ::testing::_; |
| +using ::testing::AtLeast; |
| + |
| namespace { |
| class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| @@ -17,22 +20,14 @@ class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| virtual void SelectAutofillSuggestionAtIndex(int unique_id, int list_index) |
| OVERRIDE {} |
| + |
| + virtual void ClearPreviewedForm() OVERRIDE {} |
| }; |
| class TestAutofillPopupView : public AutofillPopupView { |
| public: |
| explicit TestAutofillPopupView(AutofillExternalDelegate* external_delegate) : |
| - AutofillPopupView(NULL, external_delegate) { |
| - std::vector<string16> autofill_values; |
| - autofill_values.push_back(string16()); |
| - autofill_values.push_back(string16()); |
| - |
| - std::vector<int> autofill_ids; |
| - autofill_ids.push_back(0); |
| - autofill_ids.push_back(1); |
| - |
| - Show(autofill_values, autofill_values, autofill_values, autofill_ids, 0); |
| - } |
| + AutofillPopupView(NULL, external_delegate) {} |
| virtual ~TestAutofillPopupView() {} |
| // Making protected functions public for testing |
| @@ -51,12 +46,15 @@ class TestAutofillPopupView : public AutofillPopupView { |
| void SelectPreviousLine() { |
| AutofillPopupView::SelectPreviousLine(); |
| } |
| + bool RemoveSelectedLine() { |
| + return AutofillPopupView::RemoveSelectedLine(); |
| + } |
| MOCK_METHOD1(InvalidateRow, void(size_t)); |
| + MOCK_METHOD0(HideInternal, void()); |
| private: |
| virtual void ShowInternal() OVERRIDE {} |
| - virtual void HideInternal() OVERRIDE {} |
| }; |
| } // namespace |
| @@ -75,6 +73,15 @@ class AutofillPopupViewUnitTest : public ::testing::Test { |
| }; |
| TEST_F(AutofillPopupViewUnitTest, ChangeSelectedLine) { |
| + // Setup the popup. |
|
Ilya Sherman
2012/04/18 18:12:51
nit: "Setup" -> "Set up"
csharp
2012/04/19 15:33:24
Done.
|
| + std::vector<string16> autofill_values(2, string16()); |
| + std::vector<int> autofill_ids(2, 0); |
| + autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values, |
| + autofill_ids, 1); |
| + |
| + // To remove warnings. |
| + EXPECT_CALL(*autofill_popup_view_, InvalidateRow(_)).Times(AtLeast(0)); |
| + |
| EXPECT_LT(autofill_popup_view_->selected_line(), 0); |
| // Check that there are at least 2 values so that the first and last selection |
| // are different. |
| @@ -93,6 +100,12 @@ TEST_F(AutofillPopupViewUnitTest, ChangeSelectedLine) { |
| } |
| TEST_F(AutofillPopupViewUnitTest, RedrawSelectedLine) { |
| + // Setup the popup. |
| + std::vector<string16> autofill_values(2, string16()); |
| + std::vector<int> autofill_ids(2, 0); |
| + autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values, |
| + autofill_ids, 1); |
| + |
| // Make sure that when a new line is selected, it is invalidated so it can |
| // be updated to show it is selected. |
| int selected_line = 0; |
| @@ -107,3 +120,29 @@ TEST_F(AutofillPopupViewUnitTest, RedrawSelectedLine) { |
| EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)); |
| autofill_popup_view_->SetSelectedLine(-1); |
| } |
| + |
| +TEST_F(AutofillPopupViewUnitTest, RemoveLine) { |
| + // Setup the popup. |
| + std::vector<string16> autofill_values(2, string16()); |
| + std::vector<int> autofill_ids(2, 0); |
| + autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values, |
| + autofill_ids, 1); |
| + |
| + // To remove warnings. |
| + EXPECT_CALL(*autofill_popup_view_, InvalidateRow(_)).Times(AtLeast(0)); |
| + |
| + // No line is selected so the removal should fail. |
| + EXPECT_FALSE(autofill_popup_view_->RemoveSelectedLine()); |
| + |
| + // Try to remove the last entry and ensure it fails (it is an option). |
| + autofill_popup_view_->SetSelectedLine( |
| + autofill_popup_view_->autofill_values().size() - 1); |
| + EXPECT_FALSE(autofill_popup_view_->RemoveSelectedLine()); |
| + EXPECT_LE(0, autofill_popup_view_->selected_line()); |
| + |
| + // Remove the first (and only) entry. The popup should then be hidden since |
| + // there are no Autofill entries left. |
| + EXPECT_CALL(*autofill_popup_view_, HideInternal()); |
| + autofill_popup_view_->SetSelectedLine(0); |
| + EXPECT_TRUE(autofill_popup_view_->RemoveSelectedLine()); |
| +} |