OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/autofill/autofill_popup_base_view.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_popup_base_view.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" | 8 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "components/autofill/core/browser/suggestion.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
16 #include "ui/views/test/views_test_base.h" | 17 #include "ui/views/test/views_test_base.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
18 | 19 |
19 namespace autofill { | 20 namespace autofill { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 using testing::Return; | 24 using testing::Return; |
24 using testing::ReturnRef; | 25 using testing::ReturnRef; |
25 | 26 |
26 class MockAutofillPopupViewDelegate : public AutofillPopupViewDelegate { | 27 class MockAutofillPopupViewDelegate : public AutofillPopupViewDelegate { |
27 public: | 28 public: |
28 MOCK_METHOD0(Hide, void()); | 29 MOCK_METHOD0(Hide, void()); |
29 MOCK_METHOD0(ViewDestroyed, void()); | 30 MOCK_METHOD0(ViewDestroyed, void()); |
30 MOCK_METHOD1(SetSelectionAtPoint, void(const gfx::Point&)); | 31 MOCK_METHOD1(SetSelectionAtPoint, void(const gfx::Point&)); |
31 MOCK_METHOD0(AcceptSelectedLine, bool()); | 32 MOCK_METHOD0(AcceptSelectedLine, bool()); |
32 MOCK_METHOD0(SelectionCleared, void()); | 33 MOCK_METHOD0(SelectionCleared, void()); |
33 // TODO(jdduke): Mock this method upon resolution of crbug.com/352463. | 34 // TODO(jdduke): Mock this method upon resolution of crbug.com/352463. |
34 MOCK_CONST_METHOD0(popup_bounds, gfx::Rect&()); | 35 MOCK_CONST_METHOD0(popup_bounds, gfx::Rect()); |
35 MOCK_METHOD0(container_view, gfx::NativeView()); | 36 MOCK_METHOD0(container_view, gfx::NativeView()); |
36 MOCK_CONST_METHOD0(element_bounds, gfx::RectF&()); | 37 MOCK_CONST_METHOD0(element_bounds, gfx::RectF&()); |
37 MOCK_CONST_METHOD0(IsRTL, bool()); | 38 MOCK_CONST_METHOD0(IsRTL, bool()); |
| 39 MOCK_METHOD0(GetSuggestions, const std::vector<autofill::Suggestion>()); |
| 40 #if !defined(OS_ANDROID) |
| 41 MOCK_METHOD1(GetElidedValueWidthForRow, int(size_t)); |
| 42 MOCK_METHOD1(GetElidedLabelWidthForRow, int(size_t)); |
| 43 #endif |
38 }; | 44 }; |
39 | 45 |
40 } // namespace | 46 } // namespace |
41 | 47 |
42 class AutofillPopupBaseViewTest : public InProcessBrowserTest { | 48 class AutofillPopupBaseViewTest : public InProcessBrowserTest { |
43 public: | 49 public: |
44 AutofillPopupBaseViewTest() {} | 50 AutofillPopupBaseViewTest() {} |
45 ~AutofillPopupBaseViewTest() override {} | 51 ~AutofillPopupBaseViewTest() override {} |
46 | 52 |
47 void SetUpOnMainThread() override { | 53 void SetUpOnMainThread() override { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // Flaky on Win and Linux. http://crbug.com/376299 | 86 // Flaky on Win and Linux. http://crbug.com/376299 |
81 #if defined(OS_LINUX) || defined(OS_WIN) | 87 #if defined(OS_LINUX) || defined(OS_WIN) |
82 #define MAYBE_GestureTest DISABLED_GestureTest | 88 #define MAYBE_GestureTest DISABLED_GestureTest |
83 #else | 89 #else |
84 #define MAYBE_GestureTest GestureTest | 90 #define MAYBE_GestureTest GestureTest |
85 #endif | 91 #endif |
86 | 92 |
87 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, MAYBE_GestureTest) { | 93 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, MAYBE_GestureTest) { |
88 gfx::Rect bounds(0, 0, 5, 5); | 94 gfx::Rect bounds(0, 0, 5, 5); |
89 gfx::Point point = bounds.CenterPoint(); | 95 gfx::Point point = bounds.CenterPoint(); |
90 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(ReturnRef(bounds)); | 96 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(Return(bounds)); |
91 | 97 |
92 ShowView(); | 98 ShowView(); |
93 | 99 |
94 // Expectations. | 100 // Expectations. |
95 { | 101 { |
96 testing::InSequence dummy; | 102 testing::InSequence dummy; |
97 EXPECT_CALL(mock_delegate_, SetSelectionAtPoint(point)).Times(2); | 103 EXPECT_CALL(mock_delegate_, SetSelectionAtPoint(point)).Times(2); |
98 EXPECT_CALL(mock_delegate_, AcceptSelectedLine()); | 104 EXPECT_CALL(mock_delegate_, AcceptSelectedLine()); |
99 EXPECT_CALL(mock_delegate_, SelectionCleared()); | 105 EXPECT_CALL(mock_delegate_, SelectionCleared()); |
100 } | 106 } |
(...skipping 10 matching lines...) Expand all Loading... |
111 | 117 |
112 // Tapping outside the bounds clears any selection. | 118 // Tapping outside the bounds clears any selection. |
113 ui::GestureEvent outside_tap = CreateGestureEvent(ui::ET_GESTURE_TAP, | 119 ui::GestureEvent outside_tap = CreateGestureEvent(ui::ET_GESTURE_TAP, |
114 gfx::Point(100, 100)); | 120 gfx::Point(100, 100)); |
115 SimulateGesture(&outside_tap); | 121 SimulateGesture(&outside_tap); |
116 } | 122 } |
117 | 123 |
118 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, DoubleClickTest) { | 124 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, DoubleClickTest) { |
119 gfx::Rect bounds(0, 0, 5, 5); | 125 gfx::Rect bounds(0, 0, 5, 5); |
120 gfx::Point point = bounds.CenterPoint(); | 126 gfx::Point point = bounds.CenterPoint(); |
121 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(ReturnRef(bounds)); | 127 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(Return(bounds)); |
122 | 128 |
123 ShowView(); | 129 ShowView(); |
124 | 130 |
125 ui::MouseEvent mouse_down(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 131 ui::MouseEvent mouse_down(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), |
126 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); | 132 gfx::Point(0, 0), ui::EventTimeForNow(), 0, 0); |
127 EXPECT_TRUE(static_cast<views::View*>(view_)->OnMousePressed(mouse_down)); | 133 EXPECT_TRUE(static_cast<views::View*>(view_)->OnMousePressed(mouse_down)); |
128 | 134 |
129 // Ignore double clicks. | 135 // Ignore double clicks. |
130 mouse_down.SetClickCount(2); | 136 mouse_down.SetClickCount(2); |
131 EXPECT_FALSE(static_cast<views::View*>(view_)->OnMousePressed(mouse_down)); | 137 EXPECT_FALSE(static_cast<views::View*>(view_)->OnMousePressed(mouse_down)); |
132 } | 138 } |
133 | 139 |
134 // Regression test for crbug.com/391316 | 140 // Regression test for crbug.com/391316 |
135 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, CorrectBoundsTest) { | 141 IN_PROC_BROWSER_TEST_F(AutofillPopupBaseViewTest, CorrectBoundsTest) { |
136 gfx::Rect bounds(100, 150, 5, 5); | 142 gfx::Rect bounds(100, 150, 5, 5); |
137 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(ReturnRef(bounds)); | 143 EXPECT_CALL(mock_delegate_, popup_bounds()).WillRepeatedly(Return(bounds)); |
138 | 144 |
139 ShowView(); | 145 ShowView(); |
140 | 146 |
141 gfx::Point display_point = | 147 gfx::Point display_point = |
142 static_cast<views::View*>(view_)->GetBoundsInScreen().origin(); | 148 static_cast<views::View*>(view_)->GetBoundsInScreen().origin(); |
143 gfx::Point expected_point = bounds.origin(); | 149 gfx::Point expected_point = bounds.origin(); |
144 EXPECT_EQ(expected_point, display_point); | 150 EXPECT_EQ(expected_point, display_point); |
145 } | 151 } |
146 | 152 |
147 } // namespace autofill | 153 } // namespace autofill |
OLD | NEW |