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

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
« 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 (c) 2012 The Chromium Authors. All rights reserved.
sky 2017/03/06 18:02:57 No (c) and 2017.
csashi 2017/03/06 19:27:06 Done.
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 const int kNumInitialSuggestions = 3;
sky 2017/03/06 18:02:56 constexpr
csashi 2017/03/06 19:27:06 Done.
32
33 class MockAutofillPopupController : public AutofillPopupController {
34 public:
35 // AutofillPopupViewDelegate
36 MOCK_METHOD0(Hide, void());
37 MOCK_METHOD0(ViewDestroyed, void());
38 MOCK_METHOD1(SetSelectionAtPoint, void(const gfx::Point& point));
39 MOCK_METHOD0(AcceptSelectedLine, bool());
40 MOCK_METHOD0(SelectionCleared, void());
41 MOCK_CONST_METHOD0(popup_bounds, gfx::Rect());
42 MOCK_METHOD0(container_view, gfx::NativeView());
43 MOCK_CONST_METHOD0(element_bounds, const gfx::RectF&());
44 MOCK_CONST_METHOD0(IsRTL, bool());
45 MOCK_METHOD0(GetSuggestions, const std::vector<autofill::Suggestion>());
46 #if !defined(OS_ANDROID)
47 MOCK_METHOD1(GetElidedValueWidthForRow, int(size_t row));
48 MOCK_METHOD1(GetElidedLabelWidthForRow, int(size_t row));
49 #endif
50
51 // AutofillPopupController
52 MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void());
53 MOCK_METHOD1(AcceptSuggestion, void(size_t index));
54 MOCK_CONST_METHOD0(GetLineCount, size_t());
55 MOCK_CONST_METHOD1(GetSuggestionAt, const autofill::Suggestion&(size_t row));
56 MOCK_CONST_METHOD1(GetElidedValueAt, const base::string16&(size_t row));
57 MOCK_CONST_METHOD1(GetElidedLabelAt, const base::string16&(size_t row));
58 MOCK_METHOD3(GetRemovalConfirmationText,
59 bool(int index, base::string16* title, base::string16* body));
60 MOCK_METHOD1(RemoveSuggestion, bool(int index));
61 MOCK_CONST_METHOD1(GetBackgroundColorIDForRow,
62 ui::NativeTheme::ColorId(int index));
63 MOCK_CONST_METHOD0(selected_line, int());
64 MOCK_CONST_METHOD0(layout_model, const AutofillPopupLayoutModel&());
65 };
sky 2017/03/06 18:02:57 private: DISALLOW...
csashi 2017/03/06 19:27:06 Done.
66
67 class TestAutofillPopupViewViews : public AutofillPopupViewViews {
68 public:
69 TestAutofillPopupViewViews(AutofillPopupController* controller,
70 views::Widget* parent_widget)
71 : AutofillPopupViewViews(controller, parent_widget) {}
72 ~TestAutofillPopupViewViews() override {}
73
74 void DoUpdateBoundsAndRedrawPopup() override {}
75 };
sky 2017/03/06 18:02:57 private: DISALLOW...
csashi 2017/03/06 19:27:07 Done.
76
77 } // namespace
78
79 class AutofillPopupViewViewsTest : public InProcessBrowserTest {
80 public:
81 AutofillPopupViewViewsTest() {}
82 ~AutofillPopupViewViewsTest() override {}
83
84 void SetUpOnMainThread() override {
85 gfx::NativeView native_view =
86 browser()->tab_strip_model()->GetActiveWebContents()->GetNativeView();
87 EXPECT_CALL(autofill_popup_controller_, container_view())
88 .WillRepeatedly(Return(native_view));
89 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
90 .WillRepeatedly(Return(kNumInitialSuggestions));
91 autofill_popup_view_views_ = new TestAutofillPopupViewViews(
92 &autofill_popup_controller_,
93 views::Widget::GetWidgetForNativeWindow(
94 browser()->window()->GetNativeWindow()));
95 }
96
97 protected:
98 NiceMock<MockAutofillPopupController> autofill_popup_controller_;
99 // We intentionally do not destroy this view in the test because of
sky 2017/03/06 18:02:57 This it leak then? If so, that seems potentially e
csashi 2017/03/06 19:27:06 The browser_tests runs fine. If this is important,
100 // difficulty in mocking out 'RemoveObserver'.
101 TestAutofillPopupViewViews* autofill_popup_view_views_;
102 };
sky 2017/03/06 18:02:57 private: DISALLOW...
csashi 2017/03/06 19:27:06 Done.
103
104 IN_PROC_BROWSER_TEST_F(AutofillPopupViewViewsTest,
105 NotifyAccessibilityEventForRow) {
106 for (int i = 0; i < kNumInitialSuggestions; ++i) {
107 autofill_popup_view_views_->NotifyAccessibilityEventForRow(
108 ui::AX_EVENT_SELECTION, i);
109 }
110
111 // Increase number of suggestions.
112 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
113 .WillRepeatedly(Return(kNumInitialSuggestions + 1));
114
115 autofill_popup_view_views_->UpdateBoundsAndRedrawPopup();
116 for (int i = 0; i < kNumInitialSuggestions + 1; ++i) {
117 autofill_popup_view_views_->NotifyAccessibilityEventForRow(
118 ui::AX_EVENT_SELECTION, i);
119 }
120
121 // Decrease number of suggestions.
122 EXPECT_CALL(autofill_popup_controller_, GetLineCount())
123 .WillRepeatedly(Return(kNumInitialSuggestions - 1));
124
125 autofill_popup_view_views_->UpdateBoundsAndRedrawPopup();
126 for (int i = 0; i < kNumInitialSuggestions - 1; ++i) {
127 autofill_popup_view_views_->NotifyAccessibilityEventForRow(
128 ui::AX_EVENT_SELECTION, i);
129 }
130 }
131
132 } // 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