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 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599
|
// Copyright 2017 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/home_button.h"
#include <memory>
#include <string>
#include <string_view>
#include <tuple>
#include <vector>
#include "ash/accessibility/accessibility_controller.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/test/app_list_test_helper.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/assistant/assistant_controller_impl.h"
#include "ash/assistant/model/assistant_ui_model.h"
#include "ash/assistant/test/test_assistant_service.h"
#include "ash/capture_mode/base_capture_mode_session.h"
#include "ash/capture_mode/capture_mode_controller.h"
#include "ash/capture_mode/capture_mode_types.h"
#include "ash/capture_mode/test_capture_mode_delegate.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/public/cpp/assistant/controller/assistant_ui_controller.h"
#include "ash/public/cpp/capture_mode/capture_mode_api.h"
#include "ash/public/cpp/tablet_mode.h"
#include "ash/root_window_controller.h"
#include "ash/scanner/scanner_enterprise_policy.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_navigation_widget.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_util.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "base/command_line.h"
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/ash/services/assistant/public/cpp/assistant_enums.h"
#include "chromeos/ash/services/assistant/public/cpp/assistant_prefs.h"
#include "chromeos/ash/services/assistant/public/cpp/features.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/layer_animation_stopped_waiter.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/bounds_animator.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/wm/core/coordinate_conversion.h"
namespace ash {
namespace {
constexpr std::string_view kNoAssistantForNewEntryPoint =
"Assistant is not available if new entry point is enabled. "
"crbug.com/388361414";
ui::GestureEvent CreateGestureEvent(ui::GestureEventDetails details) {
return ui::GestureEvent(0, 0, ui::EF_NONE, base::TimeTicks(), details);
}
class HomeButtonTestBase : public AshTestBase {
public:
HomeButtonTestBase() = default;
HomeButtonTestBase(const HomeButtonTestBase&) = delete;
HomeButtonTestBase& operator=(const HomeButtonTestBase&) = delete;
~HomeButtonTestBase() override = default;
void SendGestureEvent(ui::GestureEvent* event) {
ASSERT_TRUE(home_button());
home_button()->OnGestureEvent(event);
}
HomeButton* home_button() const {
return GetPrimaryShelf()
->shelf_widget()
->navigation_widget()
->GetHomeButton();
}
protected:
base::test::ScopedFeatureList scoped_feature_list_;
};
class HomeButtonTest : public HomeButtonTestBase,
public testing::WithParamInterface<bool> {
public:
// HomeButtonTestBase:
void SetUp() override {
scoped_feature_list_.InitWithFeatureStates({
{features::kHideShelfControlsInTabletMode,
IsHideShelfControlsInTabletModeEnabled()},
{features::kSunfishFeature, true},
{features::kScannerUpdate, true},
{features::kScannerDogfood, true},
});
HomeButtonTestBase::SetUp();
}
void SendGestureEventToSecondaryDisplay(ui::GestureEvent* event) {
// Add secondary display.
UpdateDisplay("1+1-1000x600,1002+0-600x400");
ASSERT_TRUE(Shelf::ForWindow(Shell::GetAllRootWindows()[1])
->shelf_widget()
->navigation_widget()
->GetHomeButton());
// Send the gesture event to the secondary display.
Shelf::ForWindow(Shell::GetAllRootWindows()[1])
->shelf_widget()
->navigation_widget()
->GetHomeButton()
->OnGestureEvent(event);
}
bool IsHideShelfControlsInTabletModeEnabled() const { return GetParam(); }
AssistantState* assistant_state() const { return AssistantState::Get(); }
PrefService* prefs() {
return Shell::Get()->session_controller()->GetPrimaryUserPrefService();
}
// Disables Sunfish and Scanner via enterprise policies.
void DisableSunfishScanner() {
auto* capture_mode_controller = CaptureModeController::Get();
auto* test_capture_mode_delegate = static_cast<TestCaptureModeDelegate*>(
capture_mode_controller->delegate_for_testing());
test_capture_mode_delegate->set_is_search_allowed_by_policy(false);
prefs()->SetInteger(prefs::kScannerEnterprisePolicyAllowed,
static_cast<int>(ScannerEnterprisePolicy::kDisallowed));
ASSERT_FALSE(CanShowSunfishOrScannerUi());
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// Tests home button visibility animations.
class HomeButtonAnimationTest : public HomeButtonTestBase {
public:
HomeButtonAnimationTest() {
scoped_feature_list_.InitAndEnableFeature(
features::kHideShelfControlsInTabletMode);
}
~HomeButtonAnimationTest() override = default;
// HomeButtonTestBase:
void SetUp() override {
HomeButtonTestBase::SetUp();
animation_duration_.emplace(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
}
void TearDown() override {
animation_duration_.reset();
HomeButtonTestBase::TearDown();
}
private:
std::optional<ui::ScopedAnimationDurationScaleMode> animation_duration_;
base::test::ScopedFeatureList scoped_feature_list_;
};
class HomeButtonWithTextTest : public HomeButtonTestBase {
public:
HomeButtonWithTextTest() {
scoped_feature_list_.InitAndEnableFeature(features::kHomeButtonWithText);
}
~HomeButtonWithTextTest() override = default;
bool IsLabelVisible() const {
if (!home_button())
return false;
auto* label_container = home_button()->expandable_container_for_test();
return label_container->GetVisible() &&
label_container->layer()->visible() &&
home_button()->nudge_label_for_test();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
class HomeButtonWithQuickAppAccess : public HomeButtonTestBase {
public:
HomeButtonWithQuickAppAccess() {
scoped_feature_list_.InitAndEnableFeature(
features::kHomeButtonQuickAppAccess);
}
~HomeButtonWithQuickAppAccess() override = default;
bool IsQuickAppVisible() const {
if (!home_button()) {
return false;
}
auto* expandable_container = home_button()->expandable_container_for_test();
if (!expandable_container) {
return false;
}
return expandable_container->GetVisible() &&
expandable_container->layer()->visible() &&
home_button()->quick_app_button_for_test();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
// Test that setting an existing app item as the quick app shows a working
// clickable quick app button.
TEST_F(HomeButtonWithQuickAppAccess, Basic) {
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
GetPrimaryShelf()->shelf_layout_manager()->LayoutShelf();
gfx::Point quick_app_center = home_button()
->quick_app_button_for_test()
->GetBoundsInScreen()
.CenterPoint();
// Test launching the quick app.
GetEventGenerator()->MoveMouseTo(quick_app_center);
GetEventGenerator()->ClickLeftButton();
EXPECT_EQ(1, GetTestAppListClient()->activate_item_count());
EXPECT_EQ(quick_app_id, GetTestAppListClient()->activate_item_last_id());
// Quick app button should be hidden after clicking it.
EXPECT_FALSE(IsQuickAppVisible());
}
// Test that setting a quick app which is not in the app list model does not
// show the quick app button.
TEST_F(HomeButtonWithQuickAppAccess, NonExistentApp) {
EXPECT_FALSE(IsQuickAppVisible());
EXPECT_FALSE(Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(
"Quick App Item"));
EXPECT_FALSE(IsQuickAppVisible());
}
// Test that when setting a quick app with no icon, the quick app button doesn't
// show until an icon is loaded.
TEST_F(HomeButtonWithQuickAppAccess, AppWithNoIconThenLoaded) {
base::HistogramTester histogram_tester;
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
AppListItem* item = new AppListItem(quick_app_id);
GetAppListTestHelper()->model()->AddItem(item);
EXPECT_TRUE(Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(
"Quick App Item"));
// Check that the quick app item with no icon is not visible, and that icon
// load was requested.
EXPECT_FALSE(IsQuickAppVisible());
EXPECT_EQ(std::vector<std::string>{quick_app_id},
GetTestAppListClient()->load_icon_app_ids());
// Set the default icon and check that the quick app button is visible after.
item->SetDefaultIconAndColor(
CreateSolidColorTestImage(gfx::Size(32, 32), SK_ColorRED), IconColor(),
/*is_placeholder_icon=*/false);
EXPECT_TRUE(IsQuickAppVisible());
histogram_tester.ExpectTotalCount("Apps.QuickAppIconLoadTime", 1);
}
// Test that the quick app button image changes when setting a new quick app
// with a quick app button already shown.
TEST_F(HomeButtonWithQuickAppAccess, IconUpdatesOnNewQuickAppSet) {
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
AppListItem* item = new AppListItem(quick_app_id);
GetAppListTestHelper()->model()->AddItem(item);
item->SetDefaultIconAndColor(
CreateSolidColorTestImage(gfx::Size(32, 32), SK_ColorRED), IconColor(),
/*is_placeholder_icon=*/false);
const std::string quick_app_id_two = "Quick App Item Two";
AppListItem* item_two = new AppListItem(quick_app_id_two);
GetAppListTestHelper()->model()->AddItem(item_two);
item_two->SetDefaultIconAndColor(
CreateSolidColorTestImage(gfx::Size(32, 32), SK_ColorBLUE), IconColor(),
/*is_placeholder_icon=*/false);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
gfx::ImageSkia image_one =
home_button()->quick_app_button_for_test()->GetImage(
views::Button::STATE_NORMAL);
EXPECT_TRUE(Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(
quick_app_id_two));
EXPECT_TRUE(IsQuickAppVisible());
gfx::ImageSkia image_two =
home_button()->quick_app_button_for_test()->GetImage(
views::Button::STATE_NORMAL);
// Check that the quick app button image is changed after setting a new quick
// app.
EXPECT_FALSE(
gfx::test::AreImagesEqual(gfx::Image(image_one), gfx::Image(image_two)));
}
// Test that the quick app button is hidden when the home button is pressed.
TEST_F(HomeButtonWithQuickAppAccess, HomeButtonPressed) {
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
gfx::Point center = home_button()->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->MoveMouseTo(center);
GetEventGenerator()->ClickLeftButton();
EXPECT_FALSE(IsQuickAppVisible());
}
// Test that the quick app button is hidden when the app list is opened.
TEST_F(HomeButtonWithQuickAppAccess, AppListOpened) {
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
GetAppListTestHelper()->ShowAppList();
EXPECT_FALSE(IsQuickAppVisible());
}
// Test that the quick app button on both displays get shown and hidden
// together.
TEST_F(HomeButtonWithQuickAppAccess, TwoDisplays) {
UpdateDisplay("10+10-500x400,600+10-1000x600/r");
HomeButton* second_home_button =
Shelf::ForWindow(Shell::GetAllRootWindows()[1])
->shelf_widget()
->navigation_widget()
->GetHomeButton();
EXPECT_NE(home_button(), second_home_button);
EXPECT_FALSE(second_home_button->quick_app_button_for_test());
EXPECT_FALSE(home_button()->quick_app_button_for_test());
// Set the quick app and ensure the quick app button is shown on both
// displays.
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(second_home_button->quick_app_button_for_test());
EXPECT_TRUE(home_button()->quick_app_button_for_test());
// Click the home button on the first display.
gfx::Point center = home_button()->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->MoveMouseTo(center);
GetEventGenerator()->ClickLeftButton();
// Both quick app buttons should be hidden.
EXPECT_FALSE(second_home_button->quick_app_button_for_test());
EXPECT_FALSE(home_button()->quick_app_button_for_test());
}
TEST_F(HomeButtonWithQuickAppAccess, AccessibleTooltipText) {
ui::AXNodeData data;
auto* controller = Shell::Get()->app_list_controller();
ASSERT_TRUE(controller);
// Initially no target is visible
EXPECT_FALSE(home_button()->IsShowingAppList());
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE),
home_button()->GetRenderedTooltipText(gfx::Point()));
// The description will be empty because the name is being used as the
// TooltipText
home_button()->GetViewAccessibility().GetAccessibleNodeData(&data);
EXPECT_EQ(data.GetString16Attribute(ax::mojom::StringAttribute::kDescription),
u"");
controller->ToggleAppList(home_button()->GetDisplayId(),
AppListShowSource::kShelfButton, base::TimeTicks());
EXPECT_TRUE(home_button()->IsShowingAppList());
EXPECT_EQ(u"", home_button()->GetRenderedTooltipText(gfx::Point()));
// Add secondary display
UpdateDisplay("10+10-500x400,600+10-1000x600/r");
HomeButton* second_home_button =
Shelf::ForWindow(Shell::GetAllRootWindows()[1])
->shelf_widget()
->navigation_widget()
->GetHomeButton();
EXPECT_NE(home_button(), second_home_button);
// The visibility of the home_button causes the second_home_button to be
// hidden.
EXPECT_FALSE(second_home_button->IsShowingAppList());
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE),
second_home_button->GetRenderedTooltipText(gfx::Point()));
controller->ToggleAppList(home_button()->GetDisplayId(),
AppListShowSource::kShelfButton, base::TimeTicks());
EXPECT_FALSE(home_button()->IsShowingAppList());
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE),
home_button()->GetRenderedTooltipText(gfx::Point()));
controller->ToggleAppList(second_home_button->GetDisplayId(),
AppListShowSource::kShelfButton, base::TimeTicks());
EXPECT_TRUE(second_home_button->IsShowingAppList());
EXPECT_EQ(u"", second_home_button->GetRenderedTooltipText(gfx::Point()));
}
// Test that setting an empty string as the quick app id hides the existing
// quick app button.
TEST_F(HomeButtonWithQuickAppAccess, EmptyAppId) {
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
// Setting the quick app to emtpy app id initially does not show the quick app
// button.
EXPECT_FALSE(Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(""));
EXPECT_FALSE(IsQuickAppVisible());
// Set quick app id shows the quick app button.
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
// Setting to an empty app id hides the quick app button.
EXPECT_TRUE(Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(""));
EXPECT_FALSE(IsQuickAppVisible());
}
// Test that the quick app button animates when showing and hiding.
TEST_F(HomeButtonWithQuickAppAccess, QuickAppButtonAnimation) {
EXPECT_FALSE(IsQuickAppVisible());
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
// The quick app button should be animating when shown.
EXPECT_TRUE(IsQuickAppVisible());
auto* quick_app_button = home_button()->quick_app_button_for_test();
EXPECT_EQ(0.0f, quick_app_button->layer()->opacity());
EXPECT_EQ(1.0f, quick_app_button->layer()->GetTargetOpacity());
EXPECT_TRUE(quick_app_button->layer()->GetAnimator()->is_animating());
// Wait for quick app button to finish show animation.
ui::LayerAnimationStoppedWaiter quick_app_button_animation_waiter;
quick_app_button_animation_waiter.Wait(quick_app_button->layer());
EXPECT_FALSE(quick_app_button->layer()->GetAnimator()->is_animating());
const int quick_app_margin = 8;
EXPECT_EQ(ShelfConfig::Get()->control_size() + quick_app_margin,
quick_app_button->bounds().x());
EXPECT_EQ(0, quick_app_button->bounds().y());
// Show the app list to begin the hide quick app button animation.
GetAppListTestHelper()->ShowAppList();
EXPECT_TRUE(IsQuickAppVisible());
EXPECT_EQ(1.0f, quick_app_button->layer()->opacity());
EXPECT_EQ(0.0f, quick_app_button->layer()->GetTargetOpacity());
EXPECT_TRUE(quick_app_button->layer()->GetAnimator()->is_animating());
quick_app_button_animation_waiter.Wait(quick_app_button->layer());
EXPECT_FALSE(IsQuickAppVisible());
}
// Test the left shelf quick app button position.
TEST_F(HomeButtonWithQuickAppAccess, LeftShelf) {
Shelf* shelf = GetPrimaryShelf();
EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
const int quick_app_margin = 8;
// Set shelf to left alignment and check quick app button bounds.
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kLeft);
auto* quick_app_button = home_button()->quick_app_button_for_test();
EXPECT_EQ(home_button()->width() + quick_app_margin,
quick_app_button->bounds().y());
EXPECT_EQ(0, quick_app_button->bounds().x());
// Test launching the quick app on the left aligned shelf.
GetEventGenerator()->MoveMouseTo(
quick_app_button->GetBoundsInScreen().CenterPoint());
GetEventGenerator()->ClickLeftButton();
EXPECT_FALSE(IsQuickAppVisible());
}
// Test the right shelf quick app button position.
TEST_F(HomeButtonWithQuickAppAccess, RightShelf) {
Shelf* shelf = GetPrimaryShelf();
EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
const int quick_app_margin = 8;
// Set shelf to right alignment and check quick app button bounds.
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kRight);
auto* quick_app_button = home_button()->quick_app_button_for_test();
EXPECT_EQ(home_button()->width() + quick_app_margin,
quick_app_button->bounds().y());
EXPECT_EQ(0, quick_app_button->bounds().x());
// Test launching the quick app on the right aligned shelf.
GetEventGenerator()->MoveMouseTo(
quick_app_button->GetBoundsInScreen().CenterPoint());
GetEventGenerator()->ClickLeftButton();
EXPECT_FALSE(IsQuickAppVisible());
}
// Change the quick app access model and test that the quick app button is
// updated.
TEST_F(HomeButtonWithQuickAppAccess, ModelChange) {
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
auto model_override = std::make_unique<test::AppListTestModel>();
auto search_model_override = std::make_unique<SearchModel>();
auto quick_app_access_model = std::make_unique<QuickAppAccessModel>();
// Switch to new models, and verify that the quick app button is hidden.
Shell::Get()->app_list_controller()->SetActiveModel(
/*profile_id=*/1, model_override.get(), search_model_override.get(),
quick_app_access_model.get());
EXPECT_FALSE(IsQuickAppVisible());
// Switch to original models, and verify the quick app button is shown again.
Shell::Get()->app_list_controller()->SetActiveModel(
/*profile_id=*/1, GetAppListTestHelper()->model(),
GetAppListTestHelper()->search_model(),
GetAppListTestHelper()->quick_app_access_model());
EXPECT_TRUE(IsQuickAppVisible());
}
// Test once the quick app is hidden due to button activation, that setting
// the same quick app again will show it.
TEST_F(HomeButtonWithQuickAppAccess, SetSameQuickAppAfterActivation) {
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
auto* quick_app_button = home_button()->quick_app_button_for_test();
// Activate and hide the quick app.
GetEventGenerator()->MoveMouseTo(
quick_app_button->GetBoundsInScreen().CenterPoint());
GetEventGenerator()->ClickLeftButton();
EXPECT_FALSE(IsQuickAppVisible());
// Set the same app as quick app and check that the button exists again.
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
}
// Test once the quick app is hidden due to app list being shown, that
// setting the same quick app again will show it.
TEST_F(HomeButtonWithQuickAppAccess, SetSameQuickAppAfterAppListShown) {
EXPECT_FALSE(IsQuickAppVisible());
const std::string quick_app_id = "Quick App Item";
GetAppListTestHelper()->model()->CreateAndAddItem(quick_app_id);
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
// Open app list and expect quick app button to be hidden.
GetAppListTestHelper()->ShowAppList();
EXPECT_FALSE(IsQuickAppVisible());
// Set the same app as quick app and check that the button exists again.
EXPECT_TRUE(
Shell::Get()->app_list_controller()->SetHomeButtonQuickApp(quick_app_id));
EXPECT_TRUE(IsQuickAppVisible());
}
enum class TestAccessibilityFeature {
kTabletModeShelfNavigationButtons,
kSpokenFeedback,
kAutoclick,
kSwitchAccess
};
// Tests home button visibility with number of accessibility setting enabled,
// with kHideControlsInTabletModeFeature.
class HomeButtonVisibilityWithAccessibilityFeaturesTest
: public HomeButtonTestBase,
public ::testing::WithParamInterface<TestAccessibilityFeature> {
public:
HomeButtonVisibilityWithAccessibilityFeaturesTest() {
scoped_feature_list_.InitAndEnableFeature(
features::kHideShelfControlsInTabletMode);
}
~HomeButtonVisibilityWithAccessibilityFeaturesTest() override = default;
void SetTestA11yFeatureEnabled(bool enabled) {
switch (GetParam()) {
case TestAccessibilityFeature::kTabletModeShelfNavigationButtons:
Shell::Get()
->accessibility_controller()
->SetTabletModeShelfNavigationButtonsEnabled(enabled);
break;
case TestAccessibilityFeature::kSpokenFeedback:
Shell::Get()->accessibility_controller()->SetSpokenFeedbackEnabled(
enabled, A11Y_NOTIFICATION_NONE);
break;
case TestAccessibilityFeature::kAutoclick:
Shell::Get()->accessibility_controller()->autoclick().SetEnabled(
enabled);
break;
case TestAccessibilityFeature::kSwitchAccess:
Shell::Get()->accessibility_controller()->switch_access().SetEnabled(
enabled);
break;
}
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
} // namespace
// The parameter indicates whether the kHideShelfControlsInTabletMode feature
// is enabled.
INSTANTIATE_TEST_SUITE_P(All, HomeButtonTest, testing::Bool());
// Tests that the shelf navigation widget clip rect is not clipping the intended
// home button bounds.
TEST_P(HomeButtonTest, ClipRectDoesNotClipHomeButtonBounds) {
ShelfNavigationWidget* const nav_widget =
GetPrimaryShelf()->navigation_widget();
ShelfNavigationWidget::TestApi test_api(nav_widget);
ASSERT_TRUE(test_api.IsHomeButtonVisible());
ASSERT_TRUE(home_button());
auto home_button_bounds = [&]() -> gfx::Rect {
return home_button()->GetBoundsInScreen();
};
auto clip_rect_bounds = [&]() -> gfx::Rect {
gfx::Rect clip_bounds = nav_widget->GetLayer()->clip_rect();
wm::ConvertRectToScreen(nav_widget->GetNativeWindow(), &clip_bounds);
return clip_bounds;
};
std::string display_configs[] = {
"1+1-1200x1000",
"1+1-1000x1200",
"1+1-800x600",
"1+1-600x800",
};
for (const auto& display_config : display_configs) {
SCOPED_TRACE(display_config);
UpdateDisplay(display_config);
EXPECT_TRUE(clip_rect_bounds().Contains(home_button_bounds()));
// Enter tablet mode - note that home button may be invisible in this case.
ash::TabletModeControllerTestApi().EnterTabletMode();
ShelfViewTestAPI shelf_test_api(
GetPrimaryShelf()->GetShelfViewForTesting());
shelf_test_api.RunMessageLoopUntilAnimationsDone(
test_api.GetBoundsAnimator());
if (home_button() && test_api.IsHomeButtonVisible())
EXPECT_TRUE(clip_rect_bounds().Contains(home_button_bounds()));
// Create a test widget to transition to in-app shelf.
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
shelf_test_api.RunMessageLoopUntilAnimationsDone(
test_api.GetBoundsAnimator());
if (home_button() && test_api.IsHomeButtonVisible())
EXPECT_TRUE(clip_rect_bounds().Contains(home_button_bounds()));
// Back to home launcher shelf.
widget.reset();
shelf_test_api.RunMessageLoopUntilAnimationsDone(
test_api.GetBoundsAnimator());
if (home_button() && test_api.IsHomeButtonVisible())
EXPECT_TRUE(clip_rect_bounds().Contains(home_button_bounds()));
// Open another window and go back to clamshell.
ash::TabletModeControllerTestApi().LeaveTabletMode();
widget =
CreateTestWidget(views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
shelf_test_api.RunMessageLoopUntilAnimationsDone(
test_api.GetBoundsAnimator());
EXPECT_TRUE(clip_rect_bounds().Contains(home_button_bounds()));
// Verify bounds after the test widget is closed.
widget.reset();
shelf_test_api.RunMessageLoopUntilAnimationsDone(
test_api.GetBoundsAnimator());
EXPECT_TRUE(clip_rect_bounds().Contains(home_button_bounds()));
}
}
TEST_P(HomeButtonTest, ClickToOpenAppList) {
Shelf* shelf = GetPrimaryShelf();
EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
ASSERT_TRUE(test_api.IsHomeButtonVisible());
ASSERT_TRUE(home_button());
gfx::Point center = home_button()->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->MoveMouseTo(center);
// Click on the home button should toggle the app list.
GetEventGenerator()->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
GetEventGenerator()->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
}
TEST_P(HomeButtonTest, ClickToOpenAppListInTabletMode) {
ash::TabletModeControllerTestApi().EnterTabletMode();
Shelf* shelf = GetPrimaryShelf();
EXPECT_EQ(ShelfAlignment::kBottom, shelf->alignment());
ShelfNavigationWidget::TestApi test_api(shelf->navigation_widget());
// Home button is expected to be hidden in tablet mode if shelf controls
// should be hidden.
const bool should_show_home_button =
!IsHideShelfControlsInTabletModeEnabled();
EXPECT_EQ(should_show_home_button, test_api.IsHomeButtonVisible());
ASSERT_EQ(should_show_home_button, static_cast<bool>(home_button()));
if (!should_show_home_button)
return;
// App list should be shown by default in tablet mode.
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
// Click on the home button should not close the app list.
gfx::Point center = home_button()->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->MoveMouseTo(center);
GetEventGenerator()->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
// Shift-click should not close the app list.
GetEventGenerator()->set_flags(ui::EF_SHIFT_DOWN);
GetEventGenerator()->ClickLeftButton();
GetEventGenerator()->set_flags(0);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
}
TEST_P(HomeButtonTest, ButtonPositionInTabletMode) {
// Finish all setup tasks. In particular we want to finish the
// GetSwitchStates post task in (Fake)PowerManagerClient which is triggered
// by TabletModeController otherwise this will cause tablet mode to exit
// while we wait for animations in the test.
base::RunLoop().RunUntilIdle();
ash::TabletModeControllerTestApi().EnterTabletMode();
Shelf* const shelf = GetPrimaryShelf();
ShelfViewTestAPI shelf_test_api(shelf->GetShelfViewForTesting());
ShelfNavigationWidget::TestApi test_api(shelf->navigation_widget());
// Home button is expected to be hidden in tablet mode if shelf controls
// should be hidden.
const bool should_show_home_button =
!IsHideShelfControlsInTabletModeEnabled();
EXPECT_EQ(should_show_home_button, test_api.IsHomeButtonVisible());
EXPECT_EQ(should_show_home_button, static_cast<bool>(home_button()));
// Wait for the navigation widget's animation.
shelf_test_api.RunMessageLoopUntilAnimationsDone(
test_api.GetBoundsAnimator());
EXPECT_EQ(should_show_home_button, test_api.IsHomeButtonVisible());
ASSERT_EQ(should_show_home_button, static_cast<bool>(home_button()));
if (should_show_home_button) {
EXPECT_EQ(home_button()->bounds().x(),
ShelfConfig::Get()->control_button_edge_spacing(
true /* is_primary_axis_edge */));
}
// Switch to in-app shelf.
std::unique_ptr<views::Widget> widget =
CreateTestWidget(views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
// Wait for the navigation widget's animation.
shelf_test_api.RunMessageLoopUntilAnimationsDone(
test_api.GetBoundsAnimator());
EXPECT_EQ(should_show_home_button, test_api.IsHomeButtonVisible());
EXPECT_EQ(should_show_home_button, static_cast<bool>(home_button()));
if (should_show_home_button)
EXPECT_GT(home_button()->bounds().x(), 0);
ash::TabletModeControllerTestApi().LeaveTabletMode();
shelf_test_api.RunMessageLoopUntilAnimationsDone(
test_api.GetBoundsAnimator());
EXPECT_TRUE(test_api.IsHomeButtonVisible());
ASSERT_TRUE(home_button());
// The space between button and screen edge is within the widget.
EXPECT_EQ(ShelfConfig::Get()->control_button_edge_spacing(
true /* is_primary_axis_edge */),
home_button()->bounds().x());
}
// Verifies that home button visibility updates are animated.
TEST_F(HomeButtonAnimationTest, VisibilityAnimation) {
views::View* const home_button_view = home_button();
ASSERT_TRUE(home_button_view);
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
// Switch to tablet mode changes the button visibility.
ash::TabletModeControllerTestApi().EnterTabletMode();
// Verify that the button view is still visible, and animating to 0 opacity.
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(0.0f, home_button_view->layer()->GetTargetOpacity());
// Once the opacity animation finishes, the button should not be visible.
home_button_view->layer()->GetAnimator()->StopAnimating();
EXPECT_FALSE(home_button_view->GetVisible());
// Tablet mode exit should schedule animation to the visible state.
ash::TabletModeControllerTestApi().LeaveTabletMode();
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(0.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
home_button_view->layer()->GetAnimator()->StopAnimating();
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
}
// Verifies that home button visibility updates if the button gets hidden while
// it's still being shown.
TEST_F(HomeButtonAnimationTest, HideWhileAnimatingToShow) {
views::View* const home_button_view = home_button();
ASSERT_TRUE(home_button_view);
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
// Switch to tablet mode to initiate home button hide animation.
ash::TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(0.0f, home_button_view->layer()->GetTargetOpacity());
home_button_view->layer()->GetAnimator()->StopAnimating();
// Tablet mode exit should schedule an animation to the visible state.
ash::TabletModeControllerTestApi().LeaveTabletMode();
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(0.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
// Enter tablet mode immediately, to interrupt the show animation.
ash::TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(0.0f, home_button_view->layer()->opacity());
EXPECT_EQ(0.0f, home_button_view->layer()->GetTargetOpacity());
home_button_view->layer()->GetAnimator()->StopAnimating();
EXPECT_FALSE(home_button_view->GetVisible());
}
// Verifies that home button becomes visible if reshown while a hide animation
// is still in progress.
TEST_F(HomeButtonAnimationTest, ShowWhileAnimatingToHide) {
views::View* const home_button_view = home_button();
ASSERT_TRUE(home_button_view);
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
// Switch to tablet mode to initiate the home button hide animation.
ash::TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(0.0f, home_button_view->layer()->GetTargetOpacity());
// Tablet mode exit should schedule an animation to the visible state.
ash::TabletModeControllerTestApi().LeaveTabletMode();
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
// Verify that the button ends up in the visible state.
home_button_view->layer()->GetAnimator()->StopAnimating();
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
}
// Verifies that unanimated navigation widget layout update interrupts in
// progress button animation.
TEST_F(HomeButtonAnimationTest, NonAnimatedLayoutDuringAnimation) {
views::View* const home_button_view = home_button();
ASSERT_TRUE(home_button_view);
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
// Switch to tablet mode changes the button visibility.
ash::TabletModeControllerTestApi().EnterTabletMode();
Shelf* const shelf = GetPrimaryShelf();
ShelfViewTestAPI shelf_test_api(shelf->GetShelfViewForTesting());
ShelfNavigationWidget::TestApi test_api(shelf->navigation_widget());
// Verify the button bounds are animating.
EXPECT_TRUE(test_api.GetBoundsAnimator()->IsAnimating(home_button_view));
// Verify that the button visibility is animating.
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
EXPECT_EQ(0.0f, home_button_view->layer()->GetTargetOpacity());
// Request non-animated navigation widget layout, and verify the button is not
// animating any longer.
shelf->navigation_widget()->UpdateLayout(/*animate=*/false);
EXPECT_FALSE(home_button_view->GetVisible());
EXPECT_FALSE(home_button_view->layer()->GetAnimator()->is_animating());
EXPECT_FALSE(test_api.GetBoundsAnimator()->IsAnimating(home_button_view));
// Tablet mode exit should schedule animation to the visible state.
ash::TabletModeControllerTestApi().LeaveTabletMode();
EXPECT_TRUE(test_api.GetBoundsAnimator()->IsAnimating(home_button_view));
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_EQ(0.0f, home_button_view->layer()->opacity());
EXPECT_EQ(1.0f, home_button_view->layer()->GetTargetOpacity());
// Request non-animated navigation widget layout, and verify the button is not
// animating any longer.
shelf->navigation_widget()->UpdateLayout(/*animate=*/false);
EXPECT_FALSE(test_api.GetBoundsAnimator()->IsAnimating(home_button_view));
EXPECT_TRUE(home_button_view->GetVisible());
EXPECT_FALSE(home_button_view->layer()->GetAnimator()->is_animating());
EXPECT_EQ(1.0f, home_button_view->layer()->opacity());
}
inline constexpr LoginInfo k2ndRegularUserLoginInfo = {"user1@tray"};
TEST_P(HomeButtonTest, LongPressGestureAssistant) {
if (ash::assistant::features::IsNewEntryPointEnabled()) {
GTEST_SKIP() << kNoAssistantForNewEntryPoint;
}
// Simulate two users with primary user as active.
auto primary = SimulateUserLogin(kRegularUserLoginInfo);
SimulateUserLogin(k2ndRegularUserLoginInfo);
SwitchActiveUser(primary);
// Disable Sunfish and Scanner via enterprise policies.
DisableSunfishScanner();
// Enable the Assistant in system settings.
prefs()->SetBoolean(assistant::prefs::kAssistantEnabled, true);
assistant_state()->NotifyFeatureAllowed(
assistant::AssistantAllowedState::ALLOWED);
assistant_state()->NotifyStatusChanged(assistant::AssistantStatus::READY);
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
EXPECT_TRUE(test_api.IsHomeButtonVisible());
ASSERT_TRUE(home_button());
ui::GestureEvent long_press = CreateGestureEvent(
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
SendGestureEvent(&long_press);
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_EQ(AssistantVisibility::kVisible,
AssistantUiController::Get()->GetModel()->visibility());
auto* capture_mode_controller = CaptureModeController::Get();
EXPECT_FALSE(capture_mode_controller->IsActive());
AssistantUiController::Get()->CloseUi(
assistant::AssistantExitPoint::kUnspecified);
// Test long press gesture on secondary display.
SendGestureEventToSecondaryDisplay(&long_press);
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_EQ(AssistantVisibility::kVisible,
AssistantUiController::Get()->GetModel()->visibility());
EXPECT_FALSE(capture_mode_controller->IsActive());
}
TEST_P(HomeButtonTest, LongPressGestureSunfishScanner) {
// Simulate two users with primary user as active.
auto primary = SimulateUserLogin(kRegularUserLoginInfo);
SimulateUserLogin(k2ndRegularUserLoginInfo);
SwitchActiveUser(primary);
// Sunfish / Scanner should already be enabled.
ASSERT_TRUE(CanShowSunfishOrScannerUi());
// Disable Assistant in system settings.
prefs()->SetBoolean(assistant::prefs::kAssistantEnabled, false);
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
ASSERT_TRUE(test_api.IsHomeButtonVisible());
ASSERT_TRUE(home_button());
ui::GestureEvent long_press = CreateGestureEvent(
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
SendGestureEvent(&long_press);
auto* capture_mode_controller = CaptureModeController::Get();
ASSERT_TRUE(capture_mode_controller->IsActive());
EXPECT_EQ(capture_mode_controller->capture_mode_session()
->active_behavior()
->behavior_type(),
BehaviorType::kSunfish);
capture_mode_controller->Stop();
ASSERT_FALSE(capture_mode_controller->IsActive());
// Test long press gesture on secondary display.
SendGestureEventToSecondaryDisplay(&long_press);
ASSERT_TRUE(capture_mode_controller->IsActive());
EXPECT_EQ(capture_mode_controller->capture_mode_session()
->active_behavior()
->behavior_type(),
BehaviorType::kSunfish);
}
TEST_P(HomeButtonTest, LongPressGestureSunfishScannerWithAssistant) {
// Simulate two users with primary user as active.
auto primary = SimulateUserLogin({kDefaultUserEmail});
SimulateUserLogin({kDefaultUserEmail});
SwitchActiveUser(primary);
// Sunfish / Scanner should already be enabled.
ASSERT_TRUE(CanShowSunfishOrScannerUi());
// Enable the Assistant in system settings.
prefs()->SetBoolean(assistant::prefs::kAssistantEnabled, true);
assistant_state()->NotifyFeatureAllowed(
assistant::AssistantAllowedState::ALLOWED);
assistant_state()->NotifyStatusChanged(assistant::AssistantStatus::READY);
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
ASSERT_TRUE(test_api.IsHomeButtonVisible());
ASSERT_TRUE(home_button());
ui::GestureEvent long_press = CreateGestureEvent(
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
SendGestureEvent(&long_press);
auto* capture_mode_controller = CaptureModeController::Get();
ASSERT_TRUE(capture_mode_controller->IsActive());
EXPECT_EQ(capture_mode_controller->capture_mode_session()
->active_behavior()
->behavior_type(),
BehaviorType::kSunfish);
EXPECT_NE(AssistantUiController::Get()->GetModel()->visibility(),
AssistantVisibility::kVisible);
capture_mode_controller->Stop();
ASSERT_FALSE(capture_mode_controller->IsActive());
// Test long press gesture on secondary display.
SendGestureEventToSecondaryDisplay(&long_press);
ASSERT_TRUE(capture_mode_controller->IsActive());
EXPECT_EQ(capture_mode_controller->capture_mode_session()
->active_behavior()
->behavior_type(),
BehaviorType::kSunfish);
EXPECT_NE(AssistantUiController::Get()->GetModel()->visibility(),
AssistantVisibility::kVisible);
}
TEST_P(HomeButtonTest, LongPressGestureInTabletModeAssistant) {
if (ash::assistant::features::IsNewEntryPointEnabled()) {
GTEST_SKIP() << kNoAssistantForNewEntryPoint;
}
// Simulate two users with primary user as active.
auto primary = SimulateUserLogin({kDefaultUserEmail});
SimulateUserLogin({kDefaultUserEmail});
SwitchActiveUser(primary);
// Disable Sunfish and Scanner via enterprise policies.
DisableSunfishScanner();
// Enable the Assistant in system settings.
prefs()->SetBoolean(assistant::prefs::kAssistantEnabled, true);
assistant_state()->NotifyFeatureAllowed(
assistant::AssistantAllowedState::ALLOWED);
assistant_state()->NotifyStatusChanged(assistant::AssistantStatus::READY);
ash::TabletModeControllerTestApi().EnterTabletMode();
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
const bool should_show_home_button =
!IsHideShelfControlsInTabletModeEnabled();
EXPECT_EQ(should_show_home_button, test_api.IsHomeButtonVisible());
ASSERT_EQ(should_show_home_button, static_cast<bool>(home_button()));
// App list should be shown by default in tablet mode.
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
if (!should_show_home_button)
return;
ui::GestureEvent long_press = CreateGestureEvent(
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
SendGestureEvent(&long_press);
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_EQ(AssistantVisibility::kVisible,
AssistantUiController::Get()->GetModel()->visibility());
EXPECT_FALSE(CaptureModeController::Get()->IsActive());
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
// Tap on the home button should close assistant.
gfx::Point center = home_button()->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->MoveMouseTo(center);
GetEventGenerator()->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
EXPECT_EQ(AssistantVisibility::kClosed,
AssistantUiController::Get()->GetModel()->visibility());
AssistantUiController::Get()->CloseUi(
assistant::AssistantExitPoint::kUnspecified);
}
TEST_P(HomeButtonTest, LongPressGestureInTabletModeSunfishScanner) {
// Simulate two users with primary user as active.
auto primary = SimulateUserLogin({kDefaultUserEmail});
SimulateUserLogin({kDefaultUserEmail});
SwitchActiveUser(primary);
// Sunfish / Scanner should already be enabled.
ASSERT_TRUE(CanShowSunfishOrScannerUi());
// Enable the Assistant in system settings.
prefs()->SetBoolean(assistant::prefs::kAssistantEnabled, true);
assistant_state()->NotifyFeatureAllowed(
assistant::AssistantAllowedState::ALLOWED);
assistant_state()->NotifyStatusChanged(assistant::AssistantStatus::READY);
ash::TabletModeControllerTestApi().EnterTabletMode();
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
const bool should_show_home_button =
!IsHideShelfControlsInTabletModeEnabled();
EXPECT_EQ(test_api.IsHomeButtonVisible(), should_show_home_button);
ASSERT_EQ(static_cast<bool>(home_button()), should_show_home_button);
// App list should be shown by default in tablet mode.
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
if (!should_show_home_button) {
return;
}
ui::GestureEvent long_press = CreateGestureEvent(
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
SendGestureEvent(&long_press);
auto* capture_mode_controller = CaptureModeController::Get();
ASSERT_TRUE(capture_mode_controller->IsActive());
EXPECT_EQ(capture_mode_controller->capture_mode_session()
->active_behavior()
->behavior_type(),
BehaviorType::kSunfish);
EXPECT_NE(AssistantUiController::Get()->GetModel()->visibility(),
AssistantVisibility::kVisible);
}
TEST_P(HomeButtonTest,
LongPressGestureInTabletModeSunfishScannerWithAssistant) {
// Simulate two users with primary user as active.
auto primary = SimulateUserLogin({kDefaultUserEmail});
SimulateUserLogin({kDefaultUserEmail});
SwitchActiveUser(primary);
// Sunfish / Scanner should already be enabled.
ASSERT_TRUE(CanShowSunfishOrScannerUi());
// Disable Assistant in system settings.
prefs()->SetBoolean(assistant::prefs::kAssistantEnabled, false);
ash::TabletModeControllerTestApi().EnterTabletMode();
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
const bool should_show_home_button =
!IsHideShelfControlsInTabletModeEnabled();
EXPECT_EQ(test_api.IsHomeButtonVisible(), should_show_home_button);
ASSERT_EQ(static_cast<bool>(home_button()), should_show_home_button);
// App list should be shown by default in tablet mode.
GetAppListTestHelper()->CheckVisibility(true);
GetAppListTestHelper()->CheckState(AppListViewState::kFullscreenAllApps);
if (!should_show_home_button) {
return;
}
ui::GestureEvent long_press = CreateGestureEvent(
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
SendGestureEvent(&long_press);
auto* capture_mode_controller = CaptureModeController::Get();
ASSERT_TRUE(capture_mode_controller->IsActive());
EXPECT_EQ(capture_mode_controller->capture_mode_session()
->active_behavior()
->behavior_type(),
BehaviorType::kSunfish);
EXPECT_NE(AssistantUiController::Get()->GetModel()->visibility(),
AssistantVisibility::kVisible);
}
TEST_P(HomeButtonTest, LongPressGestureWithSecondaryUserAssistant) {
// Disallowed by secondary user.
assistant_state()->NotifyFeatureAllowed(
assistant::AssistantAllowedState::DISALLOWED_BY_NONPRIMARY_USER);
// Disable Sunfish and Scanner via enterprise policies.
DisableSunfishScanner();
// Enable the Assistant in system settings.
prefs()->SetBoolean(assistant::prefs::kAssistantEnabled, true);
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
EXPECT_TRUE(test_api.IsHomeButtonVisible());
ASSERT_TRUE(home_button());
ui::GestureEvent long_press = CreateGestureEvent(
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
SendGestureEvent(&long_press);
// The Assistant is disabled for secondary user.
EXPECT_NE(AssistantVisibility::kVisible,
AssistantUiController::Get()->GetModel()->visibility());
auto* capture_mode_controller = CaptureModeController::Get();
EXPECT_FALSE(capture_mode_controller->IsActive());
// Test long press gesture on secondary display.
SendGestureEventToSecondaryDisplay(&long_press);
EXPECT_NE(AssistantVisibility::kVisible,
AssistantUiController::Get()->GetModel()->visibility());
EXPECT_FALSE(capture_mode_controller->IsActive());
}
TEST_P(HomeButtonTest, LongPressGestureWithAssistantAndSunfishScannerDisabled) {
// Simulate two user with primary user as active.
auto primary = SimulateUserLogin(kRegularUserLoginInfo);
SimulateUserLogin(k2ndRegularUserLoginInfo);
SwitchActiveUser(primary);
// Disable Sunfish and Scanner via enterprise policies.
DisableSunfishScanner();
// Simulate a user who has already completed setup flow, but disabled the
// Assistant in settings.
prefs()->SetBoolean(assistant::prefs::kAssistantEnabled, false);
assistant_state()->NotifyFeatureAllowed(
assistant::AssistantAllowedState::ALLOWED);
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
EXPECT_TRUE(test_api.IsHomeButtonVisible());
ASSERT_TRUE(home_button());
ui::GestureEvent long_press = CreateGestureEvent(
ui::GestureEventDetails(ui::EventType::kGestureLongPress));
SendGestureEvent(&long_press);
EXPECT_NE(AssistantVisibility::kVisible,
AssistantUiController::Get()->GetModel()->visibility());
// Test long press gesture on secondary display.
SendGestureEventToSecondaryDisplay(&long_press);
EXPECT_NE(AssistantVisibility::kVisible,
AssistantUiController::Get()->GetModel()->visibility());
}
// Tests that tapping in the bottom left corner in tablet mode results in the
// home button activating.
TEST_P(HomeButtonTest, InteractOutsideHomeButtonBounds) {
EXPECT_EQ(ShelfAlignment::kBottom, GetPrimaryShelf()->alignment());
// Tap the bottom left of the shelf. The button should work.
gfx::Point bottom_left = GetPrimaryShelf()
->shelf_widget()
->GetWindowBoundsInScreen()
.bottom_left();
GetEventGenerator()->GestureTapAt(bottom_left);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
// Tap the top left of the shelf, the button should work.
gfx::Point bottom_right = GetPrimaryShelf()
->shelf_widget()
->GetWindowBoundsInScreen()
.bottom_right();
GetEventGenerator()->GestureTapAt(bottom_right);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
// Test left shelf.
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kLeft);
gfx::Point top_left =
GetPrimaryShelf()->shelf_widget()->GetWindowBoundsInScreen().origin();
GetEventGenerator()->GestureTapAt(top_left);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
bottom_left = GetPrimaryShelf()
->shelf_widget()
->GetWindowBoundsInScreen()
.bottom_left();
GetEventGenerator()->GestureTapAt(bottom_left);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
// Test right shelf.
GetPrimaryShelf()->SetAlignment(ShelfAlignment::kRight);
gfx::Point top_right =
GetPrimaryShelf()->shelf_widget()->GetWindowBoundsInScreen().top_right();
GetEventGenerator()->GestureTapAt(top_right);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
bottom_right = GetPrimaryShelf()
->shelf_widget()
->GetWindowBoundsInScreen()
.bottom_right();
GetEventGenerator()->GestureTapAt(bottom_right);
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
}
// Tests that clicking the corner of the display opens and closes the AppList.
TEST_P(HomeButtonTest, ClickOnCornerPixel) {
// Screen corners are extremely easy to reach with a mouse. Let's make sure
// that a click on the bottom-left corner (or bottom-right corner in RTL)
// can trigger the home button.
gfx::Point corner(
0, display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height());
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
ASSERT_TRUE(test_api.IsHomeButtonVisible());
GetAppListTestHelper()->CheckVisibility(false);
GetEventGenerator()->MoveMouseTo(corner);
GetEventGenerator()->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
GetEventGenerator()->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(false);
}
// Test that for a gesture tap which covers both the shelf navigation widget
// and the home button, the home button is returned as the event target. When
// the home button is the only button within the widget,
// ViewTageterDelegate::TargetForRect() can return the incorrect view. Ensuring
// the center point of the home button is the same as the content view's center
// point will avoid this problem. See http://crbug.com/1083713
TEST_P(HomeButtonTest, GestureHomeButtonHitTest) {
ShelfNavigationWidget* nav_widget = GetPrimaryShelf()->navigation_widget();
ShelfNavigationWidget::TestApi test_api(nav_widget);
gfx::Rect nav_widget_bounds = nav_widget->GetRootView()->bounds();
// The home button should be the only shown button.
EXPECT_TRUE(test_api.IsHomeButtonVisible());
EXPECT_FALSE(test_api.IsBackButtonVisible());
// The center point of the widget and the center point of the home button
// should be equally close to the event location.
gfx::Point home_button_center(
nav_widget->GetHomeButton()->bounds().CenterPoint());
gfx::Point nav_widget_center(nav_widget_bounds.CenterPoint());
EXPECT_EQ(home_button_center, nav_widget_center);
ui::GestureEventDetails details =
ui::GestureEventDetails(ui::EventType::kGestureTap);
// Create and test a gesture-event targeting >60% of the navigation widget,
// as well as ~60% of the home button.
gfx::RectF gesture_event_rect(0, 0, .7f * nav_widget_bounds.width(),
nav_widget_bounds.height());
details.set_bounding_box(gesture_event_rect);
{
const gfx::Point event_center(gesture_event_rect.width() / 2,
gesture_event_rect.height() / 2);
ui::GestureEvent gesture(event_center.x(), event_center.y(), 0,
base::TimeTicks(), details);
ui::EventTargeter* targeter = nav_widget->GetRootView()->GetEventTargeter();
ui::EventTarget* target =
targeter->FindTargetForEvent(nav_widget->GetRootView(), &gesture);
EXPECT_TRUE(target);
// Check that the event target is the home button.
EXPECT_EQ(target, nav_widget->GetHomeButton());
}
// Test a gesture event centered on the top corner of the home button.
{
const gfx::Point event_center(nav_widget->GetHomeButton()->bounds().x(),
nav_widget->GetHomeButton()->bounds().y());
ui::GestureEvent gesture(event_center.x(), event_center.y(), 0,
base::TimeTicks(), details);
ui::EventTargeter* targeter = nav_widget->GetRootView()->GetEventTargeter();
ui::EventTarget* target =
targeter->FindTargetForEvent(nav_widget->GetRootView(), &gesture);
EXPECT_TRUE(target);
// Check that the event target is the home button.
EXPECT_EQ(target, nav_widget->GetHomeButton());
}
// Test a gesture event centered to the left of the nav_widget's center
// point.
{
const gfx::Point event_center(nav_widget_center.x() - 1,
nav_widget_center.y());
ui::GestureEvent gesture(event_center.x(), event_center.y(), 0,
base::TimeTicks(), details);
ui::EventTargeter* targeter = nav_widget->GetRootView()->GetEventTargeter();
ui::EventTarget* target =
targeter->FindTargetForEvent(nav_widget->GetRootView(), &gesture);
EXPECT_TRUE(target);
// Check that the event target is the home button.
EXPECT_EQ(target, nav_widget->GetHomeButton());
}
}
// Checks the basic behavior of the label beside the home button when the
// HomeButtonWithText feature is enabled.
TEST_F(HomeButtonWithTextTest, Basic) {
// Verify that the label is visible at the beginning.
EXPECT_TRUE(IsLabelVisible());
// Open the app list and check that the label still exists.
gfx::Point center = home_button()->GetBoundsInScreen().CenterPoint();
GetEventGenerator()->MoveMouseTo(center);
GetEventGenerator()->ClickLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
GetAppListTestHelper()->CheckVisibility(true);
EXPECT_TRUE(IsLabelVisible());
// Change to tablet mode, where the label and home button shouldn't be
// visible.
ash::TabletModeControllerTestApi().EnterTabletMode();
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
EXPECT_FALSE(test_api.IsHomeButtonVisible());
EXPECT_FALSE(IsLabelVisible());
// Change back to clamshell mode. The label should be visible again.
ash::TabletModeControllerTestApi().LeaveTabletMode();
EXPECT_TRUE(IsLabelVisible());
}
INSTANTIATE_TEST_SUITE_P(
All,
HomeButtonVisibilityWithAccessibilityFeaturesTest,
::testing::Values(
TestAccessibilityFeature::kTabletModeShelfNavigationButtons,
TestAccessibilityFeature::kSpokenFeedback,
TestAccessibilityFeature::kAutoclick,
TestAccessibilityFeature::kSwitchAccess));
TEST_P(HomeButtonVisibilityWithAccessibilityFeaturesTest,
TabletModeSwitchWithA11yFeatureEnabled) {
SetTestA11yFeatureEnabled(true /*enabled*/);
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
EXPECT_TRUE(test_api.IsHomeButtonVisible());
// Switch to tablet mode, and verify the home button is still visible.
ash::TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(test_api.IsHomeButtonVisible());
// The button should be hidden if the feature gets disabled.
SetTestA11yFeatureEnabled(false /*enabled*/);
EXPECT_FALSE(test_api.IsHomeButtonVisible());
}
TEST_P(HomeButtonVisibilityWithAccessibilityFeaturesTest,
FeatureEnabledWhileInTabletMode) {
ShelfNavigationWidget::TestApi test_api(
GetPrimaryShelf()->navigation_widget());
EXPECT_TRUE(test_api.IsHomeButtonVisible());
// Switch to tablet mode, and verify the home button is hidden.
ash::TabletModeControllerTestApi().EnterTabletMode();
EXPECT_FALSE(test_api.IsHomeButtonVisible());
// The button should be shown if the feature gets enabled.
SetTestA11yFeatureEnabled(true /*enabled*/);
EXPECT_TRUE(test_api.IsHomeButtonVisible());
}
} // namespace ash
|