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/accelerators/accelerator_controller_unittest.cc

Issue 594383002: Change behaviour of the Alt-] and Alt-[ keys so that it cycles through SnapLeft/SnapRight to DockLe… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@event
Patch Set: Address DockLeft/DockRight issues Created 6 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/accelerators/accelerator_controller.h" 5 #include "ash/accelerators/accelerator_controller.h"
6 6
7 #include "ash/accelerators/accelerator_table.h" 7 #include "ash/accelerators/accelerator_table.h"
8 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/ime_control_delegate.h" 11 #include "ash/ime_control_delegate.h"
12 #include "ash/screen_util.h" 12 #include "ash/screen_util.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
15 #include "ash/system/brightness_control_delegate.h" 15 #include "ash/system/brightness_control_delegate.h"
16 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" 16 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
17 #include "ash/system/tray/system_tray_delegate.h" 17 #include "ash/system/tray/system_tray_delegate.h"
18 #include "ash/test/ash_test_base.h" 18 #include "ash/test/ash_test_base.h"
19 #include "ash/test/display_manager_test_api.h" 19 #include "ash/test/display_manager_test_api.h"
20 #include "ash/test/test_screenshot_delegate.h" 20 #include "ash/test/test_screenshot_delegate.h"
21 #include "ash/test/test_session_state_animator.h" 21 #include "ash/test/test_session_state_animator.h"
22 #include "ash/test/test_shelf_delegate.h"
22 #include "ash/test/test_shell_delegate.h" 23 #include "ash/test/test_shell_delegate.h"
23 #include "ash/test/test_volume_control_delegate.h" 24 #include "ash/test/test_volume_control_delegate.h"
24 #include "ash/volume_control_delegate.h" 25 #include "ash/volume_control_delegate.h"
25 #include "ash/wm/lock_state_controller.h" 26 #include "ash/wm/lock_state_controller.h"
27 #include "ash/wm/panels/panel_layout_manager.h"
26 #include "ash/wm/window_state.h" 28 #include "ash/wm/window_state.h"
27 #include "ash/wm/window_util.h" 29 #include "ash/wm/window_util.h"
28 #include "ash/wm/wm_event.h" 30 #include "ash/wm/wm_event.h"
29 #include "base/command_line.h" 31 #include "base/command_line.h"
30 #include "ui/aura/client/aura_constants.h" 32 #include "ui/aura/client/aura_constants.h"
31 #include "ui/aura/test/test_window_delegate.h" 33 #include "ui/aura/test/test_window_delegate.h"
32 #include "ui/aura/test/test_windows.h" 34 #include "ui/aura/test/test_windows.h"
33 #include "ui/aura/window.h" 35 #include "ui/aura/window.h"
34 #include "ui/events/event.h" 36 #include "ui/events/event.h"
35 #include "ui/events/event_processor.h" 37 #include "ui/events/event_processor.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 263 }
262 static bool is_ui_shown(ExitWarningHandler* ewh) { 264 static bool is_ui_shown(ExitWarningHandler* ewh) {
263 return !!ewh->widget_; 265 return !!ewh->widget_;
264 } 266 }
265 static bool is_idle(ExitWarningHandler* ewh) { 267 static bool is_idle(ExitWarningHandler* ewh) {
266 return ewh->state_ == ExitWarningHandler::IDLE; 268 return ewh->state_ == ExitWarningHandler::IDLE;
267 } 269 }
268 static bool is_exiting(ExitWarningHandler* ewh) { 270 static bool is_exiting(ExitWarningHandler* ewh) {
269 return ewh->state_ == ExitWarningHandler::EXITING; 271 return ewh->state_ == ExitWarningHandler::EXITING;
270 } 272 }
273 aura::Window* CreatePanel() {
274 aura::Window* window =
275 CreateTestWindowInShellWithDelegateAndType(NULL,
276 ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(5, 5, 20, 20));
277 test::TestShelfDelegate* shelf_delegate =
278 test::TestShelfDelegate::instance();
279 shelf_delegate->AddShelfItem(window);
280 PanelLayoutManager* manager = static_cast<PanelLayoutManager*>(
281 Shell::GetContainer(window->GetRootWindow(),
282 kShellWindowId_PanelContainer)->layout_manager());
283 manager->Relayout();
284 return window;
285 }
271 286
272 private: 287 private:
273 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); 288 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest);
274 }; 289 };
275 290
276 AcceleratorController* AcceleratorControllerTest::GetController() { 291 AcceleratorController* AcceleratorControllerTest::GetController() {
277 return Shell::GetInstance()->accelerator_controller(); 292 return Shell::GetInstance()->accelerator_controller();
278 } 293 }
279 294
280 #if !defined(OS_WIN) 295 #if !defined(OS_WIN)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 TEST_F(AcceleratorControllerTest, WindowSnap) { 443 TEST_F(AcceleratorControllerTest, WindowSnap) {
429 scoped_ptr<aura::Window> window( 444 scoped_ptr<aura::Window> window(
430 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 445 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
431 const ui::Accelerator dummy; 446 const ui::Accelerator dummy;
432 447
433 wm::WindowState* window_state = wm::GetWindowState(window.get()); 448 wm::WindowState* window_state = wm::GetWindowState(window.get());
434 449
435 window_state->Activate(); 450 window_state->Activate();
436 451
437 { 452 {
438 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); 453 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
439 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( 454 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent(
440 window.get()); 455 window.get());
441 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); 456 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
442 } 457 }
443 { 458 {
444 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); 459 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy);
445 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( 460 gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent(
446 window.get()); 461 window.get());
447 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); 462 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString());
448 } 463 }
449 { 464 {
450 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent(); 465 gfx::Rect normal_bounds = window_state->GetRestoreBoundsInParent();
451 466
452 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); 467 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
453 EXPECT_TRUE(window_state->IsMaximized()); 468 EXPECT_TRUE(window_state->IsMaximized());
454 EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString()); 469 EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString());
455 470
456 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); 471 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
457 EXPECT_FALSE(window_state->IsMaximized()); 472 EXPECT_FALSE(window_state->IsMaximized());
458 // Window gets restored to its restore bounds since side-maximized state 473 // Window gets restored to its restore bounds since side-maximized state
459 // is treated as a "maximized" state. 474 // is treated as a "maximized" state.
460 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); 475 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString());
461 476
462 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); 477 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
463 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); 478 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
464 EXPECT_FALSE(window_state->IsMaximized()); 479 EXPECT_FALSE(window_state->IsMaximized());
465 480
466 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); 481 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
467 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); 482 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy);
468 EXPECT_FALSE(window_state->IsMaximized()); 483 EXPECT_FALSE(window_state->IsMaximized());
469 484
470 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); 485 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy);
471 EXPECT_TRUE(window_state->IsMaximized()); 486 EXPECT_TRUE(window_state->IsMaximized());
472 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); 487 GetController()->PerformAction(WINDOW_MINIMIZE, dummy);
473 EXPECT_FALSE(window_state->IsMaximized()); 488 EXPECT_FALSE(window_state->IsMaximized());
474 EXPECT_TRUE(window_state->IsMinimized()); 489 EXPECT_TRUE(window_state->IsMinimized());
475 window_state->Restore(); 490 window_state->Restore();
476 window_state->Activate(); 491 window_state->Activate();
477 } 492 }
478 { 493 {
479 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); 494 GetController()->PerformAction(WINDOW_MINIMIZE, dummy);
480 EXPECT_TRUE(window_state->IsMinimized()); 495 EXPECT_TRUE(window_state->IsMinimized());
481 } 496 }
482 } 497 }
483 498
499 TEST_F(AcceleratorControllerTest, WindowDock) {
500 scoped_ptr<aura::Window> window0(
501 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
502 {
503 scoped_ptr<aura::Window> window1(
504 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
505 const ui::Accelerator dummy;
506
507 wm::WindowState* window1_state = wm::GetWindowState(window1.get());
508 window1_state->Activate();
509
510 // check snap left, dock left, restore cycle
varkha 2014/09/29 21:04:34 Comments should be English sentences - capitalized
511 {
512 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
513 gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent();
514 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent(
515 window1.get());
516 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString());
517 EXPECT_TRUE(window1_state->IsSnapped());
518 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
519 EXPECT_FALSE(window1_state->IsNormalOrSnapped());
520 EXPECT_TRUE(window1_state->IsDocked());
521 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
522 EXPECT_FALSE(window1_state->IsDocked());
523 EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString());
524 }
525 // check snap right, dock right, restore cycle
varkha 2014/09/29 21:04:34 Consider separating those into separate methods. I
dtapuska 2014/09/30 14:40:49 Done.
526 {
527 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy);
528 gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent();
529 gfx::Rect expected_bounds =
530 wm::GetDefaultRightSnappedWindowBoundsInParent(window1.get());
531 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString());
532 EXPECT_TRUE(window1_state->IsSnapped());
533 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy);
534 EXPECT_FALSE(window1_state->IsNormalOrSnapped());
535 EXPECT_TRUE(window1_state->IsDocked());
536 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy);
537 EXPECT_FALSE(window1_state->IsDocked());
538 EXPECT_EQ(normal_bounds.ToString(), window1->bounds().ToString());
539 }
540
541 // check snap left, dock left, snap right
542 {
543 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
544 gfx::Rect expected_bounds =
545 wm::GetDefaultLeftSnappedWindowBoundsInParent(window1.get());
546 gfx::Rect expected_bounds2 =
547 wm::GetDefaultRightSnappedWindowBoundsInParent(window1.get());
548 EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString());
549 EXPECT_TRUE(window1_state->IsSnapped());
550 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
551 EXPECT_FALSE(window1_state->IsNormalOrSnapped());
552 EXPECT_TRUE(window1_state->IsDocked());
553 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy);
554 EXPECT_FALSE(window1_state->IsDocked());
555 EXPECT_TRUE(window1_state->IsSnapped());
556 EXPECT_EQ(expected_bounds2.ToString(), window1->bounds().ToString());
557 }
558
559 // check snap left, dock left, snap right
560 {
561 scoped_ptr<aura::Window> window2(
562 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
563
564 wm::WindowState* window2_state = wm::GetWindowState(window2.get());
565
566 scoped_ptr<aura::Window> window3(
567 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
568
569 wm::WindowState* window3_state = wm::GetWindowState(window3.get());
570 window3_state->Activate();
571
572 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
573 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
574 gfx::Rect window3_docked_bounds = window3->bounds();
575
576 window2_state->Activate();
577 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
578 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
579 window1_state->Activate();
580 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
581 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
582
583 EXPECT_TRUE(window3_state->IsDocked());
584 EXPECT_TRUE(window2_state->IsDocked());
585 EXPECT_TRUE(window1_state->IsDocked());
586 EXPECT_TRUE(window3_state->IsMinimized());
587
588 window1_state->Activate();
589 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
590 window2_state->Activate();
591 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
592 window3_state->Unminimize();
593 EXPECT_FALSE(window1_state->IsDocked());
594 EXPECT_FALSE(window2_state->IsDocked());
595 EXPECT_TRUE(window3_state->IsDocked());
596 EXPECT_EQ(window3_docked_bounds.ToString(), window3->bounds().ToString());
597 }
598 }
599
600 // Panel docking tests
601 {
602 scoped_ptr<aura::Window> window(CreatePanel());
603
604 const ui::Accelerator dummy;
605
606 wm::WindowState* window_state = wm::GetWindowState(window.get());
607
608 window_state->Activate();
609
610 // check snap left (doesn't apply for panels), dock left, dock, right,
611 // restore cycle
612 {
613 gfx::Rect window_restore_bounds2 = window->bounds();
614 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_LEFT, dummy);
615 gfx::Rect expected_bounds =
616 wm::GetDefaultLeftSnappedWindowBoundsInParent(window.get());
617 gfx::Rect window_restore_bounds =
618 window_state->GetRestoreBoundsInScreen();
619 EXPECT_NE(expected_bounds.ToString(), window->bounds().ToString());
620 EXPECT_FALSE(window_state->IsSnapped());
621 EXPECT_FALSE(window_state->IsNormalOrSnapped());
622 EXPECT_TRUE(window_state->IsDocked());
623 window_state->Restore();
624 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy);
625 EXPECT_TRUE(window_state->IsDocked());
626 GetController()->PerformAction(WINDOW_SNAP_OR_DOCK_RIGHT, dummy);
627 EXPECT_FALSE(window_state->IsDocked());
628 EXPECT_EQ(window_restore_bounds.ToString(),
629 window_restore_bounds2.ToString());
630 EXPECT_EQ(window_restore_bounds.ToString(), window->bounds().ToString());
631 }
632 }
633 }
634
484 TEST_F(AcceleratorControllerTest, CenterWindowAccelerator) { 635 TEST_F(AcceleratorControllerTest, CenterWindowAccelerator) {
485 scoped_ptr<aura::Window> window( 636 scoped_ptr<aura::Window> window(
486 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 637 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
487 const ui::Accelerator dummy; 638 const ui::Accelerator dummy;
488 wm::WindowState* window_state = wm::GetWindowState(window.get()); 639 wm::WindowState* window_state = wm::GetWindowState(window.get());
489 window_state->Activate(); 640 window_state->Activate();
490 641
491 // Center the window using accelerator. 642 // Center the window using accelerator.
492 GetController()->PerformAction(WINDOW_POSITION_CENTER, dummy); 643 GetController()->PerformAction(WINDOW_POSITION_CENTER, dummy);
493 gfx::Rect work_area = 644 gfx::Rect work_area =
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); 1474 window.reset(CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
1324 wm::ActivateWindow(window.get()); 1475 wm::ActivateWindow(window.get());
1325 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); 1476 GetController()->PerformAction(WINDOW_MINIMIZE, dummy);
1326 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); 1477 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE);
1327 GetController()->PerformAction(kActionsNeedingWindow[i], dummy); 1478 GetController()->PerformAction(kActionsNeedingWindow[i], dummy);
1328 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED); 1479 EXPECT_NE(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_WINDOW_NEEDED);
1329 } 1480 }
1330 } 1481 }
1331 1482
1332 } // namespace ash 1483 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698