Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/autofill/autofill_popup_unittest.cc

Issue 10408070: Upgrade Seperator in New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
(...skipping 19 matching lines...) Expand all
30 class TestAutofillPopupView : public AutofillPopupView { 30 class TestAutofillPopupView : public AutofillPopupView {
31 public: 31 public:
32 explicit TestAutofillPopupView(AutofillExternalDelegate* external_delegate) : 32 explicit TestAutofillPopupView(AutofillExternalDelegate* external_delegate) :
33 AutofillPopupView(NULL, external_delegate) {} 33 AutofillPopupView(NULL, external_delegate) {}
34 virtual ~TestAutofillPopupView() {} 34 virtual ~TestAutofillPopupView() {}
35 35
36 // Making protected functions public for testing 36 // Making protected functions public for testing
37 const std::vector<string16>& autofill_values() const { 37 const std::vector<string16>& autofill_values() const {
38 return AutofillPopupView::autofill_values(); 38 return AutofillPopupView::autofill_values();
39 } 39 }
40 int row_count() {
41 return AutofillPopupView::row_count();
42 }
40 int selected_line() const { 43 int selected_line() const {
41 return AutofillPopupView::selected_line(); 44 return AutofillPopupView::selected_line();
42 } 45 }
43 void SetSelectedLine(size_t selected_line) { 46 void SetSelectedLine(size_t selected_line) {
44 AutofillPopupView::SetSelectedLine(selected_line); 47 AutofillPopupView::SetSelectedLine(selected_line);
45 } 48 }
46 void SelectNextLine() { 49 void SelectNextLine() {
47 AutofillPopupView::SelectNextLine(); 50 AutofillPopupView::SelectNextLine();
48 } 51 }
49 void SelectPreviousLine() { 52 void SelectPreviousLine() {
50 AutofillPopupView::SelectPreviousLine(); 53 AutofillPopupView::SelectPreviousLine();
51 } 54 }
52 bool RemoveSelectedLine() { 55 bool RemoveSelectedLine() {
53 return AutofillPopupView::RemoveSelectedLine(); 56 return AutofillPopupView::RemoveSelectedLine();
54 } 57 }
55 bool IsSeparatorIndex(int index) { 58 int RowToIndex(size_t row) {
56 return AutofillPopupView::IsSeparatorIndex(index); 59 return AutofillPopupView::RowToIndex(row);
57 } 60 }
58 61
59 MOCK_METHOD1(InvalidateRow, void(size_t)); 62 MOCK_METHOD1(InvalidateRow, void(size_t));
60 MOCK_METHOD0(HideInternal, void()); 63 MOCK_METHOD0(HideInternal, void());
61 64
62 private: 65 private:
63 virtual void ShowInternal() OVERRIDE {} 66 virtual void ShowInternal() OVERRIDE {}
64 67
65 virtual void ResizePopup() OVERRIDE {} 68 virtual void ResizePopup() OVERRIDE {}
66 }; 69 };
(...skipping 20 matching lines...) Expand all
87 autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values, 90 autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values,
88 autofill_ids); 91 autofill_ids);
89 92
90 // To remove warnings. 93 // To remove warnings.
91 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(_)).Times(AtLeast(0)); 94 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(_)).Times(AtLeast(0));
92 95
93 EXPECT_LT(autofill_popup_view_->selected_line(), 0); 96 EXPECT_LT(autofill_popup_view_->selected_line(), 0);
94 // Check that there are at least 2 values so that the first and last selection 97 // Check that there are at least 2 values so that the first and last selection
95 // are different. 98 // are different.
96 EXPECT_GE(2, 99 EXPECT_GE(2,
97 static_cast<int>(autofill_popup_view_->autofill_values().size())); 100 static_cast<int>(autofill_popup_view_->row_count()));
98 101
99 // Test wrapping before the front. 102 // Test wrapping before the front.
100 autofill_popup_view_->SelectPreviousLine(); 103 autofill_popup_view_->SelectPreviousLine();
101 EXPECT_EQ( 104 EXPECT_EQ(
102 static_cast<int>(autofill_popup_view_->autofill_values().size() - 1), 105 static_cast<int>(autofill_popup_view_->row_count() - 1),
103 autofill_popup_view_->selected_line()); 106 autofill_popup_view_->selected_line());
104 107
105 // Test wrapping after the end. 108 // Test wrapping after the end.
106 autofill_popup_view_->SelectNextLine(); 109 autofill_popup_view_->SelectNextLine();
107 EXPECT_EQ(0, autofill_popup_view_->selected_line()); 110 EXPECT_EQ(0, autofill_popup_view_->selected_line());
108 } 111 }
109 112
110 TEST_F(AutofillPopupViewUnitTest, RedrawSelectedLine) { 113 TEST_F(AutofillPopupViewUnitTest, RedrawSelectedLine) {
111 // Set up the popup. 114 // Set up the popup.
112 std::vector<string16> autofill_values(2, string16()); 115 std::vector<string16> autofill_values(2, string16());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 EXPECT_FALSE(autofill_popup_view_->RemoveSelectedLine()); 153 EXPECT_FALSE(autofill_popup_view_->RemoveSelectedLine());
151 EXPECT_LE(0, autofill_popup_view_->selected_line()); 154 EXPECT_LE(0, autofill_popup_view_->selected_line());
152 155
153 // Remove the first (and only) entry. The popup should then be hidden since 156 // Remove the first (and only) entry. The popup should then be hidden since
154 // there are no Autofill entries left. 157 // there are no Autofill entries left.
155 EXPECT_CALL(*autofill_popup_view_, HideInternal()); 158 EXPECT_CALL(*autofill_popup_view_, HideInternal());
156 autofill_popup_view_->SetSelectedLine(0); 159 autofill_popup_view_->SetSelectedLine(0);
157 EXPECT_TRUE(autofill_popup_view_->RemoveSelectedLine()); 160 EXPECT_TRUE(autofill_popup_view_->RemoveSelectedLine());
158 } 161 }
159 162
160 TEST_F(AutofillPopupViewUnitTest, IsSeparatorIndex) { 163 TEST_F(AutofillPopupViewUnitTest, IndexToRowMappings) {
161 // Set up the popup. 164 // Set up the popup.
162 std::vector<string16> autofill_values(3, string16()); 165 std::vector<string16> autofill_values(6, string16());
163 std::vector<int> autofill_ids; 166 std::vector<int> autofill_ids;
167 autofill_ids.push_back(0);
168 autofill_ids.push_back(WebAutofillClient::MenuItemIDSeparator);
164 autofill_ids.push_back(3); 169 autofill_ids.push_back(3);
170 autofill_ids.push_back(WebAutofillClient::MenuItemIDSeparator);
165 autofill_ids.push_back(WebAutofillClient::MenuItemIDClearForm); 171 autofill_ids.push_back(WebAutofillClient::MenuItemIDClearForm);
166 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions); 172 autofill_ids.push_back(WebAutofillClient::MenuItemIDAutofillOptions);
167 173
168 autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values, 174 autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values,
169 autofill_ids); 175 autofill_ids);
170 176
171 EXPECT_FALSE(autofill_popup_view_->IsSeparatorIndex(0)); 177 EXPECT_EQ(4, autofill_popup_view_->row_count());
172 EXPECT_TRUE(autofill_popup_view_->IsSeparatorIndex(1)); 178
173 EXPECT_FALSE(autofill_popup_view_->IsSeparatorIndex(2)); 179 EXPECT_EQ(0, autofill_popup_view_->RowToIndex(0));
180 EXPECT_EQ(2, autofill_popup_view_->RowToIndex(1));
181 EXPECT_EQ(4, autofill_popup_view_->RowToIndex(2));
182 EXPECT_EQ(5, autofill_popup_view_->RowToIndex(3));
183 EXPECT_EQ(-1, autofill_popup_view_->RowToIndex(4));
174 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698