OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "chrome/browser/window_sizer.h" | 7 #include "chrome/browser/window_sizer.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 // Testing implementation of WindowSizer::MonitorInfoProvider that we can use | 36 // Testing implementation of WindowSizer::MonitorInfoProvider that we can use |
37 // to fake various monitor layouts and sizes. | 37 // to fake various monitor layouts and sizes. |
38 class TestMonitorInfoProvider : public WindowSizer::MonitorInfoProvider { | 38 class TestMonitorInfoProvider : public WindowSizer::MonitorInfoProvider { |
39 public: | 39 public: |
40 TestMonitorInfoProvider() {} | 40 TestMonitorInfoProvider() {} |
41 virtual ~TestMonitorInfoProvider() {} | 41 virtual ~TestMonitorInfoProvider() {} |
42 | 42 |
43 void AddMonitor(const gfx::Rect& bounds, const gfx::Rect& work_area) { | 43 void AddMonitor(const gfx::Rect& bounds, const gfx::Rect& work_area) { |
44 DCHECK(bounds.Contains(work_area)); | 44 DCHECK(bounds.Contains(work_area)); |
45 monitor_bounds_.push_back(work_area); | 45 monitor_bounds_.push_back(bounds); |
46 work_areas_.push_back(work_area); | 46 work_areas_.push_back(work_area); |
47 } | 47 } |
48 | 48 |
49 // Overridden from WindowSizer::MonitorInfoProvider: | 49 // Overridden from WindowSizer::MonitorInfoProvider: |
50 virtual gfx::Rect GetPrimaryMonitorWorkArea() const { | 50 virtual gfx::Rect GetPrimaryMonitorWorkArea() const { |
51 return work_areas_[0]; | 51 return work_areas_[0]; |
52 } | 52 } |
53 | 53 |
54 virtual gfx::Rect GetPrimaryMonitorBounds() const { | 54 virtual gfx::Rect GetPrimaryMonitorBounds() const { |
55 return monitor_bounds_[0]; | 55 return monitor_bounds_[0]; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 sp->SetPersistentState(state, maximized, true); | 159 sp->SetPersistentState(state, maximized, true); |
160 else if (source == LAST_ACTIVE) | 160 else if (source == LAST_ACTIVE) |
161 sp->SetLastActiveState(state, true); | 161 sp->SetLastActiveState(state, true); |
162 WindowSizer sizer(sp, mip); | 162 WindowSizer sizer(sp, mip); |
163 sizer.DetermineWindowBounds(gfx::Rect(), out_bounds, out_maximized); | 163 sizer.DetermineWindowBounds(gfx::Rect(), out_bounds, out_maximized); |
164 } | 164 } |
165 | 165 |
166 // Test that the window is sized appropriately for the first run experience | 166 // Test that the window is sized appropriately for the first run experience |
167 // where the default window bounds calculation is invoked. | 167 // where the default window bounds calculation is invoked. |
168 TEST(WindowSizerTest, DefaultSizeCase) { | 168 TEST(WindowSizerTest, DefaultSizeCase) { |
169 | |
170 { // 4:3 monitor case, 1024x768, no taskbar | 169 { // 4:3 monitor case, 1024x768, no taskbar |
171 gfx::Rect window_bounds; | 170 gfx::Rect window_bounds; |
172 bool maximized; | 171 bool maximized; |
173 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | 172 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), |
174 false, DEFAULT, &window_bounds, &maximized); | 173 false, DEFAULT, &window_bounds, &maximized); |
175 EXPECT_FALSE(maximized); | 174 EXPECT_FALSE(maximized); |
176 EXPECT_EQ(gfx::Rect(10, 10, 1004, 748), window_bounds); | 175 EXPECT_EQ(gfx::Rect(10, 10, 1004, 748), window_bounds); |
177 } | 176 } |
178 | 177 |
179 { // 4:3 monitor case, 1024x768, taskbar on bottom | 178 { // 4:3 monitor case, 1024x768, taskbar on bottom |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 { // normal, in the middle of the screen somewhere. | 254 { // normal, in the middle of the screen somewhere. |
256 gfx::Rect window_bounds; | 255 gfx::Rect window_bounds; |
257 bool maximized = false; | 256 bool maximized = false; |
258 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 257 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
259 gfx::Rect(10, 10, 500, 400), false, LAST_ACTIVE, | 258 gfx::Rect(10, 10, 500, 400), false, LAST_ACTIVE, |
260 &window_bounds, &maximized); | 259 &window_bounds, &maximized); |
261 EXPECT_FALSE(maximized); | 260 EXPECT_FALSE(maximized); |
262 EXPECT_EQ(gfx::Rect(20, 20, 500, 400), window_bounds); | 261 EXPECT_EQ(gfx::Rect(20, 20, 500, 400), window_bounds); |
263 } | 262 } |
264 | 263 |
| 264 { // taskbar on left. |
| 265 gfx::Rect window_bounds; |
| 266 bool maximized = false; |
| 267 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), |
| 268 gfx::Rect(10, 10, 500, 400), false, LAST_ACTIVE, |
| 269 &window_bounds, &maximized); |
| 270 EXPECT_FALSE(maximized); |
| 271 EXPECT_EQ(gfx::Rect(127, 20, 500, 400), window_bounds); |
| 272 } |
| 273 |
| 274 { // taskbar on top. |
| 275 gfx::Rect window_bounds; |
| 276 bool maximized = false; |
| 277 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), |
| 278 gfx::Rect(10, 10, 500, 400), false, LAST_ACTIVE, |
| 279 &window_bounds, &maximized); |
| 280 EXPECT_FALSE(maximized); |
| 281 EXPECT_EQ(gfx::Rect(20, 54, 500, 400), window_bounds); |
| 282 } |
| 283 |
265 { // too small to satisify the minimum visibility condition. | 284 { // too small to satisify the minimum visibility condition. |
266 gfx::Rect window_bounds; | 285 gfx::Rect window_bounds; |
267 bool maximized = false; | 286 bool maximized = false; |
268 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 287 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
269 gfx::Rect(10, 10, 29, 29), false, LAST_ACTIVE, | 288 gfx::Rect(10, 10, 29, 29), false, LAST_ACTIVE, |
270 &window_bounds, &maximized); | 289 &window_bounds, &maximized); |
271 EXPECT_FALSE(maximized); | 290 EXPECT_FALSE(maximized); |
272 EXPECT_EQ(gfx::Rect(20, 20, 30 /* not 29 */, 30 /* not 29 */), | 291 EXPECT_EQ(gfx::Rect(20, 20, 30 /* not 29 */, 30 /* not 29 */), |
273 window_bounds); | 292 window_bounds); |
274 } | 293 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 gfx::Rect(985, 729, 500, 400), false, LAST_ACTIVE, | 355 gfx::Rect(985, 729, 500, 400), false, LAST_ACTIVE, |
337 &window_bounds, &maximized); | 356 &window_bounds, &maximized); |
338 EXPECT_FALSE(maximized); | 357 EXPECT_FALSE(maximized); |
339 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), | 358 EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400), |
340 window_bounds); | 359 window_bounds); |
341 } | 360 } |
342 } | 361 } |
343 | 362 |
344 // Test that the window opened is sized appropriately given persisted sizes. | 363 // Test that the window opened is sized appropriately given persisted sizes. |
345 TEST(WindowSizerTest, PersistedBoundsCase) { | 364 TEST(WindowSizerTest, PersistedBoundsCase) { |
346 | |
347 { // normal, in the middle of the screen somewhere. | 365 { // normal, in the middle of the screen somewhere. |
348 gfx::Rect initial_bounds(10, 10, 500, 400); | 366 gfx::Rect initial_bounds(10, 10, 500, 400); |
349 | 367 |
350 gfx::Rect window_bounds; | 368 gfx::Rect window_bounds; |
351 bool maximized; | 369 bool maximized; |
352 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, | 370 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds, |
353 false, PERSISTED, &window_bounds, &maximized); | 371 false, PERSISTED, &window_bounds, &maximized); |
354 EXPECT_FALSE(maximized); | 372 EXPECT_FALSE(maximized); |
355 EXPECT_EQ(initial_bounds, window_bounds); | 373 EXPECT_EQ(initial_bounds, window_bounds); |
356 } | 374 } |
(...skipping 29 matching lines...) Expand all Loading... |
386 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, | 404 GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary, |
387 initial_bounds, true, PERSISTED, &window_bounds, | 405 initial_bounds, true, PERSISTED, &window_bounds, |
388 &maximized); | 406 &maximized); |
389 EXPECT_TRUE(maximized); | 407 EXPECT_TRUE(maximized); |
390 EXPECT_EQ(initial_bounds, window_bounds); | 408 EXPECT_EQ(initial_bounds, window_bounds); |
391 } | 409 } |
392 | 410 |
393 { // off the left but the minimum visibility condition is barely satisfied | 411 { // off the left but the minimum visibility condition is barely satisfied |
394 // without relocaiton. | 412 // without relocaiton. |
395 gfx::Rect initial_bounds(-470, 50, 500, 400); | 413 gfx::Rect initial_bounds(-470, 50, 500, 400); |
396 | 414 |
397 gfx::Rect window_bounds; | 415 gfx::Rect window_bounds; |
398 bool maximized; | 416 bool maximized; |
399 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 417 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
400 initial_bounds, false, PERSISTED, | 418 initial_bounds, false, PERSISTED, |
401 &window_bounds, &maximized); | 419 &window_bounds, &maximized); |
402 EXPECT_FALSE(maximized); | 420 EXPECT_FALSE(maximized); |
403 EXPECT_EQ(initial_bounds, window_bounds); | 421 EXPECT_EQ(initial_bounds, window_bounds); |
404 } | 422 } |
405 | 423 |
406 { // off the left and the minimum visibility condition is satisfied by | 424 { // off the left and the minimum visibility condition is satisfied by |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 gfx::Rect window_bounds; | 596 gfx::Rect window_bounds; |
579 bool maximized; | 597 bool maximized; |
580 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 598 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
581 gfx::Rect(10, 10, 29, 29), false, PERSISTED, | 599 gfx::Rect(10, 10, 29, 29), false, PERSISTED, |
582 &window_bounds, &maximized); | 600 &window_bounds, &maximized); |
583 EXPECT_FALSE(maximized); | 601 EXPECT_FALSE(maximized); |
584 EXPECT_EQ(gfx::Rect(10, 10, 30 /* not 29 */, 30 /* not 29 */), | 602 EXPECT_EQ(gfx::Rect(10, 10, 30 /* not 29 */, 30 /* not 29 */), |
585 window_bounds); | 603 window_bounds); |
586 } | 604 } |
587 } | 605 } |
OLD | NEW |