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.
5 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
6 #include "chrome/browser/ui/panels/detached_panel_collection.h"
7 #include "chrome/browser/ui/panels/panel.h"
8 #include "chrome/browser/ui/panels/panel_manager.h"
9 #include "chrome/browser/ui/panels/panel_resize_controller.h"
10 #include "chrome/browser/ui/panels/stacked_panel_collection.h"
11 #include "ui/base/hit_test.h"
13 class PanelResizeBrowserTest
: public BasePanelBrowserTest
{
15 PanelResizeBrowserTest() : BasePanelBrowserTest() {
18 virtual ~PanelResizeBrowserTest() {
21 virtual void SetUpOnMainThread() override
{
22 BasePanelBrowserTest::SetUpOnMainThread();
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);
32 void ResizePanel(Panel
* panel
,
34 const gfx::Vector2d
& delta
) {
35 PanelManager
* panel_manager
= PanelManager::GetInstance();
36 gfx::Rect bounds
= panel
->GetBounds();
37 gfx::Point mouse_location
;
40 mouse_location
= bounds
.origin();
43 mouse_location
.SetPoint(bounds
.x() + bounds
.width() / 2, bounds
.y());
46 mouse_location
.SetPoint(bounds
.right(), bounds
.y());
49 mouse_location
.SetPoint(bounds
.x(), bounds
.y() + bounds
.height() / 2);
52 mouse_location
.SetPoint(bounds
.right(),
53 bounds
.y() + bounds
.height() / 2);
56 mouse_location
.SetPoint(bounds
.x(), bounds
.bottom());
59 mouse_location
.SetPoint(bounds
.x() + bounds
.width() / 2,
63 mouse_location
.SetPoint(bounds
.right(), bounds
.bottom());
69 panel_manager
->StartResizingByMouse(panel
, mouse_location
, component
);
70 mouse_location
+= delta
;
71 panel_manager
->ResizeByMouse(mouse_location
);
72 panel_manager
->EndResizingByMouse(false);
76 // http://crbug.com/175760; several panel tests failing regularly on mac.
77 #if defined(OS_MACOSX)
78 #define MAYBE_DockedPanelResizability DISABLED_DockedPanelResizability
80 #define MAYBE_DockedPanelResizability DockedPanelResizability
82 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest
, MAYBE_DockedPanelResizability
) {
83 PanelManager
* panel_manager
= PanelManager::GetInstance();
84 Panel
* panel
= CreatePanel("Panel");
86 EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM
, panel
->CanResizeByMouse());
88 gfx::Rect bounds
= panel
->GetBounds();
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
);
96 bounds
.set_size(gfx::Size(bounds
.width() + 20, bounds
.height() + 10));
97 bounds
.Offset(-20, -10);
98 EXPECT_EQ(bounds
, panel
->GetBounds());
100 panel_manager
->EndResizingByMouse(false);
101 EXPECT_EQ(bounds
, panel
->GetBounds());
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
);
109 bounds
.set_height(bounds
.height() + 10);
110 bounds
.Offset(0, -10);
111 EXPECT_EQ(bounds
, panel
->GetBounds());
113 panel_manager
->EndResizingByMouse(false);
114 EXPECT_EQ(bounds
, panel
->GetBounds());
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
);
122 bounds
.set_width(bounds
.width() + 5);
123 bounds
.Offset(-5, 0);
124 EXPECT_EQ(bounds
, panel
->GetBounds());
126 panel_manager
->EndResizingByMouse(false);
127 EXPECT_EQ(bounds
, panel
->GetBounds());
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
);
135 bounds
.set_size(gfx::Size(bounds
.width() + 30, bounds
.height() - 20));
136 bounds
.Offset(0, 20);
137 EXPECT_EQ(bounds
, panel
->GetBounds());
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());
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
);
150 bounds
.set_width(bounds
.width() + 5);
151 EXPECT_EQ(bounds
, panel
->GetBounds());
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());
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());
165 panel_manager
->EndResizingByMouse(false);
166 EXPECT_EQ(bounds
, panel
->GetBounds());
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());
175 panel_manager
->EndResizingByMouse(false);
176 EXPECT_EQ(bounds
, panel
->GetBounds());
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());
186 panel_manager
->EndResizingByMouse(false);
187 EXPECT_EQ(bounds
, panel
->GetBounds());
192 // http://crbug.com/175760; several panel tests failing regularly on mac.
193 #if defined(OS_MACOSX)
194 #define MAYBE_ResizeDetachedPanel DISABLED_ResizeDetachedPanel
196 #define MAYBE_ResizeDetachedPanel ResizeDetachedPanel
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));
202 EXPECT_EQ(panel::RESIZABLE_ALL
, panel
->CanResizeByMouse());
204 gfx::Rect bounds
= panel
->GetBounds();
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
);
213 bounds
.set_width(bounds
.width() + 5);
214 EXPECT_EQ(bounds
, panel
->GetBounds());
216 panel_manager
->EndResizingByMouse(false);
217 EXPECT_EQ(bounds
, panel
->GetBounds());
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
);
225 bounds
.set_size(gfx::Size(bounds
.width() + 10, bounds
.height() + 15));
226 bounds
.Offset(-10, 0);
227 EXPECT_EQ(bounds
, panel
->GetBounds());
229 panel_manager
->EndResizingByMouse(false);
230 EXPECT_EQ(bounds
, panel
->GetBounds());
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
);
238 bounds
.set_size(gfx::Size(bounds
.width() + 30, bounds
.height() - 20));
239 bounds
.Offset(0, 20);
240 EXPECT_EQ(bounds
, panel
->GetBounds());
242 panel_manager
->EndResizingByMouse(false);
243 EXPECT_EQ(bounds
, panel
->GetBounds());
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
);
251 bounds
.set_size(gfx::Size(bounds
.width() + 20, bounds
.height() + 10));
252 bounds
.Offset(-20, -10);
253 EXPECT_EQ(bounds
, panel
->GetBounds());
255 panel_manager
->EndResizingByMouse(false);
256 EXPECT_EQ(bounds
, panel
->GetBounds());
258 PanelManager::GetInstance()->CloseAll();
261 // http://crbug.com/175760; several panel tests failing regularly on mac.
262 #if defined(OS_MACOSX)
263 #define MAYBE_TryResizePanelBelowMinimizeSize \
264 DISABLED_TryResizePanelBelowMinimizeSize
266 #define MAYBE_TryResizePanelBelowMinimizeSize TryResizePanelBelowMinimizeSize
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
));
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
;
281 gfx::Vector2d(resize_width
, resize_height
));
283 EXPECT_EQ(panel::kPanelMinWidth
, panel
->GetBounds().width());
284 EXPECT_EQ(panel::kPanelMinHeight
, panel
->GetBounds().height());
286 PanelManager::GetInstance()->CloseAll();
289 // http://crbug.com/175760; several panel tests failing regularly on mac.
290 #if defined(OS_MACOSX)
291 #define MAYBE_ResizeDetachedPanelToClampSize \
292 DISABLED_ResizeDetachedPanelToClampSize
294 #define MAYBE_ResizeDetachedPanelToClampSize ResizeDetachedPanelToClampSize
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));
301 EXPECT_EQ(panel::RESIZABLE_ALL
, panel
->CanResizeByMouse());
303 gfx::Rect bounds
= panel
->GetBounds();
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
);
312 bounds
.set_height(panel
->min_size().height());
313 EXPECT_EQ(bounds
, panel
->GetBounds());
315 panel_manager
->EndResizingByMouse(false);
316 EXPECT_EQ(bounds
, panel
->GetBounds());
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
);
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
);
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());
334 panel_manager
->EndResizingByMouse(false);
335 EXPECT_EQ(bounds
, panel
->GetBounds());
337 PanelManager::GetInstance()->CloseAll();
340 // http://crbug.com/175760; several panel tests failing regularly on mac.
341 #if defined(OS_MACOSX)
342 #define MAYBE_CloseDetachedPanelOnResize DISABLED_CloseDetachedPanelOnResize
344 #define MAYBE_CloseDetachedPanelOnResize CloseDetachedPanelOnResize
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();
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());
359 gfx::Rect panel1_bounds
= panel1
->GetBounds();
360 gfx::Rect panel2_bounds
= panel2
->GetBounds();
361 gfx::Rect panel3_bounds
= panel3
->GetBounds();
363 // Start resizing panel1, and close panel2 in the process.
364 // Panel1 is not affected.
365 gfx::Point mouse_location
= panel1_bounds
.origin() +
366 gfx::Vector2d(1, panel1_bounds
.height() - 1);
367 panel_manager
->StartResizingByMouse(panel1
, mouse_location
, HTBOTTOMLEFT
);
368 mouse_location
.Offset(-10, 15);
369 panel_manager
->ResizeByMouse(mouse_location
);
371 panel1_bounds
.set_size(gfx::Size(panel1_bounds
.width() + 10,
372 panel1_bounds
.height() + 15));
373 panel1_bounds
.Offset(-10, 0);
374 EXPECT_EQ(panel1_bounds
, panel1
->GetBounds());
376 CloseWindowAndWait(panel2
);
377 EXPECT_TRUE(resize_controller
->IsResizing());
378 EXPECT_EQ(2, detached_collection
->num_panels());
380 panel_manager
->EndResizingByMouse(false);
381 EXPECT_EQ(panel1_bounds
, panel1
->GetBounds());
383 // Start resizing panel3, and close it in the process.
384 // Resize should abort, panel1 will not be affected.
385 mouse_location
= panel3_bounds
.origin() +
386 gfx::Vector2d(panel3_bounds
.width() - 1, panel3_bounds
.height() - 2);
387 panel_manager
->StartResizingByMouse(panel3
, mouse_location
, HTBOTTOMRIGHT
);
388 mouse_location
.Offset(7, -12);
389 panel_manager
->ResizeByMouse(mouse_location
);
391 panel3_bounds
.set_size(gfx::Size(panel3_bounds
.width() + 7,
392 panel3_bounds
.height() - 12));
393 EXPECT_EQ(panel3_bounds
, panel3
->GetBounds());
395 CloseWindowAndWait(panel3
);
396 EXPECT_EQ(1, detached_collection
->num_panels());
397 // Since we closed the panel we were resizing, we should be out of the
398 // resizing mode by now.
399 EXPECT_FALSE(resize_controller
->IsResizing());
401 panel_manager
->EndResizingByMouse(false);
402 EXPECT_FALSE(resize_controller
->IsResizing());
403 EXPECT_EQ(panel1_bounds
, panel1
->GetBounds());
405 panel_manager
->CloseAll();
408 // http://crbug.com/175760; several panel tests failing regularly on mac.
409 #if defined(OS_MACOSX)
410 #define MAYBE_ResizeAndCancel DISABLED_ResizeAndCancel
412 #define MAYBE_ResizeAndCancel ResizeAndCancel
414 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest
, MAYBE_ResizeAndCancel
) {
415 PanelManager
* panel_manager
= PanelManager::GetInstance();
416 Panel
* panel
= CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
417 PanelResizeController
* resize_controller
= panel_manager
->resize_controller();
419 EXPECT_EQ(panel::RESIZABLE_ALL
, panel
->CanResizeByMouse());
421 gfx::Rect original_bounds
= panel
->GetBounds();
423 // Resizing the panel, then cancelling should return it to the original state.
424 // Try resizing by the top right side.
425 gfx::Rect bounds
= panel
->GetBounds();
426 gfx::Point mouse_location
= bounds
.origin() +
427 gfx::Vector2d(bounds
.width() - 1, 1);
428 panel_manager
->StartResizingByMouse(panel
, mouse_location
, HTTOPRIGHT
);
429 mouse_location
.Offset(5, 25);
430 panel_manager
->ResizeByMouse(mouse_location
);
432 bounds
.set_size(gfx::Size(bounds
.width() + 5, bounds
.height() - 25));
433 bounds
.Offset(0, 25);
434 EXPECT_EQ(bounds
, panel
->GetBounds());
436 panel_manager
->EndResizingByMouse(true);
437 EXPECT_EQ(original_bounds
, panel
->GetBounds());
439 // Try resizing by the bottom left side.
440 bounds
= panel
->GetBounds();
441 mouse_location
= bounds
.origin() + gfx::Vector2d(1, bounds
.height() - 1);
442 panel_manager
->StartResizingByMouse(panel
, mouse_location
, HTBOTTOMLEFT
);
443 mouse_location
.Offset(-10, 15);
444 panel_manager
->ResizeByMouse(mouse_location
);
446 bounds
.set_size(gfx::Size(bounds
.width() + 10, bounds
.height() + 15));
447 bounds
.Offset(-10, 0);
448 EXPECT_EQ(bounds
, panel
->GetBounds());
450 panel_manager
->EndResizingByMouse(true);
451 EXPECT_EQ(original_bounds
, panel
->GetBounds());
452 EXPECT_FALSE(resize_controller
->IsResizing());
454 panel_manager
->CloseAll();
457 // http://crbug.com/175760; several panel tests failing regularly on mac.
458 #if defined(OS_MACOSX)
459 #define MAYBE_ResizeDetachedPanelToTop DISABLED_ResizeDetachedPanelToTop
461 #define MAYBE_ResizeDetachedPanelToTop ResizeDetachedPanelToTop
463 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest
, MAYBE_ResizeDetachedPanelToTop
) {
464 // Setup the test areas to have top-aligned bar excluded from work area.
465 const gfx::Rect
primary_display_area(0, 0, 800, 600);
466 const gfx::Rect
primary_work_area(0, 10, 800, 590);
467 mock_display_settings_provider()->SetPrimaryDisplay(
468 primary_display_area
, primary_work_area
);
470 PanelManager
* panel_manager
= PanelManager::GetInstance();
471 Panel
* panel
= CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
472 gfx::Rect bounds
= panel
->GetBounds();
474 // Try resizing by the top left corner.
475 gfx::Point mouse_location
= bounds
.origin();
476 panel_manager
->StartResizingByMouse(panel
,
480 // Try moving the mouse outside the top of the work area. Expect that panel's
481 // top position will not exceed the top of the work area.
482 mouse_location
= gfx::Point(250, 2);
483 panel_manager
->ResizeByMouse(mouse_location
);
485 bounds
.set_width(bounds
.width() + bounds
.x() - mouse_location
.x());
486 bounds
.set_height(bounds
.height() + bounds
.y() - primary_work_area
.y());
487 bounds
.set_x(mouse_location
.x());
488 bounds
.set_y(primary_work_area
.y());
489 EXPECT_EQ(bounds
, panel
->GetBounds());
491 // Try moving the mouse inside the work area. Expect that the panel can be
492 // resized without constraint.
493 mouse_location
= gfx::Point(280, 50);
494 panel_manager
->ResizeByMouse(mouse_location
);
496 bounds
.set_width(bounds
.width() + bounds
.x() - mouse_location
.x());
497 bounds
.set_height(bounds
.height() + bounds
.y() - mouse_location
.y());
498 bounds
.set_x(mouse_location
.x());
499 bounds
.set_y(mouse_location
.y());
500 EXPECT_EQ(bounds
, panel
->GetBounds());
502 panel_manager
->EndResizingByMouse(false);
503 EXPECT_EQ(bounds
, panel
->GetBounds());
505 panel_manager
->CloseAll();
508 // TODO(jianli): to be enabled for other platforms when stacked panels are
512 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest
, ResizeStackedPanels
) {
513 PanelManager
* panel_manager
= PanelManager::GetInstance();
515 // Create 3 stacked panels.
516 StackedPanelCollection
* stack
= panel_manager
->CreateStack();
517 gfx::Rect panel1_initial_bounds
= gfx::Rect(100, 50, 200, 150);
518 Panel
* panel1
= CreateStackedPanel("1", panel1_initial_bounds
, stack
);
519 gfx::Rect panel2_initial_bounds
= gfx::Rect(0, 0, 150, 100);
520 Panel
* panel2
= CreateStackedPanel("2", panel2_initial_bounds
, stack
);
521 gfx::Rect panel3_initial_bounds
= gfx::Rect(0, 0, 120, 110);
522 Panel
* panel3
= CreateStackedPanel("3", panel3_initial_bounds
, stack
);
523 ASSERT_EQ(3, panel_manager
->num_panels());
524 ASSERT_EQ(1, panel_manager
->num_stacks());
525 ASSERT_EQ(3, stack
->num_panels());
527 gfx::Size panel1_expected_full_size
= panel1_initial_bounds
.size();
528 EXPECT_EQ(panel1_expected_full_size
, panel1
->full_size());
529 gfx::Size
panel2_expected_full_size(panel1_initial_bounds
.width(),
530 panel2_initial_bounds
.height());
531 EXPECT_EQ(panel2_expected_full_size
, panel2
->full_size());
532 gfx::Size
panel3_expected_full_size(panel1_initial_bounds
.width(),
533 panel3_initial_bounds
.height());
534 EXPECT_EQ(panel3_expected_full_size
, panel3
->full_size());
536 gfx::Rect
panel1_expected_bounds(panel1_initial_bounds
);
537 EXPECT_EQ(panel1_expected_bounds
, panel1
->GetBounds());
538 gfx::Rect
panel2_expected_bounds(panel1_expected_bounds
.x(),
539 panel1_expected_bounds
.bottom(),
540 panel1_expected_bounds
.width(),
541 panel2_initial_bounds
.height());
542 EXPECT_EQ(panel2_expected_bounds
, panel2
->GetBounds());
543 gfx::Rect
panel3_expected_bounds(panel2_expected_bounds
.x(),
544 panel2_expected_bounds
.bottom(),
545 panel2_expected_bounds
.width(),
546 panel3_initial_bounds
.height());
547 EXPECT_EQ(panel3_expected_bounds
, panel3
->GetBounds());
549 // Resize by the top-left corner of the top panel.
550 // Expect that the width of all stacked panels get increased by the same
551 // amount and the top panel also expands in height.
552 int top_resize_width
= 15;
553 int top_resize_height
= 10;
556 gfx::Vector2d(-top_resize_width
, -top_resize_height
));
558 panel1_expected_full_size
.Enlarge(top_resize_width
, top_resize_height
);
559 EXPECT_EQ(panel1_expected_full_size
, panel1
->full_size());
560 panel2_expected_full_size
.Enlarge(top_resize_width
, 0);
561 EXPECT_EQ(panel2_expected_full_size
, panel2
->full_size());
562 panel3_expected_full_size
.Enlarge(top_resize_width
, 0);
563 EXPECT_EQ(panel3_expected_full_size
, panel3
->full_size());
565 panel1_expected_bounds
.SetRect(
566 panel1_expected_bounds
.x() - top_resize_width
,
567 panel1_expected_bounds
.y() - top_resize_height
,
568 panel1_expected_bounds
.width() + top_resize_width
,
569 panel1_expected_bounds
.height() + top_resize_height
);
570 EXPECT_EQ(panel1_expected_bounds
, panel1
->GetBounds());
571 panel2_expected_bounds
.set_x(panel2_expected_bounds
.x() - top_resize_width
);
572 panel2_expected_bounds
.set_width(
573 panel2_expected_bounds
.width() + top_resize_width
);
574 EXPECT_EQ(panel2_expected_bounds
, panel2
->GetBounds());
575 panel3_expected_bounds
.set_x(panel3_expected_bounds
.x() - top_resize_width
);
576 panel3_expected_bounds
.set_width(
577 panel3_expected_bounds
.width() + top_resize_width
);
578 EXPECT_EQ(panel3_expected_bounds
, panel3
->GetBounds());
580 // Resize by the bottom-right corner of the bottom panel.
581 // Expect that the width of all stacked panels get increased by the same
582 // amount and the bottom panel also shrinks in height.
583 int bottom_resize_width
= 12;
584 int bottom_resize_height
= 8;
587 gfx::Vector2d(-bottom_resize_width
, -bottom_resize_height
));
589 panel1_expected_full_size
.Enlarge(-bottom_resize_width
, 0);
590 EXPECT_EQ(panel1_expected_full_size
, panel1
->full_size());
591 panel2_expected_full_size
.Enlarge(-bottom_resize_width
, 0);
592 EXPECT_EQ(panel2_expected_full_size
, panel2
->full_size());
593 panel3_expected_full_size
.Enlarge(-bottom_resize_width
,
594 -bottom_resize_height
);
595 EXPECT_EQ(panel3_expected_full_size
, panel3
->full_size());
597 panel1_expected_bounds
.set_width(
598 panel1_expected_bounds
.width() - bottom_resize_width
);
599 EXPECT_EQ(panel1_expected_bounds
, panel1
->GetBounds());
600 panel2_expected_bounds
.set_width(
601 panel2_expected_bounds
.width() - bottom_resize_width
);
602 EXPECT_EQ(panel2_expected_bounds
, panel2
->GetBounds());
603 panel3_expected_bounds
.set_width(
604 panel3_expected_bounds
.width() - bottom_resize_width
);
605 panel3_expected_bounds
.set_height(
606 panel3_expected_bounds
.height() - bottom_resize_height
);
607 EXPECT_EQ(panel3_expected_bounds
, panel3
->GetBounds());
609 // Resize by the bottom edge of the middle panel.
610 // Expect that the height of the middle panel increases and the height of
611 // the bottom panel decreases by the same amount.
612 int middle_resize_height
= 5;
615 gfx::Vector2d(0, middle_resize_height
));
617 EXPECT_EQ(panel1_expected_full_size
, panel1
->full_size());
618 panel2_expected_full_size
.Enlarge(0, middle_resize_height
);
619 EXPECT_EQ(panel2_expected_full_size
, panel2
->full_size());
620 panel3_expected_full_size
.Enlarge(0, -middle_resize_height
);
621 EXPECT_EQ(panel3_expected_full_size
, panel3
->full_size());
623 EXPECT_EQ(panel1_expected_bounds
, panel1
->GetBounds());
624 panel2_expected_bounds
.set_height(
625 panel2_expected_bounds
.height() + middle_resize_height
);
626 EXPECT_EQ(panel2_expected_bounds
, panel2
->GetBounds());
627 panel3_expected_bounds
.set_y(
628 panel3_expected_bounds
.y() + middle_resize_height
);
629 panel3_expected_bounds
.set_height(
630 panel3_expected_bounds
.height() - middle_resize_height
);
631 EXPECT_EQ(panel3_expected_bounds
, panel3
->GetBounds());
633 // Collapse the middle panel.
635 WaitForBoundsAnimationFinished(panel2
);
636 EXPECT_TRUE(panel2
->IsMinimized());
638 EXPECT_EQ(panel1_expected_full_size
, panel1
->full_size());
639 EXPECT_EQ(panel2_expected_full_size
, panel2
->full_size());
640 EXPECT_EQ(panel3_expected_full_size
, panel3
->full_size());
642 EXPECT_EQ(panel1_expected_bounds
, panel1
->GetBounds());
643 panel2_expected_bounds
.set_height(panel2
->TitleOnlyHeight());
644 EXPECT_EQ(panel2_expected_bounds
, panel2
->GetBounds());
645 panel3_expected_bounds
.set_y(panel2_expected_bounds
.bottom());
646 EXPECT_EQ(panel3_expected_bounds
, panel3
->GetBounds());
648 // Resize by the bottom edge of the top panel.
649 // Expect that the height of the top panel increases and the height of
650 // the middle panel is not affected because it is collapsed.
651 top_resize_height
= 18;
654 gfx::Vector2d(0, top_resize_height
));
656 panel1_expected_full_size
.Enlarge(0, top_resize_height
);
657 EXPECT_EQ(panel1_expected_full_size
, panel1
->full_size());
658 EXPECT_EQ(panel2_expected_full_size
, panel2
->full_size());
659 EXPECT_EQ(panel3_expected_full_size
, panel3
->full_size());
661 panel1_expected_bounds
.set_height(
662 panel1_expected_bounds
.height() + top_resize_height
);
663 EXPECT_EQ(panel1_expected_bounds
, panel1
->GetBounds());
664 panel2_expected_bounds
.set_y(
665 panel2_expected_bounds
.y() + top_resize_height
);
666 EXPECT_EQ(panel2_expected_bounds
, panel2
->GetBounds());
667 panel3_expected_bounds
.set_y(
668 panel3_expected_bounds
.y() + top_resize_height
);
669 EXPECT_EQ(panel3_expected_bounds
, panel3
->GetBounds());
671 panel_manager
->CloseAll();