Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / panels / stacked_panel_browsertest.cc
blobfa60e70bf4ff55153eba1a51e0910455a6c24f37
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 base::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 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1120 AddNewPanelNotWithSystemMinimizedDetachedPanel) {
1121 PanelManager* panel_manager = PanelManager::GetInstance();
1123 // Create 1 detached panel.
1124 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(200, 50, 250, 150));
1125 EXPECT_EQ(1, panel_manager->num_panels());
1126 EXPECT_EQ(0, panel_manager->num_stacks());
1127 EXPECT_EQ(1, panel_manager->detached_collection()->num_panels());
1128 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1130 // Minimize the detached panel by system.
1131 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER);
1133 // Create new panel. Expect that new panel will open as a separate detached
1134 // panel, instead of being grouped with the system-minimized detached panel.
1135 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
1136 params.create_mode = PanelManager::CREATE_AS_DETACHED;
1137 Panel* new_panel = CreatePanelWithParams(params);
1138 EXPECT_EQ(2, panel_manager->num_panels());
1139 EXPECT_EQ(2, panel_manager->detached_collection()->num_panels());
1140 EXPECT_EQ(0, panel_manager->num_stacks());
1141 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1142 EXPECT_EQ(PanelCollection::DETACHED, new_panel->collection()->type());
1144 panel_manager->CloseAll();
1147 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1148 AddNewPanelNotWithSystemMinimizedStack) {
1149 PanelManager* panel_manager = PanelManager::GetInstance();
1151 // Create one stack with 2 panels.
1152 StackedPanelCollection* stack = panel_manager->CreateStack();
1153 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 90, 200, 150), stack);
1154 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
1155 EXPECT_EQ(2, panel_manager->num_panels());
1156 EXPECT_EQ(0, panel_manager->detached_collection()->num_panels());
1157 EXPECT_EQ(1, panel_manager->num_stacks());
1158 EXPECT_EQ(2, stack->num_panels());
1159 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1160 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1162 // Minimize the stack by system.
1163 stack->OnMinimizeButtonClicked(panel1, panel::NO_MODIFIER);
1165 // Create new panel. Expect that new panel will open as a separate detached
1166 // panel, instead of appending to the system-minimized stack.
1167 CreatePanelParams params("N", gfx::Rect(50, 50, 150, 100), SHOW_AS_ACTIVE);
1168 params.create_mode = PanelManager::CREATE_AS_DETACHED;
1169 Panel* new_panel = CreatePanelWithParams(params);
1170 EXPECT_EQ(3, panel_manager->num_panels());
1171 EXPECT_EQ(1, panel_manager->detached_collection()->num_panels());
1172 EXPECT_EQ(1, panel_manager->num_stacks());
1173 EXPECT_EQ(2, stack->num_panels());
1174 EXPECT_EQ(PanelCollection::STACKED, panel1->collection()->type());
1175 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1176 EXPECT_EQ(PanelCollection::DETACHED, new_panel->collection()->type());
1178 panel_manager->CloseAll();
1181 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest, ClosePanels) {
1182 PanelManager* panel_manager = PanelManager::GetInstance();
1184 // Create 3 stacked panels.
1185 StackedPanelCollection* stack = panel_manager->CreateStack();
1186 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
1187 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
1188 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1189 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1190 gfx::Rect panel3_initial_bounds = gfx::Rect(0, 0, 250, 120);
1191 Panel* panel3 = CreateStackedPanel("3", panel3_initial_bounds, stack);
1192 ASSERT_EQ(3, panel_manager->num_panels());
1193 ASSERT_EQ(1, panel_manager->num_stacks());
1194 ASSERT_EQ(3, stack->num_panels());
1196 gfx::Rect panel1_expected_bounds(panel1_initial_bounds);
1197 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
1198 gfx::Rect panel2_expected_bounds(panel1_expected_bounds.x(),
1199 panel1_expected_bounds.bottom(),
1200 panel1_expected_bounds.width(),
1201 panel2_initial_bounds.height());
1202 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1203 gfx::Rect panel3_expected_bounds(panel2_expected_bounds.x(),
1204 panel2_expected_bounds.bottom(),
1205 panel2_expected_bounds.width(),
1206 panel3_initial_bounds.height());
1207 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1209 // Close P1. Expect that P2 and P3 should move up.
1210 CloseWindowAndWait(panel1);
1211 WaitForBoundsAnimationFinished(panel2);
1212 WaitForBoundsAnimationFinished(panel3);
1213 ASSERT_EQ(2, panel_manager->num_panels());
1214 ASSERT_EQ(1, panel_manager->num_stacks());
1215 ASSERT_EQ(2, stack->num_panels());
1216 EXPECT_EQ(PanelCollection::STACKED, panel2->collection()->type());
1217 EXPECT_EQ(PanelCollection::STACKED, panel3->collection()->type());
1219 panel2_expected_bounds.set_y(panel1_expected_bounds.y());
1220 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
1221 panel3_expected_bounds.set_y(panel2_expected_bounds.bottom());
1222 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1224 // Close P2. Expect that P3 should become detached and move up.
1225 CloseWindowAndWait(panel2);
1226 WaitForBoundsAnimationFinished(panel3);
1227 ASSERT_EQ(1, panel_manager->num_panels());
1228 ASSERT_EQ(0, panel_manager->num_stacks());
1229 EXPECT_EQ(PanelCollection::DETACHED, panel3->collection()->type());
1231 panel3_expected_bounds.set_y(panel2_expected_bounds.y());
1232 EXPECT_EQ(panel3_expected_bounds, panel3->GetBounds());
1234 panel_manager->CloseAll();
1237 // Skip the test since active state might not be fully supported for some window
1238 // managers.
1239 #if defined(OS_MACOSX)
1240 #define MAYBE_FocusNextPanelOnPanelClose DISABLED_FocusNextPanelOnPanelClose
1241 #else
1242 #define MAYBE_FocusNextPanelOnPanelClose FocusNextPanelOnPanelClose
1243 #endif
1244 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1245 MAYBE_FocusNextPanelOnPanelClose) {
1246 PanelManager* panel_manager = PanelManager::GetInstance();
1248 // Create 3 stacked panels.
1249 StackedPanelCollection* stack = panel_manager->CreateStack();
1250 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 50, 200, 200), stack);
1251 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
1252 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 150, 120), stack);
1253 ASSERT_EQ(3, stack->num_panels());
1254 ASSERT_FALSE(panel1->IsActive());
1255 ASSERT_FALSE(panel2->IsActive());
1256 ASSERT_TRUE(panel3->IsActive());
1258 // Close P3. Expect P2 should become active.
1259 CloseWindowAndWait(panel3);
1260 EXPECT_FALSE(panel1->IsActive());
1261 EXPECT_TRUE(panel2->IsActive());
1263 // Close P2. Expect P1 should become active.
1264 CloseWindowAndWait(panel2);
1265 EXPECT_TRUE(panel1->IsActive());
1267 panel_manager->CloseAll();
1270 // Skip the test since active state might not be fully supported for some window
1271 // managers.
1272 #if defined(OS_MACOSX)
1273 #define MAYBE_FocusNextUnminimizedPanelOnPanelClose \
1274 DISABLED_FocusNextUnminimizedPanelOnPanelClose
1275 #else
1276 #define MAYBE_FocusNextUnminimizedPanelOnPanelClose \
1277 FocusNextUnminimizedPanelOnPanelClose
1278 #endif
1279 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1280 MAYBE_FocusNextUnminimizedPanelOnPanelClose) {
1281 PanelManager* panel_manager = PanelManager::GetInstance();
1283 // Create 3 stacked panels.
1284 StackedPanelCollection* stack = panel_manager->CreateStack();
1285 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 50, 200, 200), stack);
1286 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
1287 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 150, 120), stack);
1288 ASSERT_EQ(3, stack->num_panels());
1289 ASSERT_FALSE(panel1->IsActive());
1290 ASSERT_FALSE(panel2->IsActive());
1291 ASSERT_TRUE(panel3->IsActive());
1293 // Minimize P2.
1294 panel2->Minimize();
1295 WaitForBoundsAnimationFinished(panel2);
1297 // Close P3. Expect P1, not P2, should become active.
1298 CloseWindowAndWait(panel3);
1299 EXPECT_TRUE(panel1->IsActive());
1300 EXPECT_FALSE(panel2->IsActive());
1302 panel_manager->CloseAll();
1305 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1306 ExpandCollapsedTopPanelOnBottomPanelClose) {
1307 PanelManager* panel_manager = PanelManager::GetInstance();
1309 // Create 2 stacked panels.
1310 StackedPanelCollection* stack = panel_manager->CreateStack();
1311 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
1312 Panel* panel1 = CreateStackedPanel("1", panel1_initial_bounds, stack);
1313 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1314 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1315 ASSERT_EQ(2, panel_manager->num_panels());
1316 ASSERT_EQ(1, panel_manager->num_stacks());
1317 ASSERT_EQ(2, stack->num_panels());
1319 // Collapse top panel.
1320 int original_panel1_height = panel1->GetBounds().height();
1321 panel1->Minimize();
1322 WaitForBoundsAnimationFinished(panel2);
1323 EXPECT_TRUE(panel1->IsMinimized());
1324 EXPECT_FALSE(panel2->IsMinimized());
1326 // Close bottom panel. Expect that top panel should become detached and
1327 // expanded.
1328 CloseWindowAndWait(panel2);
1329 WaitForBoundsAnimationFinished(panel1);
1330 EXPECT_EQ(1, panel_manager->num_panels());
1331 EXPECT_EQ(0, panel_manager->num_stacks());
1332 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1333 EXPECT_FALSE(panel1->IsMinimized());
1334 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
1335 EXPECT_EQ(original_panel1_height, panel1->GetBounds().height());
1337 panel_manager->CloseAll();
1340 // The activation waiting logic does not work well on MacOSX. Disabled for now.
1341 #if defined(OS_MACOSX)
1342 #define MAYBE_FocusCollapsedStackedPanel DISABLED_FocusCollapsedStackedPanel
1343 #else
1344 #define MAYBE_FocusCollapsedStackedPanel FocusCollapsedStackedPanel
1345 #endif
1346 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1347 MAYBE_FocusCollapsedStackedPanel) {
1348 PanelManager* panel_manager = PanelManager::GetInstance();
1350 // Create 2 stacked panels.
1351 StackedPanelCollection* stack = panel_manager->CreateStack();
1352 gfx::Rect panel1_initial_bounds = gfx::Rect(100, 50, 200, 150);
1353 CreateStackedPanel("1", panel1_initial_bounds, stack);
1354 gfx::Rect panel2_initial_bounds = gfx::Rect(0, 0, 150, 100);
1355 Panel* panel2 = CreateStackedPanel("2", panel2_initial_bounds, stack);
1356 ASSERT_EQ(2, panel_manager->num_panels());
1357 ASSERT_EQ(1, panel_manager->num_stacks());
1358 ASSERT_EQ(2, stack->num_panels());
1360 // Collapse a panel.
1361 panel2->Minimize();
1362 WaitForBoundsAnimationFinished(panel2);
1363 EXPECT_TRUE(panel2->IsMinimized());
1364 EXPECT_FALSE(panel2->IsActive());
1366 // Focus the panel. Expect the panel is expanded.
1367 panel2->Activate();
1368 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE);
1369 EXPECT_FALSE(panel2->IsMinimized());
1371 panel_manager->CloseAll();
1374 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1375 UpdateStackedPanelsOnPrimaryDisplayChange) {
1376 PanelManager* panel_manager = PanelManager::GetInstance();
1378 // Create one stack with 5 panels.
1379 StackedPanelCollection* stack = panel_manager->CreateStack();
1380 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(50, 50, 700, 100), stack);
1381 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 100, 100), stack);
1382 Panel* panel3 = CreateStackedPanel("3", gfx::Rect(0, 0, 100, 100), stack);
1383 Panel* panel4 = CreateStackedPanel("4", gfx::Rect(0, 0, 100, 100), stack);
1384 Panel* panel5 = CreateStackedPanel("5", gfx::Rect(0, 0, 100, 100), stack);
1385 ASSERT_EQ(5, panel_manager->num_panels());
1386 ASSERT_EQ(1, panel_manager->num_stacks());
1387 ASSERT_EQ(5, stack->num_panels());
1389 // Make the primary display smaller.
1390 // Expect that all panels except P5 should be collapsed and their bounds
1391 // should be updated.
1392 int new_primary_area_width = 500;
1393 gfx::Rect primary_display_area(0, 0, new_primary_area_width, 300);
1394 gfx::Rect primary_work_area(0, 0, new_primary_area_width, 280);
1395 mock_display_settings_provider()->SetPrimaryDisplay(
1396 primary_display_area, primary_work_area);
1397 WaitForBoundsAnimationFinished(panel1);
1398 WaitForBoundsAnimationFinished(panel2);
1399 WaitForBoundsAnimationFinished(panel3);
1400 WaitForBoundsAnimationFinished(panel4);
1401 WaitForBoundsAnimationFinished(panel5);
1403 EXPECT_TRUE(panel1->IsMinimized());
1404 EXPECT_TRUE(panel2->IsMinimized());
1405 EXPECT_TRUE(panel3->IsMinimized());
1406 EXPECT_TRUE(panel4->IsMinimized());
1407 EXPECT_FALSE(panel5->IsMinimized());
1409 gfx::Rect bounds1 = panel1->GetBounds();
1410 EXPECT_EQ(primary_work_area.x(), bounds1.x());
1411 EXPECT_LE(bounds1.x(), primary_work_area.right());
1412 EXPECT_LE(primary_work_area.y(), bounds1.y());
1413 EXPECT_EQ(new_primary_area_width, bounds1.width());
1415 gfx::Rect bounds2 = panel2->GetBounds();
1416 EXPECT_EQ(bounds1.x(), bounds2.x());
1417 EXPECT_EQ(bounds1.width(), bounds2.width());
1418 EXPECT_EQ(bounds1.bottom(), bounds2.y());
1420 gfx::Rect bounds3 = panel3->GetBounds();
1421 EXPECT_EQ(bounds2.x(), bounds3.x());
1422 EXPECT_EQ(bounds2.width(), bounds3.width());
1423 EXPECT_EQ(bounds2.bottom(), bounds3.y());
1425 gfx::Rect bounds4 = panel4->GetBounds();
1426 EXPECT_EQ(bounds3.x(), bounds4.x());
1427 EXPECT_EQ(bounds3.width(), bounds4.width());
1428 EXPECT_EQ(bounds3.bottom(), bounds4.y());
1430 gfx::Rect bounds5 = panel5->GetBounds();
1431 EXPECT_EQ(bounds4.x(), bounds5.x());
1432 EXPECT_EQ(bounds4.width(), bounds5.width());
1433 EXPECT_EQ(bounds4.bottom(), bounds5.y());
1434 EXPECT_LE(bounds5.bottom(), primary_work_area.bottom());
1436 panel_manager->CloseAll();
1439 IN_PROC_BROWSER_TEST_F(StackedPanelBrowserTest,
1440 KeepShowingStackedPanelCreatedBeforeFullScreenMode) {
1441 PanelManager* panel_manager = PanelManager::GetInstance();
1443 // Create 2 stacked panels.
1444 StackedPanelCollection* stack = panel_manager->CreateStack();
1445 Panel* panel1 = CreateStackedPanel("1", gfx::Rect(100, 50, 200, 150), stack);
1446 Panel* panel2 = CreateStackedPanel("2", gfx::Rect(0, 0, 150, 100), stack);
1447 scoped_ptr<NativePanelTesting> panel1_testing(
1448 CreateNativePanelTesting(panel1));
1449 scoped_ptr<NativePanelTesting> panel2_testing(
1450 CreateNativePanelTesting(panel2));
1452 // Panels should be visible at first.
1453 EXPECT_TRUE(panel1_testing->IsWindowVisible());
1454 EXPECT_TRUE(panel2_testing->IsWindowVisible());
1456 // Panels' visibility should not be affected when entering full-screen mode.
1457 mock_display_settings_provider()->EnableFullScreenMode(true);
1458 EXPECT_TRUE(panel1_testing->IsWindowVisible());
1459 EXPECT_TRUE(panel2_testing->IsWindowVisible());
1461 // Panels' visibility should not be affected when leaving full-screen mode.
1462 mock_display_settings_provider()->EnableFullScreenMode(false);
1463 EXPECT_TRUE(panel1_testing->IsWindowVisible());
1464 EXPECT_TRUE(panel2_testing->IsWindowVisible());
1466 panel_manager->CloseAll();