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/wm/drag_window_resizer.h" | 5 #include "ash/wm/drag_window_resizer.h" |
6 | 6 |
7 #include "ash/display/mouse_cursor_event_filter.h" | 7 #include "ash/display/mouse_cursor_event_filter.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
13 #include "ash/test/cursor_manager_test_api.h" | 13 #include "ash/test/cursor_manager_test_api.h" |
14 #include "ash/wm/drag_window_controller.h" | 14 #include "ash/wm/drag_window_controller.h" |
15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
19 #include "ui/aura/test/test_window_delegate.h" | 19 #include "ui/aura/test/test_window_delegate.h" |
20 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
21 #include "ui/base/hit_test.h" | 21 #include "ui/base/hit_test.h" |
22 #include "ui/base/ui_base_types.h" | 22 #include "ui/base/ui_base_types.h" |
23 #include "ui/gfx/insets.h" | 23 #include "ui/gfx/insets.h" |
24 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
25 #include "ui/views/corewm/window_util.h" | 25 #include "ui/views/corewm/window_util.h" |
26 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
27 | 27 |
28 #if defined(OS_CHROMEOS) | |
29 #include "ash/system/tray/system_tray.h" | |
30 #include "ash/system/user/tray_user.h" | |
31 #include "ash/test/test_session_state_delegate.h" | |
32 #include "ash/test/test_shell_delegate.h" | |
33 #endif | |
34 | |
35 namespace ash { | 28 namespace ash { |
36 namespace internal { | 29 namespace internal { |
37 namespace { | 30 namespace { |
38 | 31 |
39 const int kRootHeight = 600; | 32 const int kRootHeight = 600; |
40 | 33 |
41 } // namespace | 34 } // namespace |
42 | 35 |
43 class DragWindowResizerTest : public test::AshTestBase { | 36 class DragWindowResizerTest : public test::AshTestBase { |
44 public: | 37 public: |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 625 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
633 window, gfx::Point(), HTCAPTION)); | 626 window, gfx::Point(), HTCAPTION)); |
634 ASSERT_TRUE(resizer.get()); | 627 ASSERT_TRUE(resizer.get()); |
635 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); | 628 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); |
636 EXPECT_TRUE(WarpMouseCursorIfNecessary(root_windows[0], | 629 EXPECT_TRUE(WarpMouseCursorIfNecessary(root_windows[0], |
637 gfx::Point(399, 200))); | 630 gfx::Point(399, 200))); |
638 resizer->CompleteDrag(); | 631 resizer->CompleteDrag(); |
639 } | 632 } |
640 } | 633 } |
641 | 634 |
642 #if defined(OS_CHROMEOS) | |
643 // Checks that moving a window to another desktop will properly set and reset | |
644 // the transparency. | |
645 TEST_F(DragWindowResizerTest, DragToOtherDesktopOpacity) { | |
646 // Set up a few things we need for multi profile. | |
647 ash::test::TestSessionStateDelegate* session_delegate = | |
648 static_cast<ash::test::TestSessionStateDelegate*>( | |
649 ash::Shell::GetInstance()->session_state_delegate()); | |
650 session_delegate->set_logged_in_users(2); | |
651 ash::test::TestShellDelegate* shell_delegate = | |
652 static_cast<ash::test::TestShellDelegate*>( | |
653 ash::Shell::GetInstance()->delegate()); | |
654 shell_delegate->set_multi_profiles_enabled(true); | |
655 | |
656 // Create one other user where we can drag our stuff onto. | |
657 SystemTray* tray = Shell::GetPrimaryRootWindowController()->GetSystemTray(); | |
658 TrayUser* tray_user = new TrayUser(tray, 1); | |
659 tray->AddTrayUserItemForTest(tray_user); | |
660 | |
661 // Move the view somewhere where we can hit it. | |
662 views::View* view = tray->GetTrayItemViewForTest(tray_user); | |
663 view->SetBounds(80, 0, 20, 20); | |
664 gfx::Point center = view->GetBoundsInScreen().CenterPoint(); | |
665 | |
666 gfx::Rect initial_bounds = gfx::Rect(0, 0, 50, 60); | |
667 // Drag the window over the icon and let it drop. Test that the window's | |
668 // layer gets transparent and reverts back. | |
669 { | |
670 aura::Window* window = window_.get(); | |
671 window->SetBoundsInScreen(initial_bounds, | |
672 Shell::GetScreen()->GetPrimaryDisplay()); | |
673 // Grab (0, 0) of the window. | |
674 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | |
675 window, gfx::Point(), HTCAPTION)); | |
676 ASSERT_TRUE(resizer.get()); | |
677 EXPECT_EQ(1.0, window->layer()->opacity()); | |
678 resizer->Drag(center, 0); | |
679 EXPECT_NE(1.0, window->layer()->opacity()); | |
680 EXPECT_EQ(0, session_delegate->num_transfer_to_desktop_of_user_calls()); | |
681 resizer->CompleteDrag(); | |
682 EXPECT_EQ(1.0, window->layer()->opacity()); | |
683 EXPECT_EQ(1, session_delegate->num_transfer_to_desktop_of_user_calls()); | |
684 EXPECT_EQ(initial_bounds.ToString(), window->bounds().ToString()); | |
685 } | |
686 | |
687 // Drag the window over the icon and cancel the operation. Test that the | |
688 // window's layer gets transparent and reverts back. | |
689 { | |
690 aura::Window* window = window_.get(); | |
691 window->SetBoundsInScreen(initial_bounds, | |
692 Shell::GetScreen()->GetPrimaryDisplay()); | |
693 // Grab (0, 0) of the window. | |
694 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | |
695 window, gfx::Point(), HTCAPTION)); | |
696 ASSERT_TRUE(resizer.get()); | |
697 EXPECT_EQ(1.0, window->layer()->opacity()); | |
698 resizer->Drag(center, 0); | |
699 EXPECT_NE(1.0, window->layer()->opacity()); | |
700 resizer->RevertDrag(); | |
701 EXPECT_EQ(1.0, window->layer()->opacity()); | |
702 EXPECT_EQ(1, session_delegate->num_transfer_to_desktop_of_user_calls()); | |
703 EXPECT_EQ(initial_bounds.ToString(), window->bounds().ToString()); | |
704 } | |
705 | |
706 // Drag the window over the icon and somewhere else and see that it properly | |
707 // reverts its transparency. | |
708 { | |
709 aura::Window* window = window_.get(); | |
710 window->SetBoundsInScreen(initial_bounds, | |
711 Shell::GetScreen()->GetPrimaryDisplay()); | |
712 // Grab (0, 0) of the window. | |
713 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | |
714 window, gfx::Point(), HTCAPTION)); | |
715 ASSERT_TRUE(resizer.get()); | |
716 EXPECT_EQ(1.0, window->layer()->opacity()); | |
717 resizer->Drag(center, 0); | |
718 EXPECT_NE(1.0, window->layer()->opacity()); | |
719 resizer->Drag(gfx::Point(), 0); | |
720 EXPECT_EQ(1.0, window->layer()->opacity()); | |
721 resizer->CompleteDrag(); | |
722 EXPECT_EQ(1, session_delegate->num_transfer_to_desktop_of_user_calls()); | |
723 EXPECT_NE(initial_bounds.ToString(), window->bounds().ToString()); | |
724 } | |
725 } | |
726 #endif | |
727 | |
728 | |
729 } // namespace internal | 635 } // namespace internal |
730 } // namespace ash | 636 } // namespace ash |
OLD | NEW |