| OLD | NEW |
| 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 #include "ash/accelerators/accelerator_table.h" | 6 #include "ash/accelerators/accelerator_table.h" |
| 7 #include "ash/caps_lock_delegate.h" | 7 #include "ash/caps_lock_delegate.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/ime_control_delegate.h" | 9 #include "ash/ime_control_delegate.h" |
| 10 #include "ash/screenshot_delegate.h" | 10 #include "ash/screenshot_delegate.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/system/brightness/brightness_control_delegate.h" | 13 #include "ash/system/brightness/brightness_control_delegate.h" |
| 14 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" | 14 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" |
| 15 #include "ash/system/tray/system_tray_delegate.h" | 15 #include "ash/system/tray/system_tray_delegate.h" |
| 16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/test/display_manager_test_api.h" | 17 #include "ash/test/display_manager_test_api.h" |
| 18 #include "ash/test/test_shell_delegate.h" | 18 #include "ash/test/test_shell_delegate.h" |
| 19 #include "ash/volume_control_delegate.h" | 19 #include "ash/volume_control_delegate.h" |
| 20 #include "ash/wm/window_state.h" |
| 20 #include "ash/wm/window_util.h" | 21 #include "ash/wm/window_util.h" |
| 21 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
| 22 #include "ui/aura/test/test_window_delegate.h" | 23 #include "ui/aura/test/test_window_delegate.h" |
| 23 #include "ui/aura/test/test_windows.h" | 24 #include "ui/aura/test/test_windows.h" |
| 24 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 25 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
| 26 | 27 |
| 27 #if defined(USE_X11) | 28 #if defined(USE_X11) |
| 28 #include <X11/Xlib.h> | 29 #include <X11/Xlib.h> |
| 29 #include "ui/base/x/x11_util.h" | 30 #include "ui/base/x/x11_util.h" |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); | 492 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a)); |
| 492 GetController()->UnregisterAll(&target); | 493 GetController()->UnregisterAll(&target); |
| 493 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); | 494 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a)); |
| 494 } | 495 } |
| 495 | 496 |
| 496 TEST_F(AcceleratorControllerTest, WindowSnap) { | 497 TEST_F(AcceleratorControllerTest, WindowSnap) { |
| 497 scoped_ptr<aura::Window> window( | 498 scoped_ptr<aura::Window> window( |
| 498 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 499 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| 499 const ui::Accelerator dummy; | 500 const ui::Accelerator dummy; |
| 500 | 501 |
| 501 wm::ActivateWindow(window.get()); | 502 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 503 |
| 504 window_state->Activate(); |
| 502 | 505 |
| 503 { | 506 { |
| 504 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); | 507 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); |
| 505 gfx::Rect snap_left = window->bounds(); | 508 gfx::Rect snap_left = window->bounds(); |
| 506 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); | 509 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); |
| 507 EXPECT_NE(window->bounds().ToString(), snap_left.ToString()); | 510 EXPECT_NE(window->bounds().ToString(), snap_left.ToString()); |
| 508 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); | 511 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); |
| 509 EXPECT_NE(window->bounds().ToString(), snap_left.ToString()); | 512 EXPECT_NE(window->bounds().ToString(), snap_left.ToString()); |
| 510 | 513 |
| 511 // It should cycle back to the first snapped position. | 514 // It should cycle back to the first snapped position. |
| 512 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); | 515 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); |
| 513 EXPECT_EQ(window->bounds().ToString(), snap_left.ToString()); | 516 EXPECT_EQ(window->bounds().ToString(), snap_left.ToString()); |
| 514 } | 517 } |
| 515 { | 518 { |
| 516 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); | 519 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); |
| 517 gfx::Rect snap_right = window->bounds(); | 520 gfx::Rect snap_right = window->bounds(); |
| 518 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); | 521 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); |
| 519 EXPECT_NE(window->bounds().ToString(), snap_right.ToString()); | 522 EXPECT_NE(window->bounds().ToString(), snap_right.ToString()); |
| 520 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); | 523 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); |
| 521 EXPECT_NE(window->bounds().ToString(), snap_right.ToString()); | 524 EXPECT_NE(window->bounds().ToString(), snap_right.ToString()); |
| 522 | 525 |
| 523 // It should cycle back to the first snapped position. | 526 // It should cycle back to the first snapped position. |
| 524 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); | 527 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); |
| 525 EXPECT_EQ(window->bounds().ToString(), snap_right.ToString()); | 528 EXPECT_EQ(window->bounds().ToString(), snap_right.ToString()); |
| 526 } | 529 } |
| 527 { | 530 { |
| 528 gfx::Rect normal_bounds = window->bounds(); | 531 gfx::Rect normal_bounds = window->bounds(); |
| 529 | 532 |
| 530 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); | 533 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); |
| 531 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); | 534 EXPECT_TRUE(window_state->IsMaximized()); |
| 532 EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString()); | 535 EXPECT_NE(normal_bounds.ToString(), window->bounds().ToString()); |
| 533 | 536 |
| 534 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); | 537 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); |
| 535 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 538 EXPECT_FALSE(window_state->IsMaximized()); |
| 536 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); | 539 EXPECT_EQ(normal_bounds.ToString(), window->bounds().ToString()); |
| 537 | 540 |
| 538 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); | 541 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); |
| 539 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); | 542 GetController()->PerformAction(WINDOW_SNAP_LEFT, dummy); |
| 540 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 543 EXPECT_FALSE(window_state->IsMaximized()); |
| 541 | 544 |
| 542 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); | 545 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); |
| 543 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); | 546 GetController()->PerformAction(WINDOW_SNAP_RIGHT, dummy); |
| 544 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 547 EXPECT_FALSE(window_state->IsMaximized()); |
| 545 | 548 |
| 546 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); | 549 GetController()->PerformAction(TOGGLE_MAXIMIZED, dummy); |
| 547 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); | 550 EXPECT_TRUE(window_state->IsMaximized()); |
| 548 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); | 551 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); |
| 549 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 552 EXPECT_FALSE(window_state->IsMaximized()); |
| 550 EXPECT_TRUE(wm::IsWindowMinimized(window.get())); | 553 EXPECT_TRUE(window_state->IsMinimized()); |
| 551 wm::RestoreWindow(window.get()); | 554 window_state->Restore(); |
| 552 wm::ActivateWindow(window.get()); | 555 window_state->Activate(); |
| 553 } | 556 } |
| 554 { | 557 { |
| 555 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); | 558 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); |
| 556 EXPECT_TRUE(wm::IsWindowMinimized(window.get())); | 559 EXPECT_TRUE(window_state->IsMinimized()); |
| 557 } | 560 } |
| 558 } | 561 } |
| 559 | 562 |
| 560 TEST_F(AcceleratorControllerTest, ControllerContext) { | 563 TEST_F(AcceleratorControllerTest, ControllerContext) { |
| 561 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 564 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 562 ui::Accelerator accelerator_a2(ui::VKEY_A, ui::EF_NONE); | 565 ui::Accelerator accelerator_a2(ui::VKEY_A, ui::EF_NONE); |
| 563 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 566 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
| 564 | 567 |
| 565 accelerator_a.set_type(ui::ET_KEY_PRESSED); | 568 accelerator_a.set_type(ui::ET_KEY_PRESSED); |
| 566 accelerator_a2.set_type(ui::ET_KEY_RELEASED); | 569 accelerator_a2.set_type(ui::ET_KEY_RELEASED); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 591 GetController()->context()->previous_accelerator().type()); | 594 GetController()->context()->previous_accelerator().type()); |
| 592 } | 595 } |
| 593 | 596 |
| 594 TEST_F(AcceleratorControllerTest, SuppressToggleMaximized) { | 597 TEST_F(AcceleratorControllerTest, SuppressToggleMaximized) { |
| 595 scoped_ptr<aura::Window> window( | 598 scoped_ptr<aura::Window> window( |
| 596 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 599 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
| 597 wm::ActivateWindow(window.get()); | 600 wm::ActivateWindow(window.get()); |
| 598 const ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE); | 601 const ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE); |
| 599 const ui::Accelerator empty_accelerator; | 602 const ui::Accelerator empty_accelerator; |
| 600 | 603 |
| 604 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 605 |
| 601 // Toggling not suppressed. | 606 // Toggling not suppressed. |
| 602 GetController()->context()->UpdateContext(accelerator); | 607 GetController()->context()->UpdateContext(accelerator); |
| 603 GetController()->PerformAction(TOGGLE_MAXIMIZED, accelerator); | 608 GetController()->PerformAction(TOGGLE_MAXIMIZED, accelerator); |
| 604 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); | 609 EXPECT_TRUE(window_state->IsMaximized()); |
| 605 | 610 |
| 606 // The same accelerator - toggling suppressed. | 611 // The same accelerator - toggling suppressed. |
| 607 GetController()->context()->UpdateContext(accelerator); | 612 GetController()->context()->UpdateContext(accelerator); |
| 608 GetController()->PerformAction(TOGGLE_MAXIMIZED, accelerator); | 613 GetController()->PerformAction(TOGGLE_MAXIMIZED, accelerator); |
| 609 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); | 614 EXPECT_TRUE(window_state->IsMaximized()); |
| 610 | 615 |
| 611 // Suppressed but not for gesture events. | 616 // Suppressed but not for gesture events. |
| 612 GetController()->PerformAction(TOGGLE_MAXIMIZED, empty_accelerator); | 617 GetController()->PerformAction(TOGGLE_MAXIMIZED, empty_accelerator); |
| 613 EXPECT_FALSE(wm::IsWindowMaximized(window.get())); | 618 EXPECT_FALSE(window_state->IsMaximized()); |
| 614 } | 619 } |
| 615 | 620 |
| 616 #if defined(OS_WIN) || defined(USE_X11) | 621 #if defined(OS_WIN) || defined(USE_X11) |
| 617 TEST_F(AcceleratorControllerTest, ProcessOnce) { | 622 TEST_F(AcceleratorControllerTest, ProcessOnce) { |
| 618 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 623 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
| 619 TestTarget target; | 624 TestTarget target; |
| 620 GetController()->Register(accelerator_a, &target); | 625 GetController()->Register(accelerator_a, &target); |
| 621 | 626 |
| 622 // The accelerator is processed only once. | 627 // The accelerator is processed only once. |
| 623 #if defined(OS_WIN) | 628 #if defined(OS_WIN) |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 EXPECT_EQ(volume_down, delegate->last_accelerator()); | 1336 EXPECT_EQ(volume_down, delegate->last_accelerator()); |
| 1332 EXPECT_EQ(0, delegate->handle_volume_up_count()); | 1337 EXPECT_EQ(0, delegate->handle_volume_up_count()); |
| 1333 EXPECT_TRUE(ProcessWithContext(volume_up)); | 1338 EXPECT_TRUE(ProcessWithContext(volume_up)); |
| 1334 EXPECT_EQ(1, delegate->handle_volume_up_count()); | 1339 EXPECT_EQ(1, delegate->handle_volume_up_count()); |
| 1335 EXPECT_EQ(volume_up, delegate->last_accelerator()); | 1340 EXPECT_EQ(volume_up, delegate->last_accelerator()); |
| 1336 } | 1341 } |
| 1337 } | 1342 } |
| 1338 #endif | 1343 #endif |
| 1339 | 1344 |
| 1340 } // namespace ash | 1345 } // namespace ash |
| OLD | NEW |