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

Side by Side Diff: ash/wm/overview/window_selector_unittest.cc

Issue 1138253002: Add user action for changing the active window in Ash overview mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
9 #include "ash/drag_drop/drag_drop_controller.h" 9 #include "ash/drag_drop/drag_drop_controller.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
(...skipping 17 matching lines...) Expand all
28 #include "ash/wm/window_state.h" 28 #include "ash/wm/window_state.h"
29 #include "ash/wm/window_util.h" 29 #include "ash/wm/window_util.h"
30 #include "ash/wm/wm_event.h" 30 #include "ash/wm/wm_event.h"
31 #include "base/basictypes.h" 31 #include "base/basictypes.h"
32 #include "base/command_line.h" 32 #include "base/command_line.h"
33 #include "base/compiler_specific.h" 33 #include "base/compiler_specific.h"
34 #include "base/memory/scoped_vector.h" 34 #include "base/memory/scoped_vector.h"
35 #include "base/run_loop.h" 35 #include "base/run_loop.h"
36 #include "base/strings/string_piece.h" 36 #include "base/strings/string_piece.h"
37 #include "base/strings/utf_string_conversions.h" 37 #include "base/strings/utf_string_conversions.h"
38 #include "base/test/user_action_tester.h"
38 #include "ui/aura/client/aura_constants.h" 39 #include "ui/aura/client/aura_constants.h"
39 #include "ui/aura/client/cursor_client.h" 40 #include "ui/aura/client/cursor_client.h"
40 #include "ui/aura/client/focus_client.h" 41 #include "ui/aura/client/focus_client.h"
41 #include "ui/aura/test/test_window_delegate.h" 42 #include "ui/aura/test/test_window_delegate.h"
42 #include "ui/aura/test/test_windows.h" 43 #include "ui/aura/test/test_windows.h"
43 #include "ui/aura/window.h" 44 #include "ui/aura/window.h"
44 #include "ui/aura/window_event_dispatcher.h" 45 #include "ui/aura/window_event_dispatcher.h"
45 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 46 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
46 #include "ui/events/event_utils.h" 47 #include "ui/events/event_utils.h"
47 #include "ui/events/test/event_generator.h" 48 #include "ui/events/test/event_generator.h"
48 #include "ui/gfx/geometry/point_conversions.h" 49 #include "ui/gfx/geometry/point_conversions.h"
49 #include "ui/gfx/geometry/rect_conversions.h" 50 #include "ui/gfx/geometry/rect_conversions.h"
50 #include "ui/gfx/transform.h" 51 #include "ui/gfx/transform.h"
51 #include "ui/gfx/transform_util.h" 52 #include "ui/gfx/transform_util.h"
52 #include "ui/views/controls/button/label_button.h" 53 #include "ui/views/controls/button/label_button.h"
53 #include "ui/views/widget/native_widget_aura.h" 54 #include "ui/views/widget/native_widget_aura.h"
54 #include "ui/views/widget/widget_delegate.h" 55 #include "ui/views/widget/widget_delegate.h"
55 #include "ui/wm/core/window_util.h" 56 #include "ui/wm/core/window_util.h"
56 #include "ui/wm/public/activation_delegate.h" 57 #include "ui/wm/public/activation_delegate.h"
57 58
58 namespace ash { 59 namespace ash {
59 namespace { 60 namespace {
60 61
62 const char kActiveWindowChanged[] = "WindowSelector_ActiveWindowChanged";
63
61 class NonActivatableActivationDelegate 64 class NonActivatableActivationDelegate
62 : public aura::client::ActivationDelegate { 65 : public aura::client::ActivationDelegate {
63 public: 66 public:
64 bool ShouldActivate() const override { return false; } 67 bool ShouldActivate() const override { return false; }
65 }; 68 };
66 69
67 void CancelDrag(DragDropController* controller, bool* canceled) { 70 void CancelDrag(DragDropController* controller, bool* canceled) {
68 if (controller->IsDragDropInProgress()) { 71 if (controller->IsDragDropInProgress()) {
69 *canceled = true; 72 *canceled = true;
70 controller->DragCancel(); 73 controller->DragCancel();
(...skipping 11 matching lines...) Expand all
82 85
83 void SetUp() override { 86 void SetUp() override {
84 test::AshTestBase::SetUp(); 87 test::AshTestBase::SetUp();
85 ASSERT_TRUE(test::TestShelfDelegate::instance()); 88 ASSERT_TRUE(test::TestShelfDelegate::instance());
86 89
87 shelf_view_test_.reset(new test::ShelfViewTestAPI( 90 shelf_view_test_.reset(new test::ShelfViewTestAPI(
88 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view())); 91 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view()));
89 shelf_view_test_->SetAnimationDuration(1); 92 shelf_view_test_->SetAnimationDuration(1);
90 } 93 }
91 94
95 aura::Window* CreateWindowWithType(const gfx::Rect& bounds,
96 ui::wm::WindowType type) {
97 return CreateTestWindowInShellWithDelegateAndType(&delegate_, type, -1,
98 bounds);
99 }
100
92 aura::Window* CreateWindow(const gfx::Rect& bounds) { 101 aura::Window* CreateWindow(const gfx::Rect& bounds) {
93 return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds); 102 return CreateTestWindowInShellWithDelegate(&delegate_, -1, bounds);
94 } 103 }
95 104
96 aura::Window* CreateWindowWithId(const gfx::Rect& bounds, int id) { 105 aura::Window* CreateWindowWithId(const gfx::Rect& bounds, int id) {
97 return CreateTestWindowInShellWithDelegate(&delegate_, id, bounds); 106 return CreateTestWindowInShellWithDelegate(&delegate_, id, bounds);
98 } 107 }
99 aura::Window* CreateNonActivatableWindow(const gfx::Rect& bounds) { 108 aura::Window* CreateNonActivatableWindow(const gfx::Rect& bounds) {
100 aura::Window* window = CreateWindow(bounds); 109 aura::Window* window = CreateWindow(bounds);
101 aura::client::SetActivationDelegate(window, 110 aura::client::SetActivationDelegate(window,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 return ws->grid_list_[ws->selected_grid_index_]->is_selecting(); 221 return ws->grid_list_[ws->selected_grid_index_]->is_selecting();
213 } 222 }
214 223
215 bool showing_filter_widget() { 224 bool showing_filter_widget() {
216 WindowSelector* ws = ash::Shell::GetInstance()-> 225 WindowSelector* ws = ash::Shell::GetInstance()->
217 window_selector_controller()->window_selector_.get(); 226 window_selector_controller()->window_selector_.get();
218 return ws->text_filter_widget_->GetNativeWindow()->layer()-> 227 return ws->text_filter_widget_->GetNativeWindow()->layer()->
219 GetTargetTransform().IsIdentity(); 228 GetTargetTransform().IsIdentity();
220 } 229 }
221 230
231 aura::Window* initially_active_window() {
232 return ash::Shell::GetInstance()
233 ->window_selector_controller()
234 ->initially_active_window_;
235 }
236
222 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) { 237 views::Widget* GetCloseButton(ash::WindowSelectorItem* window) {
223 return &(window->close_button_widget_); 238 return &(window->close_button_widget_);
224 } 239 }
225 240
226 views::LabelButton* GetLabelButtonView(ash::WindowSelectorItem* window) { 241 views::LabelButton* GetLabelButtonView(ash::WindowSelectorItem* window) {
227 return window->window_label_button_view_; 242 return window->window_label_button_view_;
228 } 243 }
229 244
230 // Tests that a window is contained within a given WindowSelectorItem, and 245 // Tests that a window is contained within a given WindowSelectorItem, and
231 // that both the window and its matching close button are within the same 246 // that both the window and its matching close button are within the same
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 EXPECT_EQ(window1.get(), GetFocusedWindow()); 382 EXPECT_EQ(window1.get(), GetFocusedWindow());
368 ToggleOverview(); 383 ToggleOverview();
369 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); 384 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
370 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 385 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
371 window2.get()); 386 window2.get());
372 generator.GestureTapAt(gfx::ToEnclosingRect( 387 generator.GestureTapAt(gfx::ToEnclosingRect(
373 GetTransformedTargetBounds(window2.get())).CenterPoint()); 388 GetTransformedTargetBounds(window2.get())).CenterPoint());
374 EXPECT_EQ(window2.get(), GetFocusedWindow()); 389 EXPECT_EQ(window2.get(), GetFocusedWindow());
375 } 390 }
376 391
392 // Tests that the user action defined by |kActiveWindowChanged| is recorded
393 // when a normal window is active upon entering overview mode and a different
394 // normal window is active upon exiting overview mode.
395 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionChanged) {
396 base::UserActionTester user_action_tester;
397 gfx::Rect bounds(0, 0, 400, 400);
398 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
399 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
400 wm::ActivateWindow(window1.get());
401 ASSERT_EQ(window1.get(), GetFocusedWindow());
402 ToggleOverview();
403 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
404 window2.get());
405 generator.GestureTapAt(
406 gfx::ToEnclosingRect(GetTransformedTargetBounds(window2.get()))
407 .CenterPoint());
408 ASSERT_EQ(window2.get(), GetFocusedWindow());
409 EXPECT_EQ(1, user_action_tester.GetActionCount(kActiveWindowChanged));
410 }
411
412 // Tests that the user action defined by |kActiveWindowChanged| is not recorded
413 // when the window that is active upon entering overview mode remains
414 // active upon exiting overview mode.
415 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionNoChange) {
416 base::UserActionTester user_action_tester;
417 gfx::Rect bounds(0, 0, 400, 400);
418 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
419 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
420 wm::ActivateWindow(window1.get());
421 ASSERT_EQ(window1.get(), GetFocusedWindow());
422 ToggleOverview();
423 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
424 window1.get());
425 generator.GestureTapAt(
426 gfx::ToEnclosingRect(GetTransformedTargetBounds(window1.get()))
427 .CenterPoint());
428 ASSERT_EQ(window1.get(), GetFocusedWindow());
429 EXPECT_EQ(0, user_action_tester.GetActionCount(kActiveWindowChanged));
430 }
431
432 // Tests that the user action defined by |kActiveWindowChanged| is not recorded
433 // when the window that is active upon entering overview mode is a popup, even
434 // a normal window is active upon exiting overview mode.
435 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionPopupWindow) {
436 base::UserActionTester user_action_tester;
437 gfx::Rect bounds(0, 0, 400, 400);
438 scoped_ptr<aura::Window> window1(
439 CreateWindowWithType(bounds, ui::wm::WINDOW_TYPE_POPUP));
440 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
441 wm::ActivateWindow(window1.get());
442 ASSERT_EQ(window1.get(), GetFocusedWindow());
443 ToggleOverview();
444 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
445 window2.get());
446 generator.GestureTapAt(
447 gfx::ToEnclosingRect(GetTransformedTargetBounds(window2.get()))
448 .CenterPoint());
449 ASSERT_EQ(window2.get(), GetFocusedWindow());
450 EXPECT_EQ(0, user_action_tester.GetActionCount(kActiveWindowChanged));
451 }
452
453 // Tests that the user action defined by |kActiveWindowChanged| is not recorded
454 // when the oply open window is closed while in overview mode.
bruthig 2015/05/12 17:37:38 Sp? "oply"
tdanderson 2015/05/14 01:36:32 Done.
455 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionWindowClose) {
456 base::UserActionTester user_action_tester;
457 scoped_ptr<views::Widget> widget =
458 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
459
460 ToggleOverview();
461
462 aura::Window* window = widget->GetNativeWindow();
463 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
464 gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1);
465 ui::test::EventGenerator event_generator(window->GetRootWindow(), point);
466
467 ASSERT_FALSE(widget->IsClosed());
468 event_generator.ClickLeftButton();
469 ASSERT_TRUE(widget->IsClosed());
470 EXPECT_EQ(0, user_action_tester.GetActionCount(kActiveWindowChanged));
471 }
472
473 // Tests that if a normal window is active upon entering overview mode, the
474 // member |initially_active_window_| should be set to this window while
475 // overview mode is active and cleared upon exiting overview mode.
476 TEST_F(WindowSelectorTest, InitiallyActiveWindowSetInOverviewMode) {
477 gfx::Rect bounds(0, 0, 400, 400);
478 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
479 wm::ActivateWindow(window1.get());
480 ASSERT_EQ(window1.get(), GetFocusedWindow());
481 ToggleOverview();
482 ASSERT_TRUE(IsSelecting());
483 EXPECT_EQ(window1.get(), initially_active_window());
484 ToggleOverview();
485 ASSERT_FALSE(IsSelecting());
486 EXPECT_EQ(nullptr, initially_active_window());
487 }
488
489 // Tests that if a popup window is active upon entering overview mode, the
490 // member |initially_active_window_| should not be set upon entering overview
491 // mode.
492 TEST_F(WindowSelectorTest, InitiallyActiveWindowNotSetForPopup) {
493 gfx::Rect bounds(0, 0, 400, 400);
494 scoped_ptr<aura::Window> window1(
495 CreateWindowWithType(bounds, ui::wm::WINDOW_TYPE_POPUP));
496 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
497 wm::ActivateWindow(window1.get());
498 ASSERT_EQ(window1.get(), GetFocusedWindow());
499 ToggleOverview();
500 ASSERT_TRUE(IsSelecting());
501 EXPECT_EQ(nullptr, initially_active_window());
502 }
503
377 // Tests that we do not crash and overview mode remains engaged if the desktop 504 // Tests that we do not crash and overview mode remains engaged if the desktop
378 // is tapped while a finger is already down over a window. 505 // is tapped while a finger is already down over a window.
379 TEST_F(WindowSelectorTest, NoCrashWithDesktopTap) { 506 TEST_F(WindowSelectorTest, NoCrashWithDesktopTap) {
380 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(200, 300, 250, 450))); 507 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(200, 300, 250, 450)));
381 508
382 ToggleOverview(); 509 ToggleOverview();
383 510
384 gfx::Rect bounds = 511 gfx::Rect bounds =
385 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window.get())); 512 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window.get()));
386 ui::test::EventGenerator event_generator(window->GetRootWindow(), 513 ui::test::EventGenerator event_generator(window->GetRootWindow(),
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 // Switch to overview mode. 1385 // Switch to overview mode.
1259 ToggleOverview(); 1386 ToggleOverview();
1260 ASSERT_TRUE(IsSelecting()); 1387 ASSERT_TRUE(IsSelecting());
1261 1388
1262 // Tap should now exit overview mode. 1389 // Tap should now exit overview mode.
1263 generator.GestureTapAt(point_in_background_page); 1390 generator.GestureTapAt(point_in_background_page);
1264 EXPECT_FALSE(IsSelecting()); 1391 EXPECT_FALSE(IsSelecting());
1265 } 1392 }
1266 1393
1267 } // namespace ash 1394 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698