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

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: tests added 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
« no previous file with comments | « ash/wm/overview/window_selector_item.cc ('k') | tools/metrics/actions/actions.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 kActiveWindowChangedFromOverview[] =
63 "WindowSelector_ActiveWindowChanged";
64
61 class NonActivatableActivationDelegate 65 class NonActivatableActivationDelegate
62 : public aura::client::ActivationDelegate { 66 : public aura::client::ActivationDelegate {
63 public: 67 public:
64 bool ShouldActivate() const override { return false; } 68 bool ShouldActivate() const override { return false; }
65 }; 69 };
66 70
67 void CancelDrag(DragDropController* controller, bool* canceled) { 71 void CancelDrag(DragDropController* controller, bool* canceled) {
68 if (controller->IsDragDropInProgress()) { 72 if (controller->IsDragDropInProgress()) {
69 *canceled = true; 73 *canceled = true;
70 controller->DragCancel(); 74 controller->DragCancel();
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 EXPECT_EQ(window1.get(), GetFocusedWindow()); 371 EXPECT_EQ(window1.get(), GetFocusedWindow());
368 ToggleOverview(); 372 ToggleOverview();
369 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); 373 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
370 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 374 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
371 window2.get()); 375 window2.get());
372 generator.GestureTapAt(gfx::ToEnclosingRect( 376 generator.GestureTapAt(gfx::ToEnclosingRect(
373 GetTransformedTargetBounds(window2.get())).CenterPoint()); 377 GetTransformedTargetBounds(window2.get())).CenterPoint());
374 EXPECT_EQ(window2.get(), GetFocusedWindow()); 378 EXPECT_EQ(window2.get(), GetFocusedWindow());
375 } 379 }
376 380
381 // Tests that the user action WindowSelector_ActiveWindowChanged is
382 // recorded when the mouse/touchscreen/keyboard are used to select a window
383 // in overview mode which is different from the previously-active window.
384 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionRecorded) {
385 base::UserActionTester user_action_tester;
386 gfx::Rect bounds(0, 0, 400, 400);
387 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
388 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
389
390 // Tap on |window2| to activate it and exit overview.
391 wm::ActivateWindow(window1.get());
392 ToggleOverview();
393 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
394 window2.get());
395 generator.GestureTapAt(
396 gfx::ToEnclosingRect(GetTransformedTargetBounds(window2.get()))
397 .CenterPoint());
398 EXPECT_EQ(
399 1, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview));
400
401 // Click on |window2| to activate it and exit overview.
402 wm::ActivateWindow(window1.get());
403 ToggleOverview();
404 ClickWindow(window2.get());
405 EXPECT_EQ(
406 2, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview));
407
408 // Select |window2| using the arrow keys. Activate it (and exit overview) by
409 // pressing the return key.
410 wm::ActivateWindow(window1.get());
411 ToggleOverview();
412 SendKey(ui::VKEY_RIGHT);
413 SendKey(ui::VKEY_RIGHT);
414 SendKey(ui::VKEY_RETURN);
415 EXPECT_EQ(
416 3, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview));
417 }
418
419 // Tests that the user action WindowSelector_ActiveWindowChanged is not
420 // recorded when the mouse/touchscreen/keyboard are used to select the
421 // already-active window from overview mode. Also verifies that entering and
422 // exiting overview without selecting a window does not record the action.
423 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionNotRecorded) {
424 base::UserActionTester user_action_tester;
425 gfx::Rect bounds(0, 0, 400, 400);
426 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
427 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
428
429 // Set |window1| to be initially active.
430 wm::ActivateWindow(window1.get());
431 ToggleOverview();
432
433 // Tap on |window1| to exit overview.
434 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
435 window1.get());
436 generator.GestureTapAt(
437 gfx::ToEnclosingRect(GetTransformedTargetBounds(window1.get()))
438 .CenterPoint());
439 EXPECT_EQ(
440 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview));
441
442 // |window1| remains active. Click on it to exit overview.
443 ASSERT_EQ(window1.get(), GetFocusedWindow());
444 ToggleOverview();
445 ClickWindow(window1.get());
446 EXPECT_EQ(
447 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview));
448
449 // |window1| remains active. Select using the keyboard.
450 ASSERT_EQ(window1.get(), GetFocusedWindow());
451 ToggleOverview();
452 SendKey(ui::VKEY_RIGHT);
453 SendKey(ui::VKEY_RETURN);
454 EXPECT_EQ(
455 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview));
456
457 // Entering and exiting overview without user input should not record
458 // the action.
459 ToggleOverview();
460 ToggleOverview();
461 EXPECT_EQ(
462 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview));
463 }
464
465 // Tests that the user action WindowSelector_ActiveWindowChanged is not
466 // recorded when overview mode exits as a result of closing its only window.
467 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionWindowClose) {
468 base::UserActionTester user_action_tester;
469 scoped_ptr<views::Widget> widget =
470 CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
471
472 ToggleOverview();
473
474 aura::Window* window = widget->GetNativeWindow();
475 gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
476 gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1);
477 ui::test::EventGenerator event_generator(window->GetRootWindow(), point);
478
479 ASSERT_FALSE(widget->IsClosed());
480 event_generator.ClickLeftButton();
481 ASSERT_TRUE(widget->IsClosed());
482 EXPECT_EQ(
483 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview));
484 }
485
377 // Tests that we do not crash and overview mode remains engaged if the desktop 486 // 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. 487 // is tapped while a finger is already down over a window.
379 TEST_F(WindowSelectorTest, NoCrashWithDesktopTap) { 488 TEST_F(WindowSelectorTest, NoCrashWithDesktopTap) {
380 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(200, 300, 250, 450))); 489 scoped_ptr<aura::Window> window(CreateWindow(gfx::Rect(200, 300, 250, 450)));
381 490
382 ToggleOverview(); 491 ToggleOverview();
383 492
384 gfx::Rect bounds = 493 gfx::Rect bounds =
385 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window.get())); 494 gfx::ToEnclosingRect(GetTransformedBoundsInRootWindow(window.get()));
386 ui::test::EventGenerator event_generator(window->GetRootWindow(), 495 ui::test::EventGenerator event_generator(window->GetRootWindow(),
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 // Switch to overview mode. 1367 // Switch to overview mode.
1259 ToggleOverview(); 1368 ToggleOverview();
1260 ASSERT_TRUE(IsSelecting()); 1369 ASSERT_TRUE(IsSelecting());
1261 1370
1262 // Tap should now exit overview mode. 1371 // Tap should now exit overview mode.
1263 generator.GestureTapAt(point_in_background_page); 1372 generator.GestureTapAt(point_in_background_page);
1264 EXPECT_FALSE(IsSelecting()); 1373 EXPECT_FALSE(IsSelecting());
1265 } 1374 }
1266 1375
1267 } // namespace ash 1376 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/overview/window_selector_item.cc ('k') | tools/metrics/actions/actions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698