OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/message_loop/message_loop.h" | |
6 #include "build/build_config.h" | |
7 #include "chrome/browser/chrome_notification_types.h" | |
8 #include "chrome/browser/ui/panels/base_panel_browser_test.h" | |
9 #include "chrome/browser/ui/panels/docked_panel_collection.h" | |
10 #include "chrome/browser/ui/panels/panel.h" | |
11 #include "chrome/browser/ui/panels/panel_manager.h" | |
12 #include "chrome/browser/ui/panels/test_panel_collection_squeeze_observer.h" | |
13 #include "content/public/browser/notification_service.h" | |
14 #include "content/public/test/test_utils.h" | |
15 | |
16 class DockedPanelBrowserTest : public BasePanelBrowserTest { | |
17 public: | |
18 void SetUpOnMainThread() override { | |
19 BasePanelBrowserTest::SetUpOnMainThread(); | |
20 | |
21 // All the tests here assume using mocked 800x600 display area for the | |
22 // primary monitor. Do the check now. | |
23 gfx::Rect primary_display_area = PanelManager::GetInstance()-> | |
24 display_settings_provider()->GetPrimaryDisplayArea(); | |
25 DCHECK(primary_display_area.width() == 800); | |
26 DCHECK(primary_display_area.height() == 600); | |
27 } | |
28 }; | |
29 | |
30 // http://crbug.com/143247 | |
31 #if !defined(OS_WIN) | |
32 #define MAYBE_SqueezePanelsInDock DISABLED_SqueezePanelsInDock | |
33 #else | |
34 #define MAYBE_SqueezePanelsInDock SqueezePanelsInDock | |
35 #endif | |
36 IN_PROC_BROWSER_TEST_F(DockedPanelBrowserTest, MAYBE_SqueezePanelsInDock) { | |
37 PanelManager* panel_manager = PanelManager::GetInstance(); | |
38 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
39 | |
40 // Create some docked panels. | |
41 Panel* panel1 = CreateInactiveDockedPanel("1", gfx::Rect(0, 0, 200, 100)); | |
42 Panel* panel2 = CreateInactiveDockedPanel("2", gfx::Rect(0, 0, 200, 100)); | |
43 Panel* panel3 = CreateInactiveDockedPanel("3", gfx::Rect(0, 0, 200, 100)); | |
44 ASSERT_EQ(3, docked_collection->num_panels()); | |
45 | |
46 // Check that nothing has been squeezed so far. | |
47 EXPECT_EQ(panel1->GetBounds().width(), panel1->GetRestoredBounds().width()); | |
48 EXPECT_EQ(panel2->GetBounds().width(), panel2->GetRestoredBounds().width()); | |
49 EXPECT_EQ(panel3->GetBounds().width(), panel3->GetRestoredBounds().width()); | |
50 | |
51 // Create more panels so they start getting squeezed. | |
52 Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100)); | |
53 Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100)); | |
54 Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100)); | |
55 Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100)); | |
56 | |
57 // Wait for active states to settle. | |
58 PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7); | |
59 panel7_settled.Wait(); | |
60 | |
61 // The active panel should be at full width. | |
62 EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width()); | |
63 EXPECT_GT(panel7->GetBounds().x(), docked_collection->work_area().x()); | |
64 | |
65 // The rest of them should be at reduced width. | |
66 EXPECT_LT(panel1->GetBounds().width(), panel1->GetRestoredBounds().width()); | |
67 EXPECT_LT(panel2->GetBounds().width(), panel2->GetRestoredBounds().width()); | |
68 EXPECT_LT(panel3->GetBounds().width(), panel3->GetRestoredBounds().width()); | |
69 EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width()); | |
70 EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width()); | |
71 EXPECT_LT(panel6->GetBounds().width(), panel6->GetRestoredBounds().width()); | |
72 | |
73 // Activate a different panel. | |
74 ActivatePanel(panel2); | |
75 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); | |
76 | |
77 // Wait for active states to settle. | |
78 PanelCollectionSqueezeObserver panel2_settled(docked_collection, panel2); | |
79 panel2_settled.Wait(); | |
80 | |
81 // The active panel should be at full width. | |
82 EXPECT_EQ(panel2->GetBounds().width(), panel2->GetRestoredBounds().width()); | |
83 | |
84 // The rest of them should be at reduced width. | |
85 EXPECT_LT(panel1->GetBounds().width(), panel1->GetRestoredBounds().width()); | |
86 EXPECT_LT(panel3->GetBounds().width(), panel3->GetRestoredBounds().width()); | |
87 EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width()); | |
88 EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width()); | |
89 EXPECT_LT(panel6->GetBounds().width(), panel6->GetRestoredBounds().width()); | |
90 EXPECT_LT(panel7->GetBounds().width(), panel7->GetRestoredBounds().width()); | |
91 | |
92 panel_manager->CloseAll(); | |
93 } | |
94 | |
95 #if defined(OS_LINUX) | |
96 // http://crbug.com/396484 | |
97 #define MAYBE_SqueezeAndThenSomeMore DISABLED_SqueezeAndThenSomeMore | |
98 #else | |
99 #define MAYBE_SqueezeAndThenSomeMore SqueezeAndThenSomeMore | |
100 #endif | |
101 IN_PROC_BROWSER_TEST_F(DockedPanelBrowserTest, MAYBE_SqueezeAndThenSomeMore) { | |
102 PanelManager* panel_manager = PanelManager::GetInstance(); | |
103 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
104 | |
105 // Create enough docked panels to get into squeezing. | |
106 Panel* panel1 = CreateInactiveDockedPanel("1", gfx::Rect(0, 0, 200, 100)); | |
107 Panel* panel2 = CreateInactiveDockedPanel("2", gfx::Rect(0, 0, 200, 100)); | |
108 Panel* panel3 = CreateInactiveDockedPanel("3", gfx::Rect(0, 0, 200, 100)); | |
109 Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100)); | |
110 Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100)); | |
111 Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100)); | |
112 | |
113 // Wait for active states to settle. | |
114 PanelCollectionSqueezeObserver panel6_settled(docked_collection, panel6); | |
115 panel6_settled.Wait(); | |
116 | |
117 // Record current widths of some panels. | |
118 int panel_1_width_less_squeezed = panel1->GetBounds().width(); | |
119 int panel_2_width_less_squeezed = panel2->GetBounds().width(); | |
120 int panel_3_width_less_squeezed = panel3->GetBounds().width(); | |
121 int panel_4_width_less_squeezed = panel4->GetBounds().width(); | |
122 int panel_5_width_less_squeezed = panel5->GetBounds().width(); | |
123 | |
124 // These widths should be reduced. | |
125 EXPECT_LT(panel_1_width_less_squeezed, panel1->GetRestoredBounds().width()); | |
126 EXPECT_LT(panel_2_width_less_squeezed, panel2->GetRestoredBounds().width()); | |
127 EXPECT_LT(panel_3_width_less_squeezed, panel3->GetRestoredBounds().width()); | |
128 EXPECT_LT(panel_4_width_less_squeezed, panel4->GetRestoredBounds().width()); | |
129 EXPECT_LT(panel_5_width_less_squeezed, panel5->GetRestoredBounds().width()); | |
130 | |
131 Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100)); | |
132 | |
133 // Wait for active states to settle. | |
134 PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7); | |
135 panel7_settled.Wait(); | |
136 | |
137 // The active panel should be at full width. | |
138 EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width()); | |
139 | |
140 // The panels should shrink in width. | |
141 EXPECT_LT(panel1->GetBounds().width(), panel_1_width_less_squeezed); | |
142 EXPECT_LT(panel2->GetBounds().width(), panel_2_width_less_squeezed); | |
143 EXPECT_LT(panel3->GetBounds().width(), panel_3_width_less_squeezed); | |
144 EXPECT_LT(panel4->GetBounds().width(), panel_4_width_less_squeezed); | |
145 EXPECT_LT(panel5->GetBounds().width(), panel_5_width_less_squeezed); | |
146 | |
147 panel_manager->CloseAll(); | |
148 } | |
149 | |
150 IN_PROC_BROWSER_TEST_F(DockedPanelBrowserTest, MinimizeSqueezedActive) { | |
151 PanelManager* panel_manager = PanelManager::GetInstance(); | |
152 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
153 | |
154 // Create enough docked panels to get into squeezing. | |
155 Panel* panel1 = CreateInactiveDockedPanel("1", gfx::Rect(0, 0, 200, 100)); | |
156 Panel* panel2 = CreateInactiveDockedPanel("2", gfx::Rect(0, 0, 200, 100)); | |
157 Panel* panel3 = CreateInactiveDockedPanel("3", gfx::Rect(0, 0, 200, 100)); | |
158 Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100)); | |
159 Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100)); | |
160 Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100)); | |
161 Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100)); | |
162 | |
163 // Wait for active states to settle. | |
164 PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7); | |
165 panel7_settled.Wait(); | |
166 | |
167 // The active panel should be at full width. | |
168 EXPECT_EQ(panel7->GetBounds().width(), panel7->GetRestoredBounds().width()); | |
169 | |
170 // The rest of them should be at reduced width. | |
171 EXPECT_LT(panel1->GetBounds().width(), panel1->GetRestoredBounds().width()); | |
172 EXPECT_LT(panel2->GetBounds().width(), panel2->GetRestoredBounds().width()); | |
173 EXPECT_LT(panel3->GetBounds().width(), panel3->GetRestoredBounds().width()); | |
174 EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width()); | |
175 EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width()); | |
176 EXPECT_LT(panel6->GetBounds().width(), panel6->GetRestoredBounds().width()); | |
177 | |
178 // Record the width of an inactive panel and minimize it. | |
179 int width_of_panel3_squeezed = panel3->GetBounds().width(); | |
180 panel3->Minimize(); | |
181 | |
182 // Check that this panel is still at the same width. | |
183 EXPECT_EQ(width_of_panel3_squeezed, panel3->GetBounds().width()); | |
184 | |
185 // Minimize the active panel. It should become inactive and shrink in width. | |
186 content::WindowedNotificationObserver signal( | |
187 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED, | |
188 content::NotificationService::AllSources()); | |
189 panel7->Minimize(); | |
190 | |
191 // Wait for active states to settle. | |
192 WaitForPanelActiveState(panel7, SHOW_AS_INACTIVE); | |
193 | |
194 // Wait for the scheduled layout to run. | |
195 signal.Wait(); | |
196 | |
197 // The minimized panel should now be at reduced width. | |
198 EXPECT_LT(panel7->GetBounds().width(), panel7->GetRestoredBounds().width()); | |
199 | |
200 panel_manager->CloseAll(); | |
201 } | |
202 | |
203 IN_PROC_BROWSER_TEST_F(DockedPanelBrowserTest, CloseSqueezedPanels) { | |
204 PanelManager* panel_manager = PanelManager::GetInstance(); | |
205 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); | |
206 | |
207 // Create enough docked panels to get into squeezing. | |
208 Panel* panel1 = CreateInactiveDockedPanel("1", gfx::Rect(0, 0, 200, 100)); | |
209 Panel* panel2 = CreateInactiveDockedPanel("2", gfx::Rect(0, 0, 200, 100)); | |
210 Panel* panel3 = CreateInactiveDockedPanel("3", gfx::Rect(0, 0, 200, 100)); | |
211 Panel* panel4 = CreateInactiveDockedPanel("4", gfx::Rect(0, 0, 200, 100)); | |
212 Panel* panel5 = CreateInactiveDockedPanel("5", gfx::Rect(0, 0, 200, 100)); | |
213 Panel* panel6 = CreateInactiveDockedPanel("6", gfx::Rect(0, 0, 200, 100)); | |
214 Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100)); | |
215 | |
216 // Wait for active states to settle. | |
217 PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7); | |
218 panel7_settled.Wait(); | |
219 | |
220 // Record current widths of some panels. | |
221 int panel_1_orig_width = panel1->GetBounds().width(); | |
222 int panel_2_orig_width = panel2->GetBounds().width(); | |
223 int panel_3_orig_width = panel3->GetBounds().width(); | |
224 int panel_4_orig_width = panel4->GetBounds().width(); | |
225 int panel_5_orig_width = panel5->GetBounds().width(); | |
226 int panel_6_orig_width = panel6->GetBounds().width(); | |
227 int panel_7_orig_width = panel7->GetBounds().width(); | |
228 | |
229 // The active panel should be at full width. | |
230 EXPECT_EQ(panel_7_orig_width, panel7->GetRestoredBounds().width()); | |
231 | |
232 // The rest of them should be at reduced width. | |
233 EXPECT_LT(panel_1_orig_width, panel1->GetRestoredBounds().width()); | |
234 EXPECT_LT(panel_2_orig_width, panel2->GetRestoredBounds().width()); | |
235 EXPECT_LT(panel_3_orig_width, panel3->GetRestoredBounds().width()); | |
236 EXPECT_LT(panel_4_orig_width, panel4->GetRestoredBounds().width()); | |
237 EXPECT_LT(panel_5_orig_width, panel5->GetRestoredBounds().width()); | |
238 EXPECT_LT(panel_6_orig_width, panel6->GetRestoredBounds().width()); | |
239 | |
240 // Close one panel. | |
241 content::WindowedNotificationObserver signal( | |
242 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED, | |
243 content::NotificationService::AllSources()); | |
244 CloseWindowAndWait(panel2); | |
245 signal.Wait(); | |
246 | |
247 // The widths of the remaining panels should have increased. | |
248 EXPECT_GT(panel1->GetBounds().width(), panel_1_orig_width); | |
249 EXPECT_GT(panel3->GetBounds().width(), panel_3_orig_width); | |
250 EXPECT_GT(panel4->GetBounds().width(), panel_4_orig_width); | |
251 EXPECT_GT(panel5->GetBounds().width(), panel_5_orig_width); | |
252 EXPECT_GT(panel6->GetBounds().width(), panel_6_orig_width); | |
253 | |
254 // The active panel should have stayed at full width. | |
255 EXPECT_EQ(panel7->GetBounds().width(), panel_7_orig_width); | |
256 | |
257 // Close several panels. | |
258 CloseWindowAndWait(panel3); | |
259 CloseWindowAndWait(panel5); | |
260 | |
261 // Wait for collection update after last close. | |
262 content::WindowedNotificationObserver signal2( | |
263 chrome::NOTIFICATION_PANEL_COLLECTION_UPDATED, | |
264 content::NotificationService::AllSources()); | |
265 CloseWindowAndWait(panel7); | |
266 signal2.Wait(); | |
267 | |
268 // We should not have squeezing any more; all panels should be at full width. | |
269 EXPECT_EQ(panel1->GetBounds().width(), panel1->GetRestoredBounds().width()); | |
270 EXPECT_EQ(panel4->GetBounds().width(), panel4->GetRestoredBounds().width()); | |
271 EXPECT_EQ(panel6->GetBounds().width(), panel6->GetRestoredBounds().width()); | |
272 | |
273 panel_manager->CloseAll(); | |
274 } | |
OLD | NEW |