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

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

Issue 10073018: Add Delete Support to New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Adding profile and credit card deleteion Created 8 years, 8 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 10
11 using ::testing::_;
12 using ::testing::AtLeast;
13
11 namespace { 14 namespace {
12 15
13 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { 16 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
14 public: 17 public:
15 MockAutofillExternalDelegate() : TestAutofillExternalDelegate(NULL, NULL) {}; 18 MockAutofillExternalDelegate() : TestAutofillExternalDelegate(NULL, NULL) {};
16 virtual ~MockAutofillExternalDelegate() {}; 19 virtual ~MockAutofillExternalDelegate() {};
17 20
18 virtual void SelectAutofillSuggestionAtIndex(int unique_id, int list_index) 21 virtual void SelectAutofillSuggestionAtIndex(int unique_id, int list_index)
19 OVERRIDE {} 22 OVERRIDE {}
23
24 virtual void ClearPreviewedForm() OVERRIDE {}
20 }; 25 };
21 26
22 class TestAutofillPopupView : public AutofillPopupView { 27 class TestAutofillPopupView : public AutofillPopupView {
23 public: 28 public:
24 explicit TestAutofillPopupView(AutofillExternalDelegate* external_delegate) : 29 explicit TestAutofillPopupView(AutofillExternalDelegate* external_delegate) :
25 AutofillPopupView(NULL, external_delegate) { 30 AutofillPopupView(NULL, external_delegate) {}
26 std::vector<string16> autofill_values;
27 autofill_values.push_back(string16());
28 autofill_values.push_back(string16());
29
30 std::vector<int> autofill_ids;
31 autofill_ids.push_back(0);
32 autofill_ids.push_back(1);
33
34 Show(autofill_values, autofill_values, autofill_values, autofill_ids, 0);
35 }
36 virtual ~TestAutofillPopupView() {} 31 virtual ~TestAutofillPopupView() {}
37 32
38 // Making protected functions public for testing 33 // Making protected functions public for testing
39 const std::vector<string16>& autofill_values() const { 34 const std::vector<string16>& autofill_values() const {
40 return AutofillPopupView::autofill_values(); 35 return AutofillPopupView::autofill_values();
41 } 36 }
42 int selected_line() const { 37 int selected_line() const {
43 return AutofillPopupView::selected_line(); 38 return AutofillPopupView::selected_line();
44 } 39 }
45 void SetSelectedLine(size_t selected_line) { 40 void SetSelectedLine(size_t selected_line) {
46 AutofillPopupView::SetSelectedLine(selected_line); 41 AutofillPopupView::SetSelectedLine(selected_line);
47 } 42 }
48 void SelectNextLine() { 43 void SelectNextLine() {
49 AutofillPopupView::SelectNextLine(); 44 AutofillPopupView::SelectNextLine();
50 } 45 }
51 void SelectPreviousLine() { 46 void SelectPreviousLine() {
52 AutofillPopupView::SelectPreviousLine(); 47 AutofillPopupView::SelectPreviousLine();
53 } 48 }
49 bool RemoveSelectedLine() {
50 return AutofillPopupView::RemoveSelectedLine();
51 }
54 52
55 MOCK_METHOD1(InvalidateRow, void(size_t)); 53 MOCK_METHOD1(InvalidateRow, void(size_t));
54 MOCK_METHOD0(HideInternal, void());
56 55
57 private: 56 private:
58 virtual void ShowInternal() OVERRIDE {} 57 virtual void ShowInternal() OVERRIDE {}
59 virtual void HideInternal() OVERRIDE {}
60 }; 58 };
61 59
62 } // namespace 60 } // namespace
63 61
64 class AutofillPopupViewUnitTest : public ::testing::Test { 62 class AutofillPopupViewUnitTest : public ::testing::Test {
65 public: 63 public:
66 AutofillPopupViewUnitTest() { 64 AutofillPopupViewUnitTest() {
67 autofill_popup_view_.reset(new TestAutofillPopupView(&external_delegate_)); 65 autofill_popup_view_.reset(new TestAutofillPopupView(&external_delegate_));
68 } 66 }
69 virtual ~AutofillPopupViewUnitTest() {} 67 virtual ~AutofillPopupViewUnitTest() {}
70 68
71 scoped_ptr<TestAutofillPopupView> autofill_popup_view_; 69 scoped_ptr<TestAutofillPopupView> autofill_popup_view_;
72 70
73 private: 71 private:
74 MockAutofillExternalDelegate external_delegate_; 72 MockAutofillExternalDelegate external_delegate_;
75 }; 73 };
76 74
77 TEST_F(AutofillPopupViewUnitTest, ChangeSelectedLine) { 75 TEST_F(AutofillPopupViewUnitTest, ChangeSelectedLine) {
76 // Setup the popup.
Ilya Sherman 2012/04/18 18:12:51 nit: "Setup" -> "Set up"
csharp 2012/04/19 15:33:24 Done.
77 std::vector<string16> autofill_values(2, string16());
78 std::vector<int> autofill_ids(2, 0);
79 autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values,
80 autofill_ids, 1);
81
82 // To remove warnings.
83 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(_)).Times(AtLeast(0));
84
78 EXPECT_LT(autofill_popup_view_->selected_line(), 0); 85 EXPECT_LT(autofill_popup_view_->selected_line(), 0);
79 // Check that there are at least 2 values so that the first and last selection 86 // Check that there are at least 2 values so that the first and last selection
80 // are different. 87 // are different.
81 EXPECT_GE(2, 88 EXPECT_GE(2,
82 static_cast<int>(autofill_popup_view_->autofill_values().size())); 89 static_cast<int>(autofill_popup_view_->autofill_values().size()));
83 90
84 // Test wrapping before the front. 91 // Test wrapping before the front.
85 autofill_popup_view_->SelectPreviousLine(); 92 autofill_popup_view_->SelectPreviousLine();
86 EXPECT_EQ( 93 EXPECT_EQ(
87 static_cast<int>(autofill_popup_view_->autofill_values().size() - 1), 94 static_cast<int>(autofill_popup_view_->autofill_values().size() - 1),
88 autofill_popup_view_->selected_line()); 95 autofill_popup_view_->selected_line());
89 96
90 // Test wrapping after the end. 97 // Test wrapping after the end.
91 autofill_popup_view_->SelectNextLine(); 98 autofill_popup_view_->SelectNextLine();
92 EXPECT_EQ(0, autofill_popup_view_->selected_line()); 99 EXPECT_EQ(0, autofill_popup_view_->selected_line());
93 } 100 }
94 101
95 TEST_F(AutofillPopupViewUnitTest, RedrawSelectedLine) { 102 TEST_F(AutofillPopupViewUnitTest, RedrawSelectedLine) {
103 // Setup the popup.
104 std::vector<string16> autofill_values(2, string16());
105 std::vector<int> autofill_ids(2, 0);
106 autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values,
107 autofill_ids, 1);
108
96 // Make sure that when a new line is selected, it is invalidated so it can 109 // Make sure that when a new line is selected, it is invalidated so it can
97 // be updated to show it is selected. 110 // be updated to show it is selected.
98 int selected_line = 0; 111 int selected_line = 0;
99 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)); 112 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line));
100 autofill_popup_view_->SetSelectedLine(selected_line); 113 autofill_popup_view_->SetSelectedLine(selected_line);
101 114
102 // Ensure that the row isn't invalidated if it didn't change. 115 // Ensure that the row isn't invalidated if it didn't change.
103 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)).Times(0); 116 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)).Times(0);
104 autofill_popup_view_->SetSelectedLine(selected_line); 117 autofill_popup_view_->SetSelectedLine(selected_line);
105 118
106 // Change back to no selection. 119 // Change back to no selection.
107 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line)); 120 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(selected_line));
108 autofill_popup_view_->SetSelectedLine(-1); 121 autofill_popup_view_->SetSelectedLine(-1);
109 } 122 }
123
124 TEST_F(AutofillPopupViewUnitTest, RemoveLine) {
125 // Setup the popup.
126 std::vector<string16> autofill_values(2, string16());
127 std::vector<int> autofill_ids(2, 0);
128 autofill_popup_view_->Show(autofill_values, autofill_values, autofill_values,
129 autofill_ids, 1);
130
131 // To remove warnings.
132 EXPECT_CALL(*autofill_popup_view_, InvalidateRow(_)).Times(AtLeast(0));
133
134 // No line is selected so the removal should fail.
135 EXPECT_FALSE(autofill_popup_view_->RemoveSelectedLine());
136
137 // Try to remove the last entry and ensure it fails (it is an option).
138 autofill_popup_view_->SetSelectedLine(
139 autofill_popup_view_->autofill_values().size() - 1);
140 EXPECT_FALSE(autofill_popup_view_->RemoveSelectedLine());
141 EXPECT_LE(0, autofill_popup_view_->selected_line());
142
143 // Remove the first (and only) entry. The popup should then be hidden since
144 // there are no Autofill entries left.
145 EXPECT_CALL(*autofill_popup_view_, HideInternal());
146 autofill_popup_view_->SetSelectedLine(0);
147 EXPECT_TRUE(autofill_popup_view_->RemoveSelectedLine());
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698