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

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: Uses base::Optional<size_t> instead of representing no selection as -1. 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
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(size_t row));
59 MOCK_METHOD1(GetElidedLabelWidthForRow, int(size_t row));
60 #endif
61
62 // AutofillPopupController
63 MOCK_METHOD0(OnSuggestionsChanged, void());
64 MOCK_METHOD1(AcceptSuggestion, void(size_t index));
65 MOCK_CONST_METHOD0(GetLineCount, size_t());
66 MOCK_CONST_METHOD1(GetSuggestionAt, const autofill::Suggestion&(size_t row));
67 MOCK_CONST_METHOD1(GetElidedValueAt, const base::string16&(size_t row));
68 MOCK_CONST_METHOD1(GetElidedLabelAt, const base::string16&(size_t row));
69 MOCK_METHOD3(GetRemovalConfirmationText,
70 bool(int index, base::string16* title, base::string16* body));
71 MOCK_METHOD1(RemoveSuggestion, bool(int index));
72 MOCK_CONST_METHOD1(GetBackgroundColorIDForRow,
73 ui::NativeTheme::ColorId(int index));
74 MOCK_CONST_METHOD0(selected_line, base::Optional<size_t>());
75 const AutofillPopupLayoutModel& layout_model() const override {
76 return *layout_model_;
77 }
78
79 private:
80 std::unique_ptr<AutofillPopupLayoutModel> layout_model_;
81 };
82
83 class TestAutofillPopupViewViews : public AutofillPopupViewViews {
84 public:
85 TestAutofillPopupViewViews(AutofillPopupController* controller,
86 views::Widget* parent_widget)
87 : AutofillPopupViewViews(controller, parent_widget) {}
88 ~TestAutofillPopupViewViews() override {}
89
90 void DoUpdateBoundsAndRedrawPopup() override {}
91
92 private:
93 DISALLOW_COPY_AND_ASSIGN(TestAutofillPopupViewViews);
94 };
95
96 } // namespace
97
98 class AutofillPopupViewViewsTest : public InProcessBrowserTest {
99 public:
100 AutofillPopupViewViewsTest() {}
101 ~AutofillPopupViewViewsTest() override {}
102
103 void SetUpOnMainThread() override {
104 gfx::NativeView native_view =
105 browser()->tab_strip_model()->GetActiveWebContents()->GetNativeView();
106 EXPECT_CALL(autofill_popup_controller_, container_view())
107 .WillRepeatedly(Return(native_view));
108 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
109 .WillRepeatedly(Return(kNumInitialSuggestions));
110 autofill_popup_view_views_ = new TestAutofillPopupViewViews(
111 &autofill_popup_controller_,
112 views::Widget::GetWidgetForNativeWindow(
113 browser()->window()->GetNativeWindow()));
114 }
115
116 protected:
117 NiceMock<MockAutofillPopupController> autofill_popup_controller_;
118 // We intentionally do not destroy this view in the test because of
119 // difficulty in mocking out 'RemoveObserver'.
120 TestAutofillPopupViewViews* autofill_popup_view_views_;
121 };
122
123 IN_PROC_BROWSER_TEST_F(AutofillPopupViewViewsTest, OnSelectedRowChanged) {
124 for (int i = 0; i < kNumInitialSuggestions; ++i) {
125 autofill_popup_view_views_->OnSelectedRowChanged(i - 1, i);
126 }
127
128 // Increase number of suggestions.
129 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
130 .WillRepeatedly(Return(kNumInitialSuggestions + 1));
131
132 autofill_popup_view_views_->OnSuggestionsChanged();
133 for (int i = 0; i < kNumInitialSuggestions + 1; ++i) {
134 autofill_popup_view_views_->OnSelectedRowChanged(
135 i ? i - 1 : kNumInitialSuggestions - 1, i);
136 }
137
138 // Decrease number of suggestions.
139 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
140 .WillRepeatedly(Return(kNumInitialSuggestions - 1));
141
142 autofill_popup_view_views_->OnSuggestionsChanged();
143 for (int i = 0; i < kNumInitialSuggestions - 1; ++i) {
144 autofill_popup_view_views_->OnSelectedRowChanged(
145 i ? kNumInitialSuggestions : i - 1, i);
146 }
147 }
148
149 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698