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