app_list_item_view_unittest.cc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_item_view.h"
  5. #include "ash/app_list/app_list_controller_impl.h"
  6. #include "ash/app_list/model/app_list_test_model.h"
  7. #include "ash/app_list/test/app_list_test_helper.h"
  8. #include "ash/app_list/views/paged_apps_grid_view.h"
  9. #include "ash/app_list/views/scrollable_apps_grid_view.h"
  10. #include "ash/constants/ash_features.h"
  11. #include "ash/shell.h"
  12. #include "ash/test/ash_test_base.h"
  13. #include "base/test/scoped_feature_list.h"
  14. #include "ui/accessibility/ax_enums.mojom-shared.h"
  15. #include "ui/accessibility/ax_node_data.h"
  16. #include "ui/views/controls/label.h"
  17. namespace ash {
  18. class AppListItemViewTest : public AshTestBase {
  19. public:
  20. AppListItemViewTest() = default;
  21. ~AppListItemViewTest() override = default;
  22. // testing::Test:
  23. void SetUp() override {
  24. AshTestBase::SetUp();
  25. app_list_test_model_ = std::make_unique<test::AppListTestModel>();
  26. search_model_ = std::make_unique<SearchModel>();
  27. Shell::Get()->app_list_controller()->SetActiveModel(
  28. /*profile_id=*/1, app_list_test_model_.get(), search_model_.get());
  29. }
  30. static views::View* GetNewInstallDot(AppListItemView* view) {
  31. return view->new_install_dot_;
  32. }
  33. AppListItem* CreateAppListItem(const std::string& name) {
  34. AppListItem* item = app_list_test_model_->CreateAndAddItem(name + "_id");
  35. item->SetName(name);
  36. return item;
  37. }
  38. std::unique_ptr<test::AppListTestModel> app_list_test_model_;
  39. std::unique_ptr<SearchModel> search_model_;
  40. };
  41. // Tests with ProductivityLauncher disabled.
  42. class AppListItemViewPeekingLauncherTest : public AppListItemViewTest {
  43. public:
  44. AppListItemViewPeekingLauncherTest() {
  45. feature_list_.InitAndDisableFeature(features::kProductivityLauncher);
  46. }
  47. ~AppListItemViewPeekingLauncherTest() override = default;
  48. base::test::ScopedFeatureList feature_list_;
  49. };
  50. // Tests with ProductivityLauncher enabled.
  51. class AppListItemViewProductivityLauncherTest : public AppListItemViewTest {
  52. public:
  53. AppListItemViewProductivityLauncherTest() {
  54. feature_list_.InitAndEnableFeature(features::kProductivityLauncher);
  55. }
  56. ~AppListItemViewProductivityLauncherTest() override = default;
  57. base::test::ScopedFeatureList feature_list_;
  58. };
  59. // Regression test for https://crbug.com/1298801
  60. TEST_F(AppListItemViewPeekingLauncherTest,
  61. NewInstallDotIsNotShownForPeekingLauncher) {
  62. AppListItem* item = CreateAppListItem("Google Buzz");
  63. item->SetIsNewInstall(true);
  64. auto* helper = GetAppListTestHelper();
  65. helper->ShowAppList();
  66. // The item does not have a new install dot or a new install tooltip.
  67. auto* apps_grid_view = helper->GetRootPagedAppsGridView();
  68. AppListItemView* item_view = apps_grid_view->GetItemViewAt(0);
  69. EXPECT_FALSE(GetNewInstallDot(item_view));
  70. }
  71. TEST_F(AppListItemViewProductivityLauncherTest, NewInstallDot) {
  72. AppListItem* item = CreateAppListItem("Google Buzz");
  73. ASSERT_FALSE(item->is_new_install());
  74. auto* helper = GetAppListTestHelper();
  75. helper->ShowAppList();
  76. ui::AXNodeData node_data;
  77. // By default, the new install dot is not visible.
  78. auto* apps_grid_view = helper->GetScrollableAppsGridView();
  79. AppListItemView* item_view = apps_grid_view->GetItemViewAt(0);
  80. views::View* new_install_dot = GetNewInstallDot(item_view);
  81. ASSERT_TRUE(new_install_dot);
  82. EXPECT_FALSE(new_install_dot->GetVisible());
  83. EXPECT_EQ(item_view->GetTooltipText({}), u"Google Buzz");
  84. item_view->GetAccessibleNodeData(&node_data);
  85. EXPECT_EQ(
  86. node_data.GetStringAttribute(ax::mojom::StringAttribute::kDescription),
  87. "");
  88. // When the app is a new install the dot is visible and the tooltip changes.
  89. item->SetIsNewInstall(true);
  90. EXPECT_TRUE(new_install_dot->GetVisible());
  91. EXPECT_EQ(item_view->GetTooltipText({}), u"Google Buzz\nNew install");
  92. item_view->GetAccessibleNodeData(&node_data);
  93. EXPECT_EQ(
  94. node_data.GetStringAttribute(ax::mojom::StringAttribute::kDescription),
  95. "New install");
  96. }
  97. TEST_F(AppListItemViewProductivityLauncherTest, LabelInsetWithNewInstallDot) {
  98. AppListItem* long_item = CreateAppListItem("Very very very very long name");
  99. long_item->SetIsNewInstall(true);
  100. AppListItem* short_item = CreateAppListItem("Short");
  101. short_item->SetIsNewInstall(true);
  102. auto* helper = GetAppListTestHelper();
  103. helper->ShowAppList();
  104. auto* apps_grid_view = helper->GetScrollableAppsGridView();
  105. AppListItemView* long_item_view = apps_grid_view->GetItemViewAt(0);
  106. AppListItemView* short_item_view = apps_grid_view->GetItemViewAt(1);
  107. // The item with the long name has its title bounds left edge inset to make
  108. // space for the blue dot.
  109. EXPECT_LT(long_item_view->GetDefaultTitleBoundsForTest().x(),
  110. long_item_view->title()->x());
  111. // The item with the short name does not have the title bounds inset, because
  112. // there is enough space for the blue dot as-is.
  113. EXPECT_EQ(short_item_view->GetDefaultTitleBoundsForTest(),
  114. short_item_view->title()->bounds());
  115. }
  116. } // namespace ash