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/window_sizer_common_unittest.h"
6
7#include "base/compiler_specific.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10// Test that the window is sized appropriately for the first run experience
11// where the default window bounds calculation is invoked.
12TEST(WindowSizerTest, DefaultSizeCase) {
13  { // 4:3 monitor case, 1024x768, no taskbar
14    gfx::Rect window_bounds;
15    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(),
16                    gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
17    EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
18                        1024 - kWindowTilePixels * 2,
19                        768 - kWindowTilePixels * 2),
20              window_bounds);
21  }
22
23  { // 4:3 monitor case, 1024x768, taskbar on bottom
24    gfx::Rect window_bounds;
25    GetWindowBounds(p1024x768, taskbar_bottom_work_area, gfx::Rect(),
26                    gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
27                    &window_bounds);
28    EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
29                        1024 - kWindowTilePixels * 2,
30                        (taskbar_bottom_work_area.height() -
31                         kWindowTilePixels * 2)),
32              window_bounds);
33  }
34
35  { // 4:3 monitor case, 1024x768, taskbar on right
36    gfx::Rect window_bounds;
37    GetWindowBounds(p1024x768, taskbar_right_work_area, gfx::Rect(),
38                    gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
39                    &window_bounds);
40    EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
41                        taskbar_right_work_area.width() - kWindowTilePixels*2,
42                        768 - kWindowTilePixels * 2),
43              window_bounds);
44  }
45
46  { // 4:3 monitor case, 1024x768, taskbar on left
47    gfx::Rect window_bounds;
48    GetWindowBounds(p1024x768, taskbar_left_work_area, gfx::Rect(),
49                    gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
50                    &window_bounds);
51    EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + kWindowTilePixels,
52                        kWindowTilePixels,
53                        taskbar_left_work_area.width() - kWindowTilePixels * 2,
54                        (taskbar_left_work_area.height() -
55                         kWindowTilePixels * 2)),
56              window_bounds);
57  }
58
59  { // 4:3 monitor case, 1024x768, taskbar on top
60    gfx::Rect window_bounds;
61    GetWindowBounds(p1024x768, taskbar_top_work_area, gfx::Rect(),
62                    gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
63                    &window_bounds);
64    EXPECT_EQ(gfx::Rect(kWindowTilePixels,
65                        taskbar_top_work_area.y() + kWindowTilePixels,
66                        1024 - kWindowTilePixels * 2,
67                        taskbar_top_work_area.height() - kWindowTilePixels * 2),
68              window_bounds);
69  }
70
71  { // 4:3 monitor case, 1280x1024
72    gfx::Rect window_bounds;
73    GetWindowBounds(p1280x1024, p1280x1024, gfx::Rect(), gfx::Rect(),
74                    gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
75    EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
76                        1050,
77                        1024 - kWindowTilePixels * 2),
78              window_bounds);
79  }
80
81  { // 4:3 monitor case, 1600x1200
82    gfx::Rect window_bounds;
83    GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), gfx::Rect(),
84                    gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
85    EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
86                        1050,
87                        1200 - kWindowTilePixels * 2),
88              window_bounds);
89  }
90
91  { // 16:10 monitor case, 1680x1050
92    gfx::Rect window_bounds;
93    GetWindowBounds(p1680x1050, p1680x1050, gfx::Rect(), gfx::Rect(),
94                    gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
95    EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
96                        840 - static_cast<int>(kWindowTilePixels * 1.5),
97                        1050 - kWindowTilePixels * 2),
98              window_bounds);
99  }
100
101  { // 16:10 monitor case, 1920x1200
102    gfx::Rect window_bounds;
103    GetWindowBounds(p1920x1200, p1920x1200, gfx::Rect(), gfx::Rect(),
104                    gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
105    EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
106                        960 - static_cast<int>(kWindowTilePixels * 1.5),
107                        1200 - kWindowTilePixels * 2),
108              window_bounds);
109  }
110}
111
112// Test that the next opened window is positioned appropriately given the
113// bounds of an existing window of the same type.
114TEST(WindowSizerTest, LastWindowBoundsCase) {
115  { // normal, in the middle of the screen somewhere.
116    gfx::Rect window_bounds;
117    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
118                    gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
119                    gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
120                    &window_bounds);
121    EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
122                        kWindowTilePixels * 2, 500, 400), window_bounds);
123  }
124
125  { // taskbar on top.
126    gfx::Rect window_bounds;
127    GetWindowBounds(p1024x768, taskbar_top_work_area, gfx::Rect(),
128                    gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
129                    gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
130                    &window_bounds);
131    EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
132                        std::max(kWindowTilePixels * 2,
133                                 34 /* toolbar height */),
134                        500, 400), window_bounds);
135  }
136
137  { // Too small to satisify the minimum visibility condition.
138    gfx::Rect window_bounds;
139    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
140                    gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29),
141                    gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
142                    &window_bounds);
143    EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
144                        kWindowTilePixels * 2,
145                        30 /* not 29 */,
146                        30 /* not 29 */),
147              window_bounds);
148  }
149
150
151  { // Normal.
152    gfx::Rect window_bounds;
153    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
154                    gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
155                    gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
156                    &window_bounds);
157    EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
158                        kWindowTilePixels * 2, 500, 400), window_bounds);
159  }
160}
161
162// Test that the window opened is sized appropriately given persisted sizes.
163TEST(WindowSizerTest, PersistedBoundsCase) {
164  { // normal, in the middle of the screen somewhere.
165    gfx::Rect initial_bounds(kWindowTilePixels, kWindowTilePixels, 500, 400);
166
167    gfx::Rect window_bounds;
168    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), initial_bounds,
169                    gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
170    EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
171  }
172
173  { // Normal.
174    gfx::Rect initial_bounds(0, 0, 1024, 768);
175
176    gfx::Rect window_bounds;
177    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), initial_bounds,
178                    gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
179    EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
180  }
181
182  { // normal, on non-primary monitor in negative coords.
183    gfx::Rect initial_bounds(-600, 10, 500, 400);
184
185    gfx::Rect window_bounds;
186    GetWindowBounds(p1024x768, p1024x768, left_s1024x768,
187                    initial_bounds, gfx::Rect(), PERSISTED, NULL, gfx::Rect(),
188                    &window_bounds);
189    EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
190  }
191
192  { // normal, on non-primary monitor in negative coords.
193    gfx::Rect initial_bounds(-1024, 0, 1024, 768);
194
195    gfx::Rect window_bounds;
196    GetWindowBounds(p1024x768, p1024x768, left_s1024x768,
197                    initial_bounds, gfx::Rect(), PERSISTED, NULL, gfx::Rect(),
198                    &window_bounds);
199    EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
200  }
201
202  { // Non-primary monitor resoultion has changed, but the monitor still
203    // completely contains the window.
204
205    gfx::Rect initial_bounds(1074, 50, 600, 500);
206
207    gfx::Rect window_bounds;
208    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
209                    initial_bounds, right_s1024x768, PERSISTED, NULL,
210                    gfx::Rect(), &window_bounds);
211    EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
212  }
213
214  { // Non-primary monitor resoultion has changed, and the window is partially
215    // off-screen.
216
217    gfx::Rect initial_bounds(1274, 50, 600, 500);
218
219    gfx::Rect window_bounds;
220    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
221                    initial_bounds, right_s1024x768, PERSISTED,
222                    NULL, gfx::Rect(), &window_bounds);
223    EXPECT_EQ("1224,50 600x500", window_bounds.ToString());
224  }
225
226  { // Non-primary monitor resoultion has changed, and the window is now too
227    // large for the monitor.
228
229    gfx::Rect initial_bounds(1274, 50, 900, 700);
230
231    gfx::Rect window_bounds;
232    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
233                    initial_bounds, right_s1024x768, PERSISTED,
234                    NULL, gfx::Rect(), &window_bounds);
235    EXPECT_EQ("1024,0 800x600", window_bounds.ToString());
236  }
237
238  { // width and height too small
239    gfx::Rect window_bounds;
240    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
241                    gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29),
242                    gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
243    EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
244                        30 /* not 29 */, 30 /* not 29 */),
245              window_bounds);
246  }
247
248#if defined(OS_MACOSX)
249  { // Saved state is too tall to possibly be resized.  Mac resizers
250    // are at the bottom of the window, and no piece of a window can
251    // be moved higher than the menubar.  (Perhaps the user changed
252    // resolution to something smaller before relaunching Chrome?)
253    gfx::Rect window_bounds;
254    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
255                    gfx::Rect(kWindowTilePixels, kWindowTilePixels, 30, 5000),
256                    gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
257    EXPECT_EQ(p1024x768.height(), window_bounds.height());
258  }
259#endif  // defined(OS_MACOSX)
260}
261
262//////////////////////////////////////////////////////////////////////////////
263// The following unittests have different results on Mac/non-Mac because we
264// reposition windows aggressively on Mac.  The *WithAggressiveReposition tests
265// are run on Mac, and the *WithNonAggressiveRepositioning tests are run on
266// other platforms.
267
268#if defined(OS_MACOSX)
269TEST(WindowSizerTest, LastWindowOffscreenWithAggressiveRepositioning) {
270  { // taskbar on left.  The new window overlaps slightly with the taskbar, so
271    // it is moved to be flush with the left edge of the work area.
272    gfx::Rect window_bounds;
273    GetWindowBounds(p1024x768, taskbar_left_work_area, gfx::Rect(),
274                    gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
275                    gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
276                    &window_bounds);
277    EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x(),
278                        kWindowTilePixels * 2, 500, 400), window_bounds);
279  }
280
281  { // offset would put the new window offscreen at the bottom
282    gfx::Rect window_bounds;
283    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
284                    gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE,
285                    NULL, gfx::Rect(), &window_bounds);
286    EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels,
287                        0 /* not 729 + kWindowTilePixels */,
288                        500, 400),
289              window_bounds);
290  }
291
292  { // offset would put the new window offscreen at the right
293    gfx::Rect window_bounds;
294    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
295                    gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE,
296                    NULL, gfx::Rect(), &window_bounds);
297    EXPECT_EQ(gfx::Rect(0 /* not 985 + kWindowTilePixels*/,
298                        10 + kWindowTilePixels,
299                        500, 400),
300              window_bounds);
301  }
302
303  { // offset would put the new window offscreen at the bottom right
304    gfx::Rect window_bounds;
305    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
306                    gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE,
307                    NULL, gfx::Rect(), &window_bounds);
308    EXPECT_EQ(gfx::Rect(0 /* not 985 + kWindowTilePixels*/,
309                        0 /* not 729 + kWindowTilePixels*/,
310                        500, 400),
311              window_bounds);
312  }
313}
314
315TEST(WindowSizerTest, PersistedWindowOffscreenWithAggressiveRepositioning) {
316  { // off the left
317    gfx::Rect window_bounds;
318    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
319                    gfx::Rect(-471, 50, 500, 400), gfx::Rect(), PERSISTED,
320                    NULL, gfx::Rect(), &window_bounds);
321    EXPECT_EQ(gfx::Rect(0 /* not -471 */, 50, 500, 400), window_bounds);
322  }
323
324  { // off the top
325    gfx::Rect window_bounds;
326    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
327                    gfx::Rect(50, -370, 500, 400), gfx::Rect(), PERSISTED,
328                    NULL, gfx::Rect(), &window_bounds);
329    EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
330  }
331
332  { // off the right
333    gfx::Rect window_bounds;
334    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
335                    gfx::Rect(995, 50, 500, 400), gfx::Rect(), PERSISTED,
336                    NULL, gfx::Rect(), &window_bounds);
337    EXPECT_EQ(gfx::Rect(0 /* not 995 */, 50, 500, 400), window_bounds);
338  }
339
340  { // off the bottom
341    gfx::Rect window_bounds;
342    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
343                    gfx::Rect(50, 739, 500, 400), gfx::Rect(), PERSISTED,
344                    NULL, gfx::Rect(), &window_bounds);
345    EXPECT_EQ(gfx::Rect(50, 0 /* not 739 */, 500, 400), window_bounds);
346  }
347
348  { // off the topleft
349    gfx::Rect window_bounds;
350    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
351                    gfx::Rect(-471, -371, 500, 400), gfx::Rect(), PERSISTED,
352                    NULL, gfx::Rect(), &window_bounds);
353    EXPECT_EQ(gfx::Rect(0 /* not -471 */, 0 /* not -371 */, 500, 400),
354              window_bounds);
355  }
356
357  { // off the topright
358    gfx::Rect window_bounds;
359    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
360                    gfx::Rect(995, -371, 500, 400), gfx::Rect(), PERSISTED,
361                    NULL, gfx::Rect(), &window_bounds);
362    EXPECT_EQ(gfx::Rect(0 /* not 995 */, 0 /* not -371 */, 500, 400),
363                        window_bounds);
364  }
365
366  { // off the bottomleft
367    gfx::Rect window_bounds;
368    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
369                    gfx::Rect(-471, 739, 500, 400), gfx::Rect(), PERSISTED,
370                    NULL, gfx::Rect(), &window_bounds);
371    EXPECT_EQ(gfx::Rect(0 /* not -471 */, 0 /* not 739 */, 500, 400),
372                        window_bounds);
373  }
374
375  { // off the bottomright
376    gfx::Rect window_bounds;
377    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
378                    gfx::Rect(995, 739, 500, 400), gfx::Rect(), PERSISTED,
379                    NULL, gfx::Rect(), &window_bounds);
380    EXPECT_EQ(gfx::Rect(0 /* not 995 */, 0 /* not 739 */, 500, 400),
381                        window_bounds);
382  }
383
384  { // entirely off left
385    gfx::Rect window_bounds;
386    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
387                    gfx::Rect(-700, 50, 500, 400), gfx::Rect(), PERSISTED,
388                    NULL, gfx::Rect(), &window_bounds);
389    EXPECT_EQ(gfx::Rect(0 /* not -700 */, 50, 500, 400), window_bounds);
390  }
391
392  { // entirely off left (monitor was detached since last run)
393    gfx::Rect window_bounds;
394    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
395                    gfx::Rect(-700, 50, 500, 400), left_s1024x768,
396                    PERSISTED, NULL, gfx::Rect(), &window_bounds);
397    EXPECT_EQ(gfx::Rect(0, 50, 500, 400), window_bounds);
398  }
399
400  { // entirely off top
401    gfx::Rect window_bounds;
402    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
403                    gfx::Rect(50, -500, 500, 400), gfx::Rect(), PERSISTED,
404                    NULL, gfx::Rect(), &window_bounds);
405    EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
406  }
407
408  { // entirely off top (monitor was detached since last run)
409    gfx::Rect window_bounds;
410    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
411                    gfx::Rect(50, -500, 500, 400), top_s1024x768, PERSISTED,
412                    NULL, gfx::Rect(), &window_bounds);
413    EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
414  }
415
416  { // entirely off right
417    gfx::Rect window_bounds;
418    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
419                    gfx::Rect(1200, 50, 500, 400), gfx::Rect(), PERSISTED,
420                    NULL, gfx::Rect(), &window_bounds);
421    EXPECT_EQ(gfx::Rect(0 /* not 1200 */, 50, 500, 400), window_bounds);
422  }
423
424  { // entirely off right (monitor was detached since last run)
425    gfx::Rect window_bounds;
426    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
427                    gfx::Rect(1200, 50, 500, 400), right_s1024x768, PERSISTED,
428                    NULL, gfx::Rect(), &window_bounds);
429    EXPECT_EQ(gfx::Rect(524 /* not 1200 */, 50, 500, 400), window_bounds);
430  }
431
432  { // entirely off bottom
433    gfx::Rect window_bounds;
434    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
435                    gfx::Rect(50, 800, 500, 400), gfx::Rect(), PERSISTED,
436                    NULL, gfx::Rect(), &window_bounds);
437    EXPECT_EQ(gfx::Rect(50, 0 /* not 800 */, 500, 400), window_bounds);
438  }
439
440  { // entirely off bottom (monitor was detached since last run)
441    gfx::Rect window_bounds;
442    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
443                    gfx::Rect(50, 800, 500, 400), bottom_s1024x768,
444                    PERSISTED, NULL, gfx::Rect(), &window_bounds);
445    EXPECT_EQ(gfx::Rect(50, 368 /* not 800 */, 500, 400), window_bounds);
446  }
447
448  { // wider than the screen. off both the left and right
449    gfx::Rect window_bounds;
450    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
451                    gfx::Rect(-100, 50, 2000, 400), gfx::Rect(), PERSISTED,
452                    NULL, gfx::Rect(), &window_bounds);
453    EXPECT_EQ(gfx::Rect(0 /* not -100 */, 50, 2000, 400), window_bounds);
454  }
455}
456#else
457TEST(WindowSizerTest, LastWindowOffscreenWithNonAggressiveRepositioning) {
458  { // taskbar on left.
459    gfx::Rect window_bounds;
460    GetWindowBounds(p1024x768, taskbar_left_work_area, gfx::Rect(),
461                    gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
462                    gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
463                    &window_bounds);
464    EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
465                        kWindowTilePixels * 2, 500, 400), window_bounds);
466  }
467
468  // Linux does not tile windows, so tile adjustment tests don't make sense.
469#if !defined(OS_POSIX) || defined(OS_MACOSX)
470  { // offset would put the new window offscreen at the bottom but the minimum
471    // visibility condition is barely satisfied without relocation.
472    gfx::Rect window_bounds;
473    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
474                    gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE,
475                    NULL, gfx::Rect(), &window_bounds);
476    EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738,
477                        500, 400), window_bounds);
478  }
479
480  { // offset would put the new window offscreen at the bottom and the minimum
481    // visibility condition is satisified by relocation.
482    gfx::Rect window_bounds;
483    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
484                    gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE,
485                    NULL, gfx::Rect(), &window_bounds);
486    EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738 /* not 739 */, 500, 400),
487              window_bounds);
488  }
489
490  { // offset would put the new window offscreen at the right but the minimum
491    // visibility condition is barely satisfied without relocation.
492    gfx::Rect window_bounds;
493    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
494                    gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE,
495                    NULL, gfx::Rect(), &window_bounds);
496    EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400), window_bounds);
497  }
498
499  { // offset would put the new window offscreen at the right and the minimum
500    // visibility condition is satisified by relocation.
501    gfx::Rect window_bounds;
502    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
503                    gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE,
504                    NULL, gfx::Rect(), &window_bounds);
505    EXPECT_EQ(gfx::Rect(994 /* not 995 */, 10 + kWindowTilePixels,
506                        500, 400), window_bounds);
507  }
508
509  { // offset would put the new window offscreen at the bottom right and the
510    // minimum visibility condition is satisified by relocation.
511    gfx::Rect window_bounds;
512    GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
513                    gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE,
514                    NULL, gfx::Rect(), &window_bounds);
515    EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400),
516              window_bounds);
517  }
518#endif  // !defined(OS_POSIX) || defined(OS_MACOSX)
519}
520
521#endif  //defined(OS_MACOSX)
522