Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / panels / stacked_panel_browsertest.cc
bloba59008828dbfe3bc7d3809e8b922c21926268305
1 // Copyright (c) 2013 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/browser.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/docked_panel_collection.h"
9 #include "chrome/browser/ui/panels/native_panel.h"
10 #include "chrome/browser/ui/panels/panel.h"
11 #include "chrome/browser/ui/panels/panel_manager.h"
12 #include "chrome/browser/ui/panels/stacked_panel_collection.h"
13 #include "chrome/browser/web_applications/web_app.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/test/test_utils.h"
17 class StackedPanelBrowserTest : public BasePanelBrowserTest {
20 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, CheckStackedPanelProperties) {
21 PanelManager* panel_manager = PanelManager::GetInstance();
23 // Create 2 stacked panels.
24 StackedPanelCollection* stack = panel_manager->CreateStack();
25 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
26 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
27 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
28 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
29 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 110);
30 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
32 scoped_ptr<NativePanelTesting> panel1_testing(
33 CreateNativePanelTesting(panel1));
34 scoped_ptr<NativePanelTesting> panel2_testing(
35 CreateNativePanelTesting(panel2));
36 scoped_ptr<NativePanelTesting> panel3_testing(
37 CreateNativePanelTesting(panel3));
39 // Check that all 3 panels are in a stack.
40 ASSERT_EQ(0, panel_manager->docked_collection()->num_panels());
41 ASSERT_EQ(0, panel_manager->detached_collection()->num_panels());
42 ASSERT_EQ(1, panel_manager->num_stacks());
43 ASSERT_EQ(3, stack->num_panels());
44 EXPECT_EQ(stack, panel1->stack());
45 EXPECT_EQ(stack, panel2->stack());
46 EXPECT_EQ(stack, panel3->stack());
48 // Check buttons.
49 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::CLOSE_BUTTON));
50 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::CLOSE_BUTTON));
51 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::CLOSE_BUTTON));
53 if (PanelManager::CanUseSystemMinimize())
54 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
55 else
56 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
57 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
58 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
60 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::RESTORE_BUTTON));
61 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::RESTORE_BUTTON));
62 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::RESTORE_BUTTON));
64 // Check bounds.
65 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
66 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
67 gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(),
68 panel1_expected_bounds.bottom(),
69 panel1_expected_bounds.width(),
70 panel2_initial_bounds.height());
71 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
72 gfx::Rect panel3_expected_bounds(panel2_expected_bounds.x(),
73 panel2_expected_bounds.bottom(),
74 panel2_expected_bounds.width(),
75 panel3_initial_bounds.height());
76 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
78 // Check other properties.
79 EXPECT_FALSE(panel1->IsAlwaysOnTop());
80 EXPECT_FALSE(panel2->IsAlwaysOnTop());
81 EXPECT_FALSE(panel3->IsAlwaysOnTop());
83 EXPECT_FALSE(panel1->IsMinimized());
84 EXPECT_FALSE(panel2->IsMinimized());
85 EXPECT_FALSE(panel3->IsMinimized());
87 EXPECT_EQ(panel::RESIZABLE_LEFT | panel::RESIZABLE_RIGHT |
88 panel::RESIZABLE_TOP | panel::RESIZABLE_TOP_LEFT |
89 panel::RESIZABLE_TOP_RIGHT | panel::RESIZABLE_BOTTOM,
90 panel1->CanResizeByMouse());
91 EXPECT_EQ(panel::RESIZABLE_LEFT | panel::RESIZABLE_RIGHT |
92 panel::RESIZABLE_BOTTOM,
93 panel2->CanResizeByMouse());
94 EXPECT_EQ(panel::RESIZABLE_LEFT | panel::RESIZABLE_RIGHT |
95 panel::RESIZABLE_BOTTOM | panel::RESIZABLE_BOTTOM_LEFT |
96 panel::RESIZABLE_BOTTOM_RIGHT,
97 panel3->CanResizeByMouse());
99 EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
100 EXPECT_EQ(panel::NOT_ROUNDED, panel2_testing->GetWindowCornerStyle());
101 EXPECT_EQ(panel::BOTTOM_ROUNDED, panel3_testing->GetWindowCornerStyle());
103 Panel::AttentionMode expected_attention_mode =
104 static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
105 Panel::USE_SYSTEM_ATTENTION);
106 EXPECT_EQ(expected_attention_mode, panel1->attention_mode());
107 EXPECT_EQ(expected_attention_mode, panel2->attention_mode());
108 EXPECT_EQ(expected_attention_mode, panel3->attention_mode());
110 panel_manager->CloseAll();
113 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
114 CheckMinimizedStackedPanelProperties) {
115 PanelManager* panel_manager = PanelManager::GetInstance();
117 // Create 2 stacked panels.
118 StackedPanelCollection* stack = panel_manager->CreateStack();
119 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
120 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
121 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
122 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
123 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 120, 110);
124 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
126 scoped_ptr<NativePanelTesting> panel1_testing(
127 CreateNativePanelTesting(panel1));
128 scoped_ptr<NativePanelTesting> panel2_testing(
129 CreateNativePanelTesting(panel2));
130 scoped_ptr<NativePanelTesting> panel3_testing(
131 CreateNativePanelTesting(panel3));
133 // Minimize these 2 panels.
134 panel1->Minimize();
135 WaitForBoundsAnimationFinished(panel1);
136 panel2->Minimize();
137 WaitForBoundsAnimationFinished(panel2);
138 panel3->Minimize();
139 WaitForBoundsAnimationFinished(panel3);
141 // Check that all 2 panels are in a stack.
142 ASSERT_EQ(0, panel_manager->docked_collection()->num_panels());
143 ASSERT_EQ(0, panel_manager->detached_collection()->num_panels());
144 ASSERT_EQ(1, panel_manager->num_stacks());
145 ASSERT_EQ(3, stack->num_panels());
146 EXPECT_EQ(stack, panel1->stack());
147 EXPECT_EQ(stack, panel2->stack());
148 EXPECT_EQ(stack, panel3->stack());
150 // Check buttons.
151 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::CLOSE_BUTTON));
152 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::CLOSE_BUTTON));
153 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::CLOSE_BUTTON));
155 if (PanelManager::CanUseSystemMinimize())
156 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
157 else
158 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
159 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
160 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
162 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::RESTORE_BUTTON));
163 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::RESTORE_BUTTON));
164 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::RESTORE_BUTTON));
166 // Check bounds.
167 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
168 panel1_expected_bounds.set_height(panel1->TitleOnlyHeight());
169 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
170 gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(),
171 panel1_expected_bounds.bottom(),
172 panel1_expected_bounds.width(),
173 panel2->TitleOnlyHeight());
174 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
175 gfx::Rect panel3_expected_bounds(panel2_expected_bounds.x(),
176 panel2_expected_bounds.bottom(),
177 panel2_expected_bounds.width(),
178 panel3->TitleOnlyHeight());
179 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
181 // Check other properties.
182 EXPECT_FALSE(panel1->IsAlwaysOnTop());
183 EXPECT_FALSE(panel2->IsAlwaysOnTop());
184 EXPECT_FALSE(panel3->IsAlwaysOnTop());
186 EXPECT_TRUE(panel1->IsMinimized());
187 EXPECT_TRUE(panel2->IsMinimized());
188 EXPECT_TRUE(panel3->IsMinimized());
190 EXPECT_EQ(panel::RESIZABLE_LEFT | panel::RESIZABLE_RIGHT,
191 panel1->CanResizeByMouse());
192 EXPECT_EQ(panel::RESIZABLE_LEFT | panel::RESIZABLE_RIGHT,
193 panel2->CanResizeByMouse());
194 EXPECT_EQ(panel::RESIZABLE_LEFT | panel::RESIZABLE_RIGHT,
195 panel3->CanResizeByMouse());
197 EXPECT_EQ(panel::TOP_ROUNDED, panel1_testing->GetWindowCornerStyle());
198 EXPECT_EQ(panel::NOT_ROUNDED, panel2_testing->GetWindowCornerStyle());
199 EXPECT_EQ(panel::BOTTOM_ROUNDED, panel3_testing->GetWindowCornerStyle());
201 Panel::AttentionMode expected_attention_mode =
202 static_cast<Panel::AttentionMode>(Panel::USE_PANEL_ATTENTION |
203 Panel::USE_SYSTEM_ATTENTION);
204 EXPECT_EQ(expected_attention_mode, panel1->attention_mode());
205 EXPECT_EQ(expected_attention_mode, panel2->attention_mode());
206 EXPECT_EQ(expected_attention_mode, panel3->attention_mode());
208 panel_manager->CloseAll();
211 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, ClickTitlebar) {
212 PanelManager* panel_manager = PanelManager::GetInstance();
214 // Create 2 stacked panels.
215 StackedPanelCollection* stack = panel_manager->CreateStack();
216 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
217 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
218 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
219 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
220 ASSERT_EQ(1, panel_manager->num_stacks());
222 scoped_ptr<NativePanelTesting> panel1_testing(
223 CreateNativePanelTesting(panel1));
224 scoped_ptr<NativePanelTesting> panel2_testing(
225 CreateNativePanelTesting(panel2));
227 gfx::Point panel1_origin = panel2->GetBounds().origin();
228 gfx::Point panel2_origin = panel2->GetBounds().origin();
230 EXPECT_FALSE(panel1->IsMinimized());
231 EXPECT_FALSE(panel2->IsMinimized());
233 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
234 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
235 gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(),
236 panel1_expected_bounds.bottom(),
237 panel1_expected_bounds.width(),
238 panel2_initial_bounds.height());
239 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
241 // Clicking on P2's titlebar to collapse it.
242 panel2_testing->PressLeftMouseButtonTitlebar(panel2_origin);
243 panel2_testing->ReleaseMouseButtonTitlebar();
244 WaitForBoundsAnimationFinished(panel2);
245 EXPECT_FALSE(panel1->IsMinimized());
246 EXPECT_TRUE(panel2->IsMinimized());
247 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
248 panel2_expected_bounds.set_height(panel2->TitleOnlyHeight());
249 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
251 // Clicking on P2's titlebar to expand it.
252 panel2_testing->PressLeftMouseButtonTitlebar(panel2_origin);
253 panel2_testing->ReleaseMouseButtonTitlebar();
254 WaitForBoundsAnimationFinished(panel2);
255 EXPECT_FALSE(panel1->IsMinimized());
256 EXPECT_FALSE(panel2->IsMinimized());
257 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
258 panel2_expected_bounds.set_height(panel2_initial_bounds.height());
259 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
261 // Clicking on P2's titlebar with APPLY_TO_ALL modifier to collapse all
262 // panels.
263 panel2_testing->PressLeftMouseButtonTitlebar(panel2_origin,
264 panel::APPLY_TO_ALL);
265 panel2_testing->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
266 WaitForBoundsAnimationFinished(panel1);
267 WaitForBoundsAnimationFinished(panel2);
268 EXPECT_TRUE(panel1->IsMinimized());
269 EXPECT_TRUE(panel2->IsMinimized());
270 panel1_expected_bounds.set_height(panel1->TitleOnlyHeight());
271 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
272 panel2_expected_bounds.set_y(panel1_expected_bounds.bottom());
273 panel2_expected_bounds.set_height(panel2->TitleOnlyHeight());
274 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
276 // Clicking on P1's titlebar with APPLY_TO_ALL modifier to expand all
277 // panels.
278 panel1_testing->PressLeftMouseButtonTitlebar(panel1_origin,
279 panel::APPLY_TO_ALL);
280 panel1_testing->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
281 WaitForBoundsAnimationFinished(panel1);
282 WaitForBoundsAnimationFinished(panel2);
283 EXPECT_FALSE(panel1->IsMinimized());
284 EXPECT_FALSE(panel2->IsMinimized());
285 panel1_expected_bounds.set_height(panel1_initial_bounds.height());
286 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
287 panel2_expected_bounds.set_y(panel1_expected_bounds.bottom());
288 panel2_expected_bounds.set_height(panel2_initial_bounds.height());
289 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
291 panel_manager->CloseAll();
294 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, CallMinimizeAndRestoreApi) {
295 PanelManager* panel_manager = PanelManager::GetInstance();
297 // Create 2 stacked panels.
298 StackedPanelCollection* stack = panel_manager->CreateStack();
299 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
300 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
301 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
302 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
303 ASSERT_EQ(1, panel_manager->num_stacks());
305 EXPECT_FALSE(panel1->IsMinimized());
306 EXPECT_FALSE(panel2->IsMinimized());
308 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
309 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
310 gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(),
311 panel1_expected_bounds.bottom(),
312 panel1_expected_bounds.width(),
313 panel2_initial_bounds.height());
314 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
316 // Collapsing P1 by calling its Minimize API.
317 panel1->Minimize();
318 WaitForBoundsAnimationFinished(panel1);
319 EXPECT_TRUE(panel1->IsMinimized());
320 EXPECT_FALSE(panel2->IsMinimized());
321 panel1_expected_bounds.set_height(panel1->TitleOnlyHeight());
322 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
323 panel2_expected_bounds.set_y(panel1_expected_bounds.bottom());
324 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
326 // Expanding P1 by calling its Restore API.
327 panel1->Restore();
328 WaitForBoundsAnimationFinished(panel1);
329 EXPECT_FALSE(panel1->IsMinimized());
330 EXPECT_FALSE(panel2->IsMinimized());
331 panel1_expected_bounds.set_height(panel1_initial_bounds.height());
332 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
333 panel2_expected_bounds.set_y(panel1_expected_bounds.bottom());
334 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
336 panel_manager->CloseAll();
339 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, ExpandToFitWithinScreen) {
340 PanelManager* panel_manager = PanelManager::GetInstance();
341 gfx::Rect work_area =
342 panel_manager->display_settings_provider()->GetPrimaryWorkArea();
344 // Create 4 stacked panels. P4 is the active panel.
345 StackedPanelCollection* stack = panel_manager->CreateStack();
346 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 90, 200, 150), stack);
347 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
348 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 150, 120), stack);
349 Panel* panel4 = CreateStackedPanel("4", gfx::Rect(0, 0, 150, 100), stack);
350 ASSERT_EQ(4, stack->num_panels());
351 ASSERT_FALSE(panel1->IsMinimized());
352 ASSERT_FALSE(panel2->IsMinimized());
353 ASSERT_FALSE(panel3->IsMinimized());
354 ASSERT_FALSE(panel4->IsMinimized());
355 EXPECT_LE(panel4->GetBounds().bottom(), work_area.bottom());
356 int old_stack_top_position = panel1->GetBounds().y();
358 // Collapse P2.
359 panel2->Minimize();
360 WaitForBoundsAnimationFinished(panel2);
361 ASSERT_FALSE(panel1->IsMinimized());
362 ASSERT_TRUE(panel2->IsMinimized());
363 ASSERT_FALSE(panel3->IsMinimized());
364 ASSERT_FALSE(panel4->IsMinimized());
366 // Grow P2's restored height.
367 gfx::Size panel2_full_size = panel2->full_size();
368 panel2_full_size.set_height(panel2_full_size.height() + 30);
369 panel2->set_full_size(panel2_full_size);
371 // Expand P2. Expect that the least recently active panel P1 is minimized in
372 // order to make space for P2.
373 panel2->Restore();
374 WaitForBoundsAnimationFinished(panel2);
375 WaitForBoundsAnimationFinished(panel3);
376 WaitForBoundsAnimationFinished(panel4);
377 ASSERT_TRUE(panel1->IsMinimized());
378 ASSERT_FALSE(panel2->IsMinimized());
379 ASSERT_FALSE(panel3->IsMinimized());
380 ASSERT_FALSE(panel4->IsMinimized());
381 EXPECT_EQ(old_stack_top_position, panel1->GetBounds().y());
382 EXPECT_LE(panel4->GetBounds().bottom(), work_area.bottom());
383 EXPECT_EQ(panel2->GetBounds().height(), panel2_full_size.height());
385 // Grow P1's restored height.
386 gfx::Size panel1_full_size = panel1->full_size();
387 panel1_full_size.set_height(panel1_full_size.height() + 180);
388 panel1->set_full_size(panel1_full_size);
390 // Expand P1. Expect that both P2 and P3 are collapsed and the stack moves
391 // up in order to make space for P1.
392 panel1->Restore();
393 WaitForBoundsAnimationFinished(panel1);
394 WaitForBoundsAnimationFinished(panel2);
395 WaitForBoundsAnimationFinished(panel3);
396 WaitForBoundsAnimationFinished(panel4);
397 ASSERT_FALSE(panel1->IsMinimized());
398 ASSERT_TRUE(panel2->IsMinimized());
399 ASSERT_TRUE(panel3->IsMinimized());
400 ASSERT_FALSE(panel4->IsMinimized());
401 EXPECT_LT(panel1->GetBounds().y(), old_stack_top_position);
402 EXPECT_GE(panel1->GetBounds().y(), work_area.y());
403 EXPECT_LE(panel4->GetBounds().bottom(), work_area.bottom());
404 EXPECT_EQ(panel1->GetBounds().height(), panel1_full_size.height());
405 old_stack_top_position = panel1->GetBounds().y();
407 // Expand P3. Expect that P1 get collapsed in order to make space for P3.
408 panel3->Restore();
409 WaitForBoundsAnimationFinished(panel1);
410 WaitForBoundsAnimationFinished(panel2);
411 WaitForBoundsAnimationFinished(panel3);
412 WaitForBoundsAnimationFinished(panel4);
413 ASSERT_TRUE(panel1->IsMinimized());
414 ASSERT_TRUE(panel2->IsMinimized());
415 ASSERT_FALSE(panel3->IsMinimized());
416 ASSERT_FALSE(panel4->IsMinimized());
417 EXPECT_EQ(old_stack_top_position, panel1->GetBounds().y());
418 EXPECT_LE(panel4->GetBounds().bottom(), work_area.bottom());
420 // Grow P2's restored height by a very large value such that the stack with
421 // P2 in full height will not fit within the screen.
422 panel2_full_size = panel2->full_size();
423 panel2_full_size.set_height(panel2_full_size.height() + 500);
424 panel2->set_full_size(panel2_full_size);
426 // Expand P2. Expect:
427 // 1) Both P1 and P3 are collapsed
428 // 2) The stack moves up to the top of the screen
429 // 3) P2's restored height is reduced
430 panel2->Restore();
431 WaitForBoundsAnimationFinished(panel1);
432 WaitForBoundsAnimationFinished(panel2);
433 WaitForBoundsAnimationFinished(panel3);
434 WaitForBoundsAnimationFinished(panel4);
435 EXPECT_TRUE(panel1->IsMinimized());
436 EXPECT_FALSE(panel2->IsMinimized());
437 EXPECT_TRUE(panel3->IsMinimized());
438 EXPECT_FALSE(panel4->IsMinimized());
439 EXPECT_EQ(panel1->GetBounds().y(), work_area.y());
440 EXPECT_EQ(panel4->GetBounds().bottom(), work_area.bottom());
441 EXPECT_LT(panel2->GetBounds().height(), panel2_full_size.height());
443 panel_manager->CloseAll();
446 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, ExpandAllToFitWithinScreen) {
447 PanelManager* panel_manager = PanelManager::GetInstance();
448 gfx::Rect work_area =
449 panel_manager->display_settings_provider()->GetPrimaryWorkArea();
451 // Create 3 stacked panels.
452 StackedPanelCollection* stack = panel_manager->CreateStack();
453 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 150, 200, 200), stack);
454 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
455 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 150, 120), stack);
456 ASSERT_EQ(3, stack->num_panels());
458 scoped_ptr<NativePanelTesting> panel2_testing(
459 CreateNativePanelTesting(panel2));
461 // Collapse all panels by clicking on P2's titlebar with APPLY_TO_ALL
462 // modifier.
463 panel2_testing->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
464 panel::APPLY_TO_ALL);
465 panel2_testing->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
466 WaitForBoundsAnimationFinished(panel1);
467 WaitForBoundsAnimationFinished(panel2);
468 WaitForBoundsAnimationFinished(panel3);
469 ASSERT_TRUE(panel1->IsMinimized());
470 ASSERT_TRUE(panel2->IsMinimized());
471 ASSERT_TRUE(panel3->IsMinimized());
473 // Grow P2's restored height by a very large value.
474 gfx::Size panel2_full_size = panel2->full_size();
475 panel2_full_size.set_height(panel2_full_size.height() + 500);
476 panel2->set_full_size(panel2_full_size);
478 // Expand all panels by clicking on P2's titlebar with APPLY_TO_ALL
479 // modifier again. Expect only P2 is expanded due to no available space for
480 // P1 and P3.
481 panel2_testing->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(),
482 panel::APPLY_TO_ALL);
483 panel2_testing->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL);
484 WaitForBoundsAnimationFinished(panel1);
485 WaitForBoundsAnimationFinished(panel2);
486 WaitForBoundsAnimationFinished(panel3);
487 EXPECT_TRUE(panel1->IsMinimized());
488 EXPECT_FALSE(panel2->IsMinimized());
489 EXPECT_TRUE(panel3->IsMinimized());
490 EXPECT_EQ(panel1->GetBounds().y(), work_area.y());
491 EXPECT_EQ(panel3->GetBounds().bottom(), work_area.bottom());
493 panel_manager->CloseAll();
496 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, MinimizeButtonVisibility) {
497 PanelManager* panel_manager = PanelManager::GetInstance();
499 // Create 3 stacked panels.
500 StackedPanelCollection* stack = panel_manager->CreateStack();
501 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
502 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
503 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
504 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
505 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 250, 120);
506 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
507 ASSERT_EQ(1, panel_manager->num_stacks());
508 ASSERT_EQ(3, stack->num_panels());
510 scoped_ptr<NativePanelTesting> panel1_testing(
511 CreateNativePanelTesting(panel1));
512 scoped_ptr<NativePanelTesting> panel2_testing(
513 CreateNativePanelTesting(panel2));
514 scoped_ptr<NativePanelTesting> panel3_testing(
515 CreateNativePanelTesting(panel3));
517 // Only P1 shows minimize button.
518 if (PanelManager::CanUseSystemMinimize())
519 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
520 else
521 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
522 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
523 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
525 // Drag P2 away to unstack from P1.
526 // Expect only P2, top panel of the stack consisting P2 and P3, shows minimize
527 // button.
528 gfx::Point mouse_location(panel2->GetBounds().origin());
529 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
530 gfx::Vector2d drag_delta_to_unstack(120, 50);
531 panel2_testing->DragTitlebar(mouse_location + drag_delta_to_unstack);
532 panel2_testing->FinishDragTitlebar();
533 ASSERT_EQ(1, panel_manager->detached_collection()->num_panels());
534 ASSERT_EQ(1, panel_manager->num_stacks());
535 ASSERT_EQ(2, stack->num_panels());
537 if (PanelManager::CanUseSystemMinimize()) {
538 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
539 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
540 } else {
541 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
542 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
544 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
546 // Drag P1 to stack to the top edge of P2.
547 // Expect only P1, top panel of the stack consisting P1, P2 and P3, shows
548 // minimize button.
549 gfx::Rect bounds1 = panel1->GetBounds();
550 gfx::Rect bounds2 = panel2->GetBounds();
551 mouse_location = bounds1.origin();
552 panel1_testing->PressLeftMouseButtonTitlebar(mouse_location);
553 gfx::Vector2d drag_delta_to_stack(bounds2.x() - bounds1.x(),
554 bounds2.y() - bounds1.bottom());
555 panel1_testing->DragTitlebar(mouse_location + drag_delta_to_stack);
556 panel1_testing->FinishDragTitlebar();
557 ASSERT_EQ(0, panel_manager->detached_collection()->num_panels());
558 ASSERT_EQ(1, panel_manager->num_stacks());
559 ASSERT_EQ(3, stack->num_panels());
561 if (PanelManager::CanUseSystemMinimize())
562 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
563 else
564 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
565 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
566 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON));
568 panel_manager->CloseAll();
571 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, DISABLED_ClickMinimizeButton) {
572 PanelManager* panel_manager = PanelManager::GetInstance();
574 // Create 2 stacked panels.
575 StackedPanelCollection* stack = panel_manager->CreateStack();
576 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
577 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
578 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
579 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
580 ASSERT_EQ(1, panel_manager->num_stacks());
582 scoped_ptr<NativePanelTesting> panel1_testing(
583 CreateNativePanelTesting(panel1));
585 EXPECT_FALSE(panel1->IsMinimized());
586 EXPECT_FALSE(panel2->IsMinimized());
588 // Collapsing P1 by calling its Minimize API.
589 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
590 EXPECT_FALSE(panel1->IsMinimized());
591 EXPECT_FALSE(panel2->IsMinimized());
592 EXPECT_TRUE(panel1_testing->VerifySystemMinimizeState());
594 panel_manager->CloseAll();
597 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, UngroupMinimizedPanels) {
598 PanelManager* panel_manager = PanelManager::GetInstance();
600 // Create 3 stacked panels.
601 StackedPanelCollection* stack = panel_manager->CreateStack();
602 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
603 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
604 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
605 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
606 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 250, 120);
607 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
608 ASSERT_EQ(1, panel_manager->num_stacks());
609 ASSERT_EQ(3, stack->num_panels());
611 scoped_ptr<NativePanelTesting> panel2_testing(
612 CreateNativePanelTesting(panel2));
613 scoped_ptr<NativePanelTesting> panel3_testing(
614 CreateNativePanelTesting(panel3));
616 // Minimize these 3 panels.
617 panel1->Minimize();
618 WaitForBoundsAnimationFinished(panel1);
619 panel2->Minimize();
620 WaitForBoundsAnimationFinished(panel3);
621 panel3->Minimize();
622 WaitForBoundsAnimationFinished(panel3);
624 EXPECT_TRUE(panel1->IsMinimized());
625 EXPECT_TRUE(panel2->IsMinimized());
626 EXPECT_TRUE(panel3->IsMinimized());
628 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
629 panel1_expected_bounds.set_height(panel1->TitleOnlyHeight());
630 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
631 gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(),
632 panel1_expected_bounds.bottom(),
633 panel1_expected_bounds.width(),
634 panel2->TitleOnlyHeight());
635 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
636 gfx::Rect panel3_expected_bounds(panel2_expected_bounds.x(),
637 panel2_expected_bounds.bottom(),
638 panel2_expected_bounds.width(),
639 panel3->TitleOnlyHeight());
640 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
642 // Drag P2 away to unstack from P1.
643 // Expect P2 and P3 are still stacked and minimized while P1 becomes detached
644 // and expanded. The minimize button of P2 should become visible now.
645 gfx::Point mouse_location(panel2->GetBounds().origin());
646 panel2_testing->PressLeftMouseButtonTitlebar(mouse_location);
647 gfx::Vector2d drag_delta(120, 50);
648 panel2_testing->DragTitlebar(mouse_location + drag_delta);
649 panel2_testing->FinishDragTitlebar();
650 WaitForBoundsAnimationFinished(panel1);
651 ASSERT_EQ(1, panel_manager->detached_collection()->num_panels());
652 ASSERT_EQ(1, panel_manager->num_stacks());
653 ASSERT_EQ(2, stack->num_panels());
655 EXPECT_FALSE(panel1->IsMinimized());
656 EXPECT_TRUE(panel2->IsMinimized());
657 EXPECT_TRUE(panel3->IsMinimized());
659 panel1_expected_bounds.set_height(panel1_initial_bounds.height());
660 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
661 panel2_expected_bounds.Offset(drag_delta);
662 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
663 panel3_expected_bounds.Offset(drag_delta);
664 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
666 // Drag P3 away to unstack from P2.
667 // Expect both panels become detached and expanded.
668 mouse_location = panel3->GetBounds().origin();
669 panel3_testing->PressLeftMouseButtonTitlebar(mouse_location);
670 panel3_testing->DragTitlebar(mouse_location + drag_delta);
671 panel3_testing->FinishDragTitlebar();
672 WaitForBoundsAnimationFinished(panel2);
673 WaitForBoundsAnimationFinished(panel3);
674 ASSERT_EQ(3, panel_manager->detached_collection()->num_panels());
675 ASSERT_EQ(0, panel_manager->num_stacks());
677 EXPECT_FALSE(panel1->IsMinimized());
678 EXPECT_FALSE(panel2->IsMinimized());
679 EXPECT_FALSE(panel3->IsMinimized());
681 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
682 panel2_expected_bounds.set_height(panel2_initial_bounds.height());
683 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
684 panel3_expected_bounds.Offset(drag_delta);
685 panel3_expected_bounds.set_height(panel3_initial_bounds.height());
686 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
688 panel_manager->CloseAll();
691 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
692 AddNewPanelToStackWithMostPanels) {
693 PanelManager* panel_manager = PanelManager::GetInstance();
695 // Create one stack with 2 panels.
696 StackedPanelCollection* stack1 = panel_manager->CreateStack();
697 CreateStackedPanel("1", gfx::Rect(200, 50, 200, 150), stack1);
698 CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack1);
699 ASSERT_EQ(2, panel_manager->num_panels());
700 ASSERT_EQ(1, panel_manager->num_stacks());
701 ASSERT_EQ(2, stack1->num_panels());
703 // Create another stack with 3 panels.
704 StackedPanelCollection* stack2 = panel_manager->CreateStack();
705 CreateStackedPanel("3", gfx::Rect(100, 50, 200, 150), stack2);
706 CreateStackedPanel("4", gfx::Rect(0, 0, 150, 100), stack2);
707 CreateStackedPanel("5", gfx::Rect(0, 0, 250, 120), stack2);
708 ASSERT_EQ(5, panel_manager->num_panels());
709 ASSERT_EQ(2, panel_manager->num_stacks());
710 ASSERT_EQ(3, stack2->num_panels());
712 // Create new panel. Expect that it will append to stack2 since it has most
713 // panels.
714 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
715 params.create_mode = PanelManager::CREATE_AS_DETACHED;
716 Panel* new_panel = CreatePanelWithParams(params);
717 EXPECT_EQ(6, panel_manager->num_panels());
718 EXPECT_EQ(2, panel_manager->num_stacks());
719 EXPECT_EQ(2, stack1->num_panels());
720 EXPECT_EQ(4, stack2->num_panels());
721 EXPECT_TRUE(stack2->HasPanel(new_panel));
722 EXPECT_TRUE(new_panel == stack2->bottom_panel());
724 panel_manager->CloseAll();
727 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
728 AddNewPanelToRightMostStack) {
729 PanelManager* panel_manager = PanelManager::GetInstance();
731 // Create one stack with 2 panels.
732 StackedPanelCollection* stack1 = panel_manager->CreateStack();
733 CreateStackedPanel("1", gfx::Rect(100, 50, 200, 150), stack1);
734 CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack1);
735 ASSERT_EQ(2, panel_manager->num_panels());
736 ASSERT_EQ(1, panel_manager->num_stacks());
737 ASSERT_EQ(2, stack1->num_panels());
739 // Create another stack with 2 panels.
740 StackedPanelCollection* stack2 = panel_manager->CreateStack();
741 CreateStackedPanel("3", gfx::Rect(200, 50, 200, 150), stack2);
742 CreateStackedPanel("4", gfx::Rect(0, 0, 150, 100), stack2);
743 ASSERT_EQ(4, panel_manager->num_panels());
744 ASSERT_EQ(2, panel_manager->num_stacks());
745 ASSERT_EQ(2, stack2->num_panels());
747 // Create new panel. Both stack1 and stack2 have same number of panels. Since
748 // stack2 is right-most, new panel will be added to it.
749 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
750 params.create_mode = PanelManager::CREATE_AS_DETACHED;
751 Panel* new_panel = CreatePanelWithParams(params);
752 EXPECT_EQ(5, panel_manager->num_panels());
753 EXPECT_EQ(2, panel_manager->num_stacks());
754 EXPECT_EQ(2, stack1->num_panels());
755 EXPECT_EQ(3, stack2->num_panels());
756 EXPECT_TRUE(stack2->HasPanel(new_panel));
757 EXPECT_TRUE(new_panel == stack2->bottom_panel());
759 panel_manager->CloseAll();
762 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
763 AddNewPanelToTopMostStack) {
764 PanelManager* panel_manager = PanelManager::GetInstance();
766 // Create one stack with 2 panels.
767 StackedPanelCollection* stack1 = panel_manager->CreateStack();
768 CreateStackedPanel("1", gfx::Rect(100, 90, 200, 150), stack1);
769 CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack1);
770 ASSERT_EQ(2, panel_manager->num_panels());
771 ASSERT_EQ(1, panel_manager->num_stacks());
772 ASSERT_EQ(2, stack1->num_panels());
774 // Create another stack with 2 panels.
775 StackedPanelCollection* stack2 = panel_manager->CreateStack();
776 CreateStackedPanel("3", gfx::Rect(100, 50, 200, 150), stack2);
777 CreateStackedPanel("4", gfx::Rect(0, 0, 150, 100), stack2);
778 ASSERT_EQ(4, panel_manager->num_panels());
779 ASSERT_EQ(2, panel_manager->num_stacks());
780 ASSERT_EQ(2, stack2->num_panels());
782 // Create new panel. Both stack1 and stack2 have same number of panels and
783 // same right position. Since stack2 is top-most, new panel will be added to
784 // it.
785 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
786 params.create_mode = PanelManager::CREATE_AS_DETACHED;
787 Panel* new_panel = CreatePanelWithParams(params);
788 EXPECT_EQ(5, panel_manager->num_panels());
789 EXPECT_EQ(2, panel_manager->num_stacks());
790 EXPECT_EQ(2, stack1->num_panels());
791 EXPECT_EQ(3, stack2->num_panels());
792 EXPECT_TRUE(stack2->HasPanel(new_panel));
793 EXPECT_TRUE(new_panel == stack2->bottom_panel());
795 panel_manager->CloseAll();
798 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
799 AddNewPanelToGroupWithRightMostDetachedPanel) {
800 PanelManager* panel_manager = PanelManager::GetInstance();
802 // Create 2 detached panels.
803 CreateDetachedPanel("1", gfx::Rect(200, 50, 250, 150));
804 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(250, 100, 150, 100));
805 ASSERT_EQ(2, panel_manager->num_panels());
806 ASSERT_EQ(0, panel_manager->num_stacks());
807 ASSERT_EQ(2, panel_manager->detached_collection()->num_panels());
809 // Create new panel. Expect that new panel will stack to the bottom of panel2
810 // since it is right-most.
811 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
812 params.create_mode = PanelManager::CREATE_AS_DETACHED;
813 Panel* new_panel = CreatePanelWithParams(params);
814 EXPECT_EQ(3, panel_manager->num_panels());
815 EXPECT_EQ(1, panel_manager->detached_collection()->num_panels());
816 ASSERT_EQ(1, panel_manager->num_stacks());
817 StackedPanelCollection* stack = panel_manager->stacks().front();
818 EXPECT_EQ(2, stack->num_panels());
819 EXPECT_TRUE(panel2 == stack->top_panel());
820 EXPECT_TRUE(new_panel == stack->bottom_panel());
822 panel_manager->CloseAll();
825 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
826 AddNewPanelToGroupWitTopMostDetachedPanel) {
827 PanelManager* panel_manager = PanelManager::GetInstance();
829 // Create 2 detached panels.
830 CreateDetachedPanel("1", gfx::Rect(200, 100, 100, 150));
831 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 50, 100, 100));
832 ASSERT_EQ(2, panel_manager->num_panels());
833 ASSERT_EQ(0, panel_manager->num_stacks());
834 ASSERT_EQ(2, panel_manager->detached_collection()->num_panels());
836 // Create new panel. Expect that new panel will stack to the bottom of panel2
837 // since it is top-most.
838 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
839 params.create_mode = PanelManager::CREATE_AS_DETACHED;
840 Panel* new_panel = CreatePanelWithParams(params);
841 EXPECT_EQ(3, panel_manager->num_panels());
842 EXPECT_EQ(1, panel_manager->detached_collection()->num_panels());
843 ASSERT_EQ(1, panel_manager->num_stacks());
844 StackedPanelCollection* stack = panel_manager->stacks().front();
845 EXPECT_EQ(2, stack->num_panels());
846 EXPECT_TRUE(panel2 == stack->top_panel());
847 EXPECT_TRUE(new_panel == stack->bottom_panel());
849 panel_manager->CloseAll();
852 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
853 AddNewPanelToStackWithCollapseToFit) {
854 PanelManager* panel_manager = PanelManager::GetInstance();
856 // Create one stack with 4 panels.
857 // The panels from most recent active to least recent active are:
858 // P4 P3 P2 P1
859 StackedPanelCollection* stack = panel_manager->CreateStack();
860 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 50, 200, 140), stack);
861 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 150), stack);
862 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 180, 120), stack);
863 Panel* panel4 = CreateStackedPanel("4", gfx::Rect(0, 0, 170, 110), stack);
864 ASSERT_EQ(4, panel_manager->num_panels());
865 ASSERT_EQ(1, panel_manager->num_stacks());
866 ASSERT_EQ(4, stack->num_panels());
867 EXPECT_FALSE(panel1->IsMinimized());
868 EXPECT_FALSE(panel2->IsMinimized());
869 EXPECT_FALSE(panel3->IsMinimized());
870 EXPECT_FALSE(panel4->IsMinimized());
872 // Create a panel. Expect the least recent active panel P1 gets minimized such
873 // that there is enough space for new panel to append to the stack.
874 // The panels from most recent active to least recent active are:
875 // PM P4 P3 P2 P1*
876 CreatePanelParams params1("M", gfx::Rect(50, 50, 300, 110), SHOW_AS_ACTIVE);
877 params1.create_mode = PanelManager::CREATE_AS_DETACHED;
878 Panel* new_panel1 = CreatePanelWithParams(params1);
879 EXPECT_EQ(5, panel_manager->num_panels());
880 EXPECT_EQ(1, panel_manager->num_stacks());
881 EXPECT_EQ(5, stack->num_panels());
882 EXPECT_TRUE(new_panel1 == stack->bottom_panel());
883 EXPECT_TRUE(panel1->IsMinimized());
884 EXPECT_FALSE(panel2->IsMinimized());
885 EXPECT_FALSE(panel3->IsMinimized());
886 EXPECT_FALSE(panel4->IsMinimized());
887 EXPECT_FALSE(new_panel1->IsMinimized());
889 // Create another panel. Expect P2 and P3 are minimized such that there is
890 // enough space for new panel to append to the stack.
891 CreatePanelParams params2("N", gfx::Rect(50, 50, 300, 180), SHOW_AS_ACTIVE);
892 params2.create_mode = PanelManager::CREATE_AS_DETACHED;
893 Panel* new_panel2 = CreatePanelWithParams(params2);
894 EXPECT_EQ(6, panel_manager->num_panels());
895 EXPECT_EQ(1, panel_manager->num_stacks());
896 EXPECT_EQ(6, stack->num_panels());
897 EXPECT_TRUE(new_panel2 == stack->bottom_panel());
898 EXPECT_TRUE(panel1->IsMinimized());
899 EXPECT_TRUE(panel2->IsMinimized());
900 EXPECT_TRUE(panel3->IsMinimized());
901 EXPECT_FALSE(panel4->IsMinimized());
902 EXPECT_FALSE(new_panel1->IsMinimized());
903 EXPECT_FALSE(new_panel2->IsMinimized());
905 panel_manager->CloseAll();
908 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
909 AddNewPanelToGroupWithDetachedPanelWithCollapseToFit) {
910 PanelManager* panel_manager = PanelManager::GetInstance();
912 // Create 2 detached panels.
913 // Since P2 is active, it will not get collapsed when the new panel to stack
914 // with needs the space.
915 Panel* panel1 =
916 CreateInactiveDetachedPanel("1", gfx::Rect(100, 310, 200, 200));
917 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(300, 300, 150, 200));
918 ASSERT_EQ(2, panel_manager->num_panels());
919 ASSERT_EQ(0, panel_manager->num_stacks());
920 ASSERT_EQ(2, panel_manager->detached_collection()->num_panels());
922 // Create new panel. Expect panel1 is minimized such that there is enough
923 // space for new panel to append to panel1.
924 CreatePanelParams params("N", gfx::Rect(50, 50, 300, 220), SHOW_AS_ACTIVE);
925 params.create_mode = PanelManager::CREATE_AS_DETACHED;
926 Panel* new_panel = CreatePanelWithParams(params);
927 EXPECT_EQ(3, panel_manager->num_panels());
928 EXPECT_EQ(1, panel_manager->detached_collection()->num_panels());
929 ASSERT_EQ(1, panel_manager->num_stacks());
930 StackedPanelCollection* stack = panel_manager->stacks().front();
931 EXPECT_EQ(2, stack->num_panels());
932 EXPECT_TRUE(panel1 == stack->top_panel());
933 EXPECT_TRUE(new_panel == stack->bottom_panel());
934 EXPECT_TRUE(panel1->IsMinimized());
935 EXPECT_FALSE(panel2->IsMinimized());
936 EXPECT_FALSE(new_panel->IsMinimized());
938 panel_manager->CloseAll();
941 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
942 AddNewPanelAsDetachedDueToNoPanelToGroupWith) {
943 PanelManager* panel_manager = PanelManager::GetInstance();
945 // Create one stack with 2 panels.
946 StackedPanelCollection* stack = panel_manager->CreateStack();
947 CreateStackedPanel("1", gfx::Rect(100, 350, 200, 100), stack);
948 CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
949 ASSERT_EQ(2, panel_manager->num_panels());
950 ASSERT_EQ(1, panel_manager->num_stacks());
951 ASSERT_EQ(2, stack->num_panels());
953 // Create 2 detached panels.
954 CreateDetachedPanel("3", gfx::Rect(300, 450, 200, 100));
955 CreateDetachedPanel("4", gfx::Rect(250, 150, 150, 200));
956 ASSERT_EQ(4, panel_manager->num_panels());
957 ASSERT_EQ(2, panel_manager->detached_collection()->num_panels());
958 ASSERT_EQ(1, panel_manager->num_stacks());
960 // Create new panel. Expect that new panel has to be created as detached due
961 // to that there is not enough space from any stack or detached panel.
962 CreatePanelParams params("N", gfx::Rect(50, 50, 300, 300), SHOW_AS_ACTIVE);
963 params.create_mode = PanelManager::CREATE_AS_DETACHED;
964 Panel* new_panel = CreatePanelWithParams(params);
965 EXPECT_EQ(5, panel_manager->num_panels());
966 EXPECT_EQ(3, panel_manager->detached_collection()->num_panels());
967 EXPECT_EQ(1, panel_manager->num_stacks());
968 EXPECT_EQ(2, stack->num_panels());
969 EXPECT_TRUE(panel_manager->detached_collection()->HasPanel(new_panel));
971 panel_manager->CloseAll();
974 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
975 AddNewPanelFromDifferentExtension) {
976 PanelManager* panel_manager = PanelManager::GetInstance();
978 // Create 2 test extensions.
979 DictionaryValue empty_value;
980 scoped_refptr<extensions::Extension> extension1 =
981 CreateExtension(FILE_PATH_LITERAL("TestExtension1"),
982 extensions::Manifest::INTERNAL, empty_value);
983 std::string extension1_app_name =
984 web_app::GenerateApplicationNameFromExtensionId(extension1->id());
985 scoped_refptr<extensions::Extension> extension2 =
986 CreateExtension(FILE_PATH_LITERAL("TestExtension2"),
987 extensions::Manifest::INTERNAL, empty_value);
988 std::string extension2_app_name =
989 web_app::GenerateApplicationNameFromExtensionId(extension2->id());
991 // Create 2 panels from extension1. Expect that these 2 panels stack together.
992 CreatePanelParams params1(
993 extension1_app_name, gfx::Rect(50, 50, 100, 100), SHOW_AS_ACTIVE);
994 params1.create_mode = PanelManager::CREATE_AS_DETACHED;
995 Panel* panel1 = CreatePanelWithParams(params1);
996 CreatePanelParams params2(
997 extension1_app_name, gfx::Rect(100, 100, 200, 100), SHOW_AS_ACTIVE);
998 params2.create_mode = PanelManager::CREATE_AS_DETACHED;
999 Panel* panel2 = CreatePanelWithParams(params2);
1000 EXPECT_EQ(2, panel_manager->num_panels());
1001 EXPECT_EQ(1, panel_manager->num_stacks());
1002 StackedPanelCollection* stack1 = panel_manager->stacks().back();
1003 EXPECT_TRUE(stack1->HasPanel(panel1));
1004 EXPECT_TRUE(stack1->HasPanel(panel2));
1006 // Create 2 panels from extension2. Expect that these 2 panels form a separate
1007 // stack.
1008 CreatePanelParams params3(
1009 extension2_app_name, gfx::Rect(350, 350, 100, 100), SHOW_AS_ACTIVE);
1010 params3.create_mode = PanelManager::CREATE_AS_DETACHED;
1011 Panel* panel3 = CreatePanelWithParams(params3);
1012 CreatePanelParams params4(
1013 extension2_app_name, gfx::Rect(100, 100, 200, 100), SHOW_AS_ACTIVE);
1014 params4.create_mode = PanelManager::CREATE_AS_DETACHED;
1015 Panel* panel4 = CreatePanelWithParams(params4);
1016 EXPECT_EQ(4, panel_manager->num_panels());
1017 EXPECT_EQ(2, panel_manager->num_stacks());
1018 StackedPanelCollection* stack2 = panel_manager->stacks().back();
1019 EXPECT_TRUE(stack2->HasPanel(panel3));
1020 EXPECT_TRUE(stack2->HasPanel(panel4));
1022 // Create one more panel from extension1. Expect that new panel should join
1023 // with the stack of panel1 and panel2.
1024 CreatePanelParams params5(
1025 extension1_app_name, gfx::Rect(0, 0, 100, 100), SHOW_AS_ACTIVE);
1026 params5.create_mode = PanelManager::CREATE_AS_DETACHED;
1027 Panel* panel5 = CreatePanelWithParams(params5);
1028 EXPECT_EQ(5, panel_manager->num_panels());
1029 EXPECT_EQ(2, panel_manager->num_stacks());
1030 EXPECT_TRUE(stack1->HasPanel(panel5));
1032 // Create one more panel from extension2. Expect that new panel should join
1033 // with the stack of panel3 and panel4.
1034 CreatePanelParams params6(
1035 extension2_app_name, gfx::Rect(0, 0, 100, 100), SHOW_AS_ACTIVE);
1036 params6.create_mode = PanelManager::CREATE_AS_DETACHED;
1037 Panel* panel6 = CreatePanelWithParams(params6);
1038 EXPECT_EQ(6, panel_manager->num_panels());
1039 EXPECT_EQ(2, panel_manager->num_stacks());
1040 EXPECT_TRUE(stack2->HasPanel(panel6));
1042 panel_manager->CloseAll();
1045 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1046 AddNewPanelFromDifferentProfile) {
1047 PanelManager* panel_manager = PanelManager::GetInstance();
1049 // Create a new profile.
1050 Profile* profile1 = browser()->profile();
1051 scoped_ptr<TestingProfile> profile2(new TestingProfile());
1053 // Create 2 panels from profile1. Expect that these 2 panels stack together.
1054 CreatePanelParams params1(
1055 "1", gfx::Rect(50, 50, 100, 100), SHOW_AS_ACTIVE);
1056 params1.create_mode = PanelManager::CREATE_AS_DETACHED;
1057 params1.profile = profile1;
1058 Panel* panel1 = CreatePanelWithParams(params1);
1059 CreatePanelParams params2(
1060 "2", gfx::Rect(100, 100, 200, 100), SHOW_AS_ACTIVE);
1061 params2.create_mode = PanelManager::CREATE_AS_DETACHED;
1062 params2.profile = profile1;
1063 Panel* panel2 = CreatePanelWithParams(params2);
1064 EXPECT_EQ(2, panel_manager->num_panels());
1065 EXPECT_EQ(1, panel_manager->num_stacks());
1066 StackedPanelCollection* stack1 = panel_manager->stacks().back();
1067 EXPECT_TRUE(stack1->HasPanel(panel1));
1068 EXPECT_TRUE(stack1->HasPanel(panel2));
1070 // Create 2 panels from profile2. Expect that these 2 panels form a separate
1071 // stack.
1072 CreatePanelParams params3(
1073 "3", gfx::Rect(350, 350, 100, 100), SHOW_AS_ACTIVE);
1074 params3.create_mode = PanelManager::CREATE_AS_DETACHED;
1075 params3.profile = profile2.get();
1076 Panel* panel3 = CreatePanelWithParams(params3);
1077 CreatePanelParams params4(
1078 "4", gfx::Rect(100, 100, 200, 100), SHOW_AS_ACTIVE);
1079 params4.create_mode = PanelManager::CREATE_AS_DETACHED;
1080 params4.profile = profile2.get();
1081 Panel* panel4 = CreatePanelWithParams(params4);
1082 EXPECT_EQ(4, panel_manager->num_panels());
1083 EXPECT_EQ(2, panel_manager->num_stacks());
1084 StackedPanelCollection* stack2 = panel_manager->stacks().back();
1085 EXPECT_TRUE(stack2->HasPanel(panel3));
1086 EXPECT_TRUE(stack2->HasPanel(panel4));
1088 // Create one more panel from profile1. Expect that new panel should join
1089 // with the stack of panel1 and panel2.
1090 CreatePanelParams params5(
1091 "5", gfx::Rect(0, 0, 100, 100), SHOW_AS_ACTIVE);
1092 params5.create_mode = PanelManager::CREATE_AS_DETACHED;
1093 params5.profile = profile1;
1094 Panel* panel5 = CreatePanelWithParams(params5);
1095 EXPECT_EQ(5, panel_manager->num_panels());
1096 EXPECT_EQ(2, panel_manager->num_stacks());
1097 EXPECT_TRUE(stack1->HasPanel(panel5));
1099 // Create one more panel from profile2. Expect that new panel should join
1100 // with the stack of panel3 and panel4.
1101 CreatePanelParams params6(
1102 "6", gfx::Rect(0, 0, 100, 100), SHOW_AS_ACTIVE);
1103 params6.create_mode = PanelManager::CREATE_AS_DETACHED;
1104 params6.profile = profile2.get();
1105 Panel* panel6 = CreatePanelWithParams(params6);
1106 EXPECT_EQ(6, panel_manager->num_panels());
1107 EXPECT_EQ(2, panel_manager->num_stacks());
1108 EXPECT_TRUE(stack2->HasPanel(panel6));
1110 // Wait until all panels created from profile2 get fully closed since profile2
1111 // is going out of scope at the exit of this function.
1112 CloseWindowAndWait(panel3);
1113 CloseWindowAndWait(panel4);
1114 CloseWindowAndWait(panel6);
1116 panel_manager->CloseAll();
1119 // Skip the test since system-minimize might not be supported for some window
1120 // managers on Linux.
1121 #if defined(TOOLKIT_GTK)
1122 #define MAYBE_AddNewPanelNotWithSystemMinimizedDetachedPanel \
1123 DISABLED_AddNewPanelNotWithSystemMinimizedDetachedPanel
1124 #else
1125 #define MAYBE_AddNewPanelNotWithSystemMinimizedDetachedPanel \
1126 AddNewPanelNotWithSystemMinimizedDetachedPanel
1127 #endif
1128 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1129 MAYBE_AddNewPanelNotWithSystemMinimizedDetachedPanel) {
1130 PanelManager* panel_manager = PanelManager::GetInstance();
1132 // Create 1 detached panel.
1133 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(200, 50, 250, 150));
1134 EXPECT_EQ(1, panel_manager->num_panels());
1135 EXPECT_EQ(0, panel_manager->num_stacks());
1136 EXPECT_EQ(1, panel_manager->detached_collection()->num_panels());
1137 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1139 // Minimize the detached panel by system.
1140 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
1142 // Create new panel. Expect that new panel will open as a separate detached
1143 // panel, instead of being grouped with the system-minimized detached panel.
1144 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
1145 params.create_mode = PanelManager::CREATE_AS_DETACHED;
1146 Panel* new_panel = CreatePanelWithParams(params);
1147 EXPECT_EQ(2, panel_manager->num_panels());
1148 EXPECT_EQ(2, panel_manager->detached_collection()->num_panels());
1149 EXPECT_EQ(0, panel_manager->num_stacks());
1150 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1151 EXPECT_EQ(PanelCollection::DETACHED, new_panel->collection()->type());
1153 panel_manager->CloseAll();
1156 // Skip the test since system-minimize might not be supported for some window
1157 // managers on Linux.
1158 #if defined(TOOLKIT_GTK)
1159 #define MAYBE_AddNewPanelNotWithSystemMinimizedStack \
1160 DISABLED_AddNewPanelNotWithSystemMinimizedStack
1161 #else
1162 #define MAYBE_AddNewPanelNotWithSystemMinimizedStack \
1163 AddNewPanelNotWithSystemMinimizedStack
1164 #endif
1165 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1166 MAYBE_AddNewPanelNotWithSystemMinimizedStack) {
1167 PanelManager* panel_manager = PanelManager::GetInstance();
1169 // Create one stack with 2 panels.
1170 StackedPanelCollection* stack = panel_manager->CreateStack();
1171 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 90, 200, 150), stack);
1172 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
1173 EXPECT_EQ(2, panel_manager->num_panels());
1174 EXPECT_EQ(0, panel_manager->detached_collection()->num_panels());
1175 EXPECT_EQ(1, panel_manager->num_stacks());
1176 EXPECT_EQ(2, stack->num_panels());
1177 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1178 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1180 // Minimize the stack by system.
1181 stack->OnMinimizeButtonClicked(panel1, panel::NO_MODIFIER);
1183 // Create new panel. Expect that new panel will open as a separate detached
1184 // panel, instead of appending to the system-minimized stack.
1185 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
1186 params.create_mode = PanelManager::CREATE_AS_DETACHED;
1187 Panel* new_panel = CreatePanelWithParams(params);
1188 EXPECT_EQ(3, panel_manager->num_panels());
1189 EXPECT_EQ(1, panel_manager->detached_collection()->num_panels());
1190 EXPECT_EQ(1, panel_manager->num_stacks());
1191 EXPECT_EQ(2, stack->num_panels());
1192 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1193 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1194 EXPECT_EQ(PanelCollection::DETACHED, new_panel->collection()->type());
1196 panel_manager->CloseAll();
1199 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, ClosePanels) {
1200 PanelManager* panel_manager = PanelManager::GetInstance();
1202 // Create 3 stacked panels.
1203 StackedPanelCollection* stack = panel_manager->CreateStack();
1204 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
1205 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
1206 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1207 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1208 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 250, 120);
1209 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
1210 ASSERT_EQ(3, panel_manager->num_panels());
1211 ASSERT_EQ(1, panel_manager->num_stacks());
1212 ASSERT_EQ(3, stack->num_panels());
1214 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
1215 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1216 gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(),
1217 panel1_expected_bounds.bottom(),
1218 panel1_expected_bounds.width(),
1219 panel2_initial_bounds.height());
1220 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1221 gfx::Rect panel3_expected_bounds(panel2_expected_bounds.x(),
1222 panel2_expected_bounds.bottom(),
1223 panel2_expected_bounds.width(),
1224 panel3_initial_bounds.height());
1225 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1227 // Close P1. Expect that P2 and P3 should move up.
1228 CloseWindowAndWait(panel1);
1229 WaitForBoundsAnimationFinished(panel2);
1230 WaitForBoundsAnimationFinished(panel3);
1231 ASSERT_EQ(2, panel_manager->num_panels());
1232 ASSERT_EQ(1, panel_manager->num_stacks());
1233 ASSERT_EQ(2, stack->num_panels());
1234 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1235 EXPECT_EQ(PanelCollection::STACKED, panel3->collection()->type());
1237 panel2_expected_bounds.set_y(panel1_expected_bounds.y());
1238 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1239 panel3_expected_bounds.set_y(panel2_expected_bounds.bottom());
1240 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1242 // Close P2. Expect that P3 should become detached and move up.
1243 CloseWindowAndWait(panel2);
1244 WaitForBoundsAnimationFinished(panel3);
1245 ASSERT_EQ(1, panel_manager->num_panels());
1246 ASSERT_EQ(0, panel_manager->num_stacks());
1247 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
1249 panel3_expected_bounds.set_y(panel2_expected_bounds.y());
1250 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1252 panel_manager->CloseAll();
1255 // Skip the test since active state might not be fully supported for some window
1256 // managers.
1257 #if defined(TOOLKIT_GTK)
1258 #define MAYBE_FocusNextPanelOnPanelClose DISABLED_FocusNextPanelOnPanelClose
1259 #else
1260 #define MAYBE_FocusNextPanelOnPanelClose FocusNextPanelOnPanelClose
1261 #endif
1262 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1263 MAYBE_FocusNextPanelOnPanelClose) {
1264 PanelManager* panel_manager = PanelManager::GetInstance();
1266 // Create 3 stacked panels.
1267 StackedPanelCollection* stack = panel_manager->CreateStack();
1268 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 50, 200, 200), stack);
1269 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
1270 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 150, 120), stack);
1271 ASSERT_EQ(3, stack->num_panels());
1272 ASSERT_FALSE(panel1->IsActive());
1273 ASSERT_FALSE(panel2->IsActive());
1274 ASSERT_TRUE(panel3->IsActive());
1276 // Close P3. Expect P2 should become active.
1277 CloseWindowAndWait(panel3);
1278 EXPECT_FALSE(panel1->IsActive());
1279 EXPECT_TRUE(panel2->IsActive());
1281 // Close P2. Expect P1 should become active.
1282 CloseWindowAndWait(panel2);
1283 EXPECT_TRUE(panel1->IsActive());
1285 panel_manager->CloseAll();
1288 // Skip the test since active state might not be fully supported for some window
1289 // managers.
1290 #if defined(TOOLKIT_GTK) || defined(OS_MACOSX)
1291 #define MAYBE_FocusNextUnminimizedPanelOnPanelClose \
1292 DISABLED_FocusNextUnminimizedPanelOnPanelClose
1293 #else
1294 #define MAYBE_FocusNextUnminimizedPanelOnPanelClose \
1295 FocusNextUnminimizedPanelOnPanelClose
1296 #endif
1297 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1298 MAYBE_FocusNextUnminimizedPanelOnPanelClose) {
1299 PanelManager* panel_manager = PanelManager::GetInstance();
1301 // Create 3 stacked panels.
1302 StackedPanelCollection* stack = panel_manager->CreateStack();
1303 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 50, 200, 200), stack);
1304 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
1305 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 150, 120), stack);
1306 ASSERT_EQ(3, stack->num_panels());
1307 ASSERT_FALSE(panel1->IsActive());
1308 ASSERT_FALSE(panel2->IsActive());
1309 ASSERT_TRUE(panel3->IsActive());
1311 // Minimize P2.
1312 panel2->Minimize();
1313 WaitForBoundsAnimationFinished(panel2);
1315 // Close P3. Expect P1, not P2, should become active.
1316 CloseWindowAndWait(panel3);
1317 EXPECT_TRUE(panel1->IsActive());
1318 EXPECT_FALSE(panel2->IsActive());
1320 panel_manager->CloseAll();
1323 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1324 ExpandCollapsedTopPanelOnBottomPanelClose) {
1325 PanelManager* panel_manager = PanelManager::GetInstance();
1327 // Create 2 stacked panels.
1328 StackedPanelCollection* stack = panel_manager->CreateStack();
1329 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
1330 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
1331 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1332 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1333 ASSERT_EQ(2, panel_manager->num_panels());
1334 ASSERT_EQ(1, panel_manager->num_stacks());
1335 ASSERT_EQ(2, stack->num_panels());
1337 // Collapse top panel.
1338 int original_panel1_height = panel1->GetBounds().height();
1339 panel1->Minimize();
1340 WaitForBoundsAnimationFinished(panel2);
1341 EXPECT_TRUE(panel1->IsMinimized());
1342 EXPECT_FALSE(panel2->IsMinimized());
1344 // Close bottom panel. Expect that top panel should become detached and
1345 // expanded.
1346 CloseWindowAndWait(panel2);
1347 WaitForBoundsAnimationFinished(panel1);
1348 EXPECT_EQ(1, panel_manager->num_panels());
1349 EXPECT_EQ(0, panel_manager->num_stacks());
1350 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1351 EXPECT_FALSE(panel1->IsMinimized());
1352 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
1353 EXPECT_EQ(original_panel1_height, panel1->GetBounds().height());
1355 panel_manager->CloseAll();
1358 // The activation waiting logic does not work well on MacOSX. Disabled for now.
1359 #if defined(OS_MACOSX)
1360 #define MAYBE_FocusCollapsedStackedPanel DISABLED_FocusCollapsedStackedPanel
1361 #else
1362 #define MAYBE_FocusCollapsedStackedPanel FocusCollapsedStackedPanel
1363 #endif
1364 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1365 MAYBE_FocusCollapsedStackedPanel) {
1366 PanelManager* panel_manager = PanelManager::GetInstance();
1368 // Create 2 stacked panels.
1369 StackedPanelCollection* stack = panel_manager->CreateStack();
1370 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
1371 CreateStackedPanel("1", panel1_initial_bounds, stack);
1372 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1373 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1374 ASSERT_EQ(2, panel_manager->num_panels());
1375 ASSERT_EQ(1, panel_manager->num_stacks());
1376 ASSERT_EQ(2, stack->num_panels());
1378 // Collapse a panel.
1379 panel2->Minimize();
1380 WaitForBoundsAnimationFinished(panel2);
1381 EXPECT_TRUE(panel2->IsMinimized());
1382 EXPECT_FALSE(panel2->IsActive());
1384 // Focus the panel. Expect the panel is expanded.
1385 panel2->Activate();
1386 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
1387 EXPECT_FALSE(panel2->IsMinimized());
1389 panel_manager->CloseAll();
1392 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1393 UpdateStackedPanelsOnPrimaryDisplayChange) {
1394 PanelManager* panel_manager = PanelManager::GetInstance();
1396 // Create one stack with 5 panels.
1397 StackedPanelCollection* stack = panel_manager->CreateStack();
1398 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(50, 50, 700, 100), stack);
1399 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 100, 100), stack);
1400 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 100, 100), stack);
1401 Panel* panel4 = CreateStackedPanel("4", gfx::Rect(0, 0, 100, 100), stack);
1402 Panel* panel5 = CreateStackedPanel("5", gfx::Rect(0, 0, 100, 100), stack);
1403 ASSERT_EQ(5, panel_manager->num_panels());
1404 ASSERT_EQ(1, panel_manager->num_stacks());
1405 ASSERT_EQ(5, stack->num_panels());
1407 // Make the primary display smaller.
1408 // Expect that all panels except P5 should be collapsed and their bounds
1409 // should be updated.
1410 int new_primary_area_width = 500;
1411 gfx::Rect primary_display_area(0, 0, new_primary_area_width, 300);
1412 gfx::Rect primary_work_area(0, 0, new_primary_area_width, 280);
1413 mock_display_settings_provider()->SetPrimaryDisplay(
1414 primary_display_area, primary_work_area);
1415 WaitForBoundsAnimationFinished(panel1);
1416 WaitForBoundsAnimationFinished(panel2);
1417 WaitForBoundsAnimationFinished(panel3);
1418 WaitForBoundsAnimationFinished(panel4);
1419 WaitForBoundsAnimationFinished(panel5);
1421 EXPECT_TRUE(panel1->IsMinimized());
1422 EXPECT_TRUE(panel2->IsMinimized());
1423 EXPECT_TRUE(panel3->IsMinimized());
1424 EXPECT_TRUE(panel4->IsMinimized());
1425 EXPECT_FALSE(panel5->IsMinimized());
1427 gfx::Rect bounds1 = panel1->GetBounds();
1428 EXPECT_EQ(primary_work_area.x(), bounds1.x());
1429 EXPECT_LE(bounds1.x(), primary_work_area.right());
1430 EXPECT_LE(primary_work_area.y(), bounds1.y());
1431 EXPECT_EQ(new_primary_area_width, bounds1.width());
1433 gfx::Rect bounds2 = panel2->GetBounds();
1434 EXPECT_EQ(bounds1.x(), bounds2.x());
1435 EXPECT_EQ(bounds1.width(), bounds2.width());
1436 EXPECT_EQ(bounds1.bottom(), bounds2.y());
1438 gfx::Rect bounds3 = panel3->GetBounds();
1439 EXPECT_EQ(bounds2.x(), bounds3.x());
1440 EXPECT_EQ(bounds2.width(), bounds3.width());
1441 EXPECT_EQ(bounds2.bottom(), bounds3.y());
1443 gfx::Rect bounds4 = panel4->GetBounds();
1444 EXPECT_EQ(bounds3.x(), bounds4.x());
1445 EXPECT_EQ(bounds3.width(), bounds4.width());
1446 EXPECT_EQ(bounds3.bottom(), bounds4.y());
1448 gfx::Rect bounds5 = panel5->GetBounds();
1449 EXPECT_EQ(bounds4.x(), bounds5.x());
1450 EXPECT_EQ(bounds4.width(), bounds5.width());
1451 EXPECT_EQ(bounds4.bottom(), bounds5.y());
1452 EXPECT_LE(bounds5.bottom(), primary_work_area.bottom());
1454 panel_manager->CloseAll();