| 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/window_sizer.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "ash/shell.h" | |
| 10 #include "ash/shell_window_ids.h" | |
| 11 #include "ash/test/ash_test_base.h" | |
| 12 #include "ash/test/test_shell_delegate.h" | |
| 13 #include "ash/wm/window_resizer.h" | |
| 14 #include "base/compiler_specific.h" | |
| 15 #include "base/logging.h" | |
| 16 #include "chrome/browser/ui/browser.h" | |
| 17 #include "chrome/browser/ui/window_sizer_common_unittest.h" | |
| 18 #include "chrome/test/base/testing_profile.h" | |
| 19 #include "chrome/test/base/test_browser_window.h" | |
| 20 #include "content/public/browser/browser_thread.h" | |
| 21 #include "content/public/test/render_view_test.h" | |
| 22 #include "content/public/test/test_browser_thread.h" | |
| 23 #include "testing/gtest/include/gtest/gtest.h" | |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | |
| 25 #include "ui/aura/env.h" | |
| 26 #include "ui/aura/root_window.h" | |
| 27 #include "ui/aura/test/test_windows.h" | |
| 28 | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 typedef ash::test::AshTestBase WindowSizerTest; | |
| 33 | |
| 34 // A special test class for use with browser creation - it will create a | |
| 35 // browser thread and deletes it after all other things have been destroyed. | |
| 36 class WindowSizerTestWithBrowser : public WindowSizerTest { | |
| 37 public: | |
| 38 WindowSizerTestWithBrowser(); | |
| 39 virtual ~WindowSizerTestWithBrowser(); | |
| 40 | |
| 41 private: | |
| 42 // Note: It is important to delete the thread after the browser instances got | |
| 43 // deleted. For this we transfer the thread here. | |
| 44 scoped_ptr<content::TestBrowserThread> ui_thread_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(WindowSizerTestWithBrowser); | |
| 47 }; | |
| 48 | |
| 49 WindowSizerTestWithBrowser::WindowSizerTestWithBrowser() { | |
| 50 // Set up a UI message thread. | |
| 51 MessageLoopForUI* ui_loop = message_loop(); | |
| 52 ui_thread_.reset( | |
| 53 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); | |
| 54 } | |
| 55 | |
| 56 WindowSizerTestWithBrowser::~WindowSizerTestWithBrowser() { | |
| 57 } | |
| 58 | |
| 59 // A browser window proxy which is able to associate an aura native window with | |
| 60 // it. | |
| 61 class TestBrowserWindowAura : public TestBrowserWindow { | |
| 62 public: | |
| 63 TestBrowserWindowAura(Browser* browser, aura::Window* native_window); | |
| 64 virtual ~TestBrowserWindowAura(); | |
| 65 | |
| 66 virtual gfx::NativeWindow GetNativeWindow() OVERRIDE { | |
| 67 return native_window_; | |
| 68 } | |
| 69 | |
| 70 private: | |
| 71 gfx::NativeWindow native_window_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); | |
| 74 }; | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 78 TestBrowserWindowAura::TestBrowserWindowAura( | |
| 79 Browser* browser, | |
| 80 aura::Window *native_window) | |
| 81 : TestBrowserWindow(browser), | |
| 82 native_window_(native_window) { | |
| 83 } | |
| 84 | |
| 85 TestBrowserWindowAura::~TestBrowserWindowAura() {} | |
| 86 | |
| 87 // Test that the window is sized appropriately for the first run experience | |
| 88 // where the default window bounds calculation is invoked. | |
| 89 TEST_F(WindowSizerTest, DefaultSizeCase) { | |
| 90 int grid = ash::Shell::GetInstance()->GetGridSize(); | |
| 91 EXPECT_EQ(WindowSizer::kDesktopBorderSize, grid); | |
| 92 { // 4:3 monitor case, 1024x768, no taskbar | |
| 93 gfx::Rect window_bounds; | |
| 94 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | |
| 95 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | |
| 96 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 97 WindowSizer::kDesktopBorderSize, | |
| 98 1024 - WindowSizer::kDesktopBorderSize * 2, | |
| 99 768 - WindowSizer::kDesktopBorderSize), | |
| 100 window_bounds); | |
| 101 } | |
| 102 | |
| 103 { // 4:3 monitor case, 1024x768, taskbar on bottom | |
| 104 gfx::Rect window_bounds; | |
| 105 GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(), | |
| 106 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, | |
| 107 gfx::Rect()); | |
| 108 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 109 WindowSizer::kDesktopBorderSize, | |
| 110 1024 - WindowSizer::kDesktopBorderSize * 2, | |
| 111 ash::WindowResizer::AlignToGridRoundDown( | |
| 112 taskbar_bottom_work_area.height() - | |
| 113 WindowSizer::kDesktopBorderSize, grid)), | |
| 114 window_bounds); | |
| 115 } | |
| 116 | |
| 117 { // 4:3 monitor case, 1024x768, taskbar on right | |
| 118 gfx::Rect window_bounds; | |
| 119 GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(), | |
| 120 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, | |
| 121 gfx::Rect()); | |
| 122 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 123 WindowSizer::kDesktopBorderSize, | |
| 124 ash::WindowResizer::AlignToGridRoundDown( | |
| 125 taskbar_right_work_area.width() - | |
| 126 WindowSizer::kDesktopBorderSize * 2, grid), | |
| 127 768 - WindowSizer::kDesktopBorderSize), | |
| 128 window_bounds); | |
| 129 } | |
| 130 | |
| 131 { // 4:3 monitor case, 1024x768, taskbar on left | |
| 132 gfx::Rect window_bounds; | |
| 133 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), | |
| 134 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, | |
| 135 gfx::Rect()); | |
| 136 EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + | |
| 137 WindowSizer::kDesktopBorderSize, | |
| 138 WindowSizer::kDesktopBorderSize, | |
| 139 ash::WindowResizer::AlignToGridRoundDown( | |
| 140 taskbar_left_work_area.width() - | |
| 141 WindowSizer::kDesktopBorderSize * 2, grid), | |
| 142 ash::WindowResizer::AlignToGridRoundDown( | |
| 143 taskbar_left_work_area.height() - | |
| 144 WindowSizer::kDesktopBorderSize, grid)), | |
| 145 window_bounds); | |
| 146 } | |
| 147 | |
| 148 { // 4:3 monitor case, 1024x768, taskbar on top | |
| 149 gfx::Rect window_bounds; | |
| 150 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), | |
| 151 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL, | |
| 152 gfx::Rect()); | |
| 153 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 154 taskbar_top_work_area.y() + | |
| 155 WindowSizer::kDesktopBorderSize, | |
| 156 1024 - WindowSizer::kDesktopBorderSize * 2, | |
| 157 ash::WindowResizer::AlignToGridRoundDown( | |
| 158 taskbar_top_work_area.height() - | |
| 159 WindowSizer::kDesktopBorderSize, grid)), | |
| 160 window_bounds); | |
| 161 } | |
| 162 | |
| 163 { // 4:3 monitor case, 1280x1024 | |
| 164 gfx::Rect window_bounds; | |
| 165 GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(), | |
| 166 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | |
| 167 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 168 WindowSizer::kDesktopBorderSize, | |
| 169 1280 - 2 * WindowSizer::kDesktopBorderSize, | |
| 170 1024 - WindowSizer::kDesktopBorderSize), | |
| 171 window_bounds); | |
| 172 } | |
| 173 | |
| 174 { // 4:3 monitor case, 1600x1200 | |
| 175 gfx::Rect window_bounds; | |
| 176 GetWindowBounds(sixteenhundred, sixteenhundred, gfx::Rect(), gfx::Rect(), | |
| 177 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | |
| 178 EXPECT_EQ(gfx::Rect((1600 - 1280) / 2, WindowSizer::kDesktopBorderSize, | |
| 179 1280, | |
| 180 1200 - WindowSizer::kDesktopBorderSize), | |
| 181 window_bounds); | |
| 182 } | |
| 183 | |
| 184 { // 16:10 monitor case, 1680x1050 | |
| 185 gfx::Rect window_bounds; | |
| 186 GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(), | |
| 187 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | |
| 188 EXPECT_EQ(gfx::Rect((1680 - 1280) / 2, WindowSizer::kDesktopBorderSize, | |
| 189 1280, | |
| 190 ash::WindowResizer::AlignToGridRoundDown( | |
| 191 1050 - WindowSizer::kDesktopBorderSize, | |
| 192 grid)), | |
| 193 window_bounds); | |
| 194 } | |
| 195 | |
| 196 { // 16:10 monitor case, 1920x1200 | |
| 197 gfx::Rect window_bounds; | |
| 198 GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(), | |
| 199 gfx::Rect(), DEFAULT, &window_bounds, NULL, gfx::Rect()); | |
| 200 EXPECT_EQ(gfx::Rect((1920 - 1280) / 2, WindowSizer::kDesktopBorderSize, | |
| 201 1280, | |
| 202 1200 - WindowSizer::kDesktopBorderSize), | |
| 203 window_bounds); | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 // Test that the next opened window is positioned appropriately given the | |
| 208 // bounds of an existing window of the same type. | |
| 209 TEST_F(WindowSizerTest, LastWindowBoundsCase) { | |
| 210 { // normal, in the middle of the screen somewhere. | |
| 211 gfx::Rect window_bounds; | |
| 212 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 213 gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 214 WindowSizer::kDesktopBorderSize, 500, 400), | |
| 215 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | |
| 216 gfx::Rect()); | |
| 217 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 218 kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 219 500, 400), | |
| 220 window_bounds); | |
| 221 } | |
| 222 | |
| 223 { // taskbar on top. | |
| 224 gfx::Rect window_bounds; | |
| 225 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), | |
| 226 gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 227 WindowSizer::kDesktopBorderSize, 500, 400), | |
| 228 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | |
| 229 gfx::Rect()); | |
| 230 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 231 std::max(kWindowTilePixels + | |
| 232 WindowSizer::kDesktopBorderSize, | |
| 233 34 /* toolbar height */), | |
| 234 500, 400), window_bounds); | |
| 235 } | |
| 236 | |
| 237 { // Too small to satisify the minimum visibility condition. | |
| 238 gfx::Rect window_bounds; | |
| 239 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 240 gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 241 WindowSizer::kDesktopBorderSize, 29, 29), | |
| 242 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | |
| 243 gfx::Rect()); | |
| 244 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 245 kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 246 30 /* not 29 */, | |
| 247 30 /* not 29 */), | |
| 248 window_bounds); | |
| 249 } | |
| 250 | |
| 251 | |
| 252 { // Normal. | |
| 253 gfx::Rect window_bounds; | |
| 254 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 255 gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 256 WindowSizer::kDesktopBorderSize, 500, 400), | |
| 257 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | |
| 258 gfx::Rect()); | |
| 259 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 260 kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 261 500, 400), | |
| 262 window_bounds); | |
| 263 } | |
| 264 } | |
| 265 | |
| 266 // Test that the window opened is sized appropriately given persisted sizes. | |
| 267 TEST_F(WindowSizerTest, PersistedBoundsCase) { | |
| 268 { // normal, in the middle of the screen somewhere. | |
| 269 gfx::Rect initial_bounds(WindowSizer::kDesktopBorderSize, | |
| 270 WindowSizer::kDesktopBorderSize, 500, 400); | |
| 271 | |
| 272 gfx::Rect window_bounds; | |
| 273 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, | |
| 274 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); | |
| 275 EXPECT_EQ(initial_bounds, window_bounds); | |
| 276 } | |
| 277 | |
| 278 { // Normal. | |
| 279 gfx::Rect initial_bounds(0, 0, 1024, 768); | |
| 280 | |
| 281 gfx::Rect window_bounds; | |
| 282 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, | |
| 283 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); | |
| 284 EXPECT_EQ(initial_bounds, window_bounds); | |
| 285 } | |
| 286 | |
| 287 { // normal, on non-primary monitor in negative coords. | |
| 288 gfx::Rect initial_bounds(-600, 10, 500, 400); | |
| 289 | |
| 290 gfx::Rect window_bounds; | |
| 291 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, | |
| 292 initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, | |
| 293 NULL, gfx::Rect()); | |
| 294 EXPECT_EQ(initial_bounds, window_bounds); | |
| 295 } | |
| 296 | |
| 297 { // normal, on non-primary monitor in negative coords. | |
| 298 gfx::Rect initial_bounds(-1024, 0, 1024, 768); | |
| 299 | |
| 300 gfx::Rect window_bounds; | |
| 301 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, | |
| 302 initial_bounds, gfx::Rect(), PERSISTED, &window_bounds, | |
| 303 NULL, gfx::Rect()); | |
| 304 EXPECT_EQ(initial_bounds, window_bounds); | |
| 305 } | |
| 306 | |
| 307 { // Non-primary monitor resoultion has changed, but the monitor still | |
| 308 // completely contains the window. | |
| 309 | |
| 310 gfx::Rect initial_bounds(1074, 50, 600, 500); | |
| 311 | |
| 312 gfx::Rect window_bounds; | |
| 313 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), | |
| 314 initial_bounds, right_nonprimary, PERSISTED, | |
| 315 &window_bounds, NULL, gfx::Rect()); | |
| 316 EXPECT_EQ(initial_bounds, window_bounds); | |
| 317 } | |
| 318 | |
| 319 { // Non-primary monitor resoultion has changed, and the window is partially | |
| 320 // off-screen. | |
| 321 | |
| 322 gfx::Rect initial_bounds(1274, 50, 600, 500); | |
| 323 | |
| 324 gfx::Rect window_bounds; | |
| 325 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), | |
| 326 initial_bounds, right_nonprimary, PERSISTED, | |
| 327 &window_bounds, NULL, gfx::Rect()); | |
| 328 EXPECT_EQ(gfx::Rect(1224, 50, 600, 500), window_bounds); | |
| 329 } | |
| 330 | |
| 331 { // Non-primary monitor resoultion has changed, and the window is now too | |
| 332 // large for the monitor. | |
| 333 | |
| 334 gfx::Rect initial_bounds(1274, 50, 900, 700); | |
| 335 | |
| 336 gfx::Rect window_bounds; | |
| 337 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600), | |
| 338 initial_bounds, right_nonprimary, PERSISTED, | |
| 339 &window_bounds, NULL, gfx::Rect()); | |
| 340 EXPECT_EQ(gfx::Rect(1024, 0, 800, 600), window_bounds); | |
| 341 } | |
| 342 | |
| 343 { // width and height too small | |
| 344 gfx::Rect window_bounds; | |
| 345 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 346 gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 347 WindowSizer::kDesktopBorderSize, 29, 29), | |
| 348 gfx::Rect(), PERSISTED, &window_bounds, NULL, gfx::Rect()); | |
| 349 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 350 WindowSizer::kDesktopBorderSize, | |
| 351 30 /* not 29 */, 30 /* not 29 */), | |
| 352 window_bounds); | |
| 353 } | |
| 354 } | |
| 355 | |
| 356 ////////////////////////////////////////////////////////////////////////////// | |
| 357 // The following unittests have different results on Mac/non-Mac because we | |
| 358 // reposition windows aggressively on Mac. The *WithAggressiveReposition tests | |
| 359 // are run on Mac, and the *WithNonAggressiveRepositioning tests are run on | |
| 360 // other platforms. | |
| 361 | |
| 362 TEST_F(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) { | |
| 363 { // taskbar on left. | |
| 364 gfx::Rect window_bounds; | |
| 365 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), | |
| 366 gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 367 WindowSizer::kDesktopBorderSize, 500, 400), | |
| 368 gfx::Rect(), LAST_ACTIVE, &window_bounds, NULL, | |
| 369 gfx::Rect()); | |
| 370 EXPECT_EQ(gfx::Rect(kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 371 kWindowTilePixels + WindowSizer::kDesktopBorderSize, | |
| 372 500, 400), | |
| 373 window_bounds); | |
| 374 } | |
| 375 | |
| 376 { // offset would put the new window offscreen at the bottom but the minimum | |
| 377 // visibility condition is barely satisfied without relocation. | |
| 378 gfx::Rect window_bounds; | |
| 379 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 380 gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE, | |
| 381 &window_bounds, NULL, gfx::Rect()); | |
| 382 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, | |
| 383 500, 400), window_bounds); | |
| 384 } | |
| 385 | |
| 386 { // offset would put the new window offscreen at the bottom and the minimum | |
| 387 // visibility condition is satisified by relocation. | |
| 388 gfx::Rect window_bounds; | |
| 389 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 390 gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, | |
| 391 &window_bounds, NULL, gfx::Rect()); | |
| 392 EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738 /* not 739 */, 500, 400), | |
| 393 window_bounds); | |
| 394 } | |
| 395 | |
| 396 { // offset would put the new window offscreen at the right but the minimum | |
| 397 // visibility condition is barely satisfied without relocation. | |
| 398 gfx::Rect window_bounds; | |
| 399 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 400 gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, | |
| 401 &window_bounds, NULL, gfx::Rect()); | |
| 402 EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400), window_bounds); | |
| 403 } | |
| 404 | |
| 405 { // offset would put the new window offscreen at the right and the minimum | |
| 406 // visibility condition is satisified by relocation. | |
| 407 gfx::Rect window_bounds; | |
| 408 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 409 gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE, | |
| 410 &window_bounds, NULL, gfx::Rect()); | |
| 411 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 10 + kWindowTilePixels, | |
| 412 500, 400), window_bounds); | |
| 413 } | |
| 414 | |
| 415 { // offset would put the new window offscreen at the bottom right and the | |
| 416 // minimum visibility condition is satisified by relocation. | |
| 417 gfx::Rect window_bounds; | |
| 418 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 419 gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE, | |
| 420 &window_bounds, NULL, gfx::Rect()); | |
| 421 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), | |
| 422 window_bounds); | |
| 423 } | |
| 424 } | |
| 425 | |
| 426 TEST_F(WindowSizerTest, | |
| 427 PersistedWindowOffscreenWithNonAggressiveRepositioning) { | |
| 428 { // off the left but the minimum visibility condition is barely satisfied | |
| 429 // without relocaiton. | |
| 430 gfx::Rect initial_bounds(-470, 50, 500, 400); | |
| 431 | |
| 432 gfx::Rect window_bounds; | |
| 433 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 434 initial_bounds, gfx::Rect(), PERSISTED, | |
| 435 &window_bounds, NULL, gfx::Rect()); | |
| 436 EXPECT_EQ(initial_bounds, window_bounds); | |
| 437 } | |
| 438 | |
| 439 { // off the left and the minimum visibility condition is satisfied by | |
| 440 // relocation. | |
| 441 gfx::Rect window_bounds; | |
| 442 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 443 gfx::Rect(-471, 50, 500, 400), gfx::Rect(), PERSISTED, | |
| 444 &window_bounds, NULL, gfx::Rect()); | |
| 445 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 50, 500, 400), window_bounds); | |
| 446 } | |
| 447 | |
| 448 { // off the top | |
| 449 gfx::Rect initial_bounds(50, -370, 500, 400); | |
| 450 | |
| 451 gfx::Rect window_bounds; | |
| 452 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 453 gfx::Rect(50, -370, 500, 400), gfx::Rect(), PERSISTED, | |
| 454 &window_bounds, NULL, gfx::Rect()); | |
| 455 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); | |
| 456 } | |
| 457 | |
| 458 { // off the right but the minimum visibility condition is barely satisified | |
| 459 // without relocation. | |
| 460 gfx::Rect initial_bounds(994, 50, 500, 400); | |
| 461 | |
| 462 gfx::Rect window_bounds; | |
| 463 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 464 initial_bounds, gfx::Rect(), PERSISTED, | |
| 465 &window_bounds, NULL, gfx::Rect()); | |
| 466 EXPECT_EQ(initial_bounds, window_bounds); | |
| 467 } | |
| 468 | |
| 469 { // off the right and the minimum visibility condition is satisified by | |
| 470 // relocation. | |
| 471 gfx::Rect window_bounds; | |
| 472 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 473 gfx::Rect(995, 50, 500, 400), gfx::Rect(), PERSISTED, | |
| 474 &window_bounds, NULL, gfx::Rect()); | |
| 475 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 50, 500, 400), window_bounds); | |
| 476 } | |
| 477 | |
| 478 { // off the bottom but the minimum visibility condition is barely satisified | |
| 479 // without relocation. | |
| 480 gfx::Rect initial_bounds(50, 738, 500, 400); | |
| 481 | |
| 482 gfx::Rect window_bounds; | |
| 483 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 484 initial_bounds, gfx::Rect(), PERSISTED, | |
| 485 &window_bounds, NULL, gfx::Rect()); | |
| 486 EXPECT_EQ(initial_bounds, window_bounds); | |
| 487 } | |
| 488 | |
| 489 { // off the bottom and the minimum visibility condition is satisified by | |
| 490 // relocation. | |
| 491 gfx::Rect window_bounds; | |
| 492 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 493 gfx::Rect(50, 739, 500, 400), gfx::Rect(), PERSISTED, | |
| 494 &window_bounds, NULL, gfx::Rect()); | |
| 495 EXPECT_EQ(gfx::Rect(50, 738 /* not 739 */, 500, 400), window_bounds); | |
| 496 } | |
| 497 | |
| 498 { // off the topleft | |
| 499 gfx::Rect window_bounds; | |
| 500 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 501 gfx::Rect(-471, -371, 500, 400), gfx::Rect(), PERSISTED, | |
| 502 &window_bounds, NULL, gfx::Rect()); | |
| 503 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 0, 500, 400), | |
| 504 window_bounds); | |
| 505 } | |
| 506 | |
| 507 { // off the topright and the minimum visibility condition is satisified by | |
| 508 // relocation. | |
| 509 gfx::Rect window_bounds; | |
| 510 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 511 gfx::Rect(995, -371, 500, 400), gfx::Rect(), PERSISTED, | |
| 512 &window_bounds, NULL, gfx::Rect()); | |
| 513 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 0, 500, 400), | |
| 514 window_bounds); | |
| 515 } | |
| 516 | |
| 517 { // off the bottomleft and the minimum visibility condition is satisified by | |
| 518 // relocation. | |
| 519 gfx::Rect window_bounds; | |
| 520 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 521 gfx::Rect(-471, 739, 500, 400), gfx::Rect(), PERSISTED, | |
| 522 &window_bounds, NULL, gfx::Rect()); | |
| 523 EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 738 /* not 739 */, 500, 400), | |
| 524 window_bounds); | |
| 525 } | |
| 526 | |
| 527 { // off the bottomright and the minimum visibility condition is satisified by | |
| 528 // relocation. | |
| 529 gfx::Rect window_bounds; | |
| 530 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 531 gfx::Rect(995, 739, 500, 400), gfx::Rect(), PERSISTED, | |
| 532 &window_bounds, NULL, gfx::Rect()); | |
| 533 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), | |
| 534 window_bounds); | |
| 535 } | |
| 536 | |
| 537 { // entirely off left | |
| 538 gfx::Rect window_bounds; | |
| 539 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 540 gfx::Rect(-700, 50, 500, 400), gfx::Rect(), PERSISTED, | |
| 541 &window_bounds, NULL, gfx::Rect()); | |
| 542 EXPECT_EQ(gfx::Rect(-470 /* not -700 */, 50, 500, 400), window_bounds); | |
| 543 } | |
| 544 | |
| 545 { // entirely off left (monitor was detached since last run) | |
| 546 gfx::Rect window_bounds; | |
| 547 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 548 gfx::Rect(-700, 50, 500, 400), left_nonprimary, PERSISTED, | |
| 549 &window_bounds, NULL, gfx::Rect()); | |
| 550 EXPECT_EQ(gfx::Rect(0, 50, 500, 400), window_bounds); | |
| 551 } | |
| 552 | |
| 553 { // entirely off top | |
| 554 gfx::Rect window_bounds; | |
| 555 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 556 gfx::Rect(50, -500, 500, 400), gfx::Rect(), PERSISTED, | |
| 557 &window_bounds, NULL, gfx::Rect()); | |
| 558 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); | |
| 559 } | |
| 560 | |
| 561 { // entirely off top (monitor was detached since last run) | |
| 562 gfx::Rect window_bounds; | |
| 563 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 564 gfx::Rect(50, -500, 500, 400), top_nonprimary, | |
| 565 PERSISTED, &window_bounds, NULL, gfx::Rect()); | |
| 566 EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds); | |
| 567 } | |
| 568 | |
| 569 { // entirely off right | |
| 570 gfx::Rect window_bounds; | |
| 571 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 572 gfx::Rect(1200, 50, 500, 400), gfx::Rect(), PERSISTED, | |
| 573 &window_bounds, NULL, gfx::Rect()); | |
| 574 EXPECT_EQ(gfx::Rect(994 /* not 1200 */, 50, 500, 400), window_bounds); | |
| 575 } | |
| 576 | |
| 577 { // entirely off right (monitor was detached since last run) | |
| 578 gfx::Rect window_bounds; | |
| 579 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 580 gfx::Rect(1200, 50, 500, 400), right_nonprimary, | |
| 581 PERSISTED, &window_bounds, NULL, gfx::Rect()); | |
| 582 EXPECT_EQ(gfx::Rect(524, 50, 500, 400), window_bounds); | |
| 583 } | |
| 584 | |
| 585 { // entirely off bottom | |
| 586 gfx::Rect window_bounds; | |
| 587 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 588 gfx::Rect(50, 800, 500, 400), gfx::Rect(), PERSISTED, | |
| 589 &window_bounds, NULL, gfx::Rect()); | |
| 590 EXPECT_EQ(gfx::Rect(50, 738 /* not 800 */, 500, 400), window_bounds); | |
| 591 } | |
| 592 | |
| 593 { // entirely off bottom (monitor was detached since last run) | |
| 594 gfx::Rect window_bounds; | |
| 595 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 596 gfx::Rect(50, 800, 500, 400), bottom_nonprimary, | |
| 597 PERSISTED, &window_bounds, NULL, gfx::Rect()); | |
| 598 EXPECT_EQ(gfx::Rect(50, 368, 500, 400), window_bounds); | |
| 599 } | |
| 600 } | |
| 601 | |
| 602 // Test that a newly created window gets positioned over a previously created | |
| 603 // window. | |
| 604 TEST_F(WindowSizerTestWithBrowser, PlaceNewWindowOverOldWindow) { | |
| 605 // Create a dummy window. | |
| 606 aura::Window* default_container = | |
| 607 ash::Shell::GetContainer( | |
| 608 ash::Shell::GetPrimaryRootWindow(), | |
| 609 ash::internal::kShellWindowId_DefaultContainer); | |
| 610 scoped_ptr<aura::Window> window( | |
| 611 aura::test::CreateTestWindowWithId(0, default_container)); | |
| 612 window->SetBounds(gfx::Rect(16, 32, 640, 320)); | |
| 613 | |
| 614 scoped_ptr<aura::Window> popup( | |
| 615 aura::test::CreateTestWindowWithId(1, default_container)); | |
| 616 popup->SetBounds(gfx::Rect(16, 32, 128, 256)); | |
| 617 | |
| 618 scoped_ptr<aura::Window> panel( | |
| 619 aura::test::CreateTestWindowWithId(2, default_container)); | |
| 620 panel->SetBounds(gfx::Rect(32, 48, 256, 512)); | |
| 621 | |
| 622 // Create a browser which we can use to pass into the GetWindowBounds | |
| 623 // function. | |
| 624 scoped_ptr<TestingProfile> profile; | |
| 625 profile.reset(new TestingProfile()); | |
| 626 scoped_ptr<Browser> browser; | |
| 627 // Creating a popup handler here to make sure it does not interfere with the | |
| 628 // existing windows. | |
| 629 browser.reset(new Browser(Browser::TYPE_TABBED, profile.get())); | |
| 630 | |
| 631 scoped_ptr<Browser> window_owning_browser; | |
| 632 // Creating a popup handler here to make sure it does not interfere with the | |
| 633 // existing windows. | |
| 634 window_owning_browser.reset(new Browser(Browser::TYPE_TABBED, | |
| 635 profile.get())); | |
| 636 scoped_ptr<BrowserWindow> browser_window; | |
| 637 browser_window.reset(new TestBrowserWindowAura(window_owning_browser.get(), | |
| 638 window.get())); | |
| 639 window_owning_browser->SetWindowForTesting(browser_window.get()); | |
| 640 | |
| 641 scoped_ptr<Browser> popup_owning_browser; | |
| 642 // Creating a popup to make sure it does not interfere with the positioning. | |
| 643 popup_owning_browser.reset(new Browser(Browser::TYPE_POPUP, | |
| 644 profile.get())); | |
| 645 scoped_ptr<BrowserWindow> browser_popup; | |
| 646 browser_popup.reset(new TestBrowserWindowAura(popup_owning_browser.get(), | |
| 647 popup.get())); | |
| 648 popup_owning_browser->SetWindowForTesting(browser_popup.get()); | |
| 649 | |
| 650 scoped_ptr<Browser> panel_owning_browser; | |
| 651 // Creating a panel to make sure it does not interfere with the positioning. | |
| 652 panel_owning_browser.reset(new Browser(Browser::TYPE_PANEL, | |
| 653 profile.get())); | |
| 654 scoped_ptr<BrowserWindow> browser_panel; | |
| 655 browser_panel.reset(new TestBrowserWindowAura(panel_owning_browser.get(), | |
| 656 panel.get())); | |
| 657 panel_owning_browser->SetWindowForTesting(browser_panel.get()); | |
| 658 | |
| 659 window->Show(); | |
| 660 { // With a shown window it's size should get returned. | |
| 661 gfx::Rect window_bounds; | |
| 662 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 663 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | |
| 664 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); | |
| 665 EXPECT_EQ(gfx::Rect(16, 32, 640, 320), window_bounds); | |
| 666 } | |
| 667 | |
| 668 { // Make sure that popups do not get changed. | |
| 669 gfx::Rect window_bounds; | |
| 670 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 671 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | |
| 672 PERSISTED, &window_bounds, popup_owning_browser.get(), | |
| 673 gfx::Rect()); | |
| 674 EXPECT_EQ(gfx::Rect(50, 100, 300, 150), window_bounds); | |
| 675 } | |
| 676 | |
| 677 window->SetBounds(gfx::Rect(816, 720, 640, 320)); | |
| 678 // Verifies newly created windows appear on screen. | |
| 679 { | |
| 680 gfx::Rect window_bounds; | |
| 681 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 682 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | |
| 683 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); | |
| 684 EXPECT_EQ("384,448 640x320", window_bounds.ToString()); | |
| 685 } | |
| 686 | |
| 687 window->Hide(); | |
| 688 { // If a window is there but not shown the default should be returned. | |
| 689 // The existing popup should not have any impact as well. | |
| 690 gfx::Rect window_bounds; | |
| 691 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | |
| 692 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | |
| 693 PERSISTED, &window_bounds, browser.get(), gfx::Rect()); | |
| 694 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | |
| 695 WindowSizer::kDesktopBorderSize, | |
| 696 1024 - 2 * WindowSizer::kDesktopBorderSize, | |
| 697 768 - WindowSizer::kDesktopBorderSize), | |
| 698 window_bounds); | |
| 699 } | |
| 700 } | |
| 701 | |
| 702 // Test that the window is sized appropriately for the first run experience | |
| 703 // where the default window bounds calculation is invoked. | |
| 704 TEST_F(WindowSizerTest, AdjustFitSize) { | |
| 705 { // Check that the window gets resized to the screen. | |
| 706 gfx::Rect window_bounds; | |
| 707 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | |
| 708 gfx::Rect(), DEFAULT, &window_bounds, NULL, | |
| 709 gfx::Rect(-10, -10, 1024 + 20, 768 + 20)); | |
| 710 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), window_bounds); | |
| 711 } | |
| 712 | |
| 713 { // Check that a window which hangs out of the screen get moved back in. | |
| 714 gfx::Rect window_bounds; | |
| 715 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | |
| 716 gfx::Rect(), DEFAULT, &window_bounds, NULL, | |
| 717 gfx::Rect(1020, 700, 100, 100)); | |
| 718 EXPECT_EQ(gfx::Rect(924, 668, 100, 100), window_bounds); | |
| 719 } | |
| 720 } | |
| OLD | NEW |