Chromium Code Reviews| 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/toplevel_window_event_handler.h" | 5 #include "ash/wm/toplevel_window_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/wm/resize_shadow.h" | 11 #include "ash/wm/resize_shadow.h" |
| 12 #include "ash/wm/resize_shadow_controller.h" | 12 #include "ash/wm/resize_shadow_controller.h" |
| 13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/workspace_controller.h" | 15 #include "ash/wm/workspace_controller.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
| 20 #include "ui/aura/client/capture_client.h" | |
| 20 #include "ui/aura/test/aura_test_base.h" | 21 #include "ui/aura/test/aura_test_base.h" |
| 21 #include "ui/aura/test/test_window_delegate.h" | 22 #include "ui/aura/test/test_window_delegate.h" |
| 22 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
| 23 #include "ui/base/hit_test.h" | 24 #include "ui/base/hit_test.h" |
| 24 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
| 25 #include "ui/events/test/event_generator.h" | 26 #include "ui/events/test/event_generator.h" |
| 26 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
| 27 #include "ui/wm/core/window_util.h" | 28 #include "ui/wm/core/window_util.h" |
| 28 #include "ui/wm/public/window_move_client.h" | 29 #include "ui/wm/public/window_move_client.h" |
| 29 | 30 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 60 ToplevelWindowEventHandlerTest() {} | 61 ToplevelWindowEventHandlerTest() {} |
| 61 ~ToplevelWindowEventHandlerTest() override {} | 62 ~ToplevelWindowEventHandlerTest() override {} |
| 62 | 63 |
| 63 protected: | 64 protected: |
| 64 aura::Window* CreateWindow(int hittest_code) { | 65 aura::Window* CreateWindow(int hittest_code) { |
| 65 TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code); | 66 TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code); |
| 66 aura::Window* w1 = new aura::Window(d1); | 67 aura::Window* w1 = new aura::Window(d1); |
| 67 w1->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 68 w1->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 68 w1->set_id(1); | 69 w1->set_id(1); |
| 69 w1->Init(ui::LAYER_TEXTURED); | 70 w1->Init(ui::LAYER_TEXTURED); |
| 70 aura::Window* parent = Shell::GetContainer( | 71 aura::Window* parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 71 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); | 72 kShellWindowId_DefaultContainer); |
|
oshima
2016/03/15 09:15:04
This is is to use normal dragging path (window in
| |
| 72 parent->AddChild(w1); | 73 parent->AddChild(w1); |
| 73 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); | 74 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 74 w1->Show(); | 75 w1->Show(); |
| 75 return w1; | 76 return w1; |
| 76 } | 77 } |
| 77 | 78 |
| 78 void DragFromCenterBy(aura::Window* window, int dx, int dy) { | 79 void DragFromCenterBy(aura::Window* window, int dx, int dy) { |
| 79 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); | 80 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); |
| 80 generator.DragMouseBy(dx, dy); | 81 generator.DragMouseBy(dx, dy); |
| 81 } | 82 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 102 // Size should not have. | 103 // Size should not have. |
| 103 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 104 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 104 | 105 |
| 105 TouchDragFromCenterBy(w1.get(), 100, 100); | 106 TouchDragFromCenterBy(w1.get(), 100, 100); |
| 106 // Position should have been offset by 100,100. | 107 // Position should have been offset by 100,100. |
| 107 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); | 108 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); |
| 108 // Size should not have. | 109 // Size should not have. |
| 109 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); | 110 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); |
| 110 } | 111 } |
| 111 | 112 |
| 113 namespace { | |
| 114 | |
| 115 class CancelDragObserver : public aura::WindowObserver { | |
| 116 public: | |
| 117 CancelDragObserver() {} | |
| 118 ~CancelDragObserver() override {} | |
| 119 | |
| 120 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override { | |
| 121 aura::client::CaptureClient* client = | |
| 122 aura::client::GetCaptureClient(params.target->GetRootWindow()); | |
| 123 client->SetCapture(nullptr); | |
| 124 } | |
| 125 | |
| 126 private: | |
| 127 DISALLOW_COPY_AND_ASSIGN(CancelDragObserver); | |
| 128 }; | |
| 129 | |
| 130 } // namespace | |
| 131 | |
| 132 // Cancelling drag while starting window drag should not crash. | |
| 133 TEST_F(ToplevelWindowEventHandlerTest, CancelWhileDragStart) { | |
| 134 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); | |
| 135 CancelDragObserver observer; | |
| 136 w1->AddObserver(&observer); | |
| 137 gfx::Point origin = w1->bounds().origin(); | |
| 138 DragFromCenterBy(w1.get(), 100, 100); | |
| 139 EXPECT_EQ(origin, w1->bounds().origin()); | |
| 140 w1->RemoveObserver(&observer); | |
| 141 } | |
| 142 | |
| 112 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) { | 143 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) { |
| 113 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); | 144 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); |
| 114 gfx::Point position = w1->bounds().origin(); | 145 gfx::Point position = w1->bounds().origin(); |
| 115 DragFromCenterBy(w1.get(), 100, 100); | 146 DragFromCenterBy(w1.get(), 100, 100); |
| 116 // Position should not have changed. | 147 // Position should not have changed. |
| 117 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); | 148 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); |
| 118 // Size should have increased by 100,100. | 149 // Size should have increased by 100,100. |
| 119 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); | 150 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); |
| 120 } | 151 } |
| 121 | 152 |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, | 781 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
| 751 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), | 782 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), |
| 752 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); | 783 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); |
| 753 } | 784 } |
| 754 | 785 |
| 755 // Showing the resize shadows when the mouse is over the window edges is tested | 786 // Showing the resize shadows when the mouse is over the window edges is tested |
| 756 // in resize_shadow_and_cursor_test.cc | 787 // in resize_shadow_and_cursor_test.cc |
| 757 | 788 |
| 758 } // namespace test | 789 } // namespace test |
| 759 } // namespace ash | 790 } // namespace ash |
| OLD | NEW |