app_list_folder_view_unittest.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/app_list/views/app_list_folder_view.h"
  5. #include <utility>
  6. #include "ash/app_list/app_list_controller_impl.h"
  7. #include "ash/app_list/model/app_list_test_model.h"
  8. #include "ash/app_list/test/app_list_test_helper.h"
  9. #include "ash/app_list/views/app_list_a11y_announcer.h"
  10. #include "ash/app_list/views/scrollable_apps_grid_view.h"
  11. #include "ash/constants/ash_features.h"
  12. #include "ash/shell.h"
  13. #include "ash/test/ash_test_base.h"
  14. #include "base/test/bind.h"
  15. #include "base/test/scoped_feature_list.h"
  16. #include "ui/events/keycodes/keyboard_codes_posix.h"
  17. #include "ui/views/accessibility/view_accessibility.h"
  18. #include "ui/views/controls/scroll_view.h"
  19. namespace ash {
  20. class AppListFolderViewProductivityLauncherTest : public AshTestBase {
  21. public:
  22. AppListFolderViewProductivityLauncherTest() = default;
  23. ~AppListFolderViewProductivityLauncherTest() override = default;
  24. // testing::Test:
  25. void SetUp() override {
  26. AshTestBase::SetUp();
  27. app_list_test_model_ = std::make_unique<test::AppListTestModel>();
  28. search_model_ = std::make_unique<SearchModel>();
  29. Shell::Get()->app_list_controller()->SetActiveModel(
  30. /*profile_id=*/1, app_list_test_model_.get(), search_model_.get());
  31. }
  32. base::test::ScopedFeatureList feature_list_{features::kProductivityLauncher};
  33. std::unique_ptr<test::AppListTestModel> app_list_test_model_;
  34. std::unique_ptr<SearchModel> search_model_;
  35. };
  36. TEST_F(AppListFolderViewProductivityLauncherTest,
  37. ScrollViewSizeIsCappedForLargeFolders) {
  38. // Create a large number of apps, more than a 4 rows.
  39. app_list_test_model_->CreateAndPopulateFolderWithApps(30);
  40. // Open the app list and open the folder.
  41. auto* helper = GetAppListTestHelper();
  42. helper->ShowAppList();
  43. auto* apps_grid_view = helper->GetScrollableAppsGridView();
  44. views::View* folder_item = apps_grid_view->GetItemViewAt(0);
  45. LeftClickOn(folder_item);
  46. ASSERT_TRUE(helper->IsInFolderView());
  47. auto* folder_view = helper->GetBubbleFolderView();
  48. auto* scroll_view = folder_view->scroll_view_for_test();
  49. const int tile_height =
  50. folder_view->items_grid_view()->GetTotalTileSize(/*page=*/0).height();
  51. // The scroll view has space for at least 4 full rows, but not 5.
  52. EXPECT_GE(scroll_view->height(), tile_height * 4);
  53. EXPECT_LT(scroll_view->height(), tile_height * 5);
  54. }
  55. TEST_F(AppListFolderViewProductivityLauncherTest,
  56. CloseFolderMakesA11yAnnouncement) {
  57. // Create a folder with a couple items.
  58. app_list_test_model_->CreateAndPopulateFolderWithApps(2);
  59. // Open the app list and open the folder.
  60. auto* helper = GetAppListTestHelper();
  61. helper->ShowAppList();
  62. auto* apps_grid_view = helper->GetScrollableAppsGridView();
  63. views::View* folder_item = apps_grid_view->GetItemViewAt(0);
  64. LeftClickOn(folder_item);
  65. ASSERT_TRUE(helper->IsInFolderView());
  66. // Get the accessibility announcement view.
  67. auto* folder_view = helper->GetBubbleFolderView();
  68. views::View* announcement_view =
  69. folder_view->a11y_announcer_for_test()->announcement_view_for_test();
  70. ASSERT_TRUE(announcement_view);
  71. // Add a callback to wait for an accessibility event.
  72. ax::mojom::Event event = ax::mojom::Event::kNone;
  73. base::RunLoop run_loop;
  74. announcement_view->GetViewAccessibility().set_accessibility_events_callback(
  75. base::BindLambdaForTesting([&](const ui::AXPlatformNodeDelegate* unused,
  76. const ax::mojom::Event event_in) {
  77. event = event_in;
  78. run_loop.Quit();
  79. }));
  80. // Press escape to close the folder.
  81. PressAndReleaseKey(ui::VKEY_ESCAPE);
  82. run_loop.Run();
  83. ASSERT_FALSE(helper->IsInFolderView());
  84. // An alert fired with a message.
  85. EXPECT_EQ(event, ax::mojom::Event::kAlert);
  86. ui::AXNodeData node_data;
  87. announcement_view->GetViewAccessibility().GetAccessibleNodeData(&node_data);
  88. EXPECT_EQ(node_data.GetStringAttribute(ax::mojom::StringAttribute::kName),
  89. "Close folder");
  90. }
  91. } // namespace ash