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
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/shelf_widget.h"
#include "ash/constants/ash_switches.h"
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/keyboard/ui/keyboard_util.h"
#include "ash/keyboard/ui/test/keyboard_test_util.h"
#include "ash/public/cpp/keyboard/keyboard_switches.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/tablet_mode.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/hotseat_transition_animator.h"
#include "ash/shelf/login_shelf_view.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_navigation_widget.h"
#include "ash/shelf/shelf_test_util.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shell.h"
#include "ash/style/ash_color_id.h"
#include "ash/style/dark_light_mode_controller_impl.h"
#include "ash/system/message_center/unified_message_center_bubble.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h"
#include "ash/test_shell_delegate.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/rtl.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/icu_test_util.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/session_manager/session_manager_types.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/models/image_model.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/display.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_types.h"
#include "ui/message_center/public/cpp/notifier_id.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "url/gurl.h"
namespace ash {
namespace {
ShelfWidget* GetShelfWidget() {
return AshTestBase::GetPrimaryShelf()->shelf_widget();
}
ShelfLayoutManager* GetShelfLayoutManager() {
return GetShelfWidget()->shelf_layout_manager();
}
void TestLauncherAlignment(aura::Window* root,
ShelfAlignment alignment,
const gfx::Rect& expected) {
Shelf::ForWindow(root)->SetAlignment(alignment);
EXPECT_EQ(expected.ToString(), display::Screen::GetScreen()
->GetDisplayNearestWindow(root)
.work_area()
.ToString());
}
using SessionState = session_manager::SessionState;
using ShelfWidgetTest = AshTestBase;
TEST_F(ShelfWidgetTest, TestAlignment) {
UpdateDisplay("401x400");
const int bottom_inset = 400 - ShelfConfig::Get()->shelf_size();
{
SCOPED_TRACE("Single Bottom");
TestLauncherAlignment(Shell::GetPrimaryRootWindow(),
ShelfAlignment::kBottom,
gfx::Rect(0, 0, 401, bottom_inset));
}
{
SCOPED_TRACE("Single Locked");
TestLauncherAlignment(Shell::GetPrimaryRootWindow(),
ShelfAlignment::kBottomLocked,
gfx::Rect(0, 0, 401, bottom_inset));
}
{
SCOPED_TRACE("Single Right");
TestLauncherAlignment(Shell::GetPrimaryRootWindow(), ShelfAlignment::kRight,
gfx::Rect(0, 0, bottom_inset + 1, 400));
}
{
SCOPED_TRACE("Single Left");
TestLauncherAlignment(
Shell::GetPrimaryRootWindow(), ShelfAlignment::kLeft,
gfx::Rect(ShelfConfig::Get()->shelf_size(), 0, bottom_inset + 1, 400));
}
}
TEST_F(ShelfWidgetTest, TestAlignmentForMultipleDisplays) {
UpdateDisplay("301x300,501x500");
const int shelf_inset_first = 300 - ShelfConfig::Get()->shelf_size();
const int shelf_inset_second = 500 - ShelfConfig::Get()->shelf_size();
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
{
SCOPED_TRACE("Primary Bottom");
TestLauncherAlignment(root_windows[0], ShelfAlignment::kBottom,
gfx::Rect(0, 0, 301, shelf_inset_first));
}
{
SCOPED_TRACE("Primary Locked");
TestLauncherAlignment(root_windows[0], ShelfAlignment::kBottomLocked,
gfx::Rect(0, 0, 301, shelf_inset_first));
}
{
SCOPED_TRACE("Primary Right");
TestLauncherAlignment(root_windows[0], ShelfAlignment::kRight,
gfx::Rect(0, 0, shelf_inset_first + 1, 300));
}
{
SCOPED_TRACE("Primary Left");
TestLauncherAlignment(root_windows[0], ShelfAlignment::kLeft,
gfx::Rect(ShelfConfig::Get()->shelf_size(), 0,
shelf_inset_first + 1, 300));
}
{
SCOPED_TRACE("Secondary Bottom");
TestLauncherAlignment(root_windows[1], ShelfAlignment::kBottom,
gfx::Rect(301, 0, 501, shelf_inset_second));
}
{
SCOPED_TRACE("Secondary Locked");
TestLauncherAlignment(root_windows[1], ShelfAlignment::kBottomLocked,
gfx::Rect(301, 0, 501, shelf_inset_second));
}
{
SCOPED_TRACE("Secondary Right");
TestLauncherAlignment(root_windows[1], ShelfAlignment::kRight,
gfx::Rect(301, 0, shelf_inset_second + 1, 500));
}
{
SCOPED_TRACE("Secondary Left");
TestLauncherAlignment(root_windows[1], ShelfAlignment::kLeft,
gfx::Rect(301 + ShelfConfig::Get()->shelf_size(), 0,
shelf_inset_second + 1, 500));
}
}
class ShelfWidgetDarkLightModeTest : public ShelfWidgetTest,
public testing::WithParamInterface<bool> {
public:
void SetUp() override {
scoped_features_.InitWithFeatureState(chromeos::features::kJelly,
GetParam());
ShelfWidgetTest::SetUp();
// Enable tablet mode transition screenshots to simulate production behavior
// where shelf layers get recreated during the tablet mode transition.
TabletModeController::SetUseScreenshotForTest(true);
}
private:
base::test::ScopedFeatureList scoped_features_;
};
INSTANTIATE_TEST_SUITE_P(
// Empty to simplify gtest output
,
ShelfWidgetDarkLightModeTest,
testing::Bool());
TEST_P(ShelfWidgetDarkLightModeTest, TabletModeTransition) {
ShelfWidget* const shelf_widget = GetShelfWidget();
TabletMode::Waiter enter_waiter(/*enable=*/true);
TabletModeControllerTestApi().EnterTabletMode();
enter_waiter.Wait();
shelf_widget->background_animator_for_testing()
->CompleteAnimationForTesting();
if (GetParam()) {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
cros_tokens::kCrosSysSystemBaseElevated),
shelf_widget->GetShelfBackgroundColor());
} else {
EXPECT_EQ(
shelf_widget->GetColorProvider()->GetColor(kColorAshShieldAndBase60),
shelf_widget->GetShelfBackgroundColor());
}
EXPECT_EQ(0.0, shelf_widget->GetOpaqueBackground()->background_blur());
auto* dark_light_mode_controller = ash::DarkLightModeControllerImpl::Get();
dark_light_mode_controller->ToggleColorMode();
if (GetParam()) {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
cros_tokens::kCrosSysSystemBaseElevated),
shelf_widget->GetShelfBackgroundColor());
} else {
EXPECT_EQ(
shelf_widget->GetColorProvider()->GetColor(kColorAshShieldAndBase60),
shelf_widget->GetShelfBackgroundColor());
}
EXPECT_EQ(0.0f, shelf_widget->GetOpaqueBackground()->background_blur());
TabletMode::Waiter leave_waiter(/*enable=*/false);
TabletModeControllerTestApi().LeaveTabletMode();
leave_waiter.Wait();
shelf_widget->background_animator_for_testing()
->CompleteAnimationForTesting();
if (GetParam()) {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
cros_tokens::kCrosSysSystemBaseElevated),
shelf_widget->GetShelfBackgroundColor());
} else {
EXPECT_EQ(
shelf_widget->GetColorProvider()->GetColor(kColorAshShieldAndBase80),
shelf_widget->GetShelfBackgroundColor());
}
EXPECT_GT(shelf_widget->GetOpaqueBackground()->background_blur(), 0.0f);
dark_light_mode_controller->ToggleColorMode();
if (GetParam()) {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
cros_tokens::kCrosSysSystemBaseElevated),
shelf_widget->GetShelfBackgroundColor());
} else {
EXPECT_EQ(
shelf_widget->GetColorProvider()->GetColor(kColorAshShieldAndBase80),
shelf_widget->GetShelfBackgroundColor());
}
EXPECT_GT(shelf_widget->GetOpaqueBackground()->background_blur(), 0.0f);
}
TEST_P(ShelfWidgetDarkLightModeTest, TabletModeTransitionWithWindowOpen) {
ShelfWidget* const shelf_widget = GetShelfWidget();
auto window = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 800, 800));
TabletMode::Waiter enter_waiter(/*enable=*/true);
TabletModeControllerTestApi().EnterTabletMode();
enter_waiter.Wait();
shelf_widget->background_animator_for_testing()
->CompleteAnimationForTesting();
if (GetParam()) {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
cros_tokens::kCrosSysSystemBase),
shelf_widget->GetShelfBackgroundColor());
} else {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
kColorAshShieldAndBaseOpaque),
shelf_widget->GetShelfBackgroundColor());
}
EXPECT_EQ(0.0f, shelf_widget->GetOpaqueBackground()->background_blur());
auto* dark_light_mode_controller = ash::DarkLightModeControllerImpl::Get();
dark_light_mode_controller->ToggleColorMode();
if (GetParam()) {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
cros_tokens::kCrosSysSystemBase),
shelf_widget->GetShelfBackgroundColor());
} else {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
kColorAshShieldAndBaseOpaque),
shelf_widget->GetShelfBackgroundColor());
}
EXPECT_EQ(0.0f, shelf_widget->GetOpaqueBackground()->background_blur());
TabletMode::Waiter leave_waiter(/*enable=*/false);
TabletModeControllerTestApi().LeaveTabletMode();
leave_waiter.Wait();
shelf_widget->background_animator_for_testing()
->CompleteAnimationForTesting();
if (GetParam()) {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
cros_tokens::kCrosSysSystemBaseElevated),
shelf_widget->GetShelfBackgroundColor());
} else {
EXPECT_EQ(
shelf_widget->GetColorProvider()->GetColor(kColorAshShieldAndBase80),
shelf_widget->GetShelfBackgroundColor());
}
EXPECT_GT(shelf_widget->GetOpaqueBackground()->background_blur(), 0.0f);
dark_light_mode_controller->ToggleColorMode();
if (GetParam()) {
EXPECT_EQ(shelf_widget->GetColorProvider()->GetColor(
cros_tokens::kCrosSysSystemBaseElevated),
shelf_widget->GetShelfBackgroundColor());
} else {
EXPECT_EQ(
shelf_widget->GetColorProvider()->GetColor(kColorAshShieldAndBase80),
shelf_widget->GetShelfBackgroundColor());
}
EXPECT_GT(shelf_widget->GetOpaqueBackground()->background_blur(), 0.0f);
}
class ShelfWidgetLayoutBasicsTest
: public ShelfWidgetTest,
public testing::WithParamInterface<std::tuple<bool, bool>> {
public:
ShelfWidgetLayoutBasicsTest() {
scoped_feature_list_.InitWithFeatureState(
features::kHideShelfControlsInTabletMode, std::get<1>(GetParam()));
}
~ShelfWidgetLayoutBasicsTest() override = default;
void SetUp() override {
ShelfWidgetTest::SetUp();
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(
std::get<0>(GetParam()));
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// First parameter - whether test should run in tablet mode.
// Second parameter - whether shelf navigation buttons are enabled in tablet
// mode.
INSTANTIATE_TEST_SUITE_P(All,
ShelfWidgetLayoutBasicsTest,
testing::Combine(testing::Bool(), testing::Bool()));
// Makes sure the shelf is initially sized correctly in clamshell/tablet.
TEST_P(ShelfWidgetLayoutBasicsTest, LauncherInitiallySized) {
ShelfWidget* shelf_widget = GetShelfWidget();
ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager();
ASSERT_TRUE(shelf_layout_manager);
ASSERT_TRUE(shelf_widget->status_area_widget());
int status_width =
shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width();
// Test only makes sense if the status is > 0, which it better be.
EXPECT_GT(status_width, 0);
const int total_width =
screen_util::GetDisplayBoundsWithShelf(shelf_widget->GetNativeWindow())
.width();
const gfx::Rect nav_widget_clip_rect =
shelf_widget->navigation_widget()->GetLayer()->clip_rect();
if (!nav_widget_clip_rect.IsEmpty())
EXPECT_EQ(gfx::Point(), nav_widget_clip_rect.origin());
int nav_width =
nav_widget_clip_rect.IsEmpty()
? shelf_widget->navigation_widget()->GetWindowBoundsInScreen().width()
: nav_widget_clip_rect.width();
ASSERT_GE(nav_width, 0);
if (nav_width) {
nav_width -= ShelfConfig::Get()->control_button_edge_spacing(
true /* is_primary_axis_edge */);
}
const int hotseat_width =
shelf_widget->hotseat_widget()->GetWindowBoundsInScreen().width();
const int margins = 2 * ShelfConfig::Get()->GetAppIconGroupMargin();
EXPECT_EQ(status_width, total_width - nav_width - hotseat_width - margins);
}
TEST_F(ShelfWidgetTest, CheckVerticalShelfCornersInOverviewMode) {
// Verify corners of the shelf on the left alignment.
Shelf* shelf = GetPrimaryShelf();
shelf->SetAlignment(ShelfAlignment::kLeft);
EXPECT_EQ(ShelfAlignment::kLeft, GetPrimaryShelf()->alignment());
ShelfWidget* const shelf_widget = GetShelfWidget();
ui::Layer* opaque_background_layer =
shelf_widget->GetDelegateViewOpaqueBackgroundLayerForTesting();
// The gfx::RoundedCornersF object is considered empty when all of the
// corners are squared (no effective radius).
EXPECT_FALSE(opaque_background_layer->rounded_corner_radii().IsEmpty());
OverviewController* overview_controller = OverviewController::Get();
// Enter overview mode. Expect the shelf with square corners.
EnterOverview();
WaitForOverviewAnimation(/*enter=*/true);
EXPECT_TRUE(overview_controller->InOverviewSession());
EXPECT_TRUE(opaque_background_layer->rounded_corner_radii().IsEmpty());
// Exit overview mode. Expect the shelf with rounded corners.
ExitOverview();
WaitForOverviewAnimation(/*enter=*/false);
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_FALSE(opaque_background_layer->rounded_corner_radii().IsEmpty());
// Verify corners of the shelf on the right alignment.
shelf->SetAlignment(ShelfAlignment::kRight);
EXPECT_EQ(ShelfAlignment::kRight, GetPrimaryShelf()->alignment());
EXPECT_FALSE(opaque_background_layer->rounded_corner_radii().IsEmpty());
// Enter overview mode. Expect the shelf with square corners.
EnterOverview();
WaitForOverviewAnimation(/*enter=*/true);
EXPECT_TRUE(overview_controller->InOverviewSession());
EXPECT_TRUE(opaque_background_layer->rounded_corner_radii().IsEmpty());
// Exit overview mode. Expect the shelf with rounded corners.
ExitOverview();
WaitForOverviewAnimation(/*enter=*/false);
EXPECT_FALSE(overview_controller->InOverviewSession());
EXPECT_FALSE(opaque_background_layer->rounded_corner_radii().IsEmpty());
}
// Verifies when the shell is deleted with a full screen window we don't crash.
TEST_F(ShelfWidgetTest, DontReferenceShelfAfterDeletion) {
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = GetContext();
// Widget is now owned by the parent window.
widget->Init(std::move(params));
widget->SetFullscreen(true);
}
// Verifies shelf is created with correct size after user login and when its
// container and status widget has finished sizing.
// See http://crbug.com/252533
TEST_F(ShelfWidgetTest, ShelfInitiallySizedAfterLogin) {
ClearLogin();
UpdateDisplay("300x200,400x300");
// Both displays have a shelf controller.
aura::Window::Windows roots = Shell::GetAllRootWindows();
Shelf* shelf1 = Shelf::ForWindow(roots[0]);
Shelf* shelf2 = Shelf::ForWindow(roots[1]);
ASSERT_TRUE(shelf1);
ASSERT_TRUE(shelf2);
// Both shelf controllers have a shelf widget.
ShelfWidget* shelf_widget1 = shelf1->shelf_widget();
ShelfWidget* shelf_widget2 = shelf2->shelf_widget();
ASSERT_TRUE(shelf_widget1);
ASSERT_TRUE(shelf_widget2);
// Simulate login.
CreateUserSessions(1);
const int total_width1 =
screen_util::GetDisplayBoundsWithShelf(shelf_widget1->GetNativeWindow())
.width();
const int nav_width1 =
shelf_widget1->navigation_widget()->GetWindowBoundsInScreen().width() -
ShelfConfig::Get()->control_button_edge_spacing(
true /* is_primary_axis_edge */);
const int hotseat_width1 =
shelf_widget1->hotseat_widget()->GetWindowBoundsInScreen().width();
const int margins = 2 * ShelfConfig::Get()->GetAppIconGroupMargin();
const int total_width2 =
screen_util::GetDisplayBoundsWithShelf(shelf_widget2->GetNativeWindow())
.width();
const int nav_width2 =
shelf_widget2->navigation_widget()->GetWindowBoundsInScreen().width() -
ShelfConfig::Get()->control_button_edge_spacing(
true /* is_primary_axis_edge */);
const int hotseat_width2 =
shelf_widget2->hotseat_widget()->GetWindowBoundsInScreen().width();
// The shelf view and status area horizontally fill the shelf widget.
const int status_width1 =
shelf_widget1->status_area_widget()->GetWindowBoundsInScreen().width();
EXPECT_GT(status_width1, 0);
EXPECT_EQ(total_width1,
nav_width1 + hotseat_width1 + margins + status_width1);
const int status_width2 =
shelf_widget2->status_area_widget()->GetWindowBoundsInScreen().width();
EXPECT_GT(status_width2, 0);
EXPECT_EQ(total_width2,
nav_width2 + hotseat_width2 + margins + status_width2);
}
// Tests that the shelf has a slightly larger hit-region for touch-events when
// it's in the auto-hidden state.
TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) {
Shelf* shelf = GetPrimaryShelf();
ShelfWidget* shelf_widget = GetShelfWidget();
gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
EXPECT_TRUE(!shelf_bounds.IsEmpty());
ShelfLayoutManager* shelf_layout_manager =
shelf_widget->shelf_layout_manager();
ASSERT_TRUE(shelf_layout_manager);
EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
// Create a widget to make sure that the shelf does auto-hide.
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = GetContext();
// Widget is now owned by the parent window.
widget->Init(std::move(params));
widget->Show();
aura::Window* root = shelf_widget->GetNativeWindow()->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
// Touch just over the shelf. Since the shelf is visible, the window-targeter
// should not find the shelf as the target.
{
gfx::Point event_location(20, shelf_bounds.y() - 1);
ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location,
ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::kTouch, 0));
EXPECT_NE(shelf_widget->GetNativeWindow(),
targeter->FindTargetForEvent(root, &touch));
}
// Now auto-hide (hidden) the shelf.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_layout_manager->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_layout_manager->auto_hide_state());
shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
EXPECT_TRUE(!shelf_bounds.IsEmpty());
// Touch just over the shelf again. This time, the targeter should find the
// shelf as the target.
{
gfx::Point event_location(20, shelf_bounds.y() - 1);
ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location,
ui::EventTimeForNow(),
ui::PointerDetails(ui::EventPointerType::kTouch, 0));
EXPECT_EQ(shelf_widget->GetNativeWindow(),
targeter->FindTargetForEvent(root, &touch));
}
}
// Tests that the shelf lets mouse-events close to the edge fall through to the
// window underneath.
TEST_F(ShelfWidgetTest, ShelfEdgeOverlappingWindowHitTestMouse) {
UpdateDisplay("500x400");
ShelfWidget* shelf_widget = GetShelfWidget();
gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
EXPECT_TRUE(!shelf_bounds.IsEmpty());
ShelfLayoutManager* shelf_layout_manager =
shelf_widget->shelf_layout_manager();
ASSERT_TRUE(shelf_layout_manager);
EXPECT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
// Create a Widget which overlaps the shelf in both left and bottom
// alignments.
const int kOverlapSize = 15;
const int kWindowHeight = 200;
const int kWindowWidth = 200;
const gfx::Rect bounds(shelf_bounds.height() - kOverlapSize,
shelf_bounds.y() - kWindowHeight + kOverlapSize,
kWindowWidth, kWindowHeight);
views::Widget* widget = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = bounds;
params.context = GetContext();
// Widget is now owned by the parent window.
widget->Init(std::move(params));
// Explicitly set the bounds which will allow the widget to overlap the shelf.
widget->SetBounds(bounds);
widget->Show();
gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen();
EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds));
aura::Window* root = widget->GetNativeWindow()->GetRootWindow();
ui::EventTargeter* targeter =
root->GetHost()->dispatcher()->GetDefaultEventTargeter();
{
// Create a mouse-event targeting the top of the shelf widget. The
// window-targeter should find |widget| as the target (instead of the
// shelf).
gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1);
ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
EXPECT_EQ(widget->GetNativeWindow(), target);
}
// Change shelf alignment to verify that the targeter insets are updated.
Shelf* shelf = GetPrimaryShelf();
shelf->SetAlignment(ShelfAlignment::kLeft);
shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
{
// Create a mouse-event targeting the right edge of the shelf widget. The
// window-targeter should find |widget| as the target (instead of the
// shelf).
gfx::Point event_location(shelf_bounds.right() - 1, widget_bounds.y() + 5);
ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
EXPECT_EQ(widget->GetNativeWindow(), target);
}
// Now restore shelf alignment (bottom) and auto-hide (hidden) the shelf.
shelf->SetAlignment(ShelfAlignment::kBottom);
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf_layout_manager->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_layout_manager->auto_hide_state());
shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
EXPECT_TRUE(!shelf_bounds.IsEmpty());
// Move |widget| so it still overlaps the shelf.
widget->SetBounds(gfx::Rect(0,
shelf_bounds.y() - kWindowHeight + kOverlapSize,
kWindowWidth, kWindowHeight));
widget_bounds = widget->GetWindowBoundsInScreen();
EXPECT_TRUE(widget_bounds.Intersects(shelf_bounds));
{
// Create a mouse-event targeting the top of the shelf widget. This time,
// window-target should find the shelf as the target.
gfx::Point event_location(widget_bounds.x() + 5, shelf_bounds.y() + 1);
ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
EXPECT_EQ(shelf_widget->GetNativeWindow(), target);
}
}
class TransitionAnimationWaiter
: public HotseatTransitionAnimator::TestObserver {
public:
explicit TransitionAnimationWaiter(
HotseatTransitionAnimator* hotseat_transition_animator)
: hotseat_transition_animator_(hotseat_transition_animator) {
hotseat_transition_animator_->SetTestObserver(this);
}
~TransitionAnimationWaiter() override {
hotseat_transition_animator_->SetTestObserver(nullptr);
}
void Wait() {
run_loop_ = std::make_unique<base::RunLoop>();
run_loop_->Run();
}
private:
void OnTransitionTestAnimationEnded() override {
DCHECK(run_loop_.get());
run_loop_->Quit();
}
raw_ptr<HotseatTransitionAnimator, ExperimentalAsh>
hotseat_transition_animator_ = nullptr;
std::unique_ptr<base::RunLoop> run_loop_;
};
// Tests the drag handle bounds and visibility when the in-app shelf is shown.
TEST_F(ShelfWidgetTest, OpaqueBackgroundAndDragHandleTransition) {
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
UpdateDisplay("800x700");
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
// Create a window to transition to the in-app shelf.
auto window = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 800, 800));
{
TransitionAnimationWaiter waiter(
GetShelfWidget()->hotseat_transition_animator());
waiter.Wait();
}
// Ensure the ShelfWidget and drag handle have the correct bounds and
// visibility for in-app shelf.
EXPECT_EQ(GetShelfWidget()->GetWindowBoundsInScreen(),
gfx::Rect(0, 660, 800, 40));
EXPECT_EQ(GetShelfWidget()->GetDragHandle()->bounds(),
gfx::Rect(360, 18, 80, 4));
ASSERT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
window->Hide();
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
}
// Tests the shelf widget does not animate for hotseat transitions during tablet
// mode start.
TEST_F(ShelfWidgetTest, NoAnimatingBackgroundDuringTabletModeStartToInApp) {
UpdateDisplay("800x700");
// Create a window so tablet mode uses in-app shelf.
auto window = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 800, 800));
EXPECT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
EXPECT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
}
// Tests the shelf widget does not animate for hotseat transitions during tablet
// mode end.
TEST_F(ShelfWidgetTest, NoAnimatingBackgroundDuringTabletModeEndFromInApp) {
UpdateDisplay("800x700");
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
// Create a window so tablet mode uses in-app shelf.
auto window = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 800, 800));
EXPECT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
EXPECT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
}
// Tests the shelf widget does not animate for hotseat transitions during tablet
// mode start with no app windows.
TEST_F(ShelfWidgetTest, NoAnimatingBackgroundDuringTabletModeStartToHome) {
UpdateDisplay("800x700");
EXPECT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
EXPECT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
}
// Tests the shelf widget does not animate for hotseat transitions during tablet
// mode end with no app windows.
TEST_F(ShelfWidgetTest, NoAnimatingBackgroundDuringTabletModeEndFromHome) {
UpdateDisplay("800x700");
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
EXPECT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
EXPECT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
EXPECT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
}
// Tests the shelf widget does not animate for hotseat transitions if the screen
// is locked.
TEST_F(ShelfWidgetTest, NoAnimatingBackgroundOnLockScreen) {
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
UpdateDisplay("800x700");
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
// Create a window to transition to the in-app shelf.
auto window = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 800, 800));
// At this point animations have zero duration, so the transition happens
// immediately.
ASSERT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
GetSessionControllerClient()->SetSessionState(SessionState::LOCKED);
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// Hide the test window, and verify that does not start shelf animation.
window->Hide();
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
// Ensure the ShelfWidget and the drag handle are still hidden (i.e. in home
// screen state) when the screen is unlocked.
GetSessionControllerClient()->SetSessionState(SessionState::ACTIVE);
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
}
TEST_F(ShelfWidgetTest, NoAnimationAfterDragPastIdealBounds) {
UpdateDisplay("800x700");
// Enable shelf auto-hide (shelf should still be visible until a widget is
// shown).
Shelf* shelf = GetPrimaryShelf();
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
ASSERT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
ASSERT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// Create a widget to make sure that the shelf does auto-hide.
auto widget = CreateTestWidget();
ASSERT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Enable animations, and swipe up across the whole screen to bring up the
// shelf.
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
gfx::Rect display_bounds =
display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
const gfx::Point start(display_bounds.bottom_center());
const gfx::Point end(display_bounds.top_center());
const base::TimeDelta kTimeDelta = base::Milliseconds(100);
const int kNumScrollSteps = 4;
GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
kNumScrollSteps);
ASSERT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
ASSERT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
// The shelf should not be animating when the drag is complete.
EXPECT_FALSE(GetShelfWidget()->GetLayer()->GetAnimator()->is_animating());
}
// Tests the shelf widget animations for hotseat transitions are stopped when
// the screen is locked.
TEST_F(ShelfWidgetTest, ScreenLockStopsHotseatTransitionAnimation) {
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
UpdateDisplay("800x700");
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// Create a window to transition to the in-app shelf.
auto window = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 800, 800));
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_TRUE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_TRUE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
GetSessionControllerClient()->SetSessionState(SessionState::LOCKED);
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_FALSE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
GetSessionControllerClient()->SetSessionState(SessionState::ACTIVE);
// Ensure the ShelfWidget and the drag handle have the correct bounds and
// visibility for in-app shelf when the screen is unlocked.
ASSERT_TRUE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
EXPECT_EQ(GetShelfWidget()->GetWindowBoundsInScreen(),
gfx::Rect(0, 660, 800, 40));
EXPECT_EQ(GetShelfWidget()->GetDragHandle()->bounds(),
gfx::Rect(360, 18, 80, 4));
}
// Tests the shelf widget's opaque background gets reshown if hotseat transition
// from kShown state gets interrupted by a transition back to kShown state.
TEST_F(ShelfWidgetTest,
OpaqueBackgroundReshownAfterTransitionFromHomeChangesBackToHome) {
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(true);
UpdateDisplay("800x700");
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// Create a window to transition to the in-app shelf.
auto window = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 800, 800));
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_TRUE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_TRUE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
const gfx::Rect animating_background_bounds =
GetShelfWidget()->GetAnimatingBackground()->bounds();
EXPECT_NE(GetShelfWidget()->GetAnimatingBackground()->transform(),
GetShelfWidget()->GetAnimatingBackground()->GetTargetTransform());
// Go back home before the transition to in-app shelf finishes.
window->Hide();
// The shelf background should still be animating at this point, but to
// different bounds.
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_TRUE(GetShelfWidget()->GetAnimatingBackground()->visible());
ASSERT_TRUE(GetShelfWidget()
->GetAnimatingBackground()
->GetAnimator()
->is_animating());
EXPECT_EQ(animating_background_bounds,
GetShelfWidget()->GetAnimatingBackground()->bounds());
// The original animation did not have a chance to update the transform yet,
// so the current transform matches the original state, that matches the new
// target state.
EXPECT_EQ(GetShelfWidget()->GetAnimatingBackground()->transform(),
GetShelfWidget()->GetAnimatingBackground()->GetTargetTransform());
// Run the current animation to the end, end verify the opaque background is
// reshown after ending tablet mode.
GetShelfWidget()->GetAnimatingBackground()->GetAnimator()->StopAnimating();
ASSERT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
Shell::Get()->tablet_mode_controller()->SetEnabledForTest(false);
EXPECT_FALSE(GetShelfWidget()->GetDragHandle()->GetVisible());
ASSERT_TRUE(GetShelfWidget()->GetOpaqueBackground()->visible());
ASSERT_FALSE(GetShelfWidget()->GetAnimatingBackground()->visible());
}
class ShelfWidgetAfterLoginTest : public AshTestBase {
public:
ShelfWidgetAfterLoginTest() { set_start_session(false); }
ShelfWidgetAfterLoginTest(const ShelfWidgetAfterLoginTest&) = delete;
ShelfWidgetAfterLoginTest& operator=(const ShelfWidgetAfterLoginTest&) =
delete;
~ShelfWidgetAfterLoginTest() override = default;
void TestShelf(ShelfAlignment alignment,
ShelfAutoHideBehavior auto_hide_behavior,
ShelfVisibilityState expected_shelf_visibility_state,
ShelfAutoHideState expected_shelf_auto_hide_state) {
// Simulate login.
CreateUserSessions(1);
// Simulate shelf settings being applied from profile prefs.
Shelf* shelf = GetPrimaryShelf();
ASSERT_NE(nullptr, shelf);
shelf->SetAlignment(alignment);
shelf->SetAutoHideBehavior(auto_hide_behavior);
shelf->UpdateVisibilityState();
// Ensure settings are applied correctly.
EXPECT_EQ(alignment, shelf->alignment());
EXPECT_EQ(auto_hide_behavior, shelf->auto_hide_behavior());
EXPECT_EQ(expected_shelf_visibility_state, shelf->GetVisibilityState());
EXPECT_EQ(expected_shelf_auto_hide_state, shelf->GetAutoHideState());
}
};
TEST_F(ShelfWidgetAfterLoginTest, InitialValues) {
// Ensure shelf components are created.
Shelf* shelf = GetPrimaryShelf();
ASSERT_NE(nullptr, shelf);
ShelfWidget* shelf_widget = GetShelfWidget();
ASSERT_NE(nullptr, shelf_widget);
ASSERT_NE(nullptr, shelf_widget->shelf_view_for_testing());
ASSERT_NE(nullptr, shelf_widget->GetLoginShelfView());
ASSERT_NE(nullptr, shelf_widget->shelf_layout_manager());
// Ensure settings are correct before login.
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(ShelfAlignment::kBottomLocked, shelf->alignment());
EXPECT_EQ(ShelfAutoHideBehavior::kAlwaysHidden, shelf->auto_hide_behavior());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
// Simulate login.
CreateUserSessions(1);
// Ensure settings are correct after login.
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());
EXPECT_EQ(ShelfAutoHideBehavior::kNever, shelf->auto_hide_behavior());
// "Hidden" is the default state when auto-hide is turned off.
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideAlwaysShelf) {
// The actual auto hide state is shown because there are no open windows.
TestShelf(ShelfAlignment::kBottom, ShelfAutoHideBehavior::kAlways,
SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN);
}
TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideNeverShelf) {
// The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
TestShelf(ShelfAlignment::kLeft, ShelfAutoHideBehavior::kNever, SHELF_VISIBLE,
SHELF_AUTO_HIDE_HIDDEN);
}
TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideAlwaysHideShelf) {
// The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
TestShelf(ShelfAlignment::kRight, ShelfAutoHideBehavior::kAlwaysHidden,
SHELF_HIDDEN, SHELF_AUTO_HIDE_HIDDEN);
}
TEST_F(ShelfWidgetAfterLoginTest, CreateLockedShelf) {
// The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
TestShelf(ShelfAlignment::kBottomLocked, ShelfAutoHideBehavior::kNever,
SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN);
}
class ShelfWidgetViewsVisibilityTest : public AshTestBase {
public:
ShelfWidgetViewsVisibilityTest() { set_start_session(false); }
ShelfWidgetViewsVisibilityTest(const ShelfWidgetViewsVisibilityTest&) =
delete;
ShelfWidgetViewsVisibilityTest& operator=(
const ShelfWidgetViewsVisibilityTest&) = delete;
~ShelfWidgetViewsVisibilityTest() override = default;
enum ShelfVisibility {
kNone, // Shelf views hidden.
kShelf, // ShelfView visible.
kLoginShelf, // LoginShelfView visible.
};
void InitShelfVariables() {
// Create setup with 2 displays primary and secondary.
UpdateDisplay("800x600,800x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(2u, root_windows.size());
primary_shelf_widget_ = Shelf::ForWindow(root_windows[0])->shelf_widget();
ASSERT_NE(nullptr, primary_shelf_widget_);
secondary_shelf_widget_ = Shelf::ForWindow(root_windows[1])->shelf_widget();
ASSERT_NE(nullptr, secondary_shelf_widget_);
}
void ExpectVisible(session_manager::SessionState state,
ShelfVisibility primary_shelf_visibility,
ShelfVisibility secondary_shelf_visibility) {
GetSessionControllerClient()->SetSessionState(state);
EXPECT_EQ(primary_shelf_visibility == kNone,
!primary_shelf_widget_->IsVisible());
if (primary_shelf_visibility != kNone) {
EXPECT_EQ(primary_shelf_visibility == kLoginShelf,
primary_shelf_widget_->GetLoginShelfView()->GetVisible());
EXPECT_EQ(primary_shelf_visibility == kShelf,
primary_shelf_widget_->shelf_view_for_testing()->GetVisible());
}
EXPECT_EQ(secondary_shelf_visibility == kNone,
!secondary_shelf_widget_->IsVisible());
if (secondary_shelf_visibility != kNone) {
EXPECT_EQ(secondary_shelf_visibility == kLoginShelf,
secondary_shelf_widget_->GetLoginShelfView()->GetVisible());
EXPECT_EQ(
secondary_shelf_visibility == kShelf,
secondary_shelf_widget_->shelf_view_for_testing()->GetVisible());
}
}
private:
raw_ptr<ShelfWidget, DanglingUntriaged | ExperimentalAsh>
primary_shelf_widget_ = nullptr;
raw_ptr<ShelfWidget, DanglingUntriaged | ExperimentalAsh>
secondary_shelf_widget_ = nullptr;
};
TEST_F(ShelfWidgetViewsVisibilityTest, LoginViewsLockViews) {
ASSERT_NO_FATAL_FAILURE(InitShelfVariables());
ExpectVisible(SessionState::UNKNOWN, kNone /*primary*/, kNone /*secondary*/);
ExpectVisible(SessionState::OOBE, kLoginShelf, kNone);
ExpectVisible(SessionState::LOGIN_PRIMARY, kLoginShelf, kNone);
SimulateUserLogin("user1@test.com");
ExpectVisible(SessionState::LOGGED_IN_NOT_ACTIVE, kLoginShelf, kNone);
ExpectVisible(SessionState::ACTIVE, kShelf, kShelf);
ExpectVisible(SessionState::LOCKED, kLoginShelf, kNone);
ExpectVisible(SessionState::ACTIVE, kShelf, kShelf);
ExpectVisible(SessionState::LOGIN_SECONDARY, kLoginShelf, kNone);
ExpectVisible(SessionState::ACTIVE, kShelf, kShelf);
}
class ShelfWidgetVirtualKeyboardTest : public AshTestBase {
protected:
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
keyboard::switches::kEnableVirtualKeyboard);
AshTestBase::SetUp();
ASSERT_TRUE(keyboard::IsKeyboardEnabled());
keyboard::test::WaitUntilLoaded();
// These tests only apply to the floating virtual keyboard, as it is the
// only case where both the virtual keyboard and the shelf are visible.
const gfx::Rect keyboard_bounds(0, 0, 1, 1);
keyboard_ui_controller()->SetContainerType(
keyboard::ContainerType::kFloating, keyboard_bounds, base::DoNothing());
}
keyboard::KeyboardUIController* keyboard_ui_controller() {
return keyboard::KeyboardUIController::Get();
}
};
TEST_F(ShelfWidgetVirtualKeyboardTest, ClickingHidesVirtualKeyboard) {
keyboard_ui_controller()->ShowKeyboard(false /* locked */);
ASSERT_TRUE(keyboard::WaitUntilShown());
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint());
generator->ClickLeftButton();
// Times out if test fails.
ASSERT_TRUE(keyboard::WaitUntilHidden());
}
TEST_F(ShelfWidgetVirtualKeyboardTest, TappingHidesVirtualKeyboard) {
keyboard_ui_controller()->ShowKeyboard(false /* locked */);
ASSERT_TRUE(keyboard::WaitUntilShown());
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint());
generator->PressTouch();
// Times out if test fails.
ASSERT_TRUE(keyboard::WaitUntilHidden());
}
TEST_F(ShelfWidgetVirtualKeyboardTest, DoesNotHideLockedVirtualKeyboard) {
keyboard_ui_controller()->ShowKeyboard(true /* locked */);
ASSERT_TRUE(keyboard::WaitUntilShown());
ui::test::EventGenerator* generator = GetEventGenerator();
generator->set_current_screen_location(
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint());
generator->ClickLeftButton();
EXPECT_FALSE(keyboard::IsKeyboardHiding());
generator->PressTouch();
EXPECT_FALSE(keyboard::IsKeyboardHiding());
}
} // namespace
} // namespace ash
|