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

Side by Side Diff: ash/wm/toplevel_window_event_handler_unittest.cc

Issue 10916221: Make ToplevelWindowEventFilter and WorkspaceEventFilter into event handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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) 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_filter.h" 5 #include "ash/wm/toplevel_window_event_handler.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
10 #include "ash/wm/workspace/snap_sizer.h" 10 #include "ash/wm/workspace/snap_sizer.h"
11 #include "ash/wm/workspace_controller.h" 11 #include "ash/wm/workspace_controller.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 virtual void OnWindowDestroyed() OVERRIDE { 57 virtual void OnWindowDestroyed() OVERRIDE {
58 delete this; 58 delete this;
59 } 59 }
60 60
61 int hittest_code_; 61 int hittest_code_;
62 gfx::Size min_size_; 62 gfx::Size min_size_;
63 63
64 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); 64 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
65 }; 65 };
66 66
67 class ToplevelWindowEventFilterTest : public AshTestBase { 67 class ToplevelWindowEventHandlerTest : public AshTestBase {
68 public: 68 public:
69 ToplevelWindowEventFilterTest() : filter_(NULL), parent_(NULL) {} 69 ToplevelWindowEventHandlerTest() : handler_(NULL), parent_(NULL) {}
70 virtual ~ToplevelWindowEventFilterTest() {} 70 virtual ~ToplevelWindowEventHandlerTest() {}
71 71
72 virtual void SetUp() OVERRIDE { 72 virtual void SetUp() OVERRIDE {
73 AshTestBase::SetUp(); 73 AshTestBase::SetUp();
74 parent_ = new aura::Window(NULL); 74 parent_ = new aura::Window(NULL);
75 parent_->Init(ui::LAYER_NOT_DRAWN); 75 parent_->Init(ui::LAYER_NOT_DRAWN);
76 parent_->Show(); 76 parent_->Show();
77 Shell::GetPrimaryRootWindow()->AddChild(parent_); 77 Shell::GetPrimaryRootWindow()->AddChild(parent_);
78 parent_->SetBounds(Shell::GetPrimaryRootWindow()->bounds()); 78 parent_->SetBounds(Shell::GetPrimaryRootWindow()->bounds());
79 filter_ = new ToplevelWindowEventFilter(parent_); 79 handler_ = new ToplevelWindowEventHandler(parent_);
80 parent_->SetEventFilter(filter_); 80 parent_->AddPreTargetHandler(handler_);
81 } 81 }
82 82
83 virtual void TearDown() OVERRIDE { 83 virtual void TearDown() OVERRIDE {
84 filter_ = NULL; 84 handler_ = NULL;
85 parent_ = NULL; 85 parent_ = NULL;
86 AshTestBase::TearDown(); 86 AshTestBase::TearDown();
87 } 87 }
88 88
89 protected: 89 protected:
90 aura::Window* CreateWindow(int hittest_code) { 90 aura::Window* CreateWindow(int hittest_code) {
91 TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code); 91 TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code);
92 aura::Window* w1 = new aura::Window(d1); 92 aura::Window* w1 = new aura::Window(d1);
93 w1->set_id(1); 93 w1->set_id(1);
94 w1->Init(ui::LAYER_TEXTURED); 94 w1->Init(ui::LAYER_TEXTURED);
95 w1->SetParent(parent_); 95 w1->SetParent(parent_);
96 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); 96 w1->SetBounds(gfx::Rect(0, 0, 100, 100));
97 w1->Show(); 97 w1->Show();
98 return w1; 98 return w1;
99 } 99 }
100 100
101 void DragFromCenterBy(aura::Window* window, int dx, int dy) { 101 void DragFromCenterBy(aura::Window* window, int dx, int dy) {
102 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); 102 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window);
103 generator.DragMouseBy(dx, dy); 103 generator.DragMouseBy(dx, dy);
104 } 104 }
105 105
106 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { 106 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) {
107 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); 107 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window);
108 generator.PressMoveAndReleaseTouchBy(dx, dy); 108 generator.PressMoveAndReleaseTouchBy(dx, dy);
109 } 109 }
110 110
111 ToplevelWindowEventFilter* filter_; 111 ToplevelWindowEventHandler* handler_;
112 112
113 private: 113 private:
114 // Window |filter_| is installed on. Owned by RootWindow. 114 // Window |handler_| is installed on. Owned by RootWindow.
115 aura::Window* parent_; 115 aura::Window* parent_;
116 116
117 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventFilterTest); 117 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest);
118 }; 118 };
119 119
120 } 120 }
121 121
122 TEST_F(ToplevelWindowEventFilterTest, Caption) { 122 TEST_F(ToplevelWindowEventHandlerTest, Caption) {
123 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); 123 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION));
124 gfx::Size size = w1->bounds().size(); 124 gfx::Size size = w1->bounds().size();
125 DragFromCenterBy(w1.get(), 100, 100); 125 DragFromCenterBy(w1.get(), 100, 100);
126 // Position should have been offset by 100,100. 126 // Position should have been offset by 100,100.
127 EXPECT_EQ("100,100", w1->bounds().origin().ToString()); 127 EXPECT_EQ("100,100", w1->bounds().origin().ToString());
128 // Size should not have. 128 // Size should not have.
129 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); 129 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString());
130 130
131 TouchDragFromCenterBy(w1.get(), 100, 100); 131 TouchDragFromCenterBy(w1.get(), 100, 100);
132 // Position should have been offset by 100,100. 132 // Position should have been offset by 100,100.
133 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); 133 EXPECT_EQ("200,200", w1->bounds().origin().ToString());
134 // Size should not have. 134 // Size should not have.
135 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); 135 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString());
136 } 136 }
137 137
138 TEST_F(ToplevelWindowEventFilterTest, BottomRight) { 138 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) {
139 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); 139 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT));
140 gfx::Point position = w1->bounds().origin(); 140 gfx::Point position = w1->bounds().origin();
141 DragFromCenterBy(w1.get(), 100, 100); 141 DragFromCenterBy(w1.get(), 100, 100);
142 // Position should not have changed. 142 // Position should not have changed.
143 EXPECT_EQ(position, w1->bounds().origin()); 143 EXPECT_EQ(position, w1->bounds().origin());
144 // Size should have increased by 100,100. 144 // Size should have increased by 100,100.
145 EXPECT_EQ(gfx::Size(200, 200), w1->bounds().size()); 145 EXPECT_EQ(gfx::Size(200, 200), w1->bounds().size());
146 } 146 }
147 147
148 TEST_F(ToplevelWindowEventFilterTest, GrowBox) { 148 TEST_F(ToplevelWindowEventHandlerTest, GrowBox) {
149 scoped_ptr<aura::Window> w1(CreateWindow(HTGROWBOX)); 149 scoped_ptr<aura::Window> w1(CreateWindow(HTGROWBOX));
150 TestWindowDelegate* window_delegate = 150 TestWindowDelegate* window_delegate =
151 static_cast<TestWindowDelegate*>(w1->delegate()); 151 static_cast<TestWindowDelegate*>(w1->delegate());
152 window_delegate->set_min_size(gfx::Size(40, 40)); 152 window_delegate->set_min_size(gfx::Size(40, 40));
153 153
154 gfx::Point position = w1->bounds().origin(); 154 gfx::Point position = w1->bounds().origin();
155 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 155 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
156 generator.MoveMouseToCenterOf(w1.get()); 156 generator.MoveMouseToCenterOf(w1.get());
157 generator.DragMouseBy(100, 100); 157 generator.DragMouseBy(100, 100);
158 // Position should not have changed. 158 // Position should not have changed.
159 EXPECT_EQ(position, w1->bounds().origin()); 159 EXPECT_EQ(position, w1->bounds().origin());
160 // Size should have increased by 100,100. 160 // Size should have increased by 100,100.
161 EXPECT_EQ(gfx::Size(200, 200), w1->bounds().size()); 161 EXPECT_EQ(gfx::Size(200, 200), w1->bounds().size());
162 162
163 // Shrink the wnidow by (-100, -100). 163 // Shrink the wnidow by (-100, -100).
164 generator.DragMouseBy(-100, -100); 164 generator.DragMouseBy(-100, -100);
165 // Position should not have changed. 165 // Position should not have changed.
166 EXPECT_EQ(position, w1->bounds().origin()); 166 EXPECT_EQ(position, w1->bounds().origin());
167 // Size should have decreased by 100,100. 167 // Size should have decreased by 100,100.
168 EXPECT_EQ(gfx::Size(100, 100), w1->bounds().size()); 168 EXPECT_EQ(gfx::Size(100, 100), w1->bounds().size());
169 169
170 // Enforce minimum size. 170 // Enforce minimum size.
171 generator.DragMouseBy(-60, -60); 171 generator.DragMouseBy(-60, -60);
172 EXPECT_EQ(position, w1->bounds().origin()); 172 EXPECT_EQ(position, w1->bounds().origin());
173 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); 173 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size());
174 } 174 }
175 175
176 TEST_F(ToplevelWindowEventFilterTest, Right) { 176 TEST_F(ToplevelWindowEventHandlerTest, Right) {
177 scoped_ptr<aura::Window> w1(CreateWindow(HTRIGHT)); 177 scoped_ptr<aura::Window> w1(CreateWindow(HTRIGHT));
178 gfx::Point position = w1->bounds().origin(); 178 gfx::Point position = w1->bounds().origin();
179 DragFromCenterBy(w1.get(), 100, 100); 179 DragFromCenterBy(w1.get(), 100, 100);
180 // Position should not have changed. 180 // Position should not have changed.
181 EXPECT_EQ(position, w1->bounds().origin()); 181 EXPECT_EQ(position, w1->bounds().origin());
182 // Size should have increased by 100,0. 182 // Size should have increased by 100,0.
183 EXPECT_EQ(gfx::Size(200, 100), w1->bounds().size()); 183 EXPECT_EQ(gfx::Size(200, 100), w1->bounds().size());
184 } 184 }
185 185
186 TEST_F(ToplevelWindowEventFilterTest, Bottom) { 186 TEST_F(ToplevelWindowEventHandlerTest, Bottom) {
187 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOM)); 187 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOM));
188 gfx::Point position = w1->bounds().origin(); 188 gfx::Point position = w1->bounds().origin();
189 DragFromCenterBy(w1.get(), 100, 100); 189 DragFromCenterBy(w1.get(), 100, 100);
190 // Position should not have changed. 190 // Position should not have changed.
191 EXPECT_EQ(position, w1->bounds().origin()); 191 EXPECT_EQ(position, w1->bounds().origin());
192 // Size should have increased by 0,100. 192 // Size should have increased by 0,100.
193 EXPECT_EQ(gfx::Size(100, 200), w1->bounds().size()); 193 EXPECT_EQ(gfx::Size(100, 200), w1->bounds().size());
194 } 194 }
195 195
196 TEST_F(ToplevelWindowEventFilterTest, TopRight) { 196 TEST_F(ToplevelWindowEventHandlerTest, TopRight) {
197 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT)); 197 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT));
198 DragFromCenterBy(w1.get(), -50, 50); 198 DragFromCenterBy(w1.get(), -50, 50);
199 // Position should have been offset by 0,50. 199 // Position should have been offset by 0,50.
200 EXPECT_EQ(gfx::Point(0, 50), w1->bounds().origin()); 200 EXPECT_EQ(gfx::Point(0, 50), w1->bounds().origin());
201 // Size should have decreased by 50,50. 201 // Size should have decreased by 50,50.
202 EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size()); 202 EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size());
203 } 203 }
204 204
205 TEST_F(ToplevelWindowEventFilterTest, Top) { 205 TEST_F(ToplevelWindowEventHandlerTest, Top) {
206 scoped_ptr<aura::Window> w1(CreateWindow(HTTOP)); 206 scoped_ptr<aura::Window> w1(CreateWindow(HTTOP));
207 DragFromCenterBy(w1.get(), 50, 50); 207 DragFromCenterBy(w1.get(), 50, 50);
208 // Position should have been offset by 0,50. 208 // Position should have been offset by 0,50.
209 EXPECT_EQ(gfx::Point(0, 50), w1->bounds().origin()); 209 EXPECT_EQ(gfx::Point(0, 50), w1->bounds().origin());
210 // Size should have decreased by 0,50. 210 // Size should have decreased by 0,50.
211 EXPECT_EQ(gfx::Size(100, 50), w1->bounds().size()); 211 EXPECT_EQ(gfx::Size(100, 50), w1->bounds().size());
212 } 212 }
213 213
214 TEST_F(ToplevelWindowEventFilterTest, Left) { 214 TEST_F(ToplevelWindowEventHandlerTest, Left) {
215 scoped_ptr<aura::Window> w1(CreateWindow(HTLEFT)); 215 scoped_ptr<aura::Window> w1(CreateWindow(HTLEFT));
216 DragFromCenterBy(w1.get(), 50, 50); 216 DragFromCenterBy(w1.get(), 50, 50);
217 // Position should have been offset by 50,0. 217 // Position should have been offset by 50,0.
218 EXPECT_EQ(gfx::Point(50, 0), w1->bounds().origin()); 218 EXPECT_EQ(gfx::Point(50, 0), w1->bounds().origin());
219 // Size should have decreased by 50,0. 219 // Size should have decreased by 50,0.
220 EXPECT_EQ(gfx::Size(50, 100), w1->bounds().size()); 220 EXPECT_EQ(gfx::Size(50, 100), w1->bounds().size());
221 } 221 }
222 222
223 TEST_F(ToplevelWindowEventFilterTest, BottomLeft) { 223 TEST_F(ToplevelWindowEventHandlerTest, BottomLeft) {
224 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT)); 224 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT));
225 DragFromCenterBy(w1.get(), 50, -50); 225 DragFromCenterBy(w1.get(), 50, -50);
226 // Position should have been offset by 50,0. 226 // Position should have been offset by 50,0.
227 EXPECT_EQ(gfx::Point(50, 0), w1->bounds().origin()); 227 EXPECT_EQ(gfx::Point(50, 0), w1->bounds().origin());
228 // Size should have decreased by 50,50. 228 // Size should have decreased by 50,50.
229 EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size()); 229 EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size());
230 } 230 }
231 231
232 TEST_F(ToplevelWindowEventFilterTest, TopLeft) { 232 TEST_F(ToplevelWindowEventHandlerTest, TopLeft) {
233 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT)); 233 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT));
234 DragFromCenterBy(w1.get(), 50, 50); 234 DragFromCenterBy(w1.get(), 50, 50);
235 // Position should have been offset by 50,50. 235 // Position should have been offset by 50,50.
236 EXPECT_EQ(gfx::Point(50, 50), w1->bounds().origin()); 236 EXPECT_EQ(gfx::Point(50, 50), w1->bounds().origin());
237 // Size should have decreased by 50,50. 237 // Size should have decreased by 50,50.
238 EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size()); 238 EXPECT_EQ(gfx::Size(50, 50), w1->bounds().size());
239 } 239 }
240 240
241 TEST_F(ToplevelWindowEventFilterTest, Client) { 241 TEST_F(ToplevelWindowEventHandlerTest, Client) {
242 scoped_ptr<aura::Window> w1(CreateWindow(HTCLIENT)); 242 scoped_ptr<aura::Window> w1(CreateWindow(HTCLIENT));
243 gfx::Rect bounds = w1->bounds(); 243 gfx::Rect bounds = w1->bounds();
244 DragFromCenterBy(w1.get(), 100, 100); 244 DragFromCenterBy(w1.get(), 100, 100);
245 // Neither position nor size should have changed. 245 // Neither position nor size should have changed.
246 EXPECT_EQ(bounds, w1->bounds()); 246 EXPECT_EQ(bounds, w1->bounds());
247 } 247 }
248 248
249 TEST_F(ToplevelWindowEventFilterTest, LeftPastMinimum) { 249 TEST_F(ToplevelWindowEventHandlerTest, LeftPastMinimum) {
250 scoped_ptr<aura::Window> w1(CreateWindow(HTLEFT)); 250 scoped_ptr<aura::Window> w1(CreateWindow(HTLEFT));
251 TestWindowDelegate* window_delegate = 251 TestWindowDelegate* window_delegate =
252 static_cast<TestWindowDelegate*>(w1->delegate()); 252 static_cast<TestWindowDelegate*>(w1->delegate());
253 window_delegate->set_min_size(gfx::Size(40, 40)); 253 window_delegate->set_min_size(gfx::Size(40, 40));
254 254
255 // Simulate a large left-to-right drag. Window width should be clamped to 255 // Simulate a large left-to-right drag. Window width should be clamped to
256 // minimum and position change should be limited as well. 256 // minimum and position change should be limited as well.
257 DragFromCenterBy(w1.get(), 333, 0); 257 DragFromCenterBy(w1.get(), 333, 0);
258 EXPECT_EQ(gfx::Point(60, 0), w1->bounds().origin()); 258 EXPECT_EQ(gfx::Point(60, 0), w1->bounds().origin());
259 EXPECT_EQ(gfx::Size(40, 100), w1->bounds().size()); 259 EXPECT_EQ(gfx::Size(40, 100), w1->bounds().size());
260 } 260 }
261 261
262 TEST_F(ToplevelWindowEventFilterTest, RightPastMinimum) { 262 TEST_F(ToplevelWindowEventHandlerTest, RightPastMinimum) {
263 scoped_ptr<aura::Window> w1(CreateWindow(HTRIGHT)); 263 scoped_ptr<aura::Window> w1(CreateWindow(HTRIGHT));
264 TestWindowDelegate* window_delegate = 264 TestWindowDelegate* window_delegate =
265 static_cast<TestWindowDelegate*>(w1->delegate()); 265 static_cast<TestWindowDelegate*>(w1->delegate());
266 window_delegate->set_min_size(gfx::Size(40, 40)); 266 window_delegate->set_min_size(gfx::Size(40, 40));
267 gfx::Point position = w1->bounds().origin(); 267 gfx::Point position = w1->bounds().origin();
268 268
269 // Simulate a large right-to-left drag. Window width should be clamped to 269 // Simulate a large right-to-left drag. Window width should be clamped to
270 // minimum and position should not change. 270 // minimum and position should not change.
271 DragFromCenterBy(w1.get(), -333, 0); 271 DragFromCenterBy(w1.get(), -333, 0);
272 EXPECT_EQ(position, w1->bounds().origin()); 272 EXPECT_EQ(position, w1->bounds().origin());
273 EXPECT_EQ(gfx::Size(40, 100), w1->bounds().size()); 273 EXPECT_EQ(gfx::Size(40, 100), w1->bounds().size());
274 } 274 }
275 275
276 TEST_F(ToplevelWindowEventFilterTest, TopLeftPastMinimum) { 276 TEST_F(ToplevelWindowEventHandlerTest, TopLeftPastMinimum) {
277 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT)); 277 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPLEFT));
278 TestWindowDelegate* window_delegate = 278 TestWindowDelegate* window_delegate =
279 static_cast<TestWindowDelegate*>(w1->delegate()); 279 static_cast<TestWindowDelegate*>(w1->delegate());
280 window_delegate->set_min_size(gfx::Size(40, 40)); 280 window_delegate->set_min_size(gfx::Size(40, 40));
281 281
282 // Simulate a large top-left to bottom-right drag. Window width should be 282 // Simulate a large top-left to bottom-right drag. Window width should be
283 // clamped to minimum and position should be limited. 283 // clamped to minimum and position should be limited.
284 DragFromCenterBy(w1.get(), 333, 444); 284 DragFromCenterBy(w1.get(), 333, 444);
285 EXPECT_EQ(gfx::Point(60, 60), w1->bounds().origin()); 285 EXPECT_EQ(gfx::Point(60, 60), w1->bounds().origin());
286 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); 286 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size());
287 } 287 }
288 288
289 TEST_F(ToplevelWindowEventFilterTest, TopRightPastMinimum) { 289 TEST_F(ToplevelWindowEventHandlerTest, TopRightPastMinimum) {
290 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT)); 290 scoped_ptr<aura::Window> w1(CreateWindow(HTTOPRIGHT));
291 TestWindowDelegate* window_delegate = 291 TestWindowDelegate* window_delegate =
292 static_cast<TestWindowDelegate*>(w1->delegate()); 292 static_cast<TestWindowDelegate*>(w1->delegate());
293 window_delegate->set_min_size(gfx::Size(40, 40)); 293 window_delegate->set_min_size(gfx::Size(40, 40));
294 294
295 // Simulate a large top-right to bottom-left drag. Window size should be 295 // Simulate a large top-right to bottom-left drag. Window size should be
296 // clamped to minimum, x position should not change, and y position should 296 // clamped to minimum, x position should not change, and y position should
297 // be clamped. 297 // be clamped.
298 DragFromCenterBy(w1.get(), -333, 444); 298 DragFromCenterBy(w1.get(), -333, 444);
299 EXPECT_EQ(gfx::Point(0, 60), w1->bounds().origin()); 299 EXPECT_EQ(gfx::Point(0, 60), w1->bounds().origin());
300 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); 300 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size());
301 } 301 }
302 302
303 TEST_F(ToplevelWindowEventFilterTest, BottomLeftPastMinimum) { 303 TEST_F(ToplevelWindowEventHandlerTest, BottomLeftPastMinimum) {
304 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT)); 304 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMLEFT));
305 TestWindowDelegate* window_delegate = 305 TestWindowDelegate* window_delegate =
306 static_cast<TestWindowDelegate*>(w1->delegate()); 306 static_cast<TestWindowDelegate*>(w1->delegate());
307 window_delegate->set_min_size(gfx::Size(40, 40)); 307 window_delegate->set_min_size(gfx::Size(40, 40));
308 308
309 // Simulate a large bottom-left to top-right drag. Window size should be 309 // Simulate a large bottom-left to top-right drag. Window size should be
310 // clamped to minimum, x position should be clamped, and y position should 310 // clamped to minimum, x position should be clamped, and y position should
311 // not change. 311 // not change.
312 DragFromCenterBy(w1.get(), 333, -444); 312 DragFromCenterBy(w1.get(), 333, -444);
313 EXPECT_EQ(gfx::Point(60, 0), w1->bounds().origin()); 313 EXPECT_EQ(gfx::Point(60, 0), w1->bounds().origin());
314 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); 314 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size());
315 } 315 }
316 316
317 TEST_F(ToplevelWindowEventFilterTest, BottomRightPastMinimum) { 317 TEST_F(ToplevelWindowEventHandlerTest, BottomRightPastMinimum) {
318 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); 318 scoped_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT));
319 TestWindowDelegate* window_delegate = 319 TestWindowDelegate* window_delegate =
320 static_cast<TestWindowDelegate*>(w1->delegate()); 320 static_cast<TestWindowDelegate*>(w1->delegate());
321 window_delegate->set_min_size(gfx::Size(40, 40)); 321 window_delegate->set_min_size(gfx::Size(40, 40));
322 gfx::Point position = w1->bounds().origin(); 322 gfx::Point position = w1->bounds().origin();
323 323
324 // Simulate a large bottom-right to top-left drag. Window size should be 324 // Simulate a large bottom-right to top-left drag. Window size should be
325 // clamped to minimum and position should not change. 325 // clamped to minimum and position should not change.
326 DragFromCenterBy(w1.get(), -333, -444); 326 DragFromCenterBy(w1.get(), -333, -444);
327 EXPECT_EQ(position, w1->bounds().origin()); 327 EXPECT_EQ(position, w1->bounds().origin());
328 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size()); 328 EXPECT_EQ(gfx::Size(40, 40), w1->bounds().size());
329 } 329 }
330 330
331 TEST_F(ToplevelWindowEventFilterTest, BottomRightWorkArea) { 331 TEST_F(ToplevelWindowEventHandlerTest, BottomRightWorkArea) {
332 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); 332 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT));
333 gfx::Rect work_area = 333 gfx::Rect work_area =
334 gfx::Screen::GetDisplayNearestWindow(target.get()).work_area(); 334 gfx::Screen::GetDisplayNearestWindow(target.get()).work_area();
335 gfx::Point position = target->bounds().origin(); 335 gfx::Point position = target->bounds().origin();
336 // Drag further than work_area bottom. 336 // Drag further than work_area bottom.
337 DragFromCenterBy(target.get(), 100, work_area.height()); 337 DragFromCenterBy(target.get(), 100, work_area.height());
338 // Position should not have changed. 338 // Position should not have changed.
339 EXPECT_EQ(position, target->bounds().origin()); 339 EXPECT_EQ(position, target->bounds().origin());
340 // Size should have increased by 100, work_area.height() - target->bounds.y() 340 // Size should have increased by 100, work_area.height() - target->bounds.y()
341 EXPECT_EQ(gfx::Size(200, work_area.height() - target->bounds().y()), 341 EXPECT_EQ(gfx::Size(200, work_area.height() - target->bounds().y()),
342 target->bounds().size()); 342 target->bounds().size());
343 } 343 }
344 344
345 TEST_F(ToplevelWindowEventFilterTest, BottomLeftWorkArea) { 345 TEST_F(ToplevelWindowEventHandlerTest, BottomLeftWorkArea) {
346 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMLEFT)); 346 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMLEFT));
347 gfx::Rect work_area = 347 gfx::Rect work_area =
348 gfx::Screen::GetDisplayNearestWindow(target.get()).work_area(); 348 gfx::Screen::GetDisplayNearestWindow(target.get()).work_area();
349 gfx::Point position = target->bounds().origin(); 349 gfx::Point position = target->bounds().origin();
350 // Drag further than work_area bottom. 350 // Drag further than work_area bottom.
351 DragFromCenterBy(target.get(), -30, work_area.height()); 351 DragFromCenterBy(target.get(), -30, work_area.height());
352 // origin is now at 70, 100. 352 // origin is now at 70, 100.
353 EXPECT_EQ(position.x() - 30, target->bounds().x()); 353 EXPECT_EQ(position.x() - 30, target->bounds().x());
354 EXPECT_EQ(position.y(), target->bounds().y()); 354 EXPECT_EQ(position.y(), target->bounds().y());
355 // Size should have increased by 30, work_area.height() - target->bounds.y() 355 // Size should have increased by 30, work_area.height() - target->bounds.y()
356 EXPECT_EQ(gfx::Size(130, work_area.height() - target->bounds().y()), 356 EXPECT_EQ(gfx::Size(130, work_area.height() - target->bounds().y()),
357 target->bounds().size()); 357 target->bounds().size());
358 } 358 }
359 359
360 TEST_F(ToplevelWindowEventFilterTest, BottomWorkArea) { 360 TEST_F(ToplevelWindowEventHandlerTest, BottomWorkArea) {
361 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOM)); 361 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOM));
362 gfx::Rect work_area = 362 gfx::Rect work_area =
363 gfx::Screen::GetDisplayNearestWindow(target.get()).work_area(); 363 gfx::Screen::GetDisplayNearestWindow(target.get()).work_area();
364 gfx::Point position = target->bounds().origin(); 364 gfx::Point position = target->bounds().origin();
365 // Drag further than work_area bottom. 365 // Drag further than work_area bottom.
366 DragFromCenterBy(target.get(), 0, work_area.height()); 366 DragFromCenterBy(target.get(), 0, work_area.height());
367 // Position should not have changed. 367 // Position should not have changed.
368 EXPECT_EQ(position, target->bounds().origin()); 368 EXPECT_EQ(position, target->bounds().origin());
369 // Size should have increased by 0, work_area.height() - target->bounds.y() 369 // Size should have increased by 0, work_area.height() - target->bounds.y()
370 EXPECT_EQ(gfx::Size(100, work_area.height() - target->bounds().y()), 370 EXPECT_EQ(gfx::Size(100, work_area.height() - target->bounds().y()),
371 target->bounds().size()); 371 target->bounds().size());
372 } 372 }
373 373
374 // Verifies we don't let windows drag to a -y location. 374 // Verifies we don't let windows drag to a -y location.
375 TEST_F(ToplevelWindowEventFilterTest, DontDragToNegativeY) { 375 TEST_F(ToplevelWindowEventHandlerTest, DontDragToNegativeY) {
376 scoped_ptr<aura::Window> target(CreateWindow(HTTOP)); 376 scoped_ptr<aura::Window> target(CreateWindow(HTTOP));
377 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 377 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
378 target.get()); 378 target.get());
379 generator.MoveMouseTo(0, 5); 379 generator.MoveMouseTo(0, 5);
380 generator.DragMouseBy(0, -5); 380 generator.DragMouseBy(0, -5);
381 // The y location and height should not have changed. 381 // The y location and height should not have changed.
382 EXPECT_EQ(0, target->bounds().y()); 382 EXPECT_EQ(0, target->bounds().y());
383 EXPECT_EQ(100, target->bounds().height()); 383 EXPECT_EQ(100, target->bounds().height());
384 } 384 }
385 385
386 // Verifies we don't let windows go bigger than the display width. 386 // Verifies we don't let windows go bigger than the display width.
387 TEST_F(ToplevelWindowEventFilterTest, DontGotWiderThanScreen) { 387 TEST_F(ToplevelWindowEventHandlerTest, DontGotWiderThanScreen) {
388 scoped_ptr<aura::Window> target(CreateWindow(HTRIGHT)); 388 scoped_ptr<aura::Window> target(CreateWindow(HTRIGHT));
389 gfx::Rect work_area = 389 gfx::Rect work_area =
390 gfx::Screen::GetDisplayNearestWindow(target.get()).bounds(); 390 gfx::Screen::GetDisplayNearestWindow(target.get()).bounds();
391 DragFromCenterBy(target.get(), work_area.width() * 2, 0); 391 DragFromCenterBy(target.get(), work_area.width() * 2, 0);
392 // The y location and height should not have changed. 392 // The y location and height should not have changed.
393 EXPECT_EQ(work_area.width(), target->bounds().width()); 393 EXPECT_EQ(work_area.width(), target->bounds().width());
394 } 394 }
395 395
396 // Verifies that touch-gestures drag the window correctly. 396 // Verifies that touch-gestures drag the window correctly.
397 TEST_F(ToplevelWindowEventFilterTest, GestureDrag) { 397 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) {
398 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); 398 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION));
399 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 399 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
400 target.get()); 400 target.get());
401 gfx::Rect old_bounds = target->bounds(); 401 gfx::Rect old_bounds = target->bounds();
402 gfx::Point location(5, 5); 402 gfx::Point location(5, 5);
403 403
404 // Snap right; 404 // Snap right;
405 gfx::Point end = location; 405 gfx::Point end = location;
406 end.Offset(100, 0); 406 end.Offset(100, 0);
407 generator.GestureScrollSequence(location, end, 407 generator.GestureScrollSequence(location, end,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString()); 458 EXPECT_NE(old_bounds.ToString(), target->bounds().ToString());
459 EXPECT_TRUE(wm::IsWindowMinimized(target.get())); 459 EXPECT_TRUE(wm::IsWindowMinimized(target.get()));
460 } 460 }
461 461
462 // Verifies pressing escape resets the bounds to the original bounds. 462 // Verifies pressing escape resets the bounds to the original bounds.
463 #if defined(OS_MACOSX) 463 #if defined(OS_MACOSX)
464 #define MAYBE_EscapeReverts FAILS_EscapeReverts 464 #define MAYBE_EscapeReverts FAILS_EscapeReverts
465 #else 465 #else
466 #define MAYBE_EscapeReverts EscapeReverts 466 #define MAYBE_EscapeReverts EscapeReverts
467 #endif 467 #endif
468 TEST_F(ToplevelWindowEventFilterTest, MAYBE_EscapeReverts) { 468 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_EscapeReverts) {
469 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 469 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
470 aura::client::ActivationClient* original_client = 470 aura::client::ActivationClient* original_client =
471 aura::client::GetActivationClient(root); 471 aura::client::GetActivationClient(root);
472 aura::test::TestActivationClient activation_client(root); 472 aura::test::TestActivationClient activation_client(root);
473 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); 473 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT));
474 target->Focus(); 474 target->Focus();
475 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 475 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
476 target.get()); 476 target.get());
477 generator.PressLeftButton(); 477 generator.PressLeftButton();
478 generator.MoveMouseTo(generator.current_location().Add(gfx::Point(10, 11))); 478 generator.MoveMouseTo(generator.current_location().Add(gfx::Point(10, 11)));
479 479
480 // Execute any scheduled draws so that pending mouse events are processed. 480 // Execute any scheduled draws so that pending mouse events are processed.
481 RunAllPendingInMessageLoop(); 481 RunAllPendingInMessageLoop();
482 482
483 EXPECT_EQ("0,0 110x111", target->bounds().ToString()); 483 EXPECT_EQ("0,0 110x111", target->bounds().ToString());
484 generator.PressKey(ui::VKEY_ESCAPE, 0); 484 generator.PressKey(ui::VKEY_ESCAPE, 0);
485 generator.ReleaseKey(ui::VKEY_ESCAPE, 0); 485 generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
486 EXPECT_EQ("0,0 100x100", target->bounds().ToString()); 486 EXPECT_EQ("0,0 100x100", target->bounds().ToString());
487 aura::client::SetActivationClient(root, original_client); 487 aura::client::SetActivationClient(root, original_client);
488 } 488 }
489 489
490 } // namespace test 490 } // namespace test
491 } // namespace ash 491 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/toplevel_window_event_handler.cc ('k') | ash/wm/workspace/multi_window_resize_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698