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 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
|
// 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 "ash/scoped_target_root_window.h"
#include "ash/screen_util.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_shell_delegate.h"
#include "ash/wm/window_positioner.h"
#include "ash/wm/window_resizer.h"
#include "ash/wm/window_state.h"
#include "base/compiler_specific.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/render_view_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/gfx/screen.h"
#include "ui/wm/public/activation_client.h"
typedef ash::test::AshTestBase WindowSizerAshTest;
namespace {
// A browser window proxy which is able to associate an aura native window with
// it.
class TestBrowserWindowAura : public TestBrowserWindow {
public:
// |native_window| will still be owned by the caller after the constructor
// was called.
explicit TestBrowserWindowAura(aura::Window* native_window)
: native_window_(native_window) {
}
~TestBrowserWindowAura() override {}
// TestBrowserWindow overrides:
void Show() override {
native_window_->Show();
Activate();
}
void Hide() override { native_window_->Hide(); }
void Activate() override {
aura::client::GetActivationClient(
native_window_->GetRootWindow())->ActivateWindow(native_window_.get());
}
gfx::NativeWindow GetNativeWindow() const override {
return native_window_.get();
}
gfx::Rect GetBounds() const override { return native_window_->bounds(); }
Browser* browser() { return browser_.get(); }
void CreateBrowser(const Browser::CreateParams& params) {
Browser::CreateParams create_params = params;
create_params.window = this;
browser_.reset(new Browser(create_params));
if (browser_->is_type_tabbed() || browser_->is_app()) {
ash::wm::GetWindowState(native_window_.get())->
set_window_position_managed(true);
}
}
private:
scoped_ptr<Browser> browser_;
scoped_ptr<aura::Window> native_window_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura);
};
scoped_ptr<TestBrowserWindowAura> CreateTestBrowserWindow(
aura::Window* window,
const gfx::Rect& bounds,
const Browser::CreateParams& params) {
if (!bounds.IsEmpty())
window->SetBounds(bounds);
scoped_ptr<TestBrowserWindowAura> browser_window(
new TestBrowserWindowAura(window));
browser_window->CreateBrowser(params);
return browser_window.Pass();
}
} // namespace
// On desktop linux aura, we currently don't use the ash frame, breaking some
// tests which expect ash sizes: http://crbug.com/303862
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#define MAYBE_DefaultSizeCase DISABLED_DefaultSizeCase
#else
#define MAYBE_DefaultSizeCase DefaultSizeCase
#endif
// Test that the window is sized appropriately for the first run experience
// where the default window bounds calculation is invoked.
TEST_F(WindowSizerAshTest, MAYBE_DefaultSizeCase) {
#if defined(OS_WIN)
base::CommandLine::ForCurrentProcess()->AppendSwitch(switches::kOpenAsh);
#endif
{ // 4:3 monitor case, 1024x768, no taskbar
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
1024 - ash::WindowPositioner::kDesktopBorderSize * 2,
768 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{ // 4:3 monitor case, 1024x768, taskbar on bottom
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, taskbar_bottom_work_area, gfx::Rect(),
gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
1024 - ash::WindowPositioner::kDesktopBorderSize * 2,
taskbar_bottom_work_area.height() -
ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{ // 4:3 monitor case, 1024x768, taskbar on right
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, taskbar_right_work_area, gfx::Rect(),
gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
taskbar_right_work_area.width() -
ash::WindowPositioner::kDesktopBorderSize * 2,
768 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{ // 4:3 monitor case, 1024x768, taskbar on left
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, taskbar_left_work_area, gfx::Rect(),
gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() +
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
taskbar_left_work_area.width() -
ash::WindowPositioner::kDesktopBorderSize * 2,
taskbar_left_work_area.height() -
ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{ // 4:3 monitor case, 1024x768, taskbar on top
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, taskbar_top_work_area, gfx::Rect(),
gfx::Rect(), gfx::Rect(), DEFAULT, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
taskbar_top_work_area.y() +
ash::WindowPositioner::kDesktopBorderSize,
1024 - ash::WindowPositioner::kDesktopBorderSize * 2,
taskbar_top_work_area.height() -
ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{ // 4:3 monitor case, 1280x1024
gfx::Rect window_bounds;
GetWindowBounds(p1280x1024, p1280x1024, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect((1280 - ash::WindowPositioner::kMaximumWindowWidth) / 2,
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kMaximumWindowWidth,
1024 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{ // 4:3 monitor case, 1600x1200
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect((1600 - ash::WindowPositioner::kMaximumWindowWidth) / 2,
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kMaximumWindowWidth,
1200 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{ // 16:10 monitor case, 1680x1050
gfx::Rect window_bounds;
GetWindowBounds(p1680x1050, p1680x1050, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect((1680 - ash::WindowPositioner::kMaximumWindowWidth) / 2,
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kMaximumWindowWidth,
1050 - ash::WindowPositioner::kDesktopBorderSize),
window_bounds);
}
{ // 16:10 monitor case, 1920x1200
gfx::Rect window_bounds;
GetWindowBounds(p1920x1200, p1920x1200, gfx::Rect(), gfx::Rect(),
gfx::Rect(), DEFAULT, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect((1920 - ash::WindowPositioner::kMaximumWindowWidth) / 2,
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kMaximumWindowWidth,
1200 - ash::WindowPositioner::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(WindowSizerAshTest, LastWindowBoundsCase) {
{ // normal, in the middle of the screen somewhere.
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
500, 400).ToString(),
window_bounds.ToString());
}
{ // taskbar on top.
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, taskbar_top_work_area, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
std::max(kWindowTilePixels +
ash::WindowPositioner::kDesktopBorderSize,
34 /* toolbar height */),
500, 400).ToString(),
window_bounds.ToString());
}
{ // Too small to satisify the minimum visibility condition.
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 29, 29),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
30 /* not 29 */,
30 /* not 29 */).ToString(),
window_bounds.ToString());
}
{ // Normal.
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
500, 400).ToString(),
window_bounds.ToString());
}
}
// Test that the window opened is sized appropriately given persisted sizes.
TEST_F(WindowSizerAshTest, PersistedBoundsCase) {
{ // normal, in the middle of the screen somewhere.
gfx::Rect initial_bounds(
ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), initial_bounds,
gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{ // Normal.
gfx::Rect initial_bounds(0, 0, 1024, 768);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(), initial_bounds,
gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{ // normal, on non-primary monitor in negative coords.
gfx::Rect initial_bounds(-600, 10, 500, 400);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, left_s1024x768,
initial_bounds, gfx::Rect(), PERSISTED, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{ // normal, on non-primary monitor in negative coords.
gfx::Rect initial_bounds(-1024, 0, 1024, 768);
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, left_s1024x768,
initial_bounds, gfx::Rect(), PERSISTED, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{ // 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(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
initial_bounds, right_s1024x768, PERSISTED, NULL,
gfx::Rect(), &window_bounds);
EXPECT_EQ(initial_bounds.ToString(), window_bounds.ToString());
}
{ // 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(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
initial_bounds, right_s1024x768, PERSISTED,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ("1224,50 600x500", window_bounds.ToString());
}
{ // 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(p1024x768, p1024x768, gfx::Rect(1024, 0, 800, 600),
initial_bounds, right_s1024x768, PERSISTED,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ("1024,0 800x600", window_bounds.ToString());
}
{ // width and height too small
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 29, 29),
gfx::Rect(), PERSISTED, NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize,
30 /* not 29 */, 30 /* not 29 */).ToString(),
window_bounds.ToString());
}
}
//////////////////////////////////////////////////////////////////////////////
// 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(WindowSizerAshTest, LastWindowOffscreenWithNonAggressiveRepositioning) {
{ // taskbar on left.
gfx::Rect window_bounds;
GetWindowBounds(
p1024x768, taskbar_left_work_area, gfx::Rect(),
gfx::Rect(ash::WindowPositioner::kDesktopBorderSize,
ash::WindowPositioner::kDesktopBorderSize, 500, 400),
gfx::Rect(), LAST_ACTIVE, NULL, gfx::Rect(),
&window_bounds);
EXPECT_EQ(
gfx::Rect(kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
kWindowTilePixels + ash::WindowPositioner::kDesktopBorderSize,
500, 400).ToString(),
window_bounds.ToString());
}
{ // 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(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(10, 728, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738, 500, 400).ToString(),
window_bounds.ToString());
}
{ // offset would put the new window offscreen at the bottom and the minimum
// visibility condition is satisified by relocation.
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(10, 729, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels,
738 /* not 739 */,
500,
400).ToString(),
window_bounds.ToString());
}
{ // 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(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(984, 10, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400).ToString(),
window_bounds.ToString());
}
{ // offset would put the new window offscreen at the right and the minimum
// visibility condition is satisified by relocation.
gfx::Rect window_bounds;
GetWindowBounds(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(985, 10, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(994 /* not 995 */,
10 + kWindowTilePixels,
500,
400).ToString(),
window_bounds.ToString());
}
{ // 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(p1024x768, p1024x768, gfx::Rect(),
gfx::Rect(985, 729, 500, 400), gfx::Rect(), LAST_ACTIVE,
NULL, gfx::Rect(), &window_bounds);
EXPECT_EQ(gfx::Rect(994 /* not 995 */,
738 /* not 739 */,
500,
400).ToString(),
window_bounds.ToString());
}
}
// On desktop linux aura, we currently don't use the ash frame, breaking some
// tests which expect ash sizes: http://crbug.com/303862
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#define MAYBE_PlaceNewWindows DISABLED_PlaceNewWindows
#else
#define MAYBE_PlaceNewWindows PlaceNewWindows
#endif
// Test the placement of newly created windows.
TEST_F(WindowSizerAshTest, MAYBE_PlaceNewWindows) {
// Create a browser to pass into the GetWindowBounds function.
scoped_ptr<TestingProfile> profile(new TestingProfile());
// Creating a popup handler here to make sure it does not interfere with the
// existing windows.
Browser::CreateParams native_params(profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH);
scoped_ptr<Browser> browser(
chrome::CreateBrowserWithTestWindowForParams(&native_params));
// Creating a popup handler here to make sure it does not interfere with the
// existing windows.
scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH)));
// Creating a popup to make sure it does not interfere with the positioning.
scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(16, 32, 128, 256),
Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
// Creating a panel to make sure it does not interfere with the positioning.
scoped_ptr<BrowserWindow> browser_panel(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(2),
gfx::Rect(32, 48, 256, 512),
Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
browser_window->Show();
{ // Make sure that popups do not get changed.
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
gfx::Rect(50, 100, 300, 150), bottom_s1600x1200,
PERSISTED, browser_popup->browser(),
gfx::Rect(), &window_bounds);
EXPECT_EQ("50,100 300x150", window_bounds.ToString());
}
browser_window->Hide();
{ // If a window is there but not shown the persisted default should be used.
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
gfx::Rect(50, 100, 300, 150), bottom_s1600x1200,
PERSISTED, browser.get(), gfx::Rect(), &window_bounds);
EXPECT_EQ("50,100 300x150", window_bounds.ToString());
}
{ // If a window is there but not shown the default should be returned.
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, gfx::Rect(),
gfx::Rect(), bottom_s1600x1200,
DEFAULT, browser.get(), gfx::Rect(), &window_bounds);
// Note: We need to also take the defaults maximum width into account here
// since that might get used if the resolution is too big.
EXPECT_EQ(
gfx::Rect(
std::max(ash::WindowPositioner::kDesktopBorderSize,
(1600 - ash::WindowPositioner::kMaximumWindowWidth) / 2),
ash::WindowPositioner::kDesktopBorderSize,
std::min(ash::WindowPositioner::kMaximumWindowWidth,
1600 - 2 * ash::WindowPositioner::kDesktopBorderSize),
1200 - ash::WindowPositioner::kDesktopBorderSize).ToString(),
window_bounds.ToString());
}
}
// On desktop linux aura, we currently don't use the ash frame, breaking some
// tests which expect ash sizes: http://crbug.com/303862
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#define MAYBE_PlaceNewBrowserWindowOnEmptyDesktop DISABLED_PlaceNewBrowserWindowOnEmptyDesktop
#else
#define MAYBE_PlaceNewBrowserWindowOnEmptyDesktop PlaceNewBrowserWindowOnEmptyDesktop
#endif
// Test the placement of newly created windows on an empty desktop.
// This test supplements "PlaceNewWindows" by testing the creation of a newly
// created browser window on an empty desktop.
TEST_F(WindowSizerAshTest, MAYBE_PlaceNewBrowserWindowOnEmptyDesktop) {
// Create a browser to pass into the GetWindowBoundsAndShowState function.
scoped_ptr<TestingProfile> profile(new TestingProfile());
Browser::CreateParams native_params(profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH);
scoped_ptr<Browser> browser(
chrome::CreateBrowserWithTestWindowForParams(&native_params));
// A common screen size for Chrome OS devices where this behavior is
// desirable.
const gfx::Rect p1366x768(0, 0, 1366, 768);
// If there is no previous state the window should get maximized if the
// screen is less than or equal to our limit (1366 pixels width).
gfx::Rect window_bounds;
ui::WindowShowState out_show_state1 = ui::SHOW_STATE_DEFAULT;
GetWindowBoundsAndShowState(
p1366x768, // The screen resolution.
p1366x768, // The monitor work area.
gfx::Rect(), // The second monitor.
gfx::Rect(), // The (persisted) bounds.
p1366x768, // The overall work area.
ui::SHOW_STATE_NORMAL, // The persisted show state.
ui::SHOW_STATE_DEFAULT, // The last show state.
DEFAULT, // No persisted values.
browser.get(), // Use this browser.
gfx::Rect(), // Don't request valid bounds.
&window_bounds,
&out_show_state1);
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, out_show_state1);
// If there is a stored coordinate however, that should be taken instead.
ui::WindowShowState out_show_state2 = ui::SHOW_STATE_DEFAULT;
GetWindowBoundsAndShowState(
p1366x768, // The screen resolution.
p1366x768, // The monitor work area.
gfx::Rect(), // The second monitor.
gfx::Rect(50, 100, 300, 150), // The (persisted) bounds.
p1366x768, // The overall work area.
ui::SHOW_STATE_NORMAL, // The persisted show state.
ui::SHOW_STATE_DEFAULT, // The last show state.
PERSISTED, // Set the persisted values.
browser.get(), // Use this browser.
gfx::Rect(), // Don't request valid bounds.
&window_bounds,
&out_show_state2);
EXPECT_EQ(ui::SHOW_STATE_NORMAL, out_show_state2);
EXPECT_EQ("50,100 300x150", window_bounds.ToString());
// A larger monitor should not trigger auto-maximize.
ui::WindowShowState out_show_state3 = ui::SHOW_STATE_DEFAULT;
GetWindowBoundsAndShowState(
p1600x1200, // The screen resolution.
p1600x1200, // The monitor work area.
gfx::Rect(), // The second monitor.
gfx::Rect(), // The (persisted) bounds.
p1600x1200, // The overall work area.
ui::SHOW_STATE_NORMAL, // The persisted show state.
ui::SHOW_STATE_DEFAULT, // The last show state.
DEFAULT, // No persisted values.
browser.get(), // Use this browser.
gfx::Rect(), // Don't request valid bounds.
&window_bounds,
&out_show_state3);
#if defined(OS_WIN)
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, out_show_state3);
#else
EXPECT_EQ(ui::SHOW_STATE_DEFAULT, out_show_state3);
#endif
}
#if defined(OS_CHROMEOS)
#define MAYBE_PlaceNewWindowsOnMultipleDisplays PlaceNewWindowsOnMultipleDisplays
#else
// No multiple displays on windows ash.
#define MAYBE_PlaceNewWindowsOnMultipleDisplays DISABLED_PlaceNewWindowsOnMultipleDisplays
#endif
// Test the placement of newly created windows on multiple dislays.
TEST_F(WindowSizerAshTest, MAYBE_PlaceNewWindowsOnMultipleDisplays) {
UpdateDisplay("1600x1200,1600x1200");
gfx::Rect primary_bounds = ash::Shell::GetInstance()->GetScreen()->
GetPrimaryDisplay().bounds();
gfx::Rect secondary_bounds = ash::ScreenUtil::GetSecondaryDisplay().bounds();
ash::Shell::GetInstance()->set_target_root_window(
ash::Shell::GetPrimaryRootWindow());
scoped_ptr<TestingProfile> profile(new TestingProfile());
// Create browser windows that are used as reference.
scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(10, 10, 200, 200),
Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH)));
browser_window->Show();
EXPECT_EQ(browser_window->GetNativeWindow()->GetRootWindow(),
ash::Shell::GetTargetRootWindow());
scoped_ptr<BrowserWindow> another_browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(400, 10, 300, 300),
Browser::CreateParams(profile.get(), chrome::HOST_DESKTOP_TYPE_ASH)));
another_browser_window->Show();
// Creating a new window to verify the new placement.
scoped_ptr<TestBrowserWindowAura> new_browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(),
Browser::CreateParams(profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
// Make sure the primary root is active.
ASSERT_EQ(ash::Shell::GetPrimaryRootWindow(),
ash::Shell::GetTargetRootWindow());
// First new window should be in the primary.
{
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds,
gfx::Rect(), secondary_bounds,
PERSISTED, new_browser_window->browser(),
gfx::Rect(), &window_bounds);
// TODO(oshima): Use exact bounds when the window_sizer_ash is
// moved to ash and changed to include the result from
// RearrangeVisibleWindowOnShow.
EXPECT_TRUE(primary_bounds.Contains(window_bounds));
}
// Move the window to the right side of the secondary display and create a new
// window. It should be opened then on the secondary display.
{
gfx::Display second_display = ash::Shell::GetScreen()->
GetDisplayNearestPoint(gfx::Point(1600 + 100,10));
browser_window->GetNativeWindow()->SetBoundsInScreen(
gfx::Rect(secondary_bounds.CenterPoint().x() - 100, 10, 200, 200),
second_display);
browser_window->Activate();
EXPECT_NE(ash::Shell::GetPrimaryRootWindow(),
ash::Shell::GetTargetRootWindow());
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds,
gfx::Rect(), secondary_bounds,
PERSISTED, new_browser_window->browser(),
gfx::Rect(), &window_bounds);
// TODO(oshima): Use exact bounds when the window_sizer_ash is
// moved to ash and changed to include the result from
// RearrangeVisibleWindowOnShow.
EXPECT_TRUE(secondary_bounds.Contains(window_bounds));
}
// Activate another window in the primary display and create a new window.
// It should be created in the primary display.
{
another_browser_window->Activate();
EXPECT_EQ(ash::Shell::GetPrimaryRootWindow(),
ash::Shell::GetTargetRootWindow());
gfx::Rect window_bounds;
GetWindowBounds(p1600x1200, p1600x1200, secondary_bounds,
gfx::Rect(), secondary_bounds,
PERSISTED, new_browser_window->browser(),
gfx::Rect(), &window_bounds);
// TODO(oshima): Use exact bounds when the window_sizer_ash is
// moved to ash and changed to include the result from
// RearrangeVisibleWindowOnShow.
EXPECT_TRUE(primary_bounds.Contains(window_bounds));
}
}
// On desktop linux aura, we currently don't use the ash frame, breaking some
// tests which expect ash sizes: http://crbug.com/303862
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#define MAYBE_TestShowState DISABLED_TestShowState
#else
#define MAYBE_TestShowState TestShowState
#endif
// Test that the show state is properly returned for non default cases.
TEST_F(WindowSizerAshTest, MAYBE_TestShowState) {
scoped_ptr<TestingProfile> profile(new TestingProfile());
// Creating a browser & window to play with.
scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
// Create also a popup browser since that behaves different.
scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
// Tabbed windows should retrieve the saved window state - since there is a
// top window.
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1600x1200,
p1600x1200));
// A window that is smaller than the whole work area is set to default state.
EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
GetWindowShowState(ui::SHOW_STATE_DEFAULT,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1280x1024,
p1600x1200));
// A window that is sized to occupy the whole work area is maximized.
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_DEFAULT,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1600x1200,
p1600x1200));
// Non tabbed windows should always follow the window saved visibility state.
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_popup->browser(),
p1600x1200,
p1600x1200));
// The non tabbed window will take the status of the last active of its kind.
EXPECT_EQ(ui::SHOW_STATE_NORMAL,
GetWindowShowState(ui::SHOW_STATE_DEFAULT,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_popup->browser(),
p1600x1200,
p1600x1200));
// Now create a top level window and check again for both. Only the tabbed
// window should follow the top level window's state.
// Creating a browser & window to play with.
scoped_ptr<TestBrowserWindowAura> browser_window2(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(3),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
// A tabbed window should now take the top level window state.
EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_DEFAULT,
BOTH,
browser_window->browser(),
p1600x1200,
p1600x1200));
// Non tabbed windows should always follow the window saved visibility state.
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_MINIMIZED,
BOTH,
browser_popup->browser(),
p1600x1200,
p1600x1200));
// In smaller screen resolutions we default to maximized if there is no other
// window visible.
int min_size = ash::WindowPositioner::GetForceMaximizedWidthLimit() / 2;
if (min_size > 0) {
const gfx::Rect tiny_screen(0, 0, min_size, min_size);
EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_DEFAULT,
BOTH,
browser_window->browser(),
tiny_screen,
tiny_screen));
browser_window->Hide();
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED,
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_DEFAULT,
BOTH,
browser_window2->browser(),
tiny_screen,
tiny_screen));
}
}
// Test that the default show state override behavior is properly handled.
TEST_F(WindowSizerAshTest, TestShowStateDefaults) {
// Creating a browser & window to play with.
scoped_ptr<TestingProfile> profile(new TestingProfile());
scoped_ptr<TestBrowserWindowAura> browser_window(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(0),
gfx::Rect(16, 32, 640, 320),
Browser::CreateParams(Browser::TYPE_TABBED, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
// Create also a popup browser since that behaves slightly different for
// defaults.
scoped_ptr<TestBrowserWindowAura> browser_popup(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(16, 32, 128, 256),
Browser::CreateParams(Browser::TYPE_POPUP, profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH)));
// Check that a browser creation state always get used if not given as
// SHOW_STATE_DEFAULT. On Windows ASH it should be SHOW_STATE_MAXIMIZED.
ui::WindowShowState window_show_state =
GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_MAXIMIZED,
DEFAULT,
browser_window->browser(),
p1600x1200,
p1600x1200);
#if defined(OS_WIN)
EXPECT_EQ(window_show_state, ui::SHOW_STATE_MAXIMIZED);
#else
EXPECT_EQ(window_show_state, ui::SHOW_STATE_DEFAULT);
#endif
browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_MAXIMIZED,
BOTH,
browser_window->browser(),
p1600x1200,
p1600x1200), ui::SHOW_STATE_MINIMIZED);
browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_MAXIMIZED,
ui::SHOW_STATE_MAXIMIZED,
BOTH,
browser_window->browser(),
p1600x1200,
p1600x1200), ui::SHOW_STATE_NORMAL);
browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1600x1200,
p1600x1200), ui::SHOW_STATE_MAXIMIZED);
// Check that setting the maximized command line option is forcing the
// maximized state.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kStartMaximized);
browser_window->browser()->set_initial_show_state(ui::SHOW_STATE_NORMAL);
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_window->browser(),
p1600x1200,
p1600x1200), ui::SHOW_STATE_MAXIMIZED);
// The popup should favor the initial show state over the command line.
EXPECT_EQ(GetWindowShowState(ui::SHOW_STATE_NORMAL,
ui::SHOW_STATE_NORMAL,
BOTH,
browser_popup->browser(),
p1600x1200,
p1600x1200), ui::SHOW_STATE_NORMAL);
}
TEST_F(WindowSizerAshTest, DefaultStateBecomesMaximized) {
// Create a browser to pass into the GetWindowBounds function.
scoped_ptr<TestingProfile> profile(new TestingProfile());
Browser::CreateParams native_params(profile.get(),
chrome::HOST_DESKTOP_TYPE_ASH);
scoped_ptr<Browser> browser(
chrome::CreateBrowserWithTestWindowForParams(&native_params));
gfx::Rect display_bounds = ash::Shell::GetInstance()->GetScreen()->
GetPrimaryDisplay().bounds();
gfx::Rect specified_bounds = display_bounds;
// Make a window bigger than the display work area.
specified_bounds.Inset(-20, -20);
ui::WindowShowState show_state = ui::SHOW_STATE_DEFAULT;
gfx::Rect bounds;
WindowSizer::GetBrowserWindowBoundsAndShowState(
std::string(), specified_bounds, browser.get(), &bounds, &show_state);
// The window should start maximized with its restore bounds shrunken.
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, show_state);
EXPECT_NE(display_bounds.ToString(), bounds.ToString());
EXPECT_TRUE(display_bounds.Contains(bounds));
// Make a window smaller than the display work area.
specified_bounds.Inset(100, 100);
show_state = ui::SHOW_STATE_DEFAULT;
WindowSizer::GetBrowserWindowBoundsAndShowState(
std::string(), specified_bounds, browser.get(), &bounds, &show_state);
// The window should start in default state.
EXPECT_EQ(ui::SHOW_STATE_DEFAULT, show_state);
EXPECT_EQ(specified_bounds.ToString(), bounds.ToString());
}
// Test that the target root window is used as the destination of
// the non browser window. This differ from PersistedBoundsCase
// in that this uses real ash shell implementations + StateProvider
// TargetDisplayProvider, rather than mocks.
TEST_F(WindowSizerAshTest, DefaultBoundsInTargetDisplay) {
if (!SupportsMultipleDisplays() || !chrome::ShouldOpenAshOnStartup())
return;
UpdateDisplay("500x500,600x600");
{
aura::Window* first_root =
ash::Shell::GetAllRootWindows()[0];
ash::ScopedTargetRootWindow tmp(first_root);
gfx::Rect bounds;
ui::WindowShowState show_state;
WindowSizer::GetBrowserWindowBoundsAndShowState(
std::string(),
gfx::Rect(),
NULL,
&bounds,
&show_state);
EXPECT_TRUE(first_root->GetBoundsInScreen().Contains(bounds));
}
{
aura::Window* second_root =
ash::Shell::GetAllRootWindows()[1];
ash::ScopedTargetRootWindow tmp(second_root);
gfx::Rect bounds;
ui::WindowShowState show_state;
WindowSizer::GetBrowserWindowBoundsAndShowState(
std::string(),
gfx::Rect(),
NULL,
&bounds,
&show_state);
EXPECT_TRUE(second_root->GetBoundsInScreen().Contains(bounds));
}
}
TEST_F(WindowSizerAshTest, TrustedPopupBehavior) {
scoped_ptr<TestingProfile> profile(new TestingProfile());
Browser::CreateParams trusted_popup_create_params(
Browser::TYPE_POPUP, profile.get(), chrome::HOST_DESKTOP_TYPE_ASH);
trusted_popup_create_params.trusted_source = true;
scoped_ptr<TestBrowserWindowAura> trusted_popup(CreateTestBrowserWindow(
CreateTestWindowInShellWithId(1),
gfx::Rect(16, 32, 640, 320),
trusted_popup_create_params));
// Trusted popup windows should follow the saved show state and ignore the
// last show state.
EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
GetWindowShowState(ui::SHOW_STATE_DEFAULT,
ui::SHOW_STATE_NORMAL,
BOTH,
trusted_popup->browser(),
p1280x1024,
p1600x1200));
// A popup that is sized to occupy the whole work area has default state.
EXPECT_EQ(ui::SHOW_STATE_DEFAULT,
GetWindowShowState(ui::SHOW_STATE_DEFAULT,
ui::SHOW_STATE_NORMAL,
BOTH,
trusted_popup->browser(),
p1600x1200,
p1600x1200));
}
|