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