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

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_popup_base_view_browsertest.cc

Issue 187583004: Fix gesture detection for autofill popup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_popup_base_view.cc ('k') | chrome/chrome_tests.gypi » ('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 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.
4
5 #include "chrome/browser/ui/views/autofill/autofill_popup_base_view.h"
6
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"
16
17 namespace autofill {
18
19 namespace {
20
21 using testing::Return;
22 using testing::ReturnRef;
23
24 class MockAutofillPopupViewDelegate : public AutofillPopupViewDelegate {
25 public:
26 MOCK_METHOD0(Hide, void());
27 MOCK_METHOD0(ViewDestroyed, void());
28 MOCK_METHOD1(SetSelectionAtPoint, void(const gfx::Point&));
29 MOCK_METHOD1(AcceptSelectionAtPoint, void(const gfx::Point&));
30 MOCK_METHOD0(SelectionCleared, void());
31 MOCK_METHOD1(ShouldRepostEvent, bool(const ui::MouseEvent&));
32 MOCK_CONST_METHOD0(ShouldHideOnOutsideClick, bool());
33 MOCK_CONST_METHOD0(popup_bounds, gfx::Rect&());
34 MOCK_METHOD0(container_view, gfx::NativeView());
35 };
36
37 } // namespace
38
39 class AutofillPopupBaseViewTest : public InProcessBrowserTest {
40 public:
41 AutofillPopupBaseViewTest() {}
42 virtual ~AutofillPopupBaseViewTest() {}
43
44 virtual void SetUpOnMainThread() OVERRIDE {
45 gfx::NativeWindow window = browser()->window()->GetNativeWindow();
46 EXPECT_CALL(mock_delegate_, container_view())
47 .WillRepeatedly(Return(window));
48 EXPECT_CALL(mock_delegate_, ShouldHideOnOutsideClick())
49 .WillRepeatedly(Return(false));
50 EXPECT_CALL(mock_delegate_, ViewDestroyed()).Times(1);
51
52 view_ = new AutofillPopupBaseView(
53 &mock_delegate_,
54 views::Widget::GetWidgetForNativeWindow(window));
55 }
56
57 void ShowView() {
58 view_->DoShow();
59 }
60
61 ui::GestureEvent CreateGestureEvent(ui::EventType type, gfx::Point point) {
62 return ui::GestureEvent(type,
63 point.x(),
64 point.y(),
65 0,
66 ui::EventTimeForNow(),
67 ui::GestureEventDetails(type, 0, 0),
68 0);
69 }
70
71 void SimulateGesture(ui::GestureEvent* event) {
72 view_->OnGestureEvent(event);
73 }
74
75 protected:
76 MockAutofillPopupViewDelegate mock_delegate_;
77 AutofillPopupBaseView* view_;
78 };
79
80 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, GestureTest) {
81 gfx::Rect bounds(0, 0, 5, 5);
82 gfx::Point point = bounds.CenterPoint();
83 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(ReturnRef(bounds));
84
85 ShowView();
86
87 // Expectations.
88 {
89 testing::InSequence dummy;
90 EXPECT_CALL(mock_delegate_, SetSelectionAtPoint(point)).Times(1);
91 EXPECT_CALL(mock_delegate_, AcceptSelectionAtPoint(point)).Times(1);
92 EXPECT_CALL(mock_delegate_, SelectionCleared()).Times(1);
93 }
94
95 // Tap down will select an element.
96 ui::GestureEvent tap_down_event = CreateGestureEvent(ui::ET_GESTURE_TAP_DOWN,
97 point);
98 SimulateGesture(&tap_down_event);
99
100
101 // Tapping will accept the selection.
102 ui::GestureEvent tap_event = CreateGestureEvent(ui::ET_GESTURE_TAP, point);
103 SimulateGesture(&tap_event);
104
105 // Tapping outside the bounds clears any selection.
106 ui::GestureEvent outside_tap = CreateGestureEvent(ui::ET_GESTURE_TAP,
107 gfx::Point(100, 100));
108 SimulateGesture(&outside_tap);
109 }
110
111 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_popup_base_view.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698