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