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