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 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
|
// 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/root_window_controller.h"
#include <memory>
#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/session/session_controller.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/system/tray/system_tray_delegate.h"
#include "ash/common/wm/system_modal_container_layout_manager.h"
#include "ash/common/wm/window_state.h"
#include "ash/common/wm_lookup.h"
#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/test/ash_md_test_base.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_state_aura.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tracker.h"
#include "ui/base/ime/dummy_text_input_client.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/touchscreen_device.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/test/test_event_handler.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_switches.h"
#include "ui/keyboard/keyboard_ui.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/views/controls/menu/menu_controller.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
using aura::Window;
using views::Widget;
namespace ash {
namespace {
class TestDelegate : public views::WidgetDelegateView {
public:
explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
~TestDelegate() override {}
// Overridden from views::WidgetDelegate:
ui::ModalType GetModalType() const override {
return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
}
private:
bool system_modal_;
DISALLOW_COPY_AND_ASSIGN(TestDelegate);
};
class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate,
public aura::client::FocusChangeObserver {
public:
DeleteOnBlurDelegate() : window_(NULL) {}
~DeleteOnBlurDelegate() override {}
void SetWindow(aura::Window* window) {
window_ = window;
aura::client::SetFocusChangeObserver(window_, this);
}
private:
// aura::test::TestWindowDelegate overrides:
bool CanFocus() override { return true; }
// aura::client::FocusChangeObserver implementation:
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override {
if (window_ == lost_focus)
delete window_;
}
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
};
WmLayoutManager* GetLayoutManager(RootWindowController* controller, int id) {
return WmWindow::Get(controller->GetContainer(id))->GetLayoutManager();
}
} // namespace
namespace test {
class RootWindowControllerTest : public AshMDTestBase {
public:
views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
NULL, CurrentContext(), bounds);
widget->Show();
return widget;
}
views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
new TestDelegate(true), CurrentContext(), bounds);
widget->Show();
return widget;
}
views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds,
gfx::NativeWindow parent) {
views::Widget* widget = views::Widget::CreateWindowWithParentAndBounds(
new TestDelegate(true), parent, bounds);
widget->Show();
return widget;
}
aura::Window* GetModalContainer(aura::Window* root_window) {
return Shell::GetContainer(root_window,
kShellWindowId_SystemModalContainer);
}
};
INSTANTIATE_TEST_CASE_P(
/* prefix intentionally left blank due to only one parameterization */,
RootWindowControllerTest,
testing::Values(MaterialDesignController::NON_MATERIAL,
MaterialDesignController::MATERIAL_NORMAL,
MaterialDesignController::MATERIAL_EXPERIMENTAL));
TEST_P(RootWindowControllerTest, MoveWindows_Basic) {
if (!SupportsMultipleDisplays())
return;
const int height_offset = GetMdMaximizedWindowHeightOffset();
// Windows origin should be doubled when moved to the 1st display.
UpdateDisplay("600x600,300x300");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
EXPECT_EQ("50,10 100x100",
normal->GetNativeView()->GetBoundsInRootWindow().ToString());
views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
maximized->Maximize();
EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
EXPECT_EQ(gfx::Rect(600, 0, 300, 253 + height_offset).ToString(),
maximized->GetWindowBoundsInScreen().ToString());
EXPECT_EQ(gfx::Rect(0, 0, 300, 253 + height_offset).ToString(),
maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
minimized->Minimize();
EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
EXPECT_EQ("800,10 100x100", minimized->GetWindowBoundsInScreen().ToString());
views::Widget* fullscreen = CreateTestWidget(gfx::Rect(850, 10, 100, 100));
fullscreen->SetFullscreen(true);
EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
EXPECT_EQ("600,0 300x300", fullscreen->GetWindowBoundsInScreen().ToString());
EXPECT_EQ("0,0 300x300",
fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
views::Widget* unparented_control = new Widget;
Widget::InitParams params;
params.bounds = gfx::Rect(650, 10, 100, 100);
params.context = CurrentContext();
params.type = Widget::InitParams::TYPE_CONTROL;
unparented_control->Init(params);
EXPECT_EQ(root_windows[1],
unparented_control->GetNativeView()->GetRootWindow());
EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
unparented_control->GetNativeView()->parent()->id());
aura::Window* panel = CreateTestWindowInShellWithDelegateAndType(
NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100));
EXPECT_EQ(root_windows[1], panel->GetRootWindow());
EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
// Make sure a window that will delete itself when losing focus
// will not crash.
aura::WindowTracker tracker;
DeleteOnBlurDelegate delete_on_blur_delegate;
aura::Window* d2 = CreateTestWindowInShellWithDelegate(
&delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100));
delete_on_blur_delegate.SetWindow(d2);
aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2);
tracker.Add(d2);
UpdateDisplay("600x600");
// d2 must have been deleted.
EXPECT_FALSE(tracker.Contains(d2));
EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
EXPECT_EQ("100,20 100x100", normal->GetWindowBoundsInScreen().ToString());
EXPECT_EQ("100,20 100x100",
normal->GetNativeView()->GetBoundsInRootWindow().ToString());
// Maximized area on primary display has 47px for non-md and 48px for md
// (defined in SHELF_SIZE) inset at the bottom.
// First clear fullscreen status, since both fullscreen and maximized windows
// share the same desktop workspace, which cancels the shelf status.
fullscreen->SetFullscreen(false);
EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
EXPECT_EQ(gfx::Rect(0, 0, 600, 553 + height_offset).ToString(),
maximized->GetWindowBoundsInScreen().ToString());
EXPECT_EQ(gfx::Rect(0, 0, 600, 553 + height_offset).ToString(),
maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
// Set fullscreen to true, but maximized window's size won't change because
// it's not visible. see crbug.com/504299.
fullscreen->SetFullscreen(true);
EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
EXPECT_EQ(gfx::Rect(0, 0, 600, 553 + height_offset).ToString(),
maximized->GetWindowBoundsInScreen().ToString());
EXPECT_EQ(gfx::Rect(0, 0, 600, 553 + height_offset).ToString(),
maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
EXPECT_EQ("400,20 100x100", minimized->GetWindowBoundsInScreen().ToString());
EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
EXPECT_TRUE(fullscreen->IsFullscreen());
EXPECT_EQ("0,0 600x600", fullscreen->GetWindowBoundsInScreen().ToString());
EXPECT_EQ("0,0 600x600",
fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
// Test if the restore bounds are correctly updated.
wm::GetWindowState(maximized->GetNativeView())->Restore();
EXPECT_EQ("200,20 100x100", maximized->GetWindowBoundsInScreen().ToString());
EXPECT_EQ("200,20 100x100",
maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
fullscreen->SetFullscreen(false);
EXPECT_EQ("500,20 100x100", fullscreen->GetWindowBoundsInScreen().ToString());
EXPECT_EQ("500,20 100x100",
fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
// Test if the unparented widget has moved.
EXPECT_EQ(root_windows[0],
unparented_control->GetNativeView()->GetRootWindow());
EXPECT_EQ(kShellWindowId_UnparentedControlContainer,
unparented_control->GetNativeView()->parent()->id());
// Test if the panel has moved.
EXPECT_EQ(root_windows[0], panel->GetRootWindow());
EXPECT_EQ(kShellWindowId_PanelContainer, panel->parent()->id());
}
TEST_P(RootWindowControllerTest, MoveWindows_Modal) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,500x500");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
// Emulate virtual screen coordinate system.
root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
EXPECT_TRUE(
GetModalContainer(root_windows[1])->Contains(modal->GetNativeView()));
EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
ui::test::EventGenerator generator_1st(root_windows[0]);
generator_1st.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
UpdateDisplay("500x500");
EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
generator_1st.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
}
// Make sure lock related windows moves.
TEST_P(RootWindowControllerTest, MoveWindows_LockWindowsInUnified) {
if (!SupportsMultipleDisplays())
return;
display_manager()->SetUnifiedDesktopEnabled(true);
UpdateDisplay("500x500");
const int kLockScreenWindowId = 1000;
const int kLockWallpaperWindowId = 1001;
RootWindowController* controller = Shell::GetPrimaryRootWindowController();
aura::Window* lock_container =
controller->GetContainer(kShellWindowId_LockScreenContainer);
aura::Window* lock_wallpaper_container =
controller->GetContainer(kShellWindowId_LockScreenWallpaperContainer);
views::Widget* lock_screen =
CreateModalWidgetWithParent(gfx::Rect(10, 10, 100, 100), lock_container);
lock_screen->GetNativeWindow()->set_id(kLockScreenWindowId);
lock_screen->SetFullscreen(true);
views::Widget* lock_wallpaper = CreateModalWidgetWithParent(
gfx::Rect(10, 10, 100, 100), lock_wallpaper_container);
lock_wallpaper->GetNativeWindow()->set_id(kLockWallpaperWindowId);
ASSERT_EQ(lock_screen->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
ASSERT_EQ(lock_wallpaper->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId));
EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
// Switch to unified.
UpdateDisplay("500x500,500x500");
// In unified mode, RWC is created
controller = Shell::GetPrimaryRootWindowController();
ASSERT_EQ(lock_screen->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
ASSERT_EQ(lock_wallpaper->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId));
EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
// Switch to mirror.
display_manager()->SetMirrorMode(true);
EXPECT_TRUE(display_manager()->IsInMirrorMode());
controller = Shell::GetPrimaryRootWindowController();
ASSERT_EQ(lock_screen->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
ASSERT_EQ(lock_wallpaper->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId));
EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
// Switch to unified.
display_manager()->SetMirrorMode(false);
EXPECT_TRUE(display_manager()->IsInUnifiedMode());
controller = Shell::GetPrimaryRootWindowController();
ASSERT_EQ(lock_screen->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
ASSERT_EQ(lock_wallpaper->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId));
EXPECT_EQ("0,0 500x500", lock_screen->GetNativeWindow()->bounds().ToString());
// Switch to single display.
UpdateDisplay("600x500");
EXPECT_FALSE(display_manager()->IsInUnifiedMode());
EXPECT_FALSE(display_manager()->IsInMirrorMode());
controller = Shell::GetPrimaryRootWindowController();
ASSERT_EQ(lock_screen->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockScreenWindowId));
ASSERT_EQ(lock_wallpaper->GetNativeWindow(),
controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId));
EXPECT_EQ("0,0 600x500", lock_screen->GetNativeWindow()->bounds().ToString());
}
TEST_P(RootWindowControllerTest, ModalContainer) {
UpdateDisplay("600x600");
WmShell* wm_shell = WmShell::Get();
RootWindowController* controller = wm_shell->GetPrimaryRootWindowController();
EXPECT_EQ(LoginStatus::USER,
wm_shell->system_tray_delegate()->GetUserLoginStatus());
EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer),
controller->GetSystemModalLayoutManager(NULL));
views::Widget* session_modal_widget =
CreateModalWidget(gfx::Rect(300, 10, 100, 100));
EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer),
controller->GetSystemModalLayoutManager(
WmLookup::Get()->GetWindowForWidget(session_modal_widget)));
wm_shell->GetSessionStateDelegate()->LockScreen();
EXPECT_EQ(LoginStatus::LOCKED,
wm_shell->system_tray_delegate()->GetUserLoginStatus());
EXPECT_EQ(
GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer),
controller->GetSystemModalLayoutManager(nullptr));
aura::Window* lock_container =
controller->GetContainer(kShellWindowId_LockScreenContainer);
views::Widget* lock_modal_widget =
CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
EXPECT_EQ(
GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer),
controller->GetSystemModalLayoutManager(
WmLookup::Get()->GetWindowForWidget(lock_modal_widget)));
EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer),
controller->GetSystemModalLayoutManager(
WmLookup::Get()->GetWindowForWidget(session_modal_widget)));
wm_shell->GetSessionStateDelegate()->UnlockScreen();
}
TEST_P(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
UpdateDisplay("600x600");
// Configure login screen environment.
SessionStateDelegate* session_state_delegate =
WmShell::Get()->GetSessionStateDelegate();
SetUserLoggedIn(false);
EXPECT_EQ(LoginStatus::NOT_LOGGED_IN,
WmShell::Get()->system_tray_delegate()->GetUserLoginStatus());
EXPECT_EQ(0, session_state_delegate->NumberOfLoggedInUsers());
EXPECT_FALSE(session_state_delegate->IsActiveUserSessionStarted());
RootWindowController* controller =
WmShell::Get()->GetPrimaryRootWindowController();
EXPECT_EQ(
GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer),
controller->GetSystemModalLayoutManager(NULL));
aura::Window* lock_container =
controller->GetContainer(kShellWindowId_LockScreenContainer);
views::Widget* login_modal_widget =
CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
EXPECT_EQ(
GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer),
controller->GetSystemModalLayoutManager(
WmLookup::Get()->GetWindowForWidget(login_modal_widget)));
login_modal_widget->Close();
// Configure user session environment.
SetUserLoggedIn(true);
SetSessionStarted(true);
EXPECT_EQ(LoginStatus::USER,
WmShell::Get()->system_tray_delegate()->GetUserLoginStatus());
EXPECT_EQ(1, session_state_delegate->NumberOfLoggedInUsers());
EXPECT_TRUE(session_state_delegate->IsActiveUserSessionStarted());
EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer),
controller->GetSystemModalLayoutManager(NULL));
views::Widget* session_modal_widget =
CreateModalWidget(gfx::Rect(300, 10, 100, 100));
EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer),
controller->GetSystemModalLayoutManager(
WmLookup::Get()->GetWindowForWidget(session_modal_widget)));
}
TEST_P(RootWindowControllerTest, ModalContainerBlockedSession) {
UpdateDisplay("600x600");
RootWindowController* controller =
WmShell::Get()->GetPrimaryRootWindowController();
aura::Window* lock_container =
controller->GetContainer(kShellWindowId_LockScreenContainer);
for (int block_reason = FIRST_BLOCK_REASON;
block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) {
views::Widget* session_modal_widget =
CreateModalWidget(gfx::Rect(300, 10, 100, 100));
EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer),
controller->GetSystemModalLayoutManager(
WmLookup::Get()->GetWindowForWidget(session_modal_widget)));
EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer),
controller->GetSystemModalLayoutManager(NULL));
session_modal_widget->Close();
BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
EXPECT_EQ(
GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer),
controller->GetSystemModalLayoutManager(NULL));
views::Widget* lock_modal_widget = CreateModalWidgetWithParent(
gfx::Rect(300, 10, 100, 100), lock_container);
EXPECT_EQ(
GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer),
controller->GetSystemModalLayoutManager(
WmLookup::Get()->GetWindowForWidget(lock_modal_widget)));
session_modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100));
EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer),
controller->GetSystemModalLayoutManager(
WmLookup::Get()->GetWindowForWidget(session_modal_widget)));
session_modal_widget->Close();
lock_modal_widget->Close();
UnblockUserSession();
}
}
TEST_P(RootWindowControllerTest, GetWindowForFullscreenMode) {
UpdateDisplay("600x600");
RootWindowController* controller = Shell::GetPrimaryRootWindowController();
Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
w1->Maximize();
Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
w2->SetFullscreen(true);
// |w3| is a transient child of |w2|.
Widget* w3 = Widget::CreateWindowWithParentAndBounds(
NULL, w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
// Test that GetWindowForFullscreenMode() finds the fullscreen window when one
// of its transient children is active.
w3->Activate();
EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
// If the topmost window is not fullscreen, it returns NULL.
w1->Activate();
EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
w1->Close();
w3->Close();
// Only w2 remains, if minimized GetWindowForFullscreenMode should return
// NULL.
w2->Activate();
EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
w2->Minimize();
EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
}
TEST_P(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("600x600,600x600");
Shell::RootWindowControllerList controllers =
Shell::GetInstance()->GetAllRootWindowControllers();
Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
w1->Maximize();
Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
w2->SetFullscreen(true);
Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100));
EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(),
controllers[0]->GetRootWindow());
EXPECT_EQ(w2->GetNativeWindow()->GetRootWindow(),
controllers[0]->GetRootWindow());
EXPECT_EQ(w3->GetNativeWindow()->GetRootWindow(),
controllers[1]->GetRootWindow());
w1->Activate();
EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode());
EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
w2->Activate();
EXPECT_EQ(w2->GetNativeWindow(),
controllers[0]->GetWindowForFullscreenMode());
EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
// Verify that the first root window controller remains in fullscreen mode
// when a window on the other display is activated.
w3->Activate();
EXPECT_EQ(w2->GetNativeWindow(),
controllers[0]->GetWindowForFullscreenMode());
EXPECT_EQ(NULL, controllers[1]->GetWindowForFullscreenMode());
}
// Test that GetRootWindowController() works with multiple displays and
// child widgets.
TEST_P(RootWindowControllerTest, GetRootWindowController) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("600x600,600x600");
Shell::RootWindowControllerList controllers =
Shell::GetInstance()->GetAllRootWindowControllers();
ASSERT_EQ(2u, controllers.size());
// Test null.
EXPECT_FALSE(GetRootWindowController(nullptr));
// Test a widget on the first display.
Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
EXPECT_EQ(controllers[0],
GetRootWindowController(w1->GetNativeWindow()->GetRootWindow()));
// Test a child widget.
Widget* w2 = Widget::CreateWindowWithParentAndBounds(
nullptr, w1->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
EXPECT_EQ(controllers[0],
GetRootWindowController(w2->GetNativeWindow()->GetRootWindow()));
// Test a widget on the second display.
Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100));
EXPECT_EQ(controllers[1],
GetRootWindowController(w3->GetNativeWindow()->GetRootWindow()));
}
// Test that user session window can't be focused if user session blocked by
// some overlapping UI.
TEST_P(RootWindowControllerTest, FocusBlockedWindow) {
UpdateDisplay("600x600");
RootWindowController* controller = Shell::GetPrimaryRootWindowController();
aura::Window* lock_container =
controller->GetContainer(kShellWindowId_LockScreenContainer);
aura::Window* lock_window =
Widget::CreateWindowWithParentAndBounds(NULL, lock_container,
gfx::Rect(0, 0, 100, 100))
->GetNativeView();
lock_window->Show();
aura::Window* session_window =
CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
session_window->Show();
for (int block_reason = FIRST_BLOCK_REASON;
block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) {
BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
lock_window->Focus();
EXPECT_TRUE(lock_window->HasFocus());
session_window->Focus();
EXPECT_FALSE(session_window->HasFocus());
UnblockUserSession();
}
}
// Tracks whether OnWindowDestroying() has been invoked.
class DestroyedWindowObserver : public aura::WindowObserver {
public:
DestroyedWindowObserver() : destroyed_(false), window_(NULL) {}
~DestroyedWindowObserver() override { Shutdown(); }
void SetWindow(Window* window) {
window_ = window;
window->AddObserver(this);
}
bool destroyed() const { return destroyed_; }
// WindowObserver overrides:
void OnWindowDestroying(Window* window) override {
destroyed_ = true;
Shutdown();
}
private:
void Shutdown() {
if (!window_)
return;
window_->RemoveObserver(this);
window_ = NULL;
}
bool destroyed_;
Window* window_;
DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver);
};
// Verifies shutdown doesn't delete windows that are not owned by the parent.
TEST_P(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) {
DestroyedWindowObserver observer1;
aura::test::TestWindowDelegate delegate1;
aura::Window* window1 = new aura::Window(&delegate1);
window1->SetType(ui::wm::WINDOW_TYPE_CONTROL);
window1->set_owned_by_parent(false);
observer1.SetWindow(window1);
window1->Init(ui::LAYER_NOT_DRAWN);
aura::client::ParentWindowWithContext(
window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
DestroyedWindowObserver observer2;
aura::Window* window2 = new aura::Window(NULL);
window2->set_owned_by_parent(false);
observer2.SetWindow(window2);
window2->Init(ui::LAYER_NOT_DRAWN);
Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2);
Shell::GetPrimaryRootWindowController()->CloseChildWindows();
ASSERT_FALSE(observer1.destroyed());
delete window1;
ASSERT_FALSE(observer2.destroyed());
delete window2;
}
class VirtualKeyboardRootWindowControllerTest
: public RootWindowControllerTest {
public:
VirtualKeyboardRootWindowControllerTest() {}
~VirtualKeyboardRootWindowControllerTest() override {}
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
test::AshTestBase::SetUp();
keyboard::SetTouchKeyboardEnabled(true);
Shell::GetInstance()->CreateKeyboard();
}
void TearDown() override {
keyboard::SetTouchKeyboardEnabled(false);
test::AshTestBase::TearDown();
}
private:
DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest);
};
class MockTextInputClient : public ui::DummyTextInputClient {
public:
MockTextInputClient() : ui::DummyTextInputClient(ui::TEXT_INPUT_TYPE_TEXT) {}
void EnsureCaretNotInRect(const gfx::Rect& rect) override {
caret_exclude_rect_ = rect;
}
const gfx::Rect& caret_exclude_rect() const { return caret_exclude_rect_; }
private:
gfx::Rect caret_exclude_rect_;
DISALLOW_COPY_AND_ASSIGN(MockTextInputClient);
};
class TargetHitTestEventHandler : public ui::test::TestEventHandler {
public:
TargetHitTestEventHandler() {}
// ui::test::TestEventHandler overrides.
void OnMouseEvent(ui::MouseEvent* event) override {
if (event->type() == ui::ET_MOUSE_PRESSED)
ui::test::TestEventHandler::OnMouseEvent(event);
event->StopPropagation();
}
private:
DISALLOW_COPY_AND_ASSIGN(TargetHitTestEventHandler);
};
// Test for http://crbug.com/297858. Virtual keyboard container should only show
// on primary root window if no window has touch capability.
TEST_F(VirtualKeyboardRootWindowControllerTest,
VirtualKeyboardOnPrimaryRootWindowDefault) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,500x500");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
aura::Window* secondary_root_window = root_windows[0] == primary_root_window
? root_windows[1]
: root_windows[0];
ASSERT_TRUE(Shell::GetContainer(primary_root_window,
kShellWindowId_VirtualKeyboardContainer));
ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
kShellWindowId_VirtualKeyboardContainer));
}
// Test for http://crbug.com/303429. Virtual keyboard container should show on
// a display which has touch capability.
TEST_F(VirtualKeyboardRootWindowControllerTest,
VirtualKeyboardOnTouchableDisplayOnly) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,500x500");
display::Display secondary_display =
Shell::GetInstance()->display_manager()->GetSecondaryDisplay();
display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
.SetTouchSupport(secondary_display.id(),
display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
// The primary display doesn't have touch capability and the secondary display
// does.
ASSERT_NE(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE,
display::Screen::GetScreen()->GetPrimaryDisplay().touch_support());
ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE,
Shell::GetInstance()
->display_manager()
->GetSecondaryDisplay()
.touch_support());
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
aura::Window* secondary_root_window = root_windows[0] == primary_root_window
? root_windows[1]
: root_windows[0];
keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
ASSERT_FALSE(Shell::GetContainer(primary_root_window,
kShellWindowId_VirtualKeyboardContainer));
ASSERT_TRUE(Shell::GetContainer(secondary_root_window,
kShellWindowId_VirtualKeyboardContainer));
// Move the focus to the primary display.
aura::Window* focusable_window_in_primary_display =
CreateTestWindowInShellWithBounds(
primary_root_window->GetBoundsInScreen());
ASSERT_EQ(primary_root_window,
focusable_window_in_primary_display->GetRootWindow());
focusable_window_in_primary_display->Focus();
ASSERT_TRUE(focusable_window_in_primary_display->HasFocus());
// Virtual keyboard shows up on the secondary display even if a window in the
// primary screen has the focus.
keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
EXPECT_FALSE(Shell::GetContainer(primary_root_window,
kShellWindowId_VirtualKeyboardContainer));
EXPECT_TRUE(Shell::GetContainer(secondary_root_window,
kShellWindowId_VirtualKeyboardContainer));
}
// Test for http://crbug.com/303429. If both of displays have touch capability,
// virtual keyboard follows the input focus.
TEST_F(VirtualKeyboardRootWindowControllerTest, FollowInputFocus) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,500x500");
const int64_t primary_display_id =
display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
.SetTouchSupport(primary_display_id,
display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
const int64_t secondary_display_id =
Shell::GetInstance()->display_manager()->GetSecondaryDisplay().id();
display::test::DisplayManagerTestApi(Shell::GetInstance()->display_manager())
.SetTouchSupport(secondary_display_id,
display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE);
// Both of displays have touch capability.
ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE,
display::Screen::GetScreen()->GetPrimaryDisplay().touch_support());
ASSERT_EQ(display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE,
Shell::GetInstance()
->display_manager()
->GetSecondaryDisplay()
.touch_support());
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
aura::Window* secondary_root_window = root_windows[0] == primary_root_window
? root_windows[1]
: root_windows[0];
aura::Window* focusable_window_in_primary_display =
CreateTestWindowInShellWithBounds(
primary_root_window->GetBoundsInScreen());
ASSERT_EQ(primary_root_window,
focusable_window_in_primary_display->GetRootWindow());
aura::Window* focusable_window_in_secondary_display =
CreateTestWindowInShellWithBounds(
secondary_root_window->GetBoundsInScreen());
ASSERT_EQ(secondary_root_window,
focusable_window_in_secondary_display->GetRootWindow());
keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
EXPECT_TRUE(Shell::GetContainer(primary_root_window,
kShellWindowId_VirtualKeyboardContainer));
EXPECT_FALSE(Shell::GetContainer(secondary_root_window,
kShellWindowId_VirtualKeyboardContainer));
// Move the focus to the secondary display.
focusable_window_in_secondary_display->Focus();
ASSERT_TRUE(focusable_window_in_secondary_display->HasFocus());
keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
ASSERT_FALSE(Shell::GetContainer(primary_root_window,
kShellWindowId_VirtualKeyboardContainer));
ASSERT_TRUE(Shell::GetContainer(secondary_root_window,
kShellWindowId_VirtualKeyboardContainer));
// Move back focus to the primary display.
focusable_window_in_primary_display->Focus();
ASSERT_TRUE(focusable_window_in_primary_display->HasFocus());
keyboard::KeyboardController::GetInstance()->ShowKeyboard(false);
EXPECT_TRUE(Shell::GetContainer(primary_root_window,
kShellWindowId_VirtualKeyboardContainer));
EXPECT_FALSE(Shell::GetContainer(secondary_root_window,
kShellWindowId_VirtualKeyboardContainer));
}
// Test for http://crbug.com/303429. Even if both of display don't have touch
// capability, the virtual keyboard shows up on the specified display.
TEST_F(VirtualKeyboardRootWindowControllerTest,
VirtualKeyboardShowOnSpecifiedDisplay) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,500x500");
display::Display secondary_display =
Shell::GetInstance()->display_manager()->GetSecondaryDisplay();
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
aura::Window* secondary_root_window = root_windows[0] == primary_root_window
? root_windows[1]
: root_windows[0];
ASSERT_TRUE(Shell::GetContainer(primary_root_window,
kShellWindowId_VirtualKeyboardContainer));
ASSERT_FALSE(Shell::GetContainer(secondary_root_window,
kShellWindowId_VirtualKeyboardContainer));
const int64_t secondary_display_id = secondary_display.id();
keyboard::KeyboardController::GetInstance()->ShowKeyboardInDisplay(
secondary_display_id);
EXPECT_FALSE(Shell::GetContainer(primary_root_window,
kShellWindowId_VirtualKeyboardContainer));
EXPECT_TRUE(Shell::GetContainer(secondary_root_window,
kShellWindowId_VirtualKeyboardContainer));
}
// Test for http://crbug.com/263599. Virtual keyboard should be able to receive
// events at blocked user session.
TEST_F(VirtualKeyboardRootWindowControllerTest,
ClickVirtualKeyboardInBlockedWindow) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* keyboard_container =
Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
ASSERT_TRUE(keyboard_container);
keyboard_container->Show();
aura::Window* keyboard_window =
keyboard::KeyboardController::GetInstance()->ui()->GetKeyboardWindow();
keyboard_container->AddChild(keyboard_window);
keyboard_window->set_owned_by_parent(false);
keyboard_window->SetBounds(gfx::Rect());
keyboard_window->Show();
ui::test::TestEventHandler handler;
root_window->AddPreTargetHandler(&handler);
ui::test::EventGenerator event_generator(root_window, keyboard_window);
event_generator.ClickLeftButton();
int expected_mouse_presses = 1;
EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
for (int block_reason = FIRST_BLOCK_REASON;
block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) {
BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
event_generator.ClickLeftButton();
expected_mouse_presses++;
EXPECT_EQ(expected_mouse_presses, handler.num_mouse_events() / 2);
UnblockUserSession();
}
root_window->RemovePreTargetHandler(&handler);
}
// Test for http://crbug.com/299787. RootWindowController should delete
// the old container since the keyboard controller creates a new window in
// GetWindowContainer().
TEST_F(VirtualKeyboardRootWindowControllerTest,
DeleteOldContainerOnVirtualKeyboardInit) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* keyboard_container =
Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
ASSERT_TRUE(keyboard_container);
// Track the keyboard container window.
aura::WindowTracker tracker;
tracker.Add(keyboard_container);
// Reinitialize the keyboard.
Shell::GetInstance()->CreateKeyboard();
// keyboard_container should no longer be present.
EXPECT_FALSE(tracker.Contains(keyboard_container));
}
// Test for crbug.com/342524. After user login, the work space should restore to
// full screen.
TEST_F(VirtualKeyboardRootWindowControllerTest, RestoreWorkspaceAfterLogin) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* keyboard_container =
Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
keyboard_container->Show();
keyboard::KeyboardController* controller =
keyboard::KeyboardController::GetInstance();
aura::Window* keyboard_window = controller->ui()->GetKeyboardWindow();
keyboard_container->AddChild(keyboard_window);
keyboard_window->set_owned_by_parent(false);
keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
root_window->bounds(), 100));
keyboard_window->Show();
gfx::Rect before =
display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
// Notify keyboard bounds changing.
controller->NotifyKeyboardBoundsChanging(keyboard_container->bounds());
if (!keyboard::IsKeyboardOverscrollEnabled()) {
gfx::Rect after =
display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
EXPECT_LT(after, before);
}
// Mock a login user profile change to reinitialize the keyboard.
mojom::SessionInfoPtr info = mojom::SessionInfo::New();
info->state = session_manager::SessionState::ACTIVE;
WmShell::Get()->session_controller()->SetSessionInfo(std::move(info));
EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().work_area(),
before);
}
// Ensure that system modal dialogs do not block events targeted at the virtual
// keyboard.
TEST_F(VirtualKeyboardRootWindowControllerTest, ClickWithActiveModalDialog) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* keyboard_container =
Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
ASSERT_TRUE(keyboard_container);
keyboard_container->Show();
aura::Window* keyboard_window =
keyboard::KeyboardController::GetInstance()->ui()->GetKeyboardWindow();
keyboard_container->AddChild(keyboard_window);
keyboard_window->set_owned_by_parent(false);
keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
root_window->bounds(), 100));
ui::test::TestEventHandler handler;
root_window->AddPreTargetHandler(&handler);
ui::test::EventGenerator root_window_event_generator(root_window);
ui::test::EventGenerator keyboard_event_generator(root_window,
keyboard_window);
views::Widget* modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100));
// Verify that mouse events to the root window are block with a visble modal
// dialog.
root_window_event_generator.ClickLeftButton();
EXPECT_EQ(0, handler.num_mouse_events());
// Verify that event dispatch to the virtual keyboard is unblocked.
keyboard_event_generator.ClickLeftButton();
EXPECT_EQ(1, handler.num_mouse_events() / 2);
modal_widget->Close();
// Verify that mouse events are now unblocked to the root window.
root_window_event_generator.ClickLeftButton();
EXPECT_EQ(2, handler.num_mouse_events() / 2);
root_window->RemovePreTargetHandler(&handler);
}
// Ensure that the visible area for scrolling the text caret excludes the
// region occluded by the on-screen keyboard.
TEST_F(VirtualKeyboardRootWindowControllerTest, EnsureCaretInWorkArea) {
keyboard::KeyboardController* keyboard_controller =
keyboard::KeyboardController::GetInstance();
keyboard::KeyboardUI* ui = keyboard_controller->ui();
MockTextInputClient text_input_client;
ui::InputMethod* input_method = ui->GetInputMethod();
ASSERT_TRUE(input_method);
input_method->SetFocusedTextInputClient(&text_input_client);
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* keyboard_container =
Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
ASSERT_TRUE(keyboard_container);
keyboard_container->Show();
const int keyboard_height = 100;
aura::Window* keyboard_window = ui->GetKeyboardWindow();
keyboard_container->AddChild(keyboard_window);
keyboard_window->set_owned_by_parent(false);
keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
root_window->bounds(), keyboard_height));
ui->EnsureCaretInWorkArea();
ASSERT_EQ(root_window->bounds().width(),
text_input_client.caret_exclude_rect().width());
ASSERT_EQ(keyboard_height, text_input_client.caret_exclude_rect().height());
input_method->SetFocusedTextInputClient(NULL);
}
TEST_F(VirtualKeyboardRootWindowControllerTest,
EnsureCaretInWorkAreaWithMultipleDisplays) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,600x600");
const int64_t primary_display_id =
display::Screen::GetScreen()->GetPrimaryDisplay().id();
const int64_t secondary_display_id =
Shell::GetInstance()->display_manager()->GetSecondaryDisplay().id();
ASSERT_NE(primary_display_id, secondary_display_id);
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(static_cast<size_t>(2), root_windows.size());
aura::Window* primary_root_window = root_windows[0];
aura::Window* secondary_root_window = root_windows[1];
keyboard::KeyboardController* keyboard_controller =
keyboard::KeyboardController::GetInstance();
keyboard::KeyboardUI* ui = keyboard_controller->ui();
MockTextInputClient text_input_client;
ui::InputMethod* input_method = ui->GetInputMethod();
ASSERT_TRUE(input_method);
input_method->SetFocusedTextInputClient(&text_input_client);
const int keyboard_height = 100;
// Check that the keyboard on the primary screen doesn't cover the window on
// the secondary screen.
aura::Window* keyboard_container = Shell::GetContainer(
primary_root_window, kShellWindowId_VirtualKeyboardContainer);
ASSERT_TRUE(keyboard_container);
keyboard_container->Show();
aura::Window* keyboard_window = ui->GetKeyboardWindow();
keyboard_container->AddChild(keyboard_window);
keyboard_window->set_owned_by_parent(false);
keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
primary_root_window->bounds(), keyboard_height));
EXPECT_TRUE(primary_root_window->GetBoundsInScreen().Contains(
text_input_client.caret_exclude_rect()));
EXPECT_FALSE(secondary_root_window->GetBoundsInScreen().Contains(
text_input_client.caret_exclude_rect()));
// Move the keyboard into the secondary display and check that the keyboard
// doesn't cover the window on the primary screen.
keyboard_controller->ShowKeyboardInDisplay(secondary_display_id);
keyboard_window->SetBounds(keyboard::FullWidthKeyboardBoundsFromRootBounds(
secondary_root_window->bounds(), keyboard_height));
ui->EnsureCaretInWorkArea();
EXPECT_FALSE(primary_root_window->GetBoundsInScreen().Contains(
text_input_client.caret_exclude_rect()));
EXPECT_TRUE(secondary_root_window->GetBoundsInScreen().Contains(
text_input_client.caret_exclude_rect()));
input_method->SetFocusedTextInputClient(nullptr);
}
// Tests that the virtual keyboard does not block context menus. The virtual
// keyboard should appear in front of most content, but not context menus. See
// crbug/377180.
TEST_F(VirtualKeyboardRootWindowControllerTest, ZOrderTest) {
UpdateDisplay("800x600");
keyboard::KeyboardController* keyboard_controller =
keyboard::KeyboardController::GetInstance();
keyboard::KeyboardUI* ui = keyboard_controller->ui();
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* keyboard_container =
Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
ASSERT_TRUE(keyboard_container);
keyboard_container->Show();
const int keyboard_height = 200;
aura::Window* keyboard_window = ui->GetKeyboardWindow();
keyboard_container->AddChild(keyboard_window);
keyboard_window->set_owned_by_parent(false);
gfx::Rect keyboard_bounds = keyboard::FullWidthKeyboardBoundsFromRootBounds(
root_window->bounds(), keyboard_height);
keyboard_window->SetBounds(keyboard_bounds);
keyboard_window->Show();
ui::test::EventGenerator generator(root_window);
// Cover the screen with two windows: a normal window on the left side and a
// context menu on the right side. When the virtual keyboard is displayed it
// partially occludes the normal window, but not the context menu. Compute
// positions for generating synthetic click events to perform hit tests,
// ensuring the correct window layering. 'top' is above the VK, whereas
// 'bottom' lies within the VK. 'left' is centered in the normal window, and
// 'right' is centered in the context menu.
int window_height = keyboard_bounds.bottom();
int window_width = keyboard_bounds.width() / 2;
int left = window_width / 2;
int right = 3 * window_width / 2;
int top = keyboard_bounds.y() / 2;
int bottom = window_height - keyboard_height / 2;
// Normal window is partially occluded by the virtual keyboard.
aura::test::TestWindowDelegate delegate;
std::unique_ptr<aura::Window> normal(
CreateTestWindowInShellWithDelegateAndType(
&delegate, ui::wm::WINDOW_TYPE_NORMAL, 0,
gfx::Rect(0, 0, window_width, window_height)));
normal->set_owned_by_parent(false);
normal->Show();
TargetHitTestEventHandler normal_handler;
normal->AddPreTargetHandler(&normal_handler);
// Test that only the click on the top portion of the window is picked up. The
// click on the bottom hits the virtual keyboard instead.
generator.MoveMouseTo(left, top);
generator.ClickLeftButton();
EXPECT_EQ(1, normal_handler.num_mouse_events());
generator.MoveMouseTo(left, bottom);
generator.ClickLeftButton();
EXPECT_EQ(1, normal_handler.num_mouse_events());
// Menu overlaps virtual keyboard.
aura::test::TestWindowDelegate delegate2;
std::unique_ptr<aura::Window> menu(CreateTestWindowInShellWithDelegateAndType(
&delegate2, ui::wm::WINDOW_TYPE_MENU, 0,
gfx::Rect(window_width, 0, window_width, window_height)));
menu->set_owned_by_parent(false);
menu->Show();
TargetHitTestEventHandler menu_handler;
menu->AddPreTargetHandler(&menu_handler);
// Test that both clicks register.
generator.MoveMouseTo(right, top);
generator.ClickLeftButton();
EXPECT_EQ(1, menu_handler.num_mouse_events());
generator.MoveMouseTo(right, bottom);
generator.ClickLeftButton();
EXPECT_EQ(2, menu_handler.num_mouse_events());
// Cleanup to ensure that the test windows are destroyed before their
// delegates.
normal.reset();
menu.reset();
}
// Tests that the virtual keyboard correctly resizes with a change to display
// orientation. See crbug/417612.
TEST_F(VirtualKeyboardRootWindowControllerTest, DisplayRotation) {
UpdateDisplay("800x600");
aura::Window* root_window = Shell::GetPrimaryRootWindow();
aura::Window* keyboard_container =
Shell::GetContainer(root_window, kShellWindowId_VirtualKeyboardContainer);
ASSERT_TRUE(keyboard_container);
keyboard::KeyboardController* keyboard_controller =
keyboard::KeyboardController::GetInstance();
keyboard_controller->ShowKeyboard(false);
keyboard_controller->ui()->GetKeyboardWindow()->SetBounds(
gfx::Rect(0, 400, 800, 200));
EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString());
UpdateDisplay("600x800");
EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString());
}
} // namespace test
} // namespace ash
|