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

Side by Side Diff: ash/app_list/app_list_presenter_delegate_unittest.cc

Issue 2952763002: SearchBoxView now enables/disables cursor based on user interaction. (Closed)
Patch Set: SearchBoxView now enables/disables cursor based on user interaction. Created 3 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <memory> 5 #include <memory>
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/public/cpp/config.h" 8 #include "ash/public/cpp/config.h"
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/test_app_list_view_presenter_impl.h" 12 #include "ash/test/test_app_list_view_presenter_impl.h"
13 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/test/scoped_feature_list.h" 16 #include "base/test/scoped_feature_list.h"
17 #include "ui/app_list/app_list_features.h" 17 #include "ui/app_list/app_list_features.h"
18 #include "ui/app_list/app_list_switches.h" 18 #include "ui/app_list/app_list_switches.h"
19 #include "ui/app_list/views/app_list_main_view.h" 19 #include "ui/app_list/views/app_list_main_view.h"
20 #include "ui/app_list/views/app_list_view.h" 20 #include "ui/app_list/views/app_list_view.h"
21 #include "ui/app_list/views/search_box_view.h"
21 #include "ui/aura/test/test_windows.h" 22 #include "ui/aura/test/test_windows.h"
22 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
23 #include "ui/display/display.h" 24 #include "ui/display/display.h"
24 #include "ui/display/screen.h" 25 #include "ui/display/screen.h"
25 #include "ui/events/test/event_generator.h" 26 #include "ui/events/test/event_generator.h"
27 #include "ui/views/controls/textfield/textfield.h"
26 28
27 namespace ash { 29 namespace ash {
28 namespace { 30 namespace {
29 31
30 int64_t GetPrimaryDisplayId() { 32 int64_t GetPrimaryDisplayId() {
31 return display::Screen::GetScreen()->GetPrimaryDisplay().id(); 33 return display::Screen::GetScreen()->GetPrimaryDisplay().id();
32 } 34 }
33 35
34 } // namespace 36 } // namespace
35 37
36 class AppListPresenterDelegateTest : public test::AshTestBase, 38 class AppListPresenterDelegateTest : public test::AshTestBase,
37 public testing::WithParamInterface<bool> { 39 public testing::WithParamInterface<bool> {
38 public: 40 public:
39 AppListPresenterDelegateTest() {} 41 AppListPresenterDelegateTest() {}
40 ~AppListPresenterDelegateTest() override {} 42 ~AppListPresenterDelegateTest() override {}
41 43
42 app_list::AppListPresenterImpl* app_list_presenter_impl() { 44 app_list::AppListPresenterImpl* app_list_presenter_impl() {
43 return &app_list_presenter_impl_; 45 return &app_list_presenter_impl_;
44 } 46 }
45 47
46 // testing::Test: 48 // testing::Test:
47 void SetUp() override { 49 void SetUp() override {
48 AshTestBase::SetUp(); 50 AshTestBase::SetUp();
49 51
50 // If the current test is parameterized. 52 if (testing::UnitTest::GetInstance()->current_test_info()->value_param() &&
51 if (testing::UnitTest::GetInstance()->current_test_info()->value_param()) { 53 GetParam())
52 test_with_fullscreen_ = GetParam(); 54 EnableFullscreenAppList();
oshima 2017/07/06 21:05:51 nit: you need {} in this case
newcomer 2017/07/10 15:24:06 Done.
53 if (test_with_fullscreen_) 55
54 EnableFullscreenAppList();
55 }
56 // Make the display big enough to hold the app list. 56 // Make the display big enough to hold the app list.
57 UpdateDisplay("1024x768"); 57 UpdateDisplay("1024x768");
58 } 58 }
59 59
60 void EnableFullscreenAppList() { 60 void EnableFullscreenAppList() {
61 scoped_feature_list_.InitAndEnableFeature( 61 scoped_feature_list_.InitAndEnableFeature(
62 app_list::features::kEnableFullscreenAppList); 62 app_list::features::kEnableFullscreenAppList);
63 } 63 }
64 64
65 private: 65 private:
66 test::TestAppListViewPresenterImpl app_list_presenter_impl_; 66 test::TestAppListViewPresenterImpl app_list_presenter_impl_;
67 bool test_with_fullscreen_;
68 base::test::ScopedFeatureList scoped_feature_list_; 67 base::test::ScopedFeatureList scoped_feature_list_;
69 68
70 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest); 69 DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateTest);
71 }; 70 };
72 71
72 class FullscreenAppListPresenterDelegateTest
73 : public test::AshTestBase,
74 public testing::WithParamInterface<bool> {
75 public:
76 FullscreenAppListPresenterDelegateTest() {}
77 ~FullscreenAppListPresenterDelegateTest() override {}
78
79 app_list::AppListPresenterImpl* app_list_presenter_impl() {
80 return &app_list_presenter_impl_;
81 }
82
83 // testing::Test:
84 void SetUp() override {
85 AshTestBase::SetUp();
86
87 scoped_feature_list_.InitAndEnableFeature(
88 app_list::features::kEnableFullscreenAppList);
89
90 // Make the display big enough to hold the app list.
91 UpdateDisplay("1024x768");
92 }
93
94 private:
95 test::TestAppListViewPresenterImpl app_list_presenter_impl_;
96 base::test::ScopedFeatureList scoped_feature_list_;
97
98 DISALLOW_COPY_AND_ASSIGN(FullscreenAppListPresenterDelegateTest);
99 };
100
73 // Instantiate the Boolean which is used to toggle the Fullscreen app list in 101 // Instantiate the Boolean which is used to toggle the Fullscreen app list in
74 // the parameterized tests. 102 // the parameterized tests.
75 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool()); 103 INSTANTIATE_TEST_CASE_P(, AppListPresenterDelegateTest, testing::Bool());
76 104
105 // Instantiate the Boolean which is used to toggle mouse and touch events in
106 // the parameterized tests.
107 INSTANTIATE_TEST_CASE_P(,
108 FullscreenAppListPresenterDelegateTest,
109 testing::Bool());
110
77 // Tests that app list hides when focus moves to a normal window. 111 // Tests that app list hides when focus moves to a normal window.
78 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) { 112 TEST_P(AppListPresenterDelegateTest, HideOnFocusOut) {
79 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 113 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
80 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 114 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
81 115
82 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 116 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
83 wm::ActivateWindow(window.get()); 117 wm::ActivateWindow(window.get());
84 118
85 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); 119 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility());
86 } 120 }
(...skipping 28 matching lines...) Expand all
115 // Click outside the bubble. This should close it. 149 // Click outside the bubble. This should close it.
116 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); 150 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
117 gfx::Point point_outside = 151 gfx::Point point_outside =
118 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) + 152 gfx::Point(app_window_bounds.right(), app_window_bounds.y()) +
119 gfx::Vector2d(10, 0); 153 gfx::Vector2d(10, 0);
120 generator.MoveMouseToInHost(point_outside); 154 generator.MoveMouseToInHost(point_outside);
121 generator.ClickLeftButton(); 155 generator.ClickLeftButton();
122 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); 156 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility());
123 } 157 }
124 158
125 // Tests that clicking outside the app-list bubble closes it. 159 // Tests that tapping outside the app-list bubble closes it.
126 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) { 160 TEST_F(AppListPresenterDelegateTest, TapOutsideBubbleClosesBubble) {
127 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 161 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
128 162
129 aura::Window* app_window = app_list_presenter_impl()->GetWindow(); 163 aura::Window* app_window = app_list_presenter_impl()->GetWindow();
130 ASSERT_TRUE(app_window); 164 ASSERT_TRUE(app_window);
131 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow(); 165 gfx::Rect app_window_bounds = app_window->GetBoundsInRootWindow();
132 166
133 ui::test::EventGenerator& generator = GetEventGenerator(); 167 ui::test::EventGenerator& generator = GetEventGenerator();
134 // Click on the bubble itself. The bubble should remain visible. 168 // Click on the bubble itself. The bubble should remain visible.
135 generator.GestureTapAt(app_window_bounds.CenterPoint()); 169 generator.GestureTapAt(app_window_bounds.CenterPoint());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 app_list::AppListView* app_list = app_list_presenter_impl()->GetView(); 218 app_list::AppListView* app_list = app_list_presenter_impl()->GetView();
185 int app_list_view_top = 219 int app_list_view_top =
186 app_list->anchor_rect().y() - app_list->bounds().height() / 2; 220 app_list->anchor_rect().y() - app_list->bounds().height() / 2;
187 const int kMinimalAppListMargin = 10; 221 const int kMinimalAppListMargin = 10;
188 222
189 EXPECT_GE(app_list_view_top, kMinimalAppListMargin); 223 EXPECT_GE(app_list_view_top, kMinimalAppListMargin);
190 } 224 }
191 225
192 // Tests that the peeking app list closes if the user taps outside its 226 // Tests that the peeking app list closes if the user taps outside its
193 // bounds. 227 // bounds.
194 TEST_F(AppListPresenterDelegateTest, TapAndClickOutsideClosesPeekingAppList) { 228 TEST_F(FullscreenAppListPresenterDelegateTest,
195 EnableFullscreenAppList(); 229 TapAndClickOutsideClosesPeekingAppList) {
196
197 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 230 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
198 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 231 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
199 ui::test::EventGenerator& generator = GetEventGenerator(); 232 ui::test::EventGenerator& generator = GetEventGenerator();
200 233
201 // Grab the bounds of the search box, 234 // Grab the bounds of the search box,
202 // which is guaranteed to be inside the app list. 235 // which is guaranteed to be inside the app list.
203 gfx::Point tap_point = app_list_presenter_impl() 236 gfx::Point tap_point = app_list_presenter_impl()
204 ->GetView() 237 ->GetView()
205 ->search_box_widget() 238 ->search_box_widget()
206 ->GetContentsView() 239 ->GetContentsView()
(...skipping 16 matching lines...) Expand all
223 256
224 app_list_presenter_impl()->Show(GetPrimaryDisplayId()); 257 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
225 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility()); 258 EXPECT_TRUE(app_list_presenter_impl()->GetTargetVisibility());
226 259
227 // Clicking outside the bounds closes the app list. 260 // Clicking outside the bounds closes the app list.
228 generator.MoveMouseTo(tap_point); 261 generator.MoveMouseTo(tap_point);
229 generator.ClickLeftButton(); 262 generator.ClickLeftButton();
230 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility()); 263 EXPECT_FALSE(app_list_presenter_impl()->GetTargetVisibility());
231 } 264 }
232 265
266 // Tests that a keypress activates the searchbox and that clearing the searchbox
267 // deactivates the searchbox.
268 TEST_F(FullscreenAppListPresenterDelegateTest, KeyPressEnablesSearchBox) {
269 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
270 ui::test::EventGenerator& generator = GetEventGenerator();
271 app_list::SearchBoxView* search_box_view =
272 app_list_presenter_impl()->GetView()->search_box_view();
273 EXPECT_FALSE(search_box_view->is_search_box_active());
274
275 // Press any key, the search box should be active.
276 generator.PressKey(ui::VKEY_0, 0);
277 EXPECT_TRUE(search_box_view->is_search_box_active());
278
279 // Delete the text, the search box should be inactive.
280 search_box_view->ClearSearch();
281 EXPECT_FALSE(search_box_view->is_search_box_active());
282 }
283
284 // Tests that a tap/click on the AppListView from half launcher returns the
285 // AppListView to Peeking, and that a tap/click on the AppListView from Peeking
286 // closes the app list.
287 TEST_P(FullscreenAppListPresenterDelegateTest,
288 StateTransitionsByTapAndClickingAppListBodyFromHalf) {
289 bool tap_or_click = GetParam();
oshima 2017/07/06 21:05:51 test_mouse_event (a_or_b sounds like it's true for
newcomer 2017/07/10 15:24:07 Done.
290 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
291 app_list::AppListView* app_list_view = app_list_presenter_impl()->GetView();
292 app_list::SearchBoxView* search_box_view = app_list_view->search_box_view();
293 ui::test::EventGenerator& generator = GetEventGenerator();
294 EXPECT_TRUE(app_list_view->app_list_state() ==
oshima 2017/07/06 21:05:51 nit: EXPECT_EQ
newcomer 2017/07/10 15:24:06 Done.
295 app_list::AppListView::AppListState::PEEKING);
296
297 // Press a key, the AppListView should transition to half.
298 generator.PressKey(ui::KeyboardCode::VKEY_0, 0);
299 EXPECT_TRUE(app_list_view->app_list_state() ==
oshima 2017/07/06 21:05:51 ditto
newcomer 2017/07/10 15:24:04 Done.
300 app_list::AppListView::AppListState::HALF);
301 EXPECT_TRUE(search_box_view->is_search_box_active());
302
303 // Tap outside the search box, the AppListView should transition to Peeking
304 // and the search box should be inactive.
305 gfx::Point outside_search_box =
306 search_box_view->search_box()->GetBoundsInScreen().CenterPoint();
307 outside_search_box.set_x(20);
oshima 2017/07/06 21:05:51 how about BoundsInScreen().top_right() Offset(0,
newcomer 2017/07/10 15:24:08 Done.
308 if (tap_or_click) {
309 generator.MoveMouseTo(outside_search_box);
310 generator.ClickLeftButton();
311 } else {
312 generator.GestureTapDownAndUp(outside_search_box);
313 }
314 EXPECT_TRUE(app_list_view->app_list_state() ==
315 app_list::AppListView::AppListState::PEEKING);
oshima 2017/07/06 21:05:51 ditto
newcomer 2017/07/10 15:24:04 Done.
316 EXPECT_FALSE(search_box_view->is_search_box_active());
317
318 // Tap outside the search box again, the AppListView should hide.
319 outside_search_box =
320 search_box_view->search_box()->GetBoundsInScreen().CenterPoint();
321 outside_search_box.set_x(20);
322 if (tap_or_click) {
323 generator.MoveMouseTo(outside_search_box);
324 generator.ClickLeftButton();
325 } else {
326 generator.GestureTapDownAndUp(outside_search_box);
327 }
328 EXPECT_TRUE(app_list_view->app_list_state() ==
oshima 2017/07/06 21:05:51 ditto
newcomer 2017/07/10 15:24:04 Done.
329 app_list::AppListView::AppListState::CLOSED);
330 }
331
332 // Tests that a tap/click on the AppListView from Fullscreen search returns the
333 // AppListView to fullscreen all apps, and that a tap/click on the AppListView
334 // from fullscreen all apps closes the app list.
335 TEST_P(FullscreenAppListPresenterDelegateTest,
336 StateTransitionsByTappingAppListBodyFromFullscreen) {
337 bool tap_or_click = GetParam();
338 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
339 app_list::AppListView* app_list_view = app_list_presenter_impl()->GetView();
340 app_list::SearchBoxView* search_box_view = app_list_view->search_box_view();
341 ui::test::EventGenerator& generator = GetEventGenerator();
342
343 // Execute a long upwards drag, this should transition the app list to
344 // fullscreen.
345 int top_of_app_list =
346 app_list_view->GetWidget()->GetWindowBoundsInScreen().y();
347 generator.GestureScrollSequence(gfx::Point(10, top_of_app_list + 20),
348 gfx::Point(10, 10),
349 base::TimeDelta::FromMilliseconds(100), 10);
350 EXPECT_EQ(app_list_view->app_list_state(),
351 app_list::AppListView::FULLSCREEN_ALL_APPS);
352
353 // Press a key, this should activate the searchbox and transition to
354 // fullscreen search.
355 generator.PressKey(ui::KeyboardCode::VKEY_0, 0);
356 EXPECT_TRUE(app_list_view->app_list_state() ==
357 app_list::AppListView::AppListState::FULLSCREEN_SEARCH);
oshima 2017/07/06 21:05:51 ditto
newcomer 2017/07/10 15:24:04 Done.
358 EXPECT_TRUE(search_box_view->is_search_box_active());
359
360 // Tap outside the searchbox, this should deactivate the searchbox and the
361 // applistview should return to fullscreen all apps.
362 gfx::Point outside_search_box =
363 search_box_view->search_box()->GetBoundsInScreen().CenterPoint();
364 outside_search_box.set_x(20);
oshima 2017/07/06 21:05:51 ditto
newcomer 2017/07/10 15:24:06 Done.
365 if (tap_or_click) {
366 generator.MoveMouseTo(outside_search_box);
367 generator.ClickLeftButton();
368 } else {
369 generator.GestureTapDownAndUp(outside_search_box);
370 }
371 EXPECT_TRUE(app_list_view->app_list_state() ==
372 app_list::AppListView::AppListState::FULLSCREEN_ALL_APPS);
373 EXPECT_FALSE(search_box_view->is_search_box_active());
374
375 // Tap outside the searchbox again, this should close the applistview.
376 if (tap_or_click) {
377 generator.MoveMouseTo(outside_search_box);
378 generator.ClickLeftButton();
379 } else {
380 generator.GestureTapDownAndUp(outside_search_box);
381 }
382 EXPECT_TRUE(app_list_view->app_list_state() ==
oshima 2017/07/06 21:05:51 ditto
newcomer 2017/07/10 15:24:07 Done.
383 app_list::AppListView::AppListState::CLOSED);
384 }
385
386 // Tests that the searchbox activates when it is tapped and that the widget is
387 // closed after tapping outside the searchbox.
388 TEST_P(FullscreenAppListPresenterDelegateTest, TapOrClickEnablesSearchBox) {
389 bool tap_or_click = GetParam();
390 app_list_presenter_impl()->Show(GetPrimaryDisplayId());
391 app_list::SearchBoxView* search_box_view =
392 app_list_presenter_impl()->GetView()->search_box_view();
393
394 // Tap/Click the search box, it should activate.
395 gfx::Point search_box_point =
396 search_box_view->search_box()->GetBoundsInScreen().CenterPoint();
397 ui::test::EventGenerator& generator = GetEventGenerator();
398 if (tap_or_click) {
399 generator.GestureTapAt(search_box_point);
400 } else {
401 generator.MoveMouseTo(search_box_point);
402 generator.PressLeftButton();
403 generator.ReleaseLeftButton();
404 }
405
406 EXPECT_TRUE(search_box_view->is_search_box_active());
407
408 // Tap on the body of the app list, the search box should deactivate.
409 search_box_point.set_x(20);
oshima 2017/07/06 21:05:51 ditto
newcomer 2017/07/10 15:24:04 Done.
410 if (tap_or_click) {
411 generator.GestureTapAt(search_box_point);
412 } else {
413 generator.MoveMouseTo(search_box_point);
414 generator.PressLeftButton();
415 generator.ReleaseLeftButton();
416 }
417 EXPECT_FALSE(search_box_view->is_search_box_active());
418 EXPECT_TRUE(app_list_presenter_impl()->IsVisible());
419
420 // Tap on the body of the app list again, the app list should hide.
421 if (tap_or_click) {
422 generator.GestureTapAt(search_box_point);
423 } else {
424 generator.PressLeftButton();
425 generator.ReleaseLeftButton();
426 }
427 EXPECT_EQ(app_list_presenter_impl()->GetView()->app_list_state(),
428 app_list::AppListView::AppListState::CLOSED);
429 }
430
233 } // namespace ash 431 } // namespace ash
OLDNEW
« no previous file with comments | « ash/app_list/app_list_delegate_impl.cc ('k') | ash/app_list/app_list_presenter_delegate_unittest.cc.autosave » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698