Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/autofill/autofill_popup_view.h" | 6 #include "chrome/browser/autofill/autofill_popup_view.h" |
| 7 #include "chrome/browser/autofill/test_autofill_external_delegate.h" | 7 #include "chrome/browser/autofill/test_autofill_external_delegate.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 | 10 |
| 11 using ::testing::_; | |
| 12 using ::testing::AtLeast; | |
| 13 | |
| 11 namespace { | 14 namespace { |
| 12 | 15 |
| 16 const int kNoSelection = -1; | |
| 17 | |
| 13 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { | 18 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { |
| 14 public: | 19 public: |
| 15 MockAutofillExternalDelegate() : TestAutofillExternalDelegate(NULL, NULL) {}; | 20 MockAutofillExternalDelegate() : TestAutofillExternalDelegate(NULL, NULL) {}; |
| 16 virtual ~MockAutofillExternalDelegate() {}; | 21 virtual ~MockAutofillExternalDelegate() {}; |
| 17 | 22 |
| 18 virtual void SelectAutofillSuggestionAtIndex(int unique_id, int list_index) | 23 virtual void SelectAutofillSuggestionAtIndex(int unique_id, int list_index) |
| 19 OVERRIDE {} | 24 OVERRIDE {} |
| 25 | |
| 26 virtual void ClearPreviewedForm() OVERRIDE {} | |
| 20 }; | 27 }; |
| 21 | 28 |
| 22 class TestAutofillPopupView : public AutofillPopupView { | 29 class TestAutofillPopupView : public AutofillPopupView { |
| 23 public: | 30 public: |
| 24 explicit TestAutofillPopupView(AutofillExternalDelegate* external_delegate) : | 31 explicit TestAutofillPopupView(AutofillExternalDelegate* external_delegate) : |
| 25 AutofillPopupView(NULL, external_delegate) { | 32 AutofillPopupView(NULL, external_delegate) { |
| 26 std::vector<string16> autofill_values; | 33 std::vector<string16> autofill_values(2, string16()); |
| 27 autofill_values.push_back(string16()); | |
| 28 autofill_values.push_back(string16()); | |
| 29 | 34 |
| 30 std::vector<int> autofill_ids; | 35 std::vector<int> autofill_ids(2, 0); |
| 31 autofill_ids.push_back(0); | |
| 32 autofill_ids.push_back(1); | |
| 33 | 36 |
| 34 Show(autofill_values, autofill_values, autofill_values, autofill_ids, 0); | 37 Show(autofill_values, autofill_values, autofill_values, autofill_ids, 1); |
|
Ilya Sherman
2012/04/17 08:31:20
Hmm, it's not great that there is this long-distan
csharp
2012/04/18 15:35:58
Done.
| |
| 35 } | 38 } |
| 36 virtual ~TestAutofillPopupView() {} | 39 virtual ~TestAutofillPopupView() {} |
| 37 | 40 |
| 38 // Making protected functions public for testing | 41 // Making protected functions public for testing |
| 39 const std::vector<string16>& autofill_values() const { | 42 const std::vector<string16>& autofill_values() const { |
| 40 return AutofillPopupView::autofill_values(); | 43 return AutofillPopupView::autofill_values(); |
| 41 } | 44 } |
| 42 int selected_line() const { | 45 int selected_line() const { |
| 43 return AutofillPopupView::selected_line(); | 46 return AutofillPopupView::selected_line(); |
| 44 } | 47 } |
| 45 void SetSelectedLine(size_t selected_line) { | 48 void SetSelectedLine(size_t selected_line) { |
| 46 AutofillPopupView::SetSelectedLine(selected_line); | 49 AutofillPopupView::SetSelectedLine(selected_line); |
| 47 } | 50 } |
| 48 void SelectNextLine() { | 51 void SelectNextLine() { |
| 49 AutofillPopupView::SelectNextLine(); | 52 AutofillPopupView::SelectNextLine(); |
| 50 } | 53 } |
| 51 void SelectPreviousLine() { | 54 void SelectPreviousLine() { |
| 52 AutofillPopupView::SelectPreviousLine(); | 55 AutofillPopupView::SelectPreviousLine(); |
| 53 } | 56 } |
| 57 bool RemoveSelectedLine() { | |
| 58 return AutofillPopupView::RemoveSelectedLine(); | |
| 59 } | |
| 54 | 60 |
| 55 MOCK_METHOD1(InvalidateRow, void(size_t)); | 61 MOCK_METHOD1(InvalidateRow, void(size_t)); |
| 62 MOCK_METHOD0(HideInternal, void()); | |
| 56 | 63 |
| 57 private: | 64 private: |
| 58 virtual void ShowInternal() OVERRIDE {} | 65 virtual void ShowInternal() OVERRIDE {} |
| 59 virtual void HideInternal() OVERRIDE {} | |
| 60 }; | 66 }; |
| 61 | 67 |
| 62 } // namespace | 68 } // namespace |
| 63 | 69 |
| 64 class AutofillPopupViewUnitTest : public ::testing::Test { | 70 class AutofillPopupViewUnitTest : public ::testing::Test { |
| 65 public: | 71 public: |
| 66 AutofillPopupViewUnitTest() { | 72 AutofillPopupViewUnitTest() { |
| 67 autofill_popup_view_.reset(new TestAutofillPopupView(&external_delegate_)); | 73 autofill_popup_view_.reset(new TestAutofillPopupView(&external_delegate_)); |
| 68 } | 74 } |
| 69 virtual ~AutofillPopupViewUnitTest() {} | 75 virtual ~AutofillPopupViewUnitTest() {} |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 100 autofill_popup_view_->SetSelectedLine(selected_line); | 106 autofill_popup_view_->SetSelectedLine(selected_line); |
| 101 | 107 |
| 102 // Ensure that the row isn't invalidated if it didn't change. | 108 // Ensure that the row isn't invalidated if it didn't change. |
| 103 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)).Times(0); | 109 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)).Times(0); |
| 104 autofill_popup_view_->SetSelectedLine(selected_line); | 110 autofill_popup_view_->SetSelectedLine(selected_line); |
| 105 | 111 |
| 106 // Change back to no selection. | 112 // Change back to no selection. |
| 107 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)); | 113 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)); |
| 108 autofill_popup_view_->SetSelectedLine(-1); | 114 autofill_popup_view_->SetSelectedLine(-1); |
| 109 } | 115 } |
| 116 | |
| 117 TEST_F(AutofillPopupViewUnitTest, RemoveLine) { | |
| 118 // To remove warnings. | |
| 119 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(_)).Times(AtLeast(0)); | |
| 120 | |
| 121 // No line is selected so the removal should fail. | |
| 122 EXPECT_FALSE(autofill_popup_view_->RemoveSelectedLine()); | |
| 123 | |
| 124 // Try to remove the last entry and ensure it fails (it is an option). | |
| 125 autofill_popup_view_->SetSelectedLine( | |
| 126 autofill_popup_view_->autofill_values().size() - 1); | |
| 127 EXPECT_FALSE(autofill_popup_view_->RemoveSelectedLine()); | |
| 128 EXPECT_NE(kNoSelection, autofill_popup_view_->selected_line()); | |
|
Ilya Sherman
2012/04/17 08:31:20
nit: Perhaps EXPECT_GE(0, ...) so that kNoSelectio
csharp
2012/04/18 15:35:58
Replaced with EXPECT_LE(0,
Ilya Sherman
2012/04/18 18:12:51
Sorry, I meant EXPECT_GE(..., 0) -- for the EXPECT
| |
| 129 | |
| 130 // Remove the first (and only) entry. The popup should then be hidden since | |
| 131 // there are no Autofill entries left. | |
| 132 EXPECT_CALL(*autofill_popup_view_, HideInternal()); | |
| 133 autofill_popup_view_->SetSelectedLine(0); | |
| 134 EXPECT_TRUE(autofill_popup_view_->RemoveSelectedLine()); | |
| 135 } | |
| OLD | NEW |