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 "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"
12
13class PanelResizeBrowserTest : public BasePanelBrowserTest {
14 public:
15  PanelResizeBrowserTest() : BasePanelBrowserTest() {
16  }
17
18  virtual ~PanelResizeBrowserTest() {
19  }
20
21  virtual 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
82IN_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
198IN_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
268IN_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
296IN_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
346IN_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 panel2_bounds = panel2->GetBounds();
361  gfx::Rect panel3_bounds = panel3->GetBounds();
362
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);
370
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());
375
376  CloseWindowAndWait(panel2);
377  EXPECT_TRUE(resize_controller->IsResizing());
378  EXPECT_EQ(2, detached_collection->num_panels());
379
380  panel_manager->EndResizingByMouse(false);
381  EXPECT_EQ(panel1_bounds, panel1->GetBounds());
382
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);
390
391  panel3_bounds.set_size(gfx::Size(panel3_bounds.width() + 7,
392                                   panel3_bounds.height() - 12));
393  EXPECT_EQ(panel3_bounds, panel3->GetBounds());
394
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());
400
401  panel_manager->EndResizingByMouse(false);
402  EXPECT_FALSE(resize_controller->IsResizing());
403  EXPECT_EQ(panel1_bounds, panel1->GetBounds());
404
405  panel_manager->CloseAll();
406}
407
408// http://crbug.com/175760; several panel tests failing regularly on mac.
409#if defined(OS_MACOSX)
410#define MAYBE_ResizeAndCancel DISABLED_ResizeAndCancel
411#else
412#define MAYBE_ResizeAndCancel ResizeAndCancel
413#endif
414IN_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();
418
419  EXPECT_EQ(panel::RESIZABLE_ALL, panel->CanResizeByMouse());
420
421  gfx::Rect original_bounds = panel->GetBounds();
422
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);
431
432  bounds.set_size(gfx::Size(bounds.width() + 5, bounds.height() - 25));
433  bounds.Offset(0, 25);
434  EXPECT_EQ(bounds, panel->GetBounds());
435
436  panel_manager->EndResizingByMouse(true);
437  EXPECT_EQ(original_bounds, panel->GetBounds());
438
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);
445
446  bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15));
447  bounds.Offset(-10, 0);
448  EXPECT_EQ(bounds, panel->GetBounds());
449
450  panel_manager->EndResizingByMouse(true);
451  EXPECT_EQ(original_bounds, panel->GetBounds());
452  EXPECT_FALSE(resize_controller->IsResizing());
453
454  panel_manager->CloseAll();
455}
456
457// http://crbug.com/175760; several panel tests failing regularly on mac.
458#if defined(OS_MACOSX)
459#define MAYBE_ResizeDetachedPanelToTop DISABLED_ResizeDetachedPanelToTop
460#else
461#define MAYBE_ResizeDetachedPanelToTop ResizeDetachedPanelToTop
462#endif
463IN_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);
469
470  PanelManager* panel_manager = PanelManager::GetInstance();
471  Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200));
472  gfx::Rect bounds = panel->GetBounds();
473
474  // Try resizing by the top left corner.
475  gfx::Point mouse_location = bounds.origin();
476  panel_manager->StartResizingByMouse(panel,
477                                      mouse_location,
478                                      HTTOPLEFT);
479
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);
484
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());
490
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);
495
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());
501
502  panel_manager->EndResizingByMouse(false);
503  EXPECT_EQ(bounds, panel->GetBounds());
504
505  panel_manager->CloseAll();
506}
507
508// TODO(jianli): to be enabled for other platforms when stacked panels are
509// supported.
510#if defined(OS_WIN)
511
512IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeStackedPanels) {
513  PanelManager* panel_manager = PanelManager::GetInstance();
514
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());
526
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());
535
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());
548
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;
554  ResizePanel(panel1,
555              HTTOPLEFT,
556              gfx::Vector2d(-top_resize_width, -top_resize_height));
557
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());
564
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());
579
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;
585  ResizePanel(panel3,
586              HTBOTTOMRIGHT,
587              gfx::Vector2d(-bottom_resize_width, -bottom_resize_height));
588
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());
596
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());
608
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;
613  ResizePanel(panel2,
614              HTBOTTOM,
615              gfx::Vector2d(0, middle_resize_height));
616
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());
622
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());
632
633  // Collapse the middle panel.
634  panel2->Minimize();
635  WaitForBoundsAnimationFinished(panel2);
636  EXPECT_TRUE(panel2->IsMinimized());
637
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());
641
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());
647
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;
652  ResizePanel(panel1,
653              HTBOTTOM,
654              gfx::Vector2d(0, top_resize_height));
655
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());
660
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());
670
671  panel_manager->CloseAll();
672}
673
674#endif
675