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

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: Adds test coverage for changing number of suggestions. 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/strings/utf_string_conversions.h"
9 #include "build/build_config.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
11 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "components/autofill/core/browser/suggestion.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/accessibility/ax_enums.h"
20 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gfx/native_widget_types.h"
22 #include "ui/native_theme/native_theme.h"
23 #include "ui/views/widget/widget.h"
24
25 using ::testing::NiceMock;
26 using ::testing::Return;
27
28 namespace autofill {
29 namespace {
30
31 constexpr int kNumInitialSuggestions = 3;
32
33 class MockAutofillPopupController : public AutofillPopupController {
34 public:
35 MockAutofillPopupController() {}
36
37 // AutofillPopupViewDelegate
38 MOCK_METHOD0(Hide, void());
39 MOCK_METHOD0(ViewDestroyed, void());
40 MOCK_METHOD1(SetSelectionAtPoint, void(const gfx::Point& point));
41 MOCK_METHOD0(AcceptSelectedLine, bool());
42 MOCK_METHOD0(SelectionCleared, void());
43 MOCK_CONST_METHOD0(popup_bounds, gfx::Rect());
44 MOCK_METHOD0(container_view, gfx::NativeView());
45 MOCK_CONST_METHOD0(element_bounds, const gfx::RectF&());
46 MOCK_CONST_METHOD0(IsRTL, bool());
47 MOCK_METHOD0(GetSuggestions, const std::vector<autofill::Suggestion>());
48 #if !defined(OS_ANDROID)
49 MOCK_METHOD1(GetElidedValueWidthForRow, int(size_t row));
50 MOCK_METHOD1(GetElidedLabelWidthForRow, int(size_t row));
51 #endif
52
53 // AutofillPopupController
54 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void());
55 MOCK_METHOD1(AcceptSuggestion, void(size_t index));
56 MOCK_CONST_METHOD0(GetLineCount, size_t());
57 MOCK_CONST_METHOD1(GetSuggestionAt, const autofill::Suggestion&(size_t row));
58 MOCK_CONST_METHOD1(GetElidedValueAt, const base::string16&(size_t row));
59 MOCK_CONST_METHOD1(GetElidedLabelAt, const base::string16&(size_t row));
60 MOCK_METHOD3(GetRemovalConfirmationText,
61 bool(int index, base::string16* title, base::string16* body));
62 MOCK_METHOD1(RemoveSuggestion, bool(int index));
63 MOCK_CONST_METHOD1(GetBackgroundColorIDForRow,
64 ui::NativeTheme::ColorId(int index));
65 MOCK_CONST_METHOD0(selected_line, int());
66 MOCK_CONST_METHOD0(layout_model, const AutofillPopupLayoutModel&());
67 };
68
69 class TestAutofillPopupViewViews : public AutofillPopupViewViews {
70 public:
71 TestAutofillPopupViewViews(AutofillPopupController* controller,
72 views::Widget* parent_widget)
73 : AutofillPopupViewViews(controller, parent_widget) {}
74 ~TestAutofillPopupViewViews() override {}
75
76 void DoUpdateBoundsAndRedrawPopup() override {}
77
78 private:
79 DISALLOW_COPY_AND_ASSIGN(TestAutofillPopupViewViews);
80 };
81
82 } // namespace
83
84 class AutofillPopupViewViewsTest : public InProcessBrowserTest {
85 public:
86 AutofillPopupViewViewsTest() {}
87 ~AutofillPopupViewViewsTest() override {}
88
89 void SetUpOnMainThread() override {
90 gfx::NativeView native_view =
91 browser()->tab_strip_model()->GetActiveWebContents()->GetNativeView();
92 EXPECT_CALL(autofill_popup_controller_, container_view())
93 .WillRepeatedly(Return(native_view));
94 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
95 .WillRepeatedly(Return(kNumInitialSuggestions));
96 autofill_popup_view_views_ = new TestAutofillPopupViewViews(
97 &autofill_popup_controller_,
98 views::Widget::GetWidgetForNativeWindow(
99 browser()->window()->GetNativeWindow()));
100 }
101
102 protected:
103 NiceMock<MockAutofillPopupController> autofill_popup_controller_;
104 // We intentionally do not destroy this view in the test because of
105 // difficulty in mocking out 'RemoveObserver'.
106 TestAutofillPopupViewViews* autofill_popup_view_views_;
107 };
108
109 IN_PROC_BROWSER_TEST_F(AutofillPopupViewViewsTest,
110 NotifyAccessibilityEventForRow) {
111 for (int i = 0; i < kNumInitialSuggestions; ++i) {
112 autofill_popup_view_views_->NotifyAccessibilityEventForRow(
113 ui::AX_EVENT_SELECTION, i);
114 }
115
116 // Increase number of suggestions.
117 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
118 .WillRepeatedly(Return(kNumInitialSuggestions + 1));
119
120 autofill_popup_view_views_->UpdateBoundsAndRedrawPopup();
121 for (int i = 0; i < kNumInitialSuggestions + 1; ++i) {
122 autofill_popup_view_views_->NotifyAccessibilityEventForRow(
123 ui::AX_EVENT_SELECTION, i);
124 }
125
126 // Decrease number of suggestions.
127 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
128 .WillRepeatedly(Return(kNumInitialSuggestions - 1));
129
130 autofill_popup_view_views_->UpdateBoundsAndRedrawPopup();
131 for (int i = 0; i < kNumInitialSuggestions - 1; ++i) {
132 autofill_popup_view_views_->NotifyAccessibilityEventForRow(
133 ui::AX_EVENT_SELECTION, i);
134 }
135 }
136
137 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698