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 "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 6 #include "chrome/browser/ui/panels/detached_panel_strip.h" |
| 7 #include "chrome/browser/ui/panels/panel.h" |
| 8 #include "chrome/browser/ui/panels/panel_manager.h" |
| 9 #include "chrome/browser/ui/panels/panel_resize_controller.h" |
| 10 |
| 11 class PanelResizeBrowserTest : public BasePanelBrowserTest { |
| 12 public: |
| 13 PanelResizeBrowserTest() : BasePanelBrowserTest() { |
| 14 } |
| 15 |
| 16 virtual ~PanelResizeBrowserTest() { |
| 17 } |
| 18 |
| 19 virtual void SetUpOnMainThread() OVERRIDE { |
| 20 BasePanelBrowserTest::SetUpOnMainThread(); |
| 21 |
| 22 // All the tests here assume using mocked 800x600 screen area for the |
| 23 // primary monitor. Do the check now. |
| 24 gfx::Rect primary_screen_area = PanelManager::GetInstance()-> |
| 25 display_settings_provider()->GetPrimaryScreenArea(); |
| 26 DCHECK(primary_screen_area.width() == 800); |
| 27 DCHECK(primary_screen_area.height() == 600); |
| 28 } |
| 29 }; |
| 30 |
| 31 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, DockedPanelResizability) { |
| 32 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 33 Panel* panel = CreatePanel("Panel"); |
| 34 |
| 35 EXPECT_EQ(panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM, |
| 36 panel->CanResizeByMouse()); |
| 37 |
| 38 gfx::Rect bounds = panel->GetBounds(); |
| 39 |
| 40 // Try resizing by the top left corner. |
| 41 gfx::Point mouse_location = bounds.origin(); |
| 42 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 43 panel::RESIZE_TOP_LEFT); |
| 44 mouse_location.Offset(-20, -10); |
| 45 panel_manager->ResizeByMouse(mouse_location); |
| 46 |
| 47 bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10)); |
| 48 bounds.Offset(-20, -10); |
| 49 EXPECT_EQ(bounds, panel->GetBounds()); |
| 50 |
| 51 panel_manager->EndResizingByMouse(false); |
| 52 EXPECT_EQ(bounds, panel->GetBounds()); |
| 53 |
| 54 // Try resizing by the top. |
| 55 mouse_location = bounds.origin().Add(gfx::Point(10, 1)); |
| 56 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 57 panel::RESIZE_TOP); |
| 58 mouse_location.Offset(5, -10); |
| 59 panel_manager->ResizeByMouse(mouse_location); |
| 60 |
| 61 bounds.set_height(bounds.height() + 10); |
| 62 bounds.Offset(0, -10); |
| 63 EXPECT_EQ(bounds, panel->GetBounds()); |
| 64 |
| 65 panel_manager->EndResizingByMouse(false); |
| 66 EXPECT_EQ(bounds, panel->GetBounds()); |
| 67 |
| 68 // Try resizing by the left side. |
| 69 mouse_location = bounds.origin().Add(gfx::Point(1, 30)); |
| 70 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 71 panel::RESIZE_LEFT); |
| 72 mouse_location.Offset(-5, 25); |
| 73 panel_manager->ResizeByMouse(mouse_location); |
| 74 |
| 75 bounds.set_width(bounds.width() + 5); |
| 76 bounds.Offset(-5, 0); |
| 77 EXPECT_EQ(bounds, panel->GetBounds()); |
| 78 |
| 79 panel_manager->EndResizingByMouse(false); |
| 80 EXPECT_EQ(bounds, panel->GetBounds()); |
| 81 |
| 82 // Try resizing by the top right side. |
| 83 mouse_location = bounds.origin().Add(gfx::Point(bounds.width() - 1, 2)); |
| 84 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 85 panel::RESIZE_TOP_RIGHT); |
| 86 mouse_location.Offset(30, 20); |
| 87 panel_manager->ResizeByMouse(mouse_location); |
| 88 |
| 89 bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20)); |
| 90 bounds.Offset(0, 20); |
| 91 EXPECT_EQ(bounds, panel->GetBounds()); |
| 92 |
| 93 panel_manager->EndResizingByMouse(false); |
| 94 WaitForBoundsAnimationFinished(panel); |
| 95 bounds.Offset(-30, 0); // Layout of panel adjusted in docked strip. |
| 96 EXPECT_EQ(bounds, panel->GetBounds()); |
| 97 |
| 98 // Try resizing by the right side. |
| 99 mouse_location = bounds.origin().Add(gfx::Point(bounds.width() - 1, 30)); |
| 100 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 101 panel::RESIZE_RIGHT); |
| 102 mouse_location.Offset(5, 25); |
| 103 panel_manager->ResizeByMouse(mouse_location); |
| 104 |
| 105 bounds.set_width(bounds.width() + 5); |
| 106 EXPECT_EQ(bounds, panel->GetBounds()); |
| 107 |
| 108 panel_manager->EndResizingByMouse(false); |
| 109 WaitForBoundsAnimationFinished(panel); |
| 110 bounds.Offset(-5, 0); // Layout of panel adjusted in docked strip. |
| 111 EXPECT_EQ(bounds, panel->GetBounds()); |
| 112 |
| 113 // Try resizing by the bottom side; verify resize won't work. |
| 114 mouse_location = bounds.origin().Add(gfx::Point(10, bounds.height() - 1)); |
| 115 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 116 panel::RESIZE_BOTTOM); |
| 117 mouse_location.Offset(30, -10); |
| 118 panel_manager->ResizeByMouse(mouse_location); |
| 119 EXPECT_EQ(bounds, panel->GetBounds()); |
| 120 |
| 121 panel_manager->EndResizingByMouse(false); |
| 122 EXPECT_EQ(bounds, panel->GetBounds()); |
| 123 |
| 124 // Try resizing by the bottom left corner; verify resize won't work. |
| 125 mouse_location = bounds.origin().Add(gfx::Point(1, bounds.height() - 1)); |
| 126 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 127 panel::RESIZE_BOTTOM_LEFT); |
| 128 mouse_location.Offset(-10, 15); |
| 129 panel_manager->ResizeByMouse(mouse_location); |
| 130 EXPECT_EQ(bounds, panel->GetBounds()); |
| 131 |
| 132 panel_manager->EndResizingByMouse(false); |
| 133 EXPECT_EQ(bounds, panel->GetBounds()); |
| 134 |
| 135 // Try resizing by the bottom right corner; verify resize won't work. |
| 136 mouse_location = bounds.origin().Add( |
| 137 gfx::Point(bounds.width() - 2, bounds.height())); |
| 138 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 139 panel::RESIZE_BOTTOM_RIGHT); |
| 140 mouse_location.Offset(20, 10); |
| 141 panel_manager->ResizeByMouse(mouse_location); |
| 142 EXPECT_EQ(bounds, panel->GetBounds()); |
| 143 |
| 144 panel_manager->EndResizingByMouse(false); |
| 145 EXPECT_EQ(bounds, panel->GetBounds()); |
| 146 |
| 147 panel->Close(); |
| 148 } |
| 149 |
| 150 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanel) { |
| 151 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 152 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); |
| 153 |
| 154 EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse()); |
| 155 |
| 156 gfx::Rect bounds = panel->GetBounds(); |
| 157 |
| 158 // Try resizing by the right side; verify resize will change width only. |
| 159 gfx::Point mouse_location = bounds.origin().Add( |
| 160 gfx::Point(bounds.width() - 1, 30)); |
| 161 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 162 panel::RESIZE_RIGHT); |
| 163 mouse_location.Offset(5, 25); |
| 164 panel_manager->ResizeByMouse(mouse_location); |
| 165 |
| 166 bounds.set_width(bounds.width() + 5); |
| 167 EXPECT_EQ(bounds, panel->GetBounds()); |
| 168 |
| 169 panel_manager->EndResizingByMouse(false); |
| 170 EXPECT_EQ(bounds, panel->GetBounds()); |
| 171 |
| 172 // Try resizing by the bottom left side. |
| 173 mouse_location = bounds.origin().Add(gfx::Point(1, bounds.height() - 1)); |
| 174 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 175 panel::RESIZE_BOTTOM_LEFT); |
| 176 mouse_location.Offset(-10, 15); |
| 177 panel_manager->ResizeByMouse(mouse_location); |
| 178 |
| 179 bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15)); |
| 180 bounds.Offset(-10, 0); |
| 181 EXPECT_EQ(bounds, panel->GetBounds()); |
| 182 |
| 183 panel_manager->EndResizingByMouse(false); |
| 184 EXPECT_EQ(bounds, panel->GetBounds()); |
| 185 |
| 186 // Try resizing by the top right side. |
| 187 mouse_location = bounds.origin().Add(gfx::Point(bounds.width() - 1, 2)); |
| 188 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 189 panel::RESIZE_TOP_RIGHT); |
| 190 mouse_location.Offset(30, 20); |
| 191 panel_manager->ResizeByMouse(mouse_location); |
| 192 |
| 193 bounds.set_size(gfx::Size(bounds.width() + 30, bounds.height() - 20)); |
| 194 bounds.Offset(0, 20); |
| 195 EXPECT_EQ(bounds, panel->GetBounds()); |
| 196 |
| 197 panel_manager->EndResizingByMouse(false); |
| 198 EXPECT_EQ(bounds, panel->GetBounds()); |
| 199 |
| 200 // Try resizing by the top left side. |
| 201 mouse_location = bounds.origin().Add(gfx::Point(1, 0)); |
| 202 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 203 panel::RESIZE_TOP_LEFT); |
| 204 mouse_location.Offset(-20, -10); |
| 205 panel_manager->ResizeByMouse(mouse_location); |
| 206 |
| 207 bounds.set_size(gfx::Size(bounds.width() + 20, bounds.height() + 10)); |
| 208 bounds.Offset(-20, -10); |
| 209 EXPECT_EQ(bounds, panel->GetBounds()); |
| 210 |
| 211 panel_manager->EndResizingByMouse(false); |
| 212 EXPECT_EQ(bounds, panel->GetBounds()); |
| 213 |
| 214 PanelManager::GetInstance()->CloseAll(); |
| 215 } |
| 216 |
| 217 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanelToClampSize) { |
| 218 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 219 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); |
| 220 |
| 221 EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse()); |
| 222 |
| 223 gfx::Rect bounds = panel->GetBounds(); |
| 224 |
| 225 // Make sure the panel does not resize smaller than its min size. |
| 226 gfx::Point mouse_location = bounds.origin().Add( |
| 227 gfx::Point(30, bounds.height() - 2)); |
| 228 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 229 panel::RESIZE_BOTTOM); |
| 230 mouse_location.Offset(-20, -500); |
| 231 panel_manager->ResizeByMouse(mouse_location); |
| 232 |
| 233 bounds.set_height(panel->min_size().height()); |
| 234 EXPECT_EQ(bounds, panel->GetBounds()); |
| 235 |
| 236 panel_manager->EndResizingByMouse(false); |
| 237 EXPECT_EQ(bounds, panel->GetBounds()); |
| 238 |
| 239 // Make sure the panel can resize larger than its size. User is in control. |
| 240 mouse_location = bounds.origin().Add( |
| 241 gfx::Point(bounds.width(), bounds.height() - 2)); |
| 242 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 243 panel::RESIZE_BOTTOM_RIGHT); |
| 244 |
| 245 // This drag would take us beyond max size. |
| 246 int delta_x = panel->max_size().width() + 10 - panel->GetBounds().width(); |
| 247 int delta_y = panel->max_size().height() + 10 - panel->GetBounds().height(); |
| 248 mouse_location.Offset(delta_x, delta_y); |
| 249 panel_manager->ResizeByMouse(mouse_location); |
| 250 |
| 251 // The bounds if the max_size does not limit the resize. |
| 252 bounds.set_size(gfx::Size(bounds.width() + delta_x, |
| 253 bounds.height() + delta_y)); |
| 254 EXPECT_EQ(bounds, panel->GetBounds()); |
| 255 |
| 256 panel_manager->EndResizingByMouse(false); |
| 257 EXPECT_EQ(bounds, panel->GetBounds()); |
| 258 |
| 259 PanelManager::GetInstance()->CloseAll(); |
| 260 } |
| 261 |
| 262 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, CloseDetachedPanelOnResize) { |
| 263 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 264 PanelResizeController* resize_controller = panel_manager->resize_controller(); |
| 265 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); |
| 266 |
| 267 // Create 3 detached panels. |
| 268 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 200, 100, 100)); |
| 269 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 210, 110, 110)); |
| 270 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(300, 220, 120, 120)); |
| 271 ASSERT_EQ(3, detached_strip->num_panels()); |
| 272 |
| 273 gfx::Rect panel1_bounds = panel1->GetBounds(); |
| 274 gfx::Rect panel2_bounds = panel2->GetBounds(); |
| 275 gfx::Rect panel3_bounds = panel3->GetBounds(); |
| 276 |
| 277 // Start resizing panel1, and close panel2 in the process. |
| 278 // Panel1 is not affected. |
| 279 gfx::Point mouse_location = panel1_bounds.origin().Add( |
| 280 gfx::Point(1, panel1_bounds.height() - 1)); |
| 281 panel_manager->StartResizingByMouse(panel1, mouse_location, |
| 282 panel::RESIZE_BOTTOM_LEFT); |
| 283 mouse_location.Offset(-10, 15); |
| 284 panel_manager->ResizeByMouse(mouse_location); |
| 285 |
| 286 panel1_bounds.set_size(gfx::Size(panel1_bounds.width() + 10, |
| 287 panel1_bounds.height() + 15)); |
| 288 panel1_bounds.Offset(-10, 0); |
| 289 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); |
| 290 |
| 291 CloseWindowAndWait(panel2); |
| 292 EXPECT_TRUE(resize_controller->IsResizing()); |
| 293 EXPECT_EQ(2, detached_strip->num_panels()); |
| 294 |
| 295 panel_manager->EndResizingByMouse(false); |
| 296 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); |
| 297 |
| 298 // Start resizing panel3, and close it in the process. |
| 299 // Resize should abort, panel1 will not be affected. |
| 300 mouse_location = panel3_bounds.origin().Add( |
| 301 gfx::Point(panel3_bounds.width() - 1, panel3_bounds.height() - 2)); |
| 302 panel_manager->StartResizingByMouse(panel3, mouse_location, |
| 303 panel::RESIZE_BOTTOM_RIGHT); |
| 304 mouse_location.Offset(7, -12); |
| 305 panel_manager->ResizeByMouse(mouse_location); |
| 306 |
| 307 panel3_bounds.set_size(gfx::Size(panel3_bounds.width() + 7, |
| 308 panel3_bounds.height() - 12)); |
| 309 EXPECT_EQ(panel3_bounds, panel3->GetBounds()); |
| 310 |
| 311 CloseWindowAndWait(panel3); |
| 312 EXPECT_EQ(1, detached_strip->num_panels()); |
| 313 // Since we closed the panel we were resizing, we should be out of the |
| 314 // resizing mode by now. |
| 315 EXPECT_FALSE(resize_controller->IsResizing()); |
| 316 |
| 317 panel_manager->EndResizingByMouse(false); |
| 318 EXPECT_FALSE(resize_controller->IsResizing()); |
| 319 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); |
| 320 |
| 321 panel_manager->CloseAll(); |
| 322 } |
| 323 |
| 324 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeAndCancel) { |
| 325 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 326 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); |
| 327 PanelResizeController* resize_controller = panel_manager->resize_controller(); |
| 328 |
| 329 EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse()); |
| 330 |
| 331 gfx::Rect original_bounds = panel->GetBounds(); |
| 332 |
| 333 // Resizing the panel, then cancelling should return it to the original state. |
| 334 // Try resizing by the top right side. |
| 335 gfx::Rect bounds = panel->GetBounds(); |
| 336 gfx::Point mouse_location = bounds.origin().Add( |
| 337 gfx::Point(bounds.width() - 1, 1)); |
| 338 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 339 panel::RESIZE_TOP_RIGHT); |
| 340 mouse_location.Offset(5, 25); |
| 341 panel_manager->ResizeByMouse(mouse_location); |
| 342 |
| 343 bounds.set_size(gfx::Size(bounds.width() + 5, bounds.height() - 25)); |
| 344 bounds.Offset(0, 25); |
| 345 EXPECT_EQ(bounds, panel->GetBounds()); |
| 346 |
| 347 panel_manager->EndResizingByMouse(true); |
| 348 EXPECT_EQ(original_bounds, panel->GetBounds()); |
| 349 |
| 350 // Try resizing by the bottom left side. |
| 351 bounds = panel->GetBounds(); |
| 352 mouse_location = bounds.origin().Add( |
| 353 gfx::Point(1, bounds.height() - 1)); |
| 354 panel_manager->StartResizingByMouse(panel, mouse_location, |
| 355 panel::RESIZE_BOTTOM_LEFT); |
| 356 mouse_location.Offset(-10, 15); |
| 357 panel_manager->ResizeByMouse(mouse_location); |
| 358 |
| 359 bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15)); |
| 360 bounds.Offset(-10, 0); |
| 361 EXPECT_EQ(bounds, panel->GetBounds()); |
| 362 |
| 363 panel_manager->EndResizingByMouse(true); |
| 364 EXPECT_EQ(original_bounds, panel->GetBounds()); |
| 365 EXPECT_FALSE(resize_controller->IsResizing()); |
| 366 |
| 367 panel_manager->CloseAll(); |
| 368 } |
| 369 |
| 370 IN_PROC_BROWSER_TEST_F(PanelResizeBrowserTest, ResizeDetachedPanelToTop) { |
| 371 // Setup the test areas to have top-aligned bar excluded from work area. |
| 372 const gfx::Rect primary_scren_area(0, 0, 800, 600); |
| 373 const gfx::Rect work_area(0, 10, 800, 590); |
| 374 SetTestingAreas(primary_scren_area, work_area); |
| 375 |
| 376 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 377 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); |
| 378 gfx::Rect bounds = panel->GetBounds(); |
| 379 |
| 380 // Try resizing by the top left corner. |
| 381 gfx::Point mouse_location = bounds.origin(); |
| 382 panel_manager->StartResizingByMouse(panel, |
| 383 mouse_location, |
| 384 panel::RESIZE_TOP_LEFT); |
| 385 |
| 386 // Try moving the mouse outside the top of the work area. Expect that panel's |
| 387 // top position will not exceed the top of the work area. |
| 388 mouse_location = gfx::Point(250, 2); |
| 389 panel_manager->ResizeByMouse(mouse_location); |
| 390 |
| 391 bounds.set_width(bounds.width() + bounds.x() - mouse_location.x()); |
| 392 bounds.set_height(bounds.height() + bounds.y() - work_area.y()); |
| 393 bounds.set_x(mouse_location.x()); |
| 394 bounds.set_y(work_area.y()); |
| 395 EXPECT_EQ(bounds, panel->GetBounds()); |
| 396 |
| 397 // Try moving the mouse inside the work area. Expect that the panel can be |
| 398 // resized without constraint. |
| 399 mouse_location = gfx::Point(280, 50); |
| 400 panel_manager->ResizeByMouse(mouse_location); |
| 401 |
| 402 bounds.set_width(bounds.width() + bounds.x() - mouse_location.x()); |
| 403 bounds.set_height(bounds.height() + bounds.y() - mouse_location.y()); |
| 404 bounds.set_x(mouse_location.x()); |
| 405 bounds.set_y(mouse_location.y()); |
| 406 EXPECT_EQ(bounds, panel->GetBounds()); |
| 407 |
| 408 panel_manager->EndResizingByMouse(false); |
| 409 EXPECT_EQ(bounds, panel->GetBounds()); |
| 410 |
| 411 panel_manager->CloseAll(); |
| 412 } |
OLD | NEW |