Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / panels / panel_resize_browsertest.cc
blob391ff5c40de53c5bfc43d3bf8bc387d0d2492e3e
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 {
14 public:
15 PanelResizeBrowserTest() : BasePanelBrowserTest() {
18 ~PanelResizeBrowserTest() override {}
20 void SetUpOnMainThread() override {
21 BasePanelBrowserTest::SetUpOnMainThread();
23 // All the tests here assume using mocked 800x600 display area for the
24 // primary monitor. Do the check now.
25 gfx::Rect primary_display_area = PanelManager::GetInstance()->
26 display_settings_provider()->GetPrimaryDisplayArea();
27 DCHECK(primary_display_area.width() == 800);
28 DCHECK(primary_display_area.height() == 600);
31 void ResizePanel(Panel* panel,
32 int component,
33 const gfx::Vector2d& delta) {
34 PanelManager* panel_manager = PanelManager::GetInstance();
35 gfx::Rect bounds = panel->GetBounds();
36 gfx::Point mouse_location;
37 switch (component) {
38 case HTTOPLEFT:
39 mouse_location = bounds.origin();
40 break;
41 case HTTOP:
42 mouse_location.SetPoint(bounds.x() + bounds.width() / 2, bounds.y());
43 break;
44 case HTTOPRIGHT:
45 mouse_location.SetPoint(bounds.right(), bounds.y());
46 break;
47 case HTLEFT:
48 mouse_location.SetPoint(bounds.x(), bounds.y() + bounds.height() / 2);
49 break;
50 case HTRIGHT:
51 mouse_location.SetPoint(bounds.right(),
52 bounds.y() + bounds.height() / 2);
53 break;
54 case HTBOTTOMLEFT:
55 mouse_location.SetPoint(bounds.x(), bounds.bottom());
56 break;
57 case HTBOTTOM:
58 mouse_location.SetPoint(bounds.x() + bounds.width() / 2,
59 bounds.bottom());
60 break;
61 case HTBOTTOMRIGHT:
62 mouse_location.SetPoint(bounds.right(), bounds.bottom());
63 break;
64 default:
65 NOTREACHED();
66 break;
68 panel_manager->StartResizingByMouse(panel, mouse_location, component);
69 mouse_location += delta;
70 panel_manager->ResizeByMouse(mouse_location);
71 panel_manager->EndResizingByMouse(false);
75 // http://crbug.com/175760; several panel tests failing regularly on mac.
76 #if defined(OS_MACOSX)
77 #define MAYBE_DockedPanelResizability DISABLED_DockedPanelResizability
78 #else
79 #define MAYBE_DockedPanelResizability DockedPanelResizability
80 #endif
81 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_DockedPanelResizability) {
82 PanelManager* panel_manager = PanelManager::GetInstance();
83 Panel* panel = CreatePanel("Panel");
85 EXPECT_EQ(panel::RESIZABLE_EXCEPT_BOTTOM, panel->CanResizeByMouse());
87 gfx::Rect bounds = panel->GetBounds();
89 // Try resizing by the top left corner.
90 gfx::Point mouse_location = bounds.origin();
91 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPLEFT);
92 mouse_location.Offset(-20, -10);
93 panel_manager->ResizeByMouse(mouse_location);
95 bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10));
96 bounds.Offset(-20, -10);
97 EXPECT_EQ(bounds, panel->GetBounds());
99 panel_manager->EndResizingByMouse(false);
100 EXPECT_EQ(bounds, panel->GetBounds());
102 // Try resizing by the top.
103 mouse_location = bounds.origin() + gfx::Vector2d(10, 1);
104 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOP);
105 mouse_location.Offset(5, -10);
106 panel_manager->ResizeByMouse(mouse_location);
108 bounds.set_height(bounds.height() + 10);
109 bounds.Offset(0, -10);
110 EXPECT_EQ(bounds, panel->GetBounds());
112 panel_manager->EndResizingByMouse(false);
113 EXPECT_EQ(bounds, panel->GetBounds());
115 // Try resizing by the left side.
116 mouse_location = bounds.origin() + gfx::Vector2d(1, 30);
117 panel_manager->StartResizingByMouse(panel, mouse_location, HTLEFT);
118 mouse_location.Offset(-5, 25);
119 panel_manager->ResizeByMouse(mouse_location);
121 bounds.set_width(bounds.width() + 5);
122 bounds.Offset(-5, 0);
123 EXPECT_EQ(bounds, panel->GetBounds());
125 panel_manager->EndResizingByMouse(false);
126 EXPECT_EQ(bounds, panel->GetBounds());
128 // Try resizing by the top right side.
129 mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 2);
130 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPRIGHT);
131 mouse_location.Offset(30, 20);
132 panel_manager->ResizeByMouse(mouse_location);
134 bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20));
135 bounds.Offset(0, 20);
136 EXPECT_EQ(bounds, panel->GetBounds());
138 panel_manager->EndResizingByMouse(false);
139 WaitForBoundsAnimationFinished(panel);
140 bounds.Offset(-30, 0); // Layout of panel adjusted in docked collection.
141 EXPECT_EQ(bounds, panel->GetBounds());
143 // Try resizing by the right side.
144 mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 30);
145 panel_manager->StartResizingByMouse(panel, mouse_location, HTRIGHT);
146 mouse_location.Offset(5, 25);
147 panel_manager->ResizeByMouse(mouse_location);
149 bounds.set_width(bounds.width() + 5);
150 EXPECT_EQ(bounds, panel->GetBounds());
152 panel_manager->EndResizingByMouse(false);
153 WaitForBoundsAnimationFinished(panel);
154 bounds.Offset(-5, 0); // Layout of panel adjusted in docked collection.
155 EXPECT_EQ(bounds, panel->GetBounds());
157 // Try resizing by the bottom side; verify resize won't work.
158 mouse_location = bounds.origin() + gfx::Vector2d(10, bounds.height() - 1);
159 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOM);
160 mouse_location.Offset(30, -10);
161 panel_manager->ResizeByMouse(mouse_location);
162 EXPECT_EQ(bounds, panel->GetBounds());
164 panel_manager->EndResizingByMouse(false);
165 EXPECT_EQ(bounds, panel->GetBounds());
167 // Try resizing by the bottom left corner; verify resize won't work.
168 mouse_location = bounds.origin() + gfx::Vector2d(1, bounds.height() - 1);
169 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMLEFT);
170 mouse_location.Offset(-10, 15);
171 panel_manager->ResizeByMouse(mouse_location);
172 EXPECT_EQ(bounds, panel->GetBounds());
174 panel_manager->EndResizingByMouse(false);
175 EXPECT_EQ(bounds, panel->GetBounds());
177 // Try resizing by the bottom right corner; verify resize won't work.
178 mouse_location = bounds.origin() +
179 gfx::Vector2d(bounds.width() - 2, bounds.height());
180 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMRIGHT);
181 mouse_location.Offset(20, 10);
182 panel_manager->ResizeByMouse(mouse_location);
183 EXPECT_EQ(bounds, panel->GetBounds());
185 panel_manager->EndResizingByMouse(false);
186 EXPECT_EQ(bounds, panel->GetBounds());
188 panel->Close();
191 // http://crbug.com/175760; several panel tests failing regularly on mac.
192 #if defined(OS_MACOSX)
193 #define MAYBE_ResizeDetachedPanel DISABLED_ResizeDetachedPanel
194 #else
195 #define MAYBE_ResizeDetachedPanel ResizeDetachedPanel
196 #endif
197 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, MAYBE_ResizeDetachedPanel) {
198 PanelManager* panel_manager = PanelManager::GetInstance();
199 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
201 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
203 gfx::Rect bounds = panel->GetBounds();
205 // Try resizing by the right side; verify resize will change width only.
206 gfx::Point mouse_location = bounds.origin() +
207 gfx::Vector2d(bounds.width() - 1, 30);
208 panel_manager->StartResizingByMouse(panel, mouse_location, HTRIGHT);
209 mouse_location.Offset(5, 25);
210 panel_manager->ResizeByMouse(mouse_location);
212 bounds.set_width(bounds.width() + 5);
213 EXPECT_EQ(bounds, panel->GetBounds());
215 panel_manager->EndResizingByMouse(false);
216 EXPECT_EQ(bounds, panel->GetBounds());
218 // Try resizing by the bottom left side.
219 mouse_location = bounds.origin() + gfx::Vector2d(1, bounds.height() - 1);
220 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMLEFT);
221 mouse_location.Offset(-10, 15);
222 panel_manager->ResizeByMouse(mouse_location);
224 bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15));
225 bounds.Offset(-10, 0);
226 EXPECT_EQ(bounds, panel->GetBounds());
228 panel_manager->EndResizingByMouse(false);
229 EXPECT_EQ(bounds, panel->GetBounds());
231 // Try resizing by the top right side.
232 mouse_location = bounds.origin() + gfx::Vector2d(bounds.width() - 1, 2);
233 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPRIGHT);
234 mouse_location.Offset(30, 20);
235 panel_manager->ResizeByMouse(mouse_location);
237 bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20));
238 bounds.Offset(0, 20);
239 EXPECT_EQ(bounds, panel->GetBounds());
241 panel_manager->EndResizingByMouse(false);
242 EXPECT_EQ(bounds, panel->GetBounds());
244 // Try resizing by the top left side.
245 mouse_location = bounds.origin() + gfx::Vector2d(1, 0);
246 panel_manager->StartResizingByMouse(panel, mouse_location, HTTOPLEFT);
247 mouse_location.Offset(-20, -10);
248 panel_manager->ResizeByMouse(mouse_location);
250 bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10));
251 bounds.Offset(-20, -10);
252 EXPECT_EQ(bounds, panel->GetBounds());
254 panel_manager->EndResizingByMouse(false);
255 EXPECT_EQ(bounds, panel->GetBounds());
257 PanelManager::GetInstance()->CloseAll();
260 // http://crbug.com/175760; several panel tests failing regularly on mac.
261 #if defined(OS_MACOSX)
262 #define MAYBE_TryResizePanelBelowMinimizeSize \
263 DISABLED_TryResizePanelBelowMinimizeSize
264 #else
265 #define MAYBE_TryResizePanelBelowMinimizeSize TryResizePanelBelowMinimizeSize
266 #endif
267 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest,
268 MAYBE_TryResizePanelBelowMinimizeSize) {
269 int initial_width = 150;
270 int initial_height = 100;
271 Panel* panel = CreateDetachedPanel("1",
272 gfx::Rect(300, 200, initial_width, initial_height));
274 // Try to resize the panel below the minimum size. Expect that the panel
275 // shrinks to the minimum size.
276 int resize_width = panel::kPanelMinWidth / 2 - initial_width;
277 int resize_height = panel::kPanelMinHeight / 2 - initial_height;
278 ResizePanel(panel,
279 HTBOTTOMRIGHT,
280 gfx::Vector2d(resize_width, resize_height));
282 EXPECT_EQ(panel::kPanelMinWidth, panel->GetBounds().width());
283 EXPECT_EQ(panel::kPanelMinHeight, panel->GetBounds().height());
285 PanelManager::GetInstance()->CloseAll();
288 // http://crbug.com/175760; several panel tests failing regularly on mac.
289 #if defined(OS_MACOSX)
290 #define MAYBE_ResizeDetachedPanelToClampSize \
291 DISABLED_ResizeDetachedPanelToClampSize
292 #else
293 #define MAYBE_ResizeDetachedPanelToClampSize ResizeDetachedPanelToClampSize
294 #endif
295 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest,
296 MAYBE_ResizeDetachedPanelToClampSize) {
297 PanelManager* panel_manager = PanelManager::GetInstance();
298 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100));
300 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
302 gfx::Rect bounds = panel->GetBounds();
304 // Make sure the panel does not resize smaller than its min size.
305 gfx::Point mouse_location = bounds.origin() +
306 gfx::Vector2d(30, bounds.height() - 2);
307 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOM);
308 mouse_location.Offset(-20, -500);
309 panel_manager->ResizeByMouse(mouse_location);
311 bounds.set_height(panel->min_size().height());
312 EXPECT_EQ(bounds, panel->GetBounds());
314 panel_manager->EndResizingByMouse(false);
315 EXPECT_EQ(bounds, panel->GetBounds());
317 // Make sure the panel can resize larger than its size. User is in control.
318 mouse_location = bounds.origin() +
319 gfx::Vector2d(bounds.width(), bounds.height() - 2);
320 panel_manager->StartResizingByMouse(panel, mouse_location, HTBOTTOMRIGHT);
322 // This drag would take us beyond max size.
323 int delta_x = panel->max_size().width() + 10 - panel->GetBounds().width();
324 int delta_y = panel->max_size().height() + 10 - panel->GetBounds().height();
325 mouse_location.Offset(delta_x, delta_y);
326 panel_manager->ResizeByMouse(mouse_location);
328 // The bounds if the max_size does not limit the resize.
329 bounds.set_size(gfx::Size(bounds.width() + delta_x,
330 bounds.height() + delta_y));
331 EXPECT_EQ(bounds, panel->GetBounds());
333 panel_manager->EndResizingByMouse(false);
334 EXPECT_EQ(bounds, panel->GetBounds());
336 PanelManager::GetInstance()->CloseAll();
339 // http://crbug.com/175760; several panel tests failing regularly on mac.
340 #if defined(OS_MACOSX)
341 #define MAYBE_CloseDetachedPanelOnResize DISABLED_CloseDetachedPanelOnResize
342 #else
343 #define MAYBE_CloseDetachedPanelOnResize CloseDetachedPanelOnResize
344 #endif
345 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest,
346 MAYBE_CloseDetachedPanelOnResize) {
347 PanelManager* panel_manager = PanelManager::GetInstance();
348 PanelResizeController* resize_controller = panel_manager->resize_controller();
349 DetachedPanelCollection* detached_collection =
350 panel_manager->detached_collection();
352 // Create 3 detached panels.
353 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 200, 100, 100));
354 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 210, 110, 110));
355 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(300, 220, 120, 120));
356 ASSERT_EQ(3, detached_collection->num_panels());
358 gfx::Rect panel1_bounds = panel1->GetBounds();
359 gfx::Rect panel2_bounds = panel2->GetBounds();
360 gfx::Rect panel3_bounds = panel3->GetBounds();
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);
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());
375 CloseWindowAndWait(panel2);
376 EXPECT_TRUE(resize_controller->IsResizing());
377 EXPECT_EQ(2, detached_collection->num_panels());
379 panel_manager->EndResizingByMouse(false);
380 EXPECT_EQ(panel1_bounds, panel1->GetBounds());
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);
390 panel3_bounds.set_size(gfx::Size(panel3_bounds.width() + 7,
391 panel3_bounds.height() - 12));
392 EXPECT_EQ(panel3_bounds, panel3->GetBounds());
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());
400 panel_manager->EndResizingByMouse(false);
401 EXPECT_FALSE(resize_controller->IsResizing());
402 EXPECT_EQ(panel1_bounds, panel1->GetBounds());
404 panel_manager->CloseAll();
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();
418 EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
420 gfx::Rect original_bounds = panel->GetBounds();
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);
431 bounds.set_size(gfx::Size(bounds.width() + 5, bounds.height() - 25));
432 bounds.Offset(0, 25);
433 EXPECT_EQ(bounds, panel->GetBounds());
435 panel_manager->EndResizingByMouse(true);
436 EXPECT_EQ(original_bounds, panel->GetBounds());
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);
445 bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15));
446 bounds.Offset(-10, 0);
447 EXPECT_EQ(bounds, panel->GetBounds());
449 panel_manager->EndResizingByMouse(true);
450 EXPECT_EQ(original_bounds, panel->GetBounds());
451 EXPECT_FALSE(resize_controller->IsResizing());
453 panel_manager->CloseAll();
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);
469 PanelManager* panel_manager = PanelManager::GetInstance();
470 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
471 gfx::Rect bounds = panel->GetBounds();
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);
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);
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());
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);
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());
501 panel_manager->EndResizingByMouse(false);
502 EXPECT_EQ(bounds, panel->GetBounds());
504 panel_manager->CloseAll();
507 // TODO(jianli): to be enabled for other platforms when stacked panels are
508 // supported.
509 #if defined(OS_WIN)
511 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeStackedPanels) {
512 PanelManager* panel_manager = PanelManager::GetInstance();
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());
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());
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());
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));
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());
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());
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));
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());
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());
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));
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());
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());
632 // Collapse the middle panel.
633 panel2->Minimize();
634 WaitForBoundsAnimationFinished(panel2);
635 EXPECT_TRUE(panel2->IsMinimized());
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());
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());
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));
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());
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());
670 panel_manager->CloseAll();
673 #endif