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/test/base/in_process_browser_test.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/events/event_utils.h"
14 #include "ui/views/test/views_test_base.h"
15 #include "ui/views/widget/widget.h"
21 using testing::Return
;
22 using testing::ReturnRef
;
24 class MockAutofillPopupViewDelegate
: public AutofillPopupViewDelegate
{
26 MOCK_METHOD0(Hide
, void());
27 MOCK_METHOD0(ViewDestroyed
, void());
28 MOCK_METHOD1(SetSelectionAtPoint
, void(const gfx::Point
&));
29 MOCK_METHOD0(AcceptSelectedLine
, bool());
30 MOCK_METHOD0(SelectionCleared
, void());
31 // TODO(jdduke): Mock this method upon resolution of crbug.com/352463.
32 MOCK_CONST_METHOD0(popup_bounds
, gfx::Rect
&());
33 MOCK_METHOD0(container_view
, gfx::NativeView());
38 class AutofillPopupBaseViewTest
: public InProcessBrowserTest
{
40 AutofillPopupBaseViewTest() {}
41 virtual ~AutofillPopupBaseViewTest() {}
43 virtual void SetUpOnMainThread() OVERRIDE
{
44 gfx::NativeWindow window
= browser()->window()->GetNativeWindow();
45 EXPECT_CALL(mock_delegate_
, container_view())
46 .WillRepeatedly(Return(window
));
47 EXPECT_CALL(mock_delegate_
, ViewDestroyed());
49 view_
= new AutofillPopupBaseView(
51 views::Widget::GetWidgetForNativeWindow(window
));
58 ui::GestureEvent
CreateGestureEvent(ui::EventType type
, gfx::Point point
) {
59 return ui::GestureEvent(type
,
63 ui::EventTimeForNow(),
64 ui::GestureEventDetails(type
, 0, 0),
68 void SimulateGesture(ui::GestureEvent
* event
) {
69 view_
->OnGestureEvent(event
);
73 MockAutofillPopupViewDelegate mock_delegate_
;
74 AutofillPopupBaseView
* view_
;
77 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest
, GestureTest
) {
78 gfx::Rect
bounds(0, 0, 5, 5);
79 gfx::Point point
= bounds
.CenterPoint();
80 EXPECT_CALL(mock_delegate_
, popup_bounds()).WillRepeatedly(ReturnRef(bounds
));
86 testing::InSequence dummy
;
87 EXPECT_CALL(mock_delegate_
, SetSelectionAtPoint(point
)).Times(2);
88 EXPECT_CALL(mock_delegate_
, AcceptSelectedLine());
89 EXPECT_CALL(mock_delegate_
, SelectionCleared());
92 // Tap down will select an element.
93 ui::GestureEvent tap_down_event
= CreateGestureEvent(ui::ET_GESTURE_TAP_DOWN
,
95 SimulateGesture(&tap_down_event
);
98 // Tapping will accept the selection.
99 ui::GestureEvent tap_event
= CreateGestureEvent(ui::ET_GESTURE_TAP
, point
);
100 SimulateGesture(&tap_event
);
102 // Tapping outside the bounds clears any selection.
103 ui::GestureEvent outside_tap
= CreateGestureEvent(ui::ET_GESTURE_TAP
,
104 gfx::Point(100, 100));
105 SimulateGesture(&outside_tap
);
108 } // namespace autofill