OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "build/build_config.h" | |
6 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | |
7 #include "chrome/browser/ui/panels/detached_panel_collection.h" | |
8 #include "chrome/browser/ui/panels/panel.h" | |
9 #include "chrome/browser/ui/panels/panel_manager.h" | |
10 #include "chrome/browser/ui/panels/panel_resize_controller.h" | |
11 #include "chrome/browser/ui/panels/stacked_panel_collection.h" | |
12 #include "ui/base/hit_test.h" | |
13 | |
14 class PanelResizeBrowserTest : public BasePanelBrowserTest { | |
15 public: | |
16 PanelResizeBrowserTest() : BasePanelBrowserTest() { | |
17 } | |
18 | |
19 ~PanelResizeBrowserTest() override {} | |
20 | |
21 void SetUpOnMainThread() override { | |
22 BasePanelBrowserTest::SetUpOnMainThread(); | |
23 | |
24 // All the tests here assume using mocked 800x600 display area for the | |
25 // primary monitor. Do the check now. | |
26 gfx::Rect primary_display_area = PanelManager::GetInstance()-> | |
27 display_settings_provider()->GetPrimaryDisplayArea(); | |
28 DCHECK(primary_display_area.width() == 800); | |
29 DCHECK(primary_display_area.height() == 600); | |
30 } | |
31 | |
32 void ResizePanel(Panel* panel, | |
33 int component, | |
34 const gfx::Vector2d& delta) { | |
35 PanelManager* panel_manager = PanelManager::GetInstance(); | |
36 gfx::Rect bounds = panel->GetBounds(); | |
37 gfx::Point mouse_location; | |
38 switch (component) { | |
39 case HTTOPLEFT: | |
40 mouse_location = bounds.origin(); | |
41 break; | |
42 case HTTOP: | |
43 mouse_location.SetPoint(bounds.x() + bounds.width() / 2, bounds.y()); | |
44 break; | |
45 case HTTOPRIGHT: | |
46 mouse_location.SetPoint(bounds.right(), bounds.y()); | |
47 break; | |
48 case HTLEFT: | |
49 mouse_location.SetPoint(bounds.x(), bounds.y() + bounds.height() / 2); | |
50 break; | |
51 case HTRIGHT: | |
52 mouse_location.SetPoint(bounds.right(), | |
53 bounds.y() + bounds.height() / 2); | |
54 break; | |
55 case HTBOTTOMLEFT: | |
56 mouse_location.SetPoint(bounds.x(), bounds.bottom()); | |
57 break; | |
58 case HTBOTTOM: | |
59 mouse_location.SetPoint(bounds.x() + bounds.width() / 2, | |
60 bounds.bottom()); | |
61 break; | |
62 case HTBOTTOMRIGHT: | |
63 mouse_location.SetPoint(bounds.right(), bounds.bottom()); | |
64 break; | |
65 default: | |
66 NOTREACHED(); | |
67 break; | |
68 } | |
69 panel_manager->StartResizingByMouse(panel, mouse_location, component); | |
70 mouse_location += delta; | |
71 panel_manager->ResizeByMouse(mouse_location); | |
72 panel_manager->EndResizingByMouse(false); | |
73 } | |
74 }; | |
75 | |
76 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
77 #if defined(OS_MACOSX) | |
78 #define MAYBE_DockedPanelResizability DISABLED_DockedPanelResizability | |
79 #else | |
80 #define MAYBE_DockedPanelResizability DockedPanelResizability | |
81 #endif | |
82 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_DockedPanelResizability) { | |
83 PanelManager* panel_manager = PanelManager::GetInstance(); | |
84 Panel* panel = CreatePanel("Panel"); | |
85 | |
86 EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM, panel->CanResizeByMouse()); | |
87 | |
88 gfx::Rect bounds = panel->GetBounds(); | |
89 | |
90 // Try resizing by the top left corner. | |
91 gfx::Point mouse_location = bounds.origin(); | |
92 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPLEFT); | |
93 mouse_location.Offset(-20, -10); | |
94 panel_manager->ResizeByMouse(mouse_location); | |
95 | |
96 bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10)); | |
97 bounds.Offset(-20, -10); | |
98 EXPECT_EQ(bounds, panel->GetBounds()); | |
99 | |
100 panel_manager->EndResizingByMouse(false); | |
101 EXPECT_EQ(bounds, panel->GetBounds()); | |
102 | |
103 // Try resizing by the top. | |
104 mouse_location = bounds.origin() + gfx::Vector2d(10, 1); | |
105 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOP); | |
106 mouse_location.Offset(5, -10); | |
107 panel_manager->ResizeByMouse(mouse_location); | |
108 | |
109 bounds.set_height(bounds.height() + 10); | |
110 bounds.Offset(0, -10); | |
111 EXPECT_EQ(bounds, panel->GetBounds()); | |
112 | |
113 panel_manager->EndResizingByMouse(false); | |
114 EXPECT_EQ(bounds, panel->GetBounds()); | |
115 | |
116 // Try resizing by the left side. | |
117 mouse_location = bounds.origin() + gfx::Vector2d(1, 30); | |
118 panel_manager->StartResizingByMouse(panel, mouse_location, HTLEFT); | |
119 mouse_location.Offset(-5, 25); | |
120 panel_manager->ResizeByMouse(mouse_location); | |
121 | |
122 bounds.set_width(bounds.width() + 5); | |
123 bounds.Offset(-5, 0); | |
124 EXPECT_EQ(bounds, panel->GetBounds()); | |
125 | |
126 panel_manager->EndResizingByMouse(false); | |
127 EXPECT_EQ(bounds, panel->GetBounds()); | |
128 | |
129 // Try resizing by the top right side. | |
130 mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 2); | |
131 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPRIGHT); | |
132 mouse_location.Offset(30, 20); | |
133 panel_manager->ResizeByMouse(mouse_location); | |
134 | |
135 bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20)); | |
136 bounds.Offset(0, 20); | |
137 EXPECT_EQ(bounds, panel->GetBounds()); | |
138 | |
139 panel_manager->EndResizingByMouse(false); | |
140 WaitForBoundsAnimationFinished(panel); | |
141 bounds.Offset(-30, 0); // Layout of panel adjusted in docked collection. | |
142 EXPECT_EQ(bounds, panel->GetBounds()); | |
143 | |
144 // Try resizing by the right side. | |
145 mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 30); | |
146 panel_manager->StartResizingByMouse(panel, mouse_location, HTRIGHT); | |
147 mouse_location.Offset(5, 25); | |
148 panel_manager->ResizeByMouse(mouse_location); | |
149 | |
150 bounds.set_width(bounds.width() + 5); | |
151 EXPECT_EQ(bounds, panel->GetBounds()); | |
152 | |
153 panel_manager->EndResizingByMouse(false); | |
154 WaitForBoundsAnimationFinished(panel); | |
155 bounds.Offset(-5, 0); // Layout of panel adjusted in docked collection. | |
156 EXPECT_EQ(bounds, panel->GetBounds()); | |
157 | |
158 // Try resizing by the bottom side; verify resize won't work. | |
159 mouse_location = bounds.origin() + gfx::Vector2d(10, bounds.height() - 1); | |
160 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOM); | |
161 mouse_location.Offset(30, -10); | |
162 panel_manager->ResizeByMouse(mouse_location); | |
163 EXPECT_EQ(bounds, panel->GetBounds()); | |
164 | |
165 panel_manager->EndResizingByMouse(false); | |
166 EXPECT_EQ(bounds, panel->GetBounds()); | |
167 | |
168 // Try resizing by the bottom left corner; verify resize won't work. | |
169 mouse_location = bounds.origin() + gfx::Vector2d(1, bounds.height() - 1); | |
170 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMLEFT); | |
171 mouse_location.Offset(-10, 15); | |
172 panel_manager->ResizeByMouse(mouse_location); | |
173 EXPECT_EQ(bounds, panel->GetBounds()); | |
174 | |
175 panel_manager->EndResizingByMouse(false); | |
176 EXPECT_EQ(bounds, panel->GetBounds()); | |
177 | |
178 // Try resizing by the bottom right corner; verify resize won't work. | |
179 mouse_location = bounds.origin() + | |
180 gfx::Vector2d(bounds.width() - 2, bounds.height()); | |
181 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMRIGHT); | |
182 mouse_location.Offset(20, 10); | |
183 panel_manager->ResizeByMouse(mouse_location); | |
184 EXPECT_EQ(bounds, panel->GetBounds()); | |
185 | |
186 panel_manager->EndResizingByMouse(false); | |
187 EXPECT_EQ(bounds, panel->GetBounds()); | |
188 | |
189 panel->Close(); | |
190 } | |
191 | |
192 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
193 #if defined(OS_MACOSX) | |
194 #define MAYBE_ResizeDetachedPanel DISABLED_ResizeDetachedPanel | |
195 #else | |
196 #define MAYBE_ResizeDetachedPanel ResizeDetachedPanel | |
197 #endif | |
198 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_ResizeDetachedPanel) { | |
199 PanelManager* panel_manager = PanelManager::GetInstance(); | |
200 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); | |
201 | |
202 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse()); | |
203 | |
204 gfx::Rect bounds = panel->GetBounds(); | |
205 | |
206 // Try resizing by the right side; verify resize will change width only. | |
207 gfx::Point mouse_location = bounds.origin() + | |
208 gfx::Vector2d(bounds.width() - 1, 30); | |
209 panel_manager->StartResizingByMouse(panel, mouse_location, HTRIGHT); | |
210 mouse_location.Offset(5, 25); | |
211 panel_manager->ResizeByMouse(mouse_location); | |
212 | |
213 bounds.set_width(bounds.width() + 5); | |
214 EXPECT_EQ(bounds, panel->GetBounds()); | |
215 | |
216 panel_manager->EndResizingByMouse(false); | |
217 EXPECT_EQ(bounds, panel->GetBounds()); | |
218 | |
219 // Try resizing by the bottom left side. | |
220 mouse_location = bounds.origin() + gfx::Vector2d(1, bounds.height() - 1); | |
221 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMLEFT); | |
222 mouse_location.Offset(-10, 15); | |
223 panel_manager->ResizeByMouse(mouse_location); | |
224 | |
225 bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15)); | |
226 bounds.Offset(-10, 0); | |
227 EXPECT_EQ(bounds, panel->GetBounds()); | |
228 | |
229 panel_manager->EndResizingByMouse(false); | |
230 EXPECT_EQ(bounds, panel->GetBounds()); | |
231 | |
232 // Try resizing by the top right side. | |
233 mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 2); | |
234 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPRIGHT); | |
235 mouse_location.Offset(30, 20); | |
236 panel_manager->ResizeByMouse(mouse_location); | |
237 | |
238 bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20)); | |
239 bounds.Offset(0, 20); | |
240 EXPECT_EQ(bounds, panel->GetBounds()); | |
241 | |
242 panel_manager->EndResizingByMouse(false); | |
243 EXPECT_EQ(bounds, panel->GetBounds()); | |
244 | |
245 // Try resizing by the top left side. | |
246 mouse_location = bounds.origin() + gfx::Vector2d(1, 0); | |
247 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPLEFT); | |
248 mouse_location.Offset(-20, -10); | |
249 panel_manager->ResizeByMouse(mouse_location); | |
250 | |
251 bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10)); | |
252 bounds.Offset(-20, -10); | |
253 EXPECT_EQ(bounds, panel->GetBounds()); | |
254 | |
255 panel_manager->EndResizingByMouse(false); | |
256 EXPECT_EQ(bounds, panel->GetBounds()); | |
257 | |
258 PanelManager::GetInstance()->CloseAll(); | |
259 } | |
260 | |
261 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
262 #if defined(OS_MACOSX) | |
263 #define MAYBE_TryResizePanelBelowMinimizeSize \ | |
264 DISABLED_TryResizePanelBelowMinimizeSize | |
265 #else | |
266 #define MAYBE_TryResizePanelBelowMinimizeSize TryResizePanelBelowMinimizeSize | |
267 #endif | |
268 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, | |
269 MAYBE_TryResizePanelBelowMinimizeSize) { | |
270 int initial_width = 150; | |
271 int initial_height = 100; | |
272 Panel* panel = CreateDetachedPanel("1", | |
273 gfx::Rect(300, 200, initial_width, initial_height)); | |
274 | |
275 // Try to resize the panel below the minimum size. Expect that the panel | |
276 // shrinks to the minimum size. | |
277 int resize_width = panel::kPanelMinWidth / 2 - initial_width; | |
278 int resize_height = panel::kPanelMinHeight / 2 - initial_height; | |
279 ResizePanel(panel, | |
280 HTBOTTOMRIGHT, | |
281 gfx::Vector2d(resize_width, resize_height)); | |
282 | |
283 EXPECT_EQ(panel::kPanelMinWidth, panel->GetBounds().width()); | |
284 EXPECT_EQ(panel::kPanelMinHeight, panel->GetBounds().height()); | |
285 | |
286 PanelManager::GetInstance()->CloseAll(); | |
287 } | |
288 | |
289 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
290 #if defined(OS_MACOSX) | |
291 #define MAYBE_ResizeDetachedPanelToClampSize \ | |
292 DISABLED_ResizeDetachedPanelToClampSize | |
293 #else | |
294 #define MAYBE_ResizeDetachedPanelToClampSize ResizeDetachedPanelToClampSize | |
295 #endif | |
296 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, | |
297 MAYBE_ResizeDetachedPanelToClampSize) { | |
298 PanelManager* panel_manager = PanelManager::GetInstance(); | |
299 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); | |
300 | |
301 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse()); | |
302 | |
303 gfx::Rect bounds = panel->GetBounds(); | |
304 | |
305 // Make sure the panel does not resize smaller than its min size. | |
306 gfx::Point mouse_location = bounds.origin() + | |
307 gfx::Vector2d(30, bounds.height() - 2); | |
308 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOM); | |
309 mouse_location.Offset(-20, -500); | |
310 panel_manager->ResizeByMouse(mouse_location); | |
311 | |
312 bounds.set_height(panel->min_size().height()); | |
313 EXPECT_EQ(bounds, panel->GetBounds()); | |
314 | |
315 panel_manager->EndResizingByMouse(false); | |
316 EXPECT_EQ(bounds, panel->GetBounds()); | |
317 | |
318 // Make sure the panel can resize larger than its size. User is in control. | |
319 mouse_location = bounds.origin() + | |
320 gfx::Vector2d(bounds.width(), bounds.height() - 2); | |
321 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMRIGHT); | |
322 | |
323 // This drag would take us beyond max size. | |
324 int delta_x = panel->max_size().width() + 10 - panel->GetBounds().width(); | |
325 int delta_y = panel->max_size().height() + 10 - panel->GetBounds().height(); | |
326 mouse_location.Offset(delta_x, delta_y); | |
327 panel_manager->ResizeByMouse(mouse_location); | |
328 | |
329 // The bounds if the max_size does not limit the resize. | |
330 bounds.set_size(gfx::Size(bounds.width() + delta_x, | |
331 bounds.height() + delta_y)); | |
332 EXPECT_EQ(bounds, panel->GetBounds()); | |
333 | |
334 panel_manager->EndResizingByMouse(false); | |
335 EXPECT_EQ(bounds, panel->GetBounds()); | |
336 | |
337 PanelManager::GetInstance()->CloseAll(); | |
338 } | |
339 | |
340 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
341 #if defined(OS_MACOSX) | |
342 #define MAYBE_CloseDetachedPanelOnResize DISABLED_CloseDetachedPanelOnResize | |
343 #else | |
344 #define MAYBE_CloseDetachedPanelOnResize CloseDetachedPanelOnResize | |
345 #endif | |
346 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, | |
347 MAYBE_CloseDetachedPanelOnResize) { | |
348 PanelManager* panel_manager = PanelManager::GetInstance(); | |
349 PanelResizeController* resize_controller = panel_manager->resize_controller(); | |
350 DetachedPanelCollection* detached_collection = | |
351 panel_manager->detached_collection(); | |
352 | |
353 // Create 3 detached panels. | |
354 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 200, 100, 100)); | |
355 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 210, 110, 110)); | |
356 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(300, 220, 120, 120)); | |
357 ASSERT_EQ(3, detached_collection->num_panels()); | |
358 | |
359 gfx::Rect panel1_bounds = panel1->GetBounds(); | |
360 gfx::Rect panel3_bounds = panel3->GetBounds(); | |
361 | |
362 // Start resizing panel1, and close panel2 in the process. | |
363 // Panel1 is not affected. | |
364 gfx::Point mouse_location = panel1_bounds.origin() + | |
365 gfx::Vector2d(1, panel1_bounds.height() - 1); | |
366 panel_manager->StartResizingByMouse(panel1, mouse_location, HTBOTTOMLEFT); | |
367 mouse_location.Offset(-10, 15); | |
368 panel_manager->ResizeByMouse(mouse_location); | |
369 | |
370 panel1_bounds.set_size(gfx::Size(panel1_bounds.width() + 10, | |
371 panel1_bounds.height() + 15)); | |
372 panel1_bounds.Offset(-10, 0); | |
373 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); | |
374 | |
375 CloseWindowAndWait(panel2); | |
376 EXPECT_TRUE(resize_controller->IsResizing()); | |
377 EXPECT_EQ(2, detached_collection->num_panels()); | |
378 | |
379 panel_manager->EndResizingByMouse(false); | |
380 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); | |
381 | |
382 // Start resizing panel3, and close it in the process. | |
383 // Resize should abort, panel1 will not be affected. | |
384 mouse_location = panel3_bounds.origin() + | |
385 gfx::Vector2d(panel3_bounds.width() - 1, panel3_bounds.height() - 2); | |
386 panel_manager->StartResizingByMouse(panel3, mouse_location, HTBOTTOMRIGHT); | |
387 mouse_location.Offset(7, -12); | |
388 panel_manager->ResizeByMouse(mouse_location); | |
389 | |
390 panel3_bounds.set_size(gfx::Size(panel3_bounds.width() + 7, | |
391 panel3_bounds.height() - 12)); | |
392 EXPECT_EQ(panel3_bounds, panel3->GetBounds()); | |
393 | |
394 CloseWindowAndWait(panel3); | |
395 EXPECT_EQ(1, detached_collection->num_panels()); | |
396 // Since we closed the panel we were resizing, we should be out of the | |
397 // resizing mode by now. | |
398 EXPECT_FALSE(resize_controller->IsResizing()); | |
399 | |
400 panel_manager->EndResizingByMouse(false); | |
401 EXPECT_FALSE(resize_controller->IsResizing()); | |
402 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); | |
403 | |
404 panel_manager->CloseAll(); | |
405 } | |
406 | |
407 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
408 #if defined(OS_MACOSX) | |
409 #define MAYBE_ResizeAndCancel DISABLED_ResizeAndCancel | |
410 #else | |
411 #define MAYBE_ResizeAndCancel ResizeAndCancel | |
412 #endif | |
413 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_ResizeAndCancel) { | |
414 PanelManager* panel_manager = PanelManager::GetInstance(); | |
415 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); | |
416 PanelResizeController* resize_controller = panel_manager->resize_controller(); | |
417 | |
418 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse()); | |
419 | |
420 gfx::Rect original_bounds = panel->GetBounds(); | |
421 | |
422 // Resizing the panel, then cancelling should return it to the original state. | |
423 // Try resizing by the top right side. | |
424 gfx::Rect bounds = panel->GetBounds(); | |
425 gfx::Point mouse_location = bounds.origin() + | |
426 gfx::Vector2d(bounds.width() - 1, 1); | |
427 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPRIGHT); | |
428 mouse_location.Offset(5, 25); | |
429 panel_manager->ResizeByMouse(mouse_location); | |
430 | |
431 bounds.set_size(gfx::Size(bounds.width() + 5, bounds.height() - 25)); | |
432 bounds.Offset(0, 25); | |
433 EXPECT_EQ(bounds, panel->GetBounds()); | |
434 | |
435 panel_manager->EndResizingByMouse(true); | |
436 EXPECT_EQ(original_bounds, panel->GetBounds()); | |
437 | |
438 // Try resizing by the bottom left side. | |
439 bounds = panel->GetBounds(); | |
440 mouse_location = bounds.origin() + gfx::Vector2d(1, bounds.height() - 1); | |
441 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMLEFT); | |
442 mouse_location.Offset(-10, 15); | |
443 panel_manager->ResizeByMouse(mouse_location); | |
444 | |
445 bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15)); | |
446 bounds.Offset(-10, 0); | |
447 EXPECT_EQ(bounds, panel->GetBounds()); | |
448 | |
449 panel_manager->EndResizingByMouse(true); | |
450 EXPECT_EQ(original_bounds, panel->GetBounds()); | |
451 EXPECT_FALSE(resize_controller->IsResizing()); | |
452 | |
453 panel_manager->CloseAll(); | |
454 } | |
455 | |
456 // http://crbug.com/175760; several panel tests failing regularly on mac. | |
457 #if defined(OS_MACOSX) | |
458 #define MAYBE_ResizeDetachedPanelToTop DISABLED_ResizeDetachedPanelToTop | |
459 #else | |
460 #define MAYBE_ResizeDetachedPanelToTop ResizeDetachedPanelToTop | |
461 #endif | |
462 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_ResizeDetachedPanelToTop) { | |
463 // Setup the test areas to have top-aligned bar excluded from work area. | |
464 const gfx::Rect primary_display_area(0, 0, 800, 600); | |
465 const gfx::Rect primary_work_area(0, 10, 800, 590); | |
466 mock_display_settings_provider()->SetPrimaryDisplay( | |
467 primary_display_area, primary_work_area); | |
468 | |
469 PanelManager* panel_manager = PanelManager::GetInstance(); | |
470 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); | |
471 gfx::Rect bounds = panel->GetBounds(); | |
472 | |
473 // Try resizing by the top left corner. | |
474 gfx::Point mouse_location = bounds.origin(); | |
475 panel_manager->StartResizingByMouse(panel, | |
476 mouse_location, | |
477 HTTOPLEFT); | |
478 | |
479 // Try moving the mouse outside the top of the work area. Expect that panel's | |
480 // top position will not exceed the top of the work area. | |
481 mouse_location = gfx::Point(250, 2); | |
482 panel_manager->ResizeByMouse(mouse_location); | |
483 | |
484 bounds.set_width(bounds.width() + bounds.x() - mouse_location.x()); | |
485 bounds.set_height(bounds.height() + bounds.y() - primary_work_area.y()); | |
486 bounds.set_x(mouse_location.x()); | |
487 bounds.set_y(primary_work_area.y()); | |
488 EXPECT_EQ(bounds, panel->GetBounds()); | |
489 | |
490 // Try moving the mouse inside the work area. Expect that the panel can be | |
491 // resized without constraint. | |
492 mouse_location = gfx::Point(280, 50); | |
493 panel_manager->ResizeByMouse(mouse_location); | |
494 | |
495 bounds.set_width(bounds.width() + bounds.x() - mouse_location.x()); | |
496 bounds.set_height(bounds.height() + bounds.y() - mouse_location.y()); | |
497 bounds.set_x(mouse_location.x()); | |
498 bounds.set_y(mouse_location.y()); | |
499 EXPECT_EQ(bounds, panel->GetBounds()); | |
500 | |
501 panel_manager->EndResizingByMouse(false); | |
502 EXPECT_EQ(bounds, panel->GetBounds()); | |
503 | |
504 panel_manager->CloseAll(); | |
505 } | |
506 | |
507 // TODO(jianli): to be enabled for other platforms when stacked panels are | |
508 // supported. | |
509 #if defined(OS_WIN) | |
510 | |
511 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeStackedPanels) { | |
512 PanelManager* panel_manager = PanelManager::GetInstance(); | |
513 | |
514 // Create 3 stacked panels. | |
515 StackedPanelCollection* stack = panel_manager->CreateStack(); | |
516 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150); | |
517 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack); | |
518 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100); | |
519 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack); | |
520 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 110); | |
521 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack); | |
522 ASSERT_EQ(3, panel_manager->num_panels()); | |
523 ASSERT_EQ(1, panel_manager->num_stacks()); | |
524 ASSERT_EQ(3, stack->num_panels()); | |
525 | |
526 gfx::Size panel1_expected_full_size = panel1_initial_bounds.size(); | |
527 EXPECT_EQ(panel1_expected_full_size, panel1->full_size()); | |
528 gfx::Size panel2_expected_full_size(panel1_initial_bounds.width(), | |
529 panel2_initial_bounds.height()); | |
530 EXPECT_EQ(panel2_expected_full_size, panel2->full_size()); | |
531 gfx::Size panel3_expected_full_size(panel1_initial_bounds.width(), | |
532 panel3_initial_bounds.height()); | |
533 EXPECT_EQ(panel3_expected_full_size, panel3->full_size()); | |
534 | |
535 gfx::Rect panel1_expected_bounds(panel1_initial_bounds); | |
536 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
537 gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(), | |
538 panel1_expected_bounds.bottom(), | |
539 panel1_expected_bounds.width(), | |
540 panel2_initial_bounds.height()); | |
541 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
542 gfx::Rect panel3_expected_bounds(panel2_expected_bounds.x(), | |
543 panel2_expected_bounds.bottom(), | |
544 panel2_expected_bounds.width(), | |
545 panel3_initial_bounds.height()); | |
546 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
547 | |
548 // Resize by the top-left corner of the top panel. | |
549 // Expect that the width of all stacked panels get increased by the same | |
550 // amount and the top panel also expands in height. | |
551 int top_resize_width = 15; | |
552 int top_resize_height = 10; | |
553 ResizePanel(panel1, | |
554 HTTOPLEFT, | |
555 gfx::Vector2d(-top_resize_width, -top_resize_height)); | |
556 | |
557 panel1_expected_full_size.Enlarge(top_resize_width, top_resize_height); | |
558 EXPECT_EQ(panel1_expected_full_size, panel1->full_size()); | |
559 panel2_expected_full_size.Enlarge(top_resize_width, 0); | |
560 EXPECT_EQ(panel2_expected_full_size, panel2->full_size()); | |
561 panel3_expected_full_size.Enlarge(top_resize_width, 0); | |
562 EXPECT_EQ(panel3_expected_full_size, panel3->full_size()); | |
563 | |
564 panel1_expected_bounds.SetRect( | |
565 panel1_expected_bounds.x() - top_resize_width, | |
566 panel1_expected_bounds.y() - top_resize_height, | |
567 panel1_expected_bounds.width() + top_resize_width, | |
568 panel1_expected_bounds.height() + top_resize_height); | |
569 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
570 panel2_expected_bounds.set_x(panel2_expected_bounds.x() - top_resize_width); | |
571 panel2_expected_bounds.set_width( | |
572 panel2_expected_bounds.width() + top_resize_width); | |
573 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
574 panel3_expected_bounds.set_x(panel3_expected_bounds.x() - top_resize_width); | |
575 panel3_expected_bounds.set_width( | |
576 panel3_expected_bounds.width() + top_resize_width); | |
577 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
578 | |
579 // Resize by the bottom-right corner of the bottom panel. | |
580 // Expect that the width of all stacked panels get increased by the same | |
581 // amount and the bottom panel also shrinks in height. | |
582 int bottom_resize_width = 12; | |
583 int bottom_resize_height = 8; | |
584 ResizePanel(panel3, | |
585 HTBOTTOMRIGHT, | |
586 gfx::Vector2d(-bottom_resize_width, -bottom_resize_height)); | |
587 | |
588 panel1_expected_full_size.Enlarge(-bottom_resize_width, 0); | |
589 EXPECT_EQ(panel1_expected_full_size, panel1->full_size()); | |
590 panel2_expected_full_size.Enlarge(-bottom_resize_width, 0); | |
591 EXPECT_EQ(panel2_expected_full_size, panel2->full_size()); | |
592 panel3_expected_full_size.Enlarge(-bottom_resize_width, | |
593 -bottom_resize_height); | |
594 EXPECT_EQ(panel3_expected_full_size, panel3->full_size()); | |
595 | |
596 panel1_expected_bounds.set_width( | |
597 panel1_expected_bounds.width() - bottom_resize_width); | |
598 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
599 panel2_expected_bounds.set_width( | |
600 panel2_expected_bounds.width() - bottom_resize_width); | |
601 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
602 panel3_expected_bounds.set_width( | |
603 panel3_expected_bounds.width() - bottom_resize_width); | |
604 panel3_expected_bounds.set_height( | |
605 panel3_expected_bounds.height() - bottom_resize_height); | |
606 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
607 | |
608 // Resize by the bottom edge of the middle panel. | |
609 // Expect that the height of the middle panel increases and the height of | |
610 // the bottom panel decreases by the same amount. | |
611 int middle_resize_height = 5; | |
612 ResizePanel(panel2, | |
613 HTBOTTOM, | |
614 gfx::Vector2d(0, middle_resize_height)); | |
615 | |
616 EXPECT_EQ(panel1_expected_full_size, panel1->full_size()); | |
617 panel2_expected_full_size.Enlarge(0, middle_resize_height); | |
618 EXPECT_EQ(panel2_expected_full_size, panel2->full_size()); | |
619 panel3_expected_full_size.Enlarge(0, -middle_resize_height); | |
620 EXPECT_EQ(panel3_expected_full_size, panel3->full_size()); | |
621 | |
622 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
623 panel2_expected_bounds.set_height( | |
624 panel2_expected_bounds.height() + middle_resize_height); | |
625 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
626 panel3_expected_bounds.set_y( | |
627 panel3_expected_bounds.y() + middle_resize_height); | |
628 panel3_expected_bounds.set_height( | |
629 panel3_expected_bounds.height() - middle_resize_height); | |
630 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
631 | |
632 // Collapse the middle panel. | |
633 panel2->Minimize(); | |
634 WaitForBoundsAnimationFinished(panel2); | |
635 EXPECT_TRUE(panel2->IsMinimized()); | |
636 | |
637 EXPECT_EQ(panel1_expected_full_size, panel1->full_size()); | |
638 EXPECT_EQ(panel2_expected_full_size, panel2->full_size()); | |
639 EXPECT_EQ(panel3_expected_full_size, panel3->full_size()); | |
640 | |
641 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
642 panel2_expected_bounds.set_height(panel2->TitleOnlyHeight()); | |
643 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
644 panel3_expected_bounds.set_y(panel2_expected_bounds.bottom()); | |
645 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
646 | |
647 // Resize by the bottom edge of the top panel. | |
648 // Expect that the height of the top panel increases and the height of | |
649 // the middle panel is not affected because it is collapsed. | |
650 top_resize_height = 18; | |
651 ResizePanel(panel1, | |
652 HTBOTTOM, | |
653 gfx::Vector2d(0, top_resize_height)); | |
654 | |
655 panel1_expected_full_size.Enlarge(0, top_resize_height); | |
656 EXPECT_EQ(panel1_expected_full_size, panel1->full_size()); | |
657 EXPECT_EQ(panel2_expected_full_size, panel2->full_size()); | |
658 EXPECT_EQ(panel3_expected_full_size, panel3->full_size()); | |
659 | |
660 panel1_expected_bounds.set_height( | |
661 panel1_expected_bounds.height() + top_resize_height); | |
662 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); | |
663 panel2_expected_bounds.set_y( | |
664 panel2_expected_bounds.y() + top_resize_height); | |
665 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); | |
666 panel3_expected_bounds.set_y( | |
667 panel3_expected_bounds.y() + top_resize_height); | |
668 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds()); | |
669 | |
670 panel_manager->CloseAll(); | |
671 } | |
672 | |
673 #endif | |
OLD | NEW |