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

Side by Side Diff: ash/wm/panels/panel_window_resizer_unittest.cc

Issue 12441010: Attach panel while dragging to bring it in front of other panels. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments, etc. Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ash/wm/panels/panel_window_resizer.h" 5 #include "ash/wm/panels/panel_window_resizer.h"
6 6
7 #include "ash/launcher/launcher.h" 7 #include "ash/launcher/launcher.h"
8 #include "ash/root_window_controller.h" 8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_types.h" 9 #include "ash/shelf/shelf_types.h"
10 #include "ash/shelf/shelf_widget.h" 10 #include "ash/shelf/shelf_widget.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/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
14 #include "ash/test/cursor_manager_test_api.h" 14 #include "ash/test/cursor_manager_test_api.h"
15 #include "ash/test/test_launcher_delegate.h" 15 #include "ash/test/test_launcher_delegate.h"
16 #include "ash/wm/panels/panel_layout_manager.h" 16 #include "ash/wm/panels/panel_layout_manager.h"
17 #include "ash/wm/window_properties.h" 17 #include "ash/wm/window_properties.h"
18 #include "ash/wm/window_resizer_owner.h"
18 #include "ui/aura/client/aura_constants.h" 19 #include "ui/aura/client/aura_constants.h"
19 #include "ui/aura/root_window.h" 20 #include "ui/aura/root_window.h"
20 #include "ui/aura/test/test_window_delegate.h" 21 #include "ui/aura/test/test_window_delegate.h"
21 #include "ui/base/hit_test.h" 22 #include "ui/base/hit_test.h"
22 #include "ui/base/ui_base_types.h" 23 #include "ui/base/ui_base_types.h"
23 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
24 25
25 namespace ash { 26 namespace ash {
26 namespace internal { 27 namespace internal {
27 28
28 class PanelWindowResizerTest : public test::AshTestBase { 29 class PanelWindowResizerTest : public test::AshTestBase,
30 public WindowResizerOwner {
29 public: 31 public:
30 PanelWindowResizerTest() : window_(NULL) {} 32 PanelWindowResizerTest() : window_(NULL), resizer_passed_(false) {}
31 virtual ~PanelWindowResizerTest() {} 33 virtual ~PanelWindowResizerTest() {}
32 34
33 virtual void SetUp() OVERRIDE { 35 virtual void SetUp() OVERRIDE {
34 AshTestBase::SetUp(); 36 AshTestBase::SetUp();
35 window_.reset(CreatePanelWindow(gfx::Rect(0, 0, 201, 201))); 37 window_.reset(CreatePanelWindow(gfx::Rect(0, 0, 201, 201)));
36 38
37 panel_layout_manager_ = static_cast<internal::PanelLayoutManager*>( 39 panel_layout_manager_ = static_cast<internal::PanelLayoutManager*>(
38 GetPanelContainer()->layout_manager()); 40 GetPanelContainer()->layout_manager());
39 launcher_bounds_ = panel_layout_manager_->launcher()->shelf_widget()-> 41 launcher_bounds_ = panel_layout_manager_->launcher()->shelf_widget()->
40 GetWindowBoundsInScreen(); 42 GetWindowBoundsInScreen();
41 } 43 }
42 44
43 virtual void TearDown() OVERRIDE { 45 virtual void TearDown() OVERRIDE {
44 window_.reset(); 46 window_.reset();
45 AshTestBase::TearDown(); 47 AshTestBase::TearDown();
46 } 48 }
47 49
50 virtual void PassResizer(WindowResizerOwner* new_owner) {
51 resizer_passed_ = true;
52 }
53
54 virtual void AcceptResizer(WindowResizer* resizer,
55 bool in_gesture_drag) {
56 }
57
48 protected: 58 protected:
49 gfx::Point CalculateDragPoint(const PanelWindowResizer& resizer, 59 gfx::Point CalculateDragPoint(const PanelWindowResizer& resizer,
50 int delta_x, 60 int delta_x,
51 int delta_y) const { 61 int delta_y) const {
52 gfx::Point location = resizer.GetInitialLocationInParentForTest(); 62 gfx::Point location = resizer.GetInitialLocationInParentForTest();
53 location.set_x(location.x() + delta_x); 63 location.set_x(location.x() + delta_x);
54 location.set_y(location.y() + delta_y); 64 location.set_y(location.y() + delta_y);
55 return location; 65 return location;
56 } 66 }
57 67
(...skipping 12 matching lines...) Expand all
70 return window; 80 return window;
71 } 81 }
72 82
73 aura::Window* GetPanelContainer() { 83 aura::Window* GetPanelContainer() {
74 return Shell::GetContainer( 84 return Shell::GetContainer(
75 Shell::GetPrimaryRootWindow(), 85 Shell::GetPrimaryRootWindow(),
76 internal::kShellWindowId_PanelContainer); 86 internal::kShellWindowId_PanelContainer);
77 } 87 }
78 88
79 static PanelWindowResizer* CreatePanelWindowResizer( 89 static PanelWindowResizer* CreatePanelWindowResizer(
90 WindowResizerOwner* owner,
80 aura::Window* window, 91 aura::Window* window,
81 const gfx::Point& point_in_parent, 92 const gfx::Point& point_in_parent,
82 int window_component) { 93 int window_component) {
83 return static_cast<PanelWindowResizer*>(CreateWindowResizer( 94 return static_cast<PanelWindowResizer*>(CreateWindowResizer(
84 window, point_in_parent, window_component).release()); 95 owner, window, point_in_parent, window_component).release());
85 } 96 }
86 97
87 void DragStart() { 98 void DragStart() {
88 resizer_.reset(CreatePanelWindowResizer(window_.get(), gfx::Point(), 99 resizer_passed_ = false;
100 resizer_.reset(CreatePanelWindowResizer(this, window_.get(), gfx::Point(),
89 HTCAPTION)); 101 HTCAPTION));
90 ASSERT_TRUE(resizer_.get()); 102 ASSERT_TRUE(resizer_.get());
91 } 103 }
92 104
93 void DragMove(int dx, int dy) { 105 void DragMove(int dx, int dy) {
94 resizer_->Drag(CalculateDragPoint(*resizer_, dx, dy), 0); 106 resizer_->Drag(CalculateDragPoint(*resizer_, dx, dy), 0);
95 } 107 }
96 108
97 void DragEnd() { 109 void DragEnd() {
98 resizer_->CompleteDrag(0); 110 resizer_->CompleteDrag(0);
99 resizer_.reset(); 111 resizer_.reset();
100 } 112 }
101 113
102 // Test dragging the panel slightly, then detaching, and then reattaching 114 // Test dragging the panel slightly, then detaching, and then reattaching
103 // dragging out by the vector (dx, dy). 115 // dragging out by the vector (dx, dy).
104 void DetachReattachTest(int dx, int dy) { 116 void DetachReattachTest(int dx, int dy) {
105 EXPECT_TRUE(window_->GetProperty(kPanelAttachedKey)); 117 EXPECT_TRUE(window_->GetProperty(kPanelAttachedKey));
118 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window_->parent()->id());
106 DragStart(); 119 DragStart();
107 gfx::Rect initial_bounds = window_->bounds(); 120 gfx::Rect initial_bounds = window_->bounds();
108 121
109 // Drag the panel slightly. The window should still be snapped to the 122 // Drag the panel slightly. The window should still be snapped to the
110 // launcher. 123 // launcher.
111 DragMove(dx * 5, dy * 5); 124 DragMove(dx * 5, dy * 5);
112 EXPECT_EQ(initial_bounds.x(), window_->bounds().x()); 125 EXPECT_EQ(initial_bounds.x(), window_->bounds().x());
113 EXPECT_EQ(initial_bounds.y(), window_->bounds().y()); 126 EXPECT_EQ(initial_bounds.y(), window_->bounds().y());
114 127
115 // Drag further out and the window should now move to the cursor. 128 // Drag further out and the window should now move to the cursor.
116 DragMove(dx * 100, dy * 100); 129 DragMove(dx * 100, dy * 100);
117 EXPECT_EQ(initial_bounds.x() + dx * 100, window_->bounds().x()); 130 EXPECT_EQ(initial_bounds.x() + dx * 100, window_->bounds().x());
118 EXPECT_EQ(initial_bounds.y() + dy * 100, window_->bounds().y()); 131 EXPECT_EQ(initial_bounds.y() + dy * 100, window_->bounds().y());
119 132
120 // The panel should be detached when the drag completes. 133 // The panel should be detached when the drag completes.
121 DragEnd(); 134 DragEnd();
122 EXPECT_FALSE(window_->GetProperty(kPanelAttachedKey)); 135 EXPECT_FALSE(window_->GetProperty(kPanelAttachedKey));
136 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer,
137 window_->parent()->id());
123 138
124 DragStart(); 139 DragStart();
125 // Drag the panel down. 140 // Drag the panel down.
126 DragMove(dx * -95, dy * -95); 141 DragMove(dx * -95, dy * -95);
127 // Release the mouse and the panel should be reattached. 142 // Release the mouse and the panel should be reattached.
128 DragEnd(); 143 DragEnd();
129 144
130 // The panel should be reattached and have snapped to the launcher. 145 // The panel should be reattached and have snapped to the launcher.
131 EXPECT_TRUE(window_->GetProperty(kPanelAttachedKey)); 146 EXPECT_TRUE(window_->GetProperty(kPanelAttachedKey));
132 EXPECT_EQ(initial_bounds.x(), window_->bounds().x()); 147 EXPECT_EQ(initial_bounds.x(), window_->bounds().x());
133 EXPECT_EQ(initial_bounds.y(), window_->bounds().y()); 148 EXPECT_EQ(initial_bounds.y(), window_->bounds().y());
149 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window_->parent()->id());
134 } 150 }
135 151
136 aura::test::TestWindowDelegate delegate_; 152 aura::test::TestWindowDelegate delegate_;
137 scoped_ptr<aura::Window> window_; 153 scoped_ptr<aura::Window> window_;
138 scoped_ptr<PanelWindowResizer> resizer_; 154 scoped_ptr<PanelWindowResizer> resizer_;
139 aura::Window* panel_container_; 155 aura::Window* panel_container_;
140 internal::PanelLayoutManager* panel_layout_manager_; 156 internal::PanelLayoutManager* panel_layout_manager_;
141 gfx::Rect launcher_bounds_; 157 gfx::Rect launcher_bounds_;
158 bool resizer_passed_;
142 159
143 private: 160 private:
144 DISALLOW_COPY_AND_ASSIGN(PanelWindowResizerTest); 161 DISALLOW_COPY_AND_ASSIGN(PanelWindowResizerTest);
145 }; 162 };
146 163
147 // Verifies a window can be dragged from the panel and detached and then 164 // Verifies a window can be dragged from the panel and detached and then
148 // reattached. 165 // reattached.
149 TEST_F(PanelWindowResizerTest, PanelDetachReattachBottom) { 166 TEST_F(PanelWindowResizerTest, PanelDetachReattachBottom) {
150 DetachReattachTest(0, -1); 167 DetachReattachTest(0, -1);
151 } 168 }
(...skipping 18 matching lines...) Expand all
170 shell->GetPrimaryRootWindow()); 187 shell->GetPrimaryRootWindow());
171 DetachReattachTest(-1, 0); 188 DetachReattachTest(-1, 0);
172 } 189 }
173 190
174 TEST_F(PanelWindowResizerTest, PanelDetachReattachTop) { 191 TEST_F(PanelWindowResizerTest, PanelDetachReattachTop) {
175 ash::Shell* shell = ash::Shell::GetInstance(); 192 ash::Shell* shell = ash::Shell::GetInstance();
176 shell->SetShelfAlignment(SHELF_ALIGNMENT_TOP, shell->GetPrimaryRootWindow()); 193 shell->SetShelfAlignment(SHELF_ALIGNMENT_TOP, shell->GetPrimaryRootWindow());
177 DetachReattachTest(0, 1); 194 DetachReattachTest(0, 1);
178 } 195 }
179 196
197 TEST_F(PanelWindowResizerTest, DragMovesToPanelLayer) {
198 DragStart();
199 DragMove(0, -100);
200 DragEnd();
201 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer,
202 window_->parent()->id());
203
204 // While moving the panel window should be moved to the panel container.
205 DragStart();
206 DragMove(20, 0);
207 EXPECT_EQ(internal::kShellWindowId_PanelContainer, window_->parent()->id());
208 EXPECT_TRUE(resizer_passed_);
209 DragEnd();
210
211 // When dropped it should return to the default container.
212 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer,
213 window_->parent()->id());
214 }
215
180 } // namespace internal 216 } // namespace internal
181 } // namespace ash 217 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698