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

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_popup_view_views_browsertest.cc

Issue 2727233003: Uses child views in Autofill Popup so we can trigger (Closed)
Patch Set: (int) to NSInteger Created 3 years, 9 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
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_popup_view_views.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h"
6
7 #include "base/macros.h"
8 #include "base/optional.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h"
11 #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
12 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "components/autofill/core/browser/suggestion.h"
18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/gfx/font_list.h"
21 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/native_widget_types.h"
23 #include "ui/native_theme/native_theme.h"
24 #include "ui/views/widget/widget.h"
25
26 using ::testing::NiceMock;
27 using ::testing::Return;
28
29 namespace autofill {
30 namespace {
31
32 constexpr int kNumInitialSuggestions = 3;
33
34 class MockAutofillPopupController : public AutofillPopupController {
35 public:
36 MockAutofillPopupController() {
37 gfx::FontList::SetDefaultFontDescription("Arial, Times New Roman, 15px");
38 layout_model_.reset(
39 new AutofillPopupLayoutModel(this, false /* is_credit_card_field */));
40 }
41
42 // AutofillPopupViewDelegate
43 MOCK_METHOD0(Hide, void());
44 MOCK_METHOD0(ViewDestroyed, void());
45 MOCK_METHOD1(SetSelectionAtPoint, void(const gfx::Point& point));
46 MOCK_METHOD0(AcceptSelectedLine, bool());
47 MOCK_METHOD0(SelectionCleared, void());
48 MOCK_CONST_METHOD0(popup_bounds, gfx::Rect());
49 MOCK_METHOD0(container_view, gfx::NativeView());
50 MOCK_CONST_METHOD0(element_bounds, const gfx::RectF&());
51 MOCK_CONST_METHOD0(IsRTL, bool());
52 const std::vector<autofill::Suggestion> GetSuggestions() override {
53 std::vector<Suggestion> suggestions(GetLineCount(),
54 Suggestion("", "", "", 0));
55 return suggestions;
56 }
57 #if !defined(OS_ANDROID)
58 MOCK_METHOD1(GetElidedValueWidthForRow, int(int row));
59 MOCK_METHOD1(GetElidedLabelWidthForRow, int(int row));
60 #endif
61
62 // AutofillPopupController
63 MOCK_METHOD0(OnSuggestionsChanged, void());
64 MOCK_METHOD1(AcceptSuggestion, void(int index));
65 MOCK_CONST_METHOD0(GetLineCount, int());
66 const autofill::Suggestion& GetSuggestionAt(int row) const override {
67 return suggestion_;
68 }
69 MOCK_CONST_METHOD1(GetElidedValueAt, const base::string16&(int row));
70 MOCK_CONST_METHOD1(GetElidedLabelAt, const base::string16&(int row));
71 MOCK_METHOD3(GetRemovalConfirmationText,
72 bool(int index, base::string16* title, base::string16* body));
73 MOCK_METHOD1(RemoveSuggestion, bool(int index));
74 MOCK_CONST_METHOD1(GetBackgroundColorIDForRow,
75 ui::NativeTheme::ColorId(int index));
76 MOCK_CONST_METHOD0(selected_line, base::Optional<int>());
77 const AutofillPopupLayoutModel& layout_model() const override {
78 return *layout_model_;
79 }
80
81 private:
82 std::unique_ptr<AutofillPopupLayoutModel> layout_model_;
83 autofill::Suggestion suggestion_;
84 };
85
86 class TestAutofillPopupViewViews : public AutofillPopupViewViews {
87 public:
88 TestAutofillPopupViewViews(AutofillPopupController* controller,
89 views::Widget* parent_widget)
90 : AutofillPopupViewViews(controller, parent_widget) {}
91 ~TestAutofillPopupViewViews() override {}
92
93 void DoUpdateBoundsAndRedrawPopup() override {}
94
95 private:
96 DISALLOW_COPY_AND_ASSIGN(TestAutofillPopupViewViews);
97 };
98
99 } // namespace
100
101 class AutofillPopupViewViewsTest : public InProcessBrowserTest {
102 public:
103 AutofillPopupViewViewsTest() {}
104 ~AutofillPopupViewViewsTest() override {}
105
106 void SetUpOnMainThread() override {
107 gfx::NativeView native_view =
108 browser()->tab_strip_model()->GetActiveWebContents()->GetNativeView();
109 EXPECT_CALL(autofill_popup_controller_, container_view())
110 .WillRepeatedly(Return(native_view));
111 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
112 .WillRepeatedly(Return(kNumInitialSuggestions));
113 autofill_popup_view_views_ = new TestAutofillPopupViewViews(
114 &autofill_popup_controller_,
115 views::Widget::GetWidgetForNativeWindow(
116 browser()->window()->GetNativeWindow()));
117 }
118
119 protected:
120 NiceMock<MockAutofillPopupController> autofill_popup_controller_;
121 // We intentionally do not destroy this view in the test because of
122 // difficulty in mocking out 'RemoveObserver'.
123 TestAutofillPopupViewViews* autofill_popup_view_views_;
124 };
125
126 IN_PROC_BROWSER_TEST_F(AutofillPopupViewViewsTest, OnSelectedRowChanged) {
127 // No previous selection -> Selected 1st row.
128 autofill_popup_view_views_->OnSelectedRowChanged(base::nullopt, 0);
129
130 // Selected 1st row -> Selected 2nd row.
131 autofill_popup_view_views_->OnSelectedRowChanged(0, 1);
132
133 // Increase number of suggestions.
134 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
135 .WillRepeatedly(Return(kNumInitialSuggestions + 1));
136
137 autofill_popup_view_views_->OnSuggestionsChanged();
138
139 // Selected 2nd row -> Selected last row.
140 autofill_popup_view_views_->OnSelectedRowChanged(1, kNumInitialSuggestions);
141
142 // Decrease number of suggestions.
143 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
144 .WillRepeatedly(Return(kNumInitialSuggestions - 1));
145
146 autofill_popup_view_views_->OnSuggestionsChanged();
147
148 // No previous selection (because previously selected row is out of bounds
149 // now)
150 // -> Selected 1st row.
151 autofill_popup_view_views_->OnSelectedRowChanged(base::nullopt, 0);
152
153 // Selected 1st row -> No selection.
154 autofill_popup_view_views_->OnSelectedRowChanged(0, base::nullopt);
155 }
156
157 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_popup_view_views.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698