Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / autofill / autofill_popup_base_view_browsertest.cc
blob95e39e63f35269cf74f3ef778b656e1848d2ae6d
1 // Copyright 2014 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.
5 #include "chrome/browser/ui/views/autofill/autofill_popup_base_view.h"
7 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/events/event_utils.h"
15 #include "ui/views/test/views_test_base.h"
16 #include "ui/views/widget/widget.h"
18 namespace autofill {
20 namespace {
22 using testing::Return;
23 using testing::ReturnRef;
25 class MockAutofillPopupViewDelegate : public AutofillPopupViewDelegate {
26 public:
27 MOCK_METHOD0(Hide, void());
28 MOCK_METHOD0(ViewDestroyed, void());
29 MOCK_METHOD1(SetSelectionAtPoint, void(const gfx::Point&));
30 MOCK_METHOD0(AcceptSelectedLine, bool());
31 MOCK_METHOD0(SelectionCleared, void());
32 // TODO(jdduke): Mock this method upon resolution of crbug.com/352463.
33 MOCK_CONST_METHOD0(popup_bounds, gfx::Rect&());
34 MOCK_METHOD0(container_view, gfx::NativeView());
35 MOCK_CONST_METHOD0(element_bounds, gfx::RectF&());
36 MOCK_CONST_METHOD0(IsRTL, bool());
39 } // namespace
41 class AutofillPopupBaseViewTest : public InProcessBrowserTest {
42 public:
43 AutofillPopupBaseViewTest() {}
44 ~AutofillPopupBaseViewTest() override {}
46 void SetUpOnMainThread() override {
47 gfx::NativeView native_view =
48 browser()->tab_strip_model()->GetActiveWebContents()->GetNativeView();
49 EXPECT_CALL(mock_delegate_, container_view())
50 .WillRepeatedly(Return(native_view));
51 EXPECT_CALL(mock_delegate_, ViewDestroyed());
53 view_ = new AutofillPopupBaseView(
54 &mock_delegate_, views::Widget::GetWidgetForNativeWindow(
55 browser()->window()->GetNativeWindow()));
58 void ShowView() {
59 view_->DoShow();
62 ui::GestureEvent CreateGestureEvent(ui::EventType type, gfx::Point point) {
63 return ui::GestureEvent(point.x(),
64 point.y(),
66 ui::EventTimeForNow(),
67 ui::GestureEventDetails(type));
70 void SimulateGesture(ui::GestureEvent* event) {
71 view_->OnGestureEvent(event);
74 protected:
75 testing::NiceMock<MockAutofillPopupViewDelegate> mock_delegate_;
76 AutofillPopupBaseView* view_;
79 // Flaky on Win and Linux. http://crbug.com/376299
80 #if defined(OS_LINUX) || defined(OS_WIN)
81 #define MAYBE_GestureTest DISABLED_GestureTest
82 #else
83 #define MAYBE_GestureTest GestureTest
84 #endif
86 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, MAYBE_GestureTest) {
87 gfx::Rect bounds(0, 0, 5, 5);
88 gfx::Point point = bounds.CenterPoint();
89 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(ReturnRef(bounds));
91 ShowView();
93 // Expectations.
95 testing::InSequence dummy;
96 EXPECT_CALL(mock_delegate_, SetSelectionAtPoint(point)).Times(2);
97 EXPECT_CALL(mock_delegate_, AcceptSelectedLine());
98 EXPECT_CALL(mock_delegate_, SelectionCleared());
101 // Tap down will select an element.
102 ui::GestureEvent tap_down_event = CreateGestureEvent(ui::ET_GESTURE_TAP_DOWN,
103 point);
104 SimulateGesture(&tap_down_event);
107 // Tapping will accept the selection.
108 ui::GestureEvent tap_event = CreateGestureEvent(ui::ET_GESTURE_TAP, point);
109 SimulateGesture(&tap_event);
111 // Tapping outside the bounds clears any selection.
112 ui::GestureEvent outside_tap = CreateGestureEvent(ui::ET_GESTURE_TAP,
113 gfx::Point(100, 100));
114 SimulateGesture(&outside_tap);
117 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, DoubleClickTest) {
118 gfx::Rect bounds(0, 0, 5, 5);
119 gfx::Point point = bounds.CenterPoint();
120 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(ReturnRef(bounds));
122 ShowView();
124 ui::MouseEvent mouse_down(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
125 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0);
126 EXPECT_TRUE(static_cast<views::View*>(view_)->OnMousePressed(mouse_down));
128 // Ignore double clicks.
129 mouse_down.SetClickCount(2);
130 EXPECT_FALSE(static_cast<views::View*>(view_)->OnMousePressed(mouse_down));
133 // Regression test for crbug.com/391316
134 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, CorrectBoundsTest) {
135 gfx::Rect bounds(100, 150, 5, 5);
136 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(ReturnRef(bounds));
138 ShowView();
140 gfx::Point display_point =
141 static_cast<views::View*>(view_)->GetBoundsInScreen().origin();
142 gfx::Point expected_point = bounds.origin();
143 EXPECT_EQ(expected_point, display_point);
146 } // namespace autofill