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