| 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/old_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 OldPanelResizeBrowserTest : public OldBasePanelBrowserTest { | |
| 12 public: | |
| 13 OldPanelResizeBrowserTest() : OldBasePanelBrowserTest() { | |
| 14 } | |
| 15 | |
| 16 virtual ~OldPanelResizeBrowserTest() { | |
| 17 } | |
| 18 | |
| 19 virtual void SetUpOnMainThread() OVERRIDE { | |
| 20 OldBasePanelBrowserTest::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(OldPanelResizeBrowserTest, 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(OldPanelResizeBrowserTest, 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(OldPanelResizeBrowserTest, | |
| 218 ResizeDetachedPanelToClampSize) { | |
| 219 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 220 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); | |
| 221 | |
| 222 EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse()); | |
| 223 | |
| 224 gfx::Rect bounds = panel->GetBounds(); | |
| 225 | |
| 226 // Make sure the panel does not resize smaller than its min size. | |
| 227 gfx::Point mouse_location = bounds.origin().Add( | |
| 228 gfx::Point(30, bounds.height() - 2)); | |
| 229 panel_manager->StartResizingByMouse(panel, mouse_location, | |
| 230 panel::RESIZE_BOTTOM); | |
| 231 mouse_location.Offset(-20, -500); | |
| 232 panel_manager->ResizeByMouse(mouse_location); | |
| 233 | |
| 234 bounds.set_height(panel->min_size().height()); | |
| 235 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 236 | |
| 237 panel_manager->EndResizingByMouse(false); | |
| 238 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 239 | |
| 240 // Make sure the panel can resize larger than its size. User is in control. | |
| 241 mouse_location = bounds.origin().Add( | |
| 242 gfx::Point(bounds.width(), bounds.height() - 2)); | |
| 243 panel_manager->StartResizingByMouse(panel, mouse_location, | |
| 244 panel::RESIZE_BOTTOM_RIGHT); | |
| 245 | |
| 246 // This drag would take us beyond max size. | |
| 247 int delta_x = panel->max_size().width() + 10 - panel->GetBounds().width(); | |
| 248 int delta_y = panel->max_size().height() + 10 - panel->GetBounds().height(); | |
| 249 mouse_location.Offset(delta_x, delta_y); | |
| 250 panel_manager->ResizeByMouse(mouse_location); | |
| 251 | |
| 252 // The bounds if the max_size does not limit the resize. | |
| 253 bounds.set_size(gfx::Size(bounds.width() + delta_x, | |
| 254 bounds.height() + delta_y)); | |
| 255 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 256 | |
| 257 panel_manager->EndResizingByMouse(false); | |
| 258 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 259 | |
| 260 PanelManager::GetInstance()->CloseAll(); | |
| 261 } | |
| 262 | |
| 263 IN_PROC_BROWSER_TEST_F(OldPanelResizeBrowserTest, | |
| 264 CloseDetachedPanelOnResize) { | |
| 265 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 266 PanelResizeController* resize_controller = panel_manager->resize_controller(); | |
| 267 DetachedPanelStrip* detached_strip = panel_manager->detached_strip(); | |
| 268 | |
| 269 // Create 3 detached panels. | |
| 270 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 200, 100, 100)); | |
| 271 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 210, 110, 110)); | |
| 272 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(300, 220, 120, 120)); | |
| 273 ASSERT_EQ(3, detached_strip->num_panels()); | |
| 274 | |
| 275 gfx::Rect panel1_bounds = panel1->GetBounds(); | |
| 276 gfx::Rect panel2_bounds = panel2->GetBounds(); | |
| 277 gfx::Rect panel3_bounds = panel3->GetBounds(); | |
| 278 | |
| 279 // Start resizing panel1, and close panel2 in the process. | |
| 280 // Panel1 is not affected. | |
| 281 gfx::Point mouse_location = panel1_bounds.origin().Add( | |
| 282 gfx::Point(1, panel1_bounds.height() - 1)); | |
| 283 panel_manager->StartResizingByMouse(panel1, mouse_location, | |
| 284 panel::RESIZE_BOTTOM_LEFT); | |
| 285 mouse_location.Offset(-10, 15); | |
| 286 panel_manager->ResizeByMouse(mouse_location); | |
| 287 | |
| 288 panel1_bounds.set_size(gfx::Size(panel1_bounds.width() + 10, | |
| 289 panel1_bounds.height() + 15)); | |
| 290 panel1_bounds.Offset(-10, 0); | |
| 291 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); | |
| 292 | |
| 293 CloseWindowAndWait(panel2); | |
| 294 EXPECT_TRUE(resize_controller->IsResizing()); | |
| 295 EXPECT_EQ(2, detached_strip->num_panels()); | |
| 296 | |
| 297 panel_manager->EndResizingByMouse(false); | |
| 298 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); | |
| 299 | |
| 300 // Start resizing panel3, and close it in the process. | |
| 301 // Resize should abort, panel1 will not be affected. | |
| 302 mouse_location = panel3_bounds.origin().Add( | |
| 303 gfx::Point(panel3_bounds.width() - 1, panel3_bounds.height() - 2)); | |
| 304 panel_manager->StartResizingByMouse(panel3, mouse_location, | |
| 305 panel::RESIZE_BOTTOM_RIGHT); | |
| 306 mouse_location.Offset(7, -12); | |
| 307 panel_manager->ResizeByMouse(mouse_location); | |
| 308 | |
| 309 panel3_bounds.set_size(gfx::Size(panel3_bounds.width() + 7, | |
| 310 panel3_bounds.height() - 12)); | |
| 311 EXPECT_EQ(panel3_bounds, panel3->GetBounds()); | |
| 312 | |
| 313 CloseWindowAndWait(panel3); | |
| 314 EXPECT_EQ(1, detached_strip->num_panels()); | |
| 315 // Since we closed the panel we were resizing, we should be out of the | |
| 316 // resizing mode by now. | |
| 317 EXPECT_FALSE(resize_controller->IsResizing()); | |
| 318 | |
| 319 panel_manager->EndResizingByMouse(false); | |
| 320 EXPECT_FALSE(resize_controller->IsResizing()); | |
| 321 EXPECT_EQ(panel1_bounds, panel1->GetBounds()); | |
| 322 | |
| 323 panel_manager->CloseAll(); | |
| 324 } | |
| 325 | |
| 326 IN_PROC_BROWSER_TEST_F(OldPanelResizeBrowserTest, ResizeAndCancel) { | |
| 327 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 328 Panel* panel = CreateDetachedPanel("Panel", gfx::Rect(300, 200, 150, 100)); | |
| 329 PanelResizeController* resize_controller = panel_manager->resize_controller(); | |
| 330 | |
| 331 EXPECT_EQ(panel::RESIZABLE_ALL_SIDES, panel->CanResizeByMouse()); | |
| 332 | |
| 333 gfx::Rect original_bounds = panel->GetBounds(); | |
| 334 | |
| 335 // Resizing the panel, then cancelling should return it to the original state. | |
| 336 // Try resizing by the top right side. | |
| 337 gfx::Rect bounds = panel->GetBounds(); | |
| 338 gfx::Point mouse_location = bounds.origin().Add( | |
| 339 gfx::Point(bounds.width() - 1, 1)); | |
| 340 panel_manager->StartResizingByMouse(panel, mouse_location, | |
| 341 panel::RESIZE_TOP_RIGHT); | |
| 342 mouse_location.Offset(5, 25); | |
| 343 panel_manager->ResizeByMouse(mouse_location); | |
| 344 | |
| 345 bounds.set_size(gfx::Size(bounds.width() + 5, bounds.height() - 25)); | |
| 346 bounds.Offset(0, 25); | |
| 347 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 348 | |
| 349 panel_manager->EndResizingByMouse(true); | |
| 350 EXPECT_EQ(original_bounds, panel->GetBounds()); | |
| 351 | |
| 352 // Try resizing by the bottom left side. | |
| 353 bounds = panel->GetBounds(); | |
| 354 mouse_location = bounds.origin().Add( | |
| 355 gfx::Point(1, bounds.height() - 1)); | |
| 356 panel_manager->StartResizingByMouse(panel, mouse_location, | |
| 357 panel::RESIZE_BOTTOM_LEFT); | |
| 358 mouse_location.Offset(-10, 15); | |
| 359 panel_manager->ResizeByMouse(mouse_location); | |
| 360 | |
| 361 bounds.set_size(gfx::Size(bounds.width() + 10, bounds.height() + 15)); | |
| 362 bounds.Offset(-10, 0); | |
| 363 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 364 | |
| 365 panel_manager->EndResizingByMouse(true); | |
| 366 EXPECT_EQ(original_bounds, panel->GetBounds()); | |
| 367 EXPECT_FALSE(resize_controller->IsResizing()); | |
| 368 | |
| 369 panel_manager->CloseAll(); | |
| 370 } | |
| 371 | |
| 372 IN_PROC_BROWSER_TEST_F(OldPanelResizeBrowserTest, ResizeDetachedPanelToTop) { | |
| 373 // Setup the test areas to have top-aligned bar excluded from work area. | |
| 374 const gfx::Rect primary_scren_area(0, 0, 800, 600); | |
| 375 const gfx::Rect work_area(0, 10, 800, 590); | |
| 376 SetTestingAreas(primary_scren_area, work_area); | |
| 377 | |
| 378 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 379 Panel* panel = CreateDetachedPanel("1", gfx::Rect(300, 200, 250, 200)); | |
| 380 gfx::Rect bounds = panel->GetBounds(); | |
| 381 | |
| 382 // Try resizing by the top left corner. | |
| 383 gfx::Point mouse_location = bounds.origin(); | |
| 384 panel_manager->StartResizingByMouse(panel, | |
| 385 mouse_location, | |
| 386 panel::RESIZE_TOP_LEFT); | |
| 387 | |
| 388 // Try moving the mouse outside the top of the work area. Expect that panel's | |
| 389 // top position will not exceed the top of the work area. | |
| 390 mouse_location = gfx::Point(250, 2); | |
| 391 panel_manager->ResizeByMouse(mouse_location); | |
| 392 | |
| 393 bounds.set_width(bounds.width() + bounds.x() - mouse_location.x()); | |
| 394 bounds.set_height(bounds.height() + bounds.y() - work_area.y()); | |
| 395 bounds.set_x(mouse_location.x()); | |
| 396 bounds.set_y(work_area.y()); | |
| 397 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 398 | |
| 399 // Try moving the mouse inside the work area. Expect that the panel can be | |
| 400 // resized without constraint. | |
| 401 mouse_location = gfx::Point(280, 50); | |
| 402 panel_manager->ResizeByMouse(mouse_location); | |
| 403 | |
| 404 bounds.set_width(bounds.width() + bounds.x() - mouse_location.x()); | |
| 405 bounds.set_height(bounds.height() + bounds.y() - mouse_location.y()); | |
| 406 bounds.set_x(mouse_location.x()); | |
| 407 bounds.set_y(mouse_location.y()); | |
| 408 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 409 | |
| 410 panel_manager->EndResizingByMouse(false); | |
| 411 EXPECT_EQ(bounds, panel->GetBounds()); | |
| 412 | |
| 413 panel_manager->CloseAll(); | |
| 414 } | |
| OLD | NEW |