app_list_test_helper.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // Copyright 2018 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. #ifndef ASH_APP_LIST_TEST_APP_LIST_TEST_HELPER_H_
  5. #define ASH_APP_LIST_TEST_APP_LIST_TEST_HELPER_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "ash/app_list/app_list_metrics.h"
  9. #include "ash/app_list/model/app_list_test_model.h"
  10. #include "ash/app_list/model/search/search_model.h"
  11. #include "ash/app_list/test_app_list_client.h"
  12. #include "ash/test/ash_test_color_generator.h"
  13. #include "ui/gfx/animation/tween.h"
  14. namespace base {
  15. class TimeDelta;
  16. }
  17. namespace views {
  18. class View;
  19. }
  20. namespace ash {
  21. class AppListBubbleAppsPage;
  22. class AppListBubbleAssistantPage;
  23. class AppListBubbleSearchPage;
  24. class AppListBubbleView;
  25. class AppListControllerImpl;
  26. class AppListFolderView;
  27. class AppListView;
  28. class AppsContainerView;
  29. class ContinueSectionView;
  30. class PagedAppsGridView;
  31. class ProductivityLauncherSearchView;
  32. class RecentAppsView;
  33. class ScrollableAppsGridView;
  34. class SearchBoxView;
  35. class SearchResultPageView;
  36. class SearchResultPageAnchoredDialog;
  37. enum class AppListViewState;
  38. class AppListTestHelper {
  39. public:
  40. // The color types of app list item icons.
  41. enum class IconColorType {
  42. // Use the default icon color which is SK_ColorRED.
  43. kDefaultColor,
  44. // This color type guarantees that the neighboring app list items added by
  45. // the test helper have different icon colors.
  46. kAlternativeColor,
  47. // The icon is transparent.
  48. kNotSet,
  49. };
  50. AppListTestHelper();
  51. AppListTestHelper(const AppListTestHelper&) = delete;
  52. AppListTestHelper& operator=(const AppListTestHelper&) = delete;
  53. ~AppListTestHelper();
  54. // Shows the app list on the default display.
  55. void ShowAppList();
  56. // Show the app list in |display_id|, and wait until animation finishes.
  57. // Note: we usually don't care about the show source in tests.
  58. void ShowAndRunLoop(uint64_t display_id);
  59. // Show the app list in |display_id|.
  60. void Show(uint64_t display_id);
  61. // Show the app list in |display_id| triggered with |show_source|, and wait
  62. // until animation finishes.
  63. void ShowAndRunLoop(uint64_t display_id, AppListShowSource show_source);
  64. // Dismiss the app list, and wait until animation finishes.
  65. void DismissAndRunLoop();
  66. // Dismiss the app list.
  67. void Dismiss();
  68. // Toggle the app list in |display_id|, and wait until animation finishes.
  69. // Note: we usually don't care about the show source in tests.
  70. void ToggleAndRunLoop(uint64_t display_id);
  71. // Toggle the app list in |display_id| triggered with |show_source|, and wait
  72. // until animation finishes.
  73. void ToggleAndRunLoop(uint64_t display_id, AppListShowSource show_source);
  74. // Slides a bubble apps page's component using a layer animation.
  75. void StartSlideAnimationOnBubbleAppsPage(views::View* view,
  76. int vertical_offset,
  77. base::TimeDelta duration,
  78. gfx::Tween::Type tween_type);
  79. // Check the visibility value of the app list and its target.
  80. // Fails in tests if either one doesn't match |visible|.
  81. // DEPRECATED: Prefer to EXPECT_TRUE or EXPECT_FALSE the visibility directly,
  82. // so a failing test will print the line number of the expectation that
  83. // failed.
  84. void CheckVisibility(bool visible);
  85. // Check the current app list view state.
  86. void CheckState(AppListViewState state);
  87. // Run all pending in message loop to wait for animation to finish.
  88. void WaitUntilIdle();
  89. // If a folder view is shown, waits until the folder animations complete.
  90. void WaitForFolderAnimation();
  91. // Adds `num_apps` to the app list model. These app items have transparent
  92. // icons and their names are not set.
  93. void AddAppItems(int num_apps);
  94. // Similar to `AddAppItems()` but provides the options to set item icon colors
  95. // and names.
  96. void AddAppItemsWithColorAndName(int num_apps,
  97. IconColorType color_type,
  98. bool set_name);
  99. // Adds a page break item to the app list model.
  100. void AddPageBreakItem();
  101. // Adds `num_results` to continue section in the app list.
  102. void AddContinueSuggestionResults(int num_results);
  103. // Adds `num_apps` recent apps to the recent apps view.
  104. void AddRecentApps(int num_apps);
  105. // Whether the app list is showing a folder.
  106. bool IsInFolderView();
  107. // Enables/Disables the app list nudge for testing.
  108. void DisableAppListNudge(bool disable);
  109. // Fullscreen/peeking launcher helpers.
  110. AppListView* GetAppListView();
  111. SearchBoxView* GetSearchBoxView();
  112. AppsContainerView* GetAppsContainerView();
  113. AppListFolderView* GetFullscreenFolderView();
  114. RecentAppsView* GetFullscreenRecentAppsView();
  115. ContinueSectionView* GetFullscreenContinueSectionView();
  116. SearchResultPageView* GetFullscreenSearchResultPageView();
  117. SearchResultPageAnchoredDialog* GetFullscreenSearchPageDialog();
  118. ProductivityLauncherSearchView* GetProductivityLauncherSearchView();
  119. views::View* GetFullscreenLauncherAppsSeparatorView();
  120. // Whether the fullscreen/peeking launcher is showing the search results view.
  121. bool IsShowingFullscreenSearchResults();
  122. // Paged launcher helpers.
  123. PagedAppsGridView* GetRootPagedAppsGridView();
  124. // Bubble launcher helpers. The bubble must be open before calling these.
  125. AppListBubbleView* GetBubbleView();
  126. SearchBoxView* GetBubbleSearchBoxView();
  127. AppListFolderView* GetBubbleFolderView();
  128. AppListBubbleAppsPage* GetBubbleAppsPage();
  129. ContinueSectionView* GetBubbleContinueSectionView();
  130. RecentAppsView* GetBubbleRecentAppsView();
  131. ScrollableAppsGridView* GetScrollableAppsGridView();
  132. AppListBubbleSearchPage* GetBubbleSearchPage();
  133. SearchResultPageAnchoredDialog* GetBubbleSearchPageDialog();
  134. AppListBubbleAssistantPage* GetBubbleAssistantPage();
  135. SearchModel::SearchResults* GetSearchResults();
  136. views::View* GetBubbleLauncherAppsSeparatorView();
  137. std::vector<ash::AppListSearchResultCategory>* GetOrderedResultCategories();
  138. test::AppListTestModel* model() { return &model_; }
  139. SearchModel* search_model() { return &search_model_; }
  140. TestAppListClient* app_list_client() { return app_list_client_.get(); }
  141. private:
  142. // Helper function to set user prefs relative to the app_list in tests.
  143. void ConfigureDefaultUserPrefs();
  144. test::AppListTestModel model_;
  145. SearchModel search_model_;
  146. AppListControllerImpl* app_list_controller_ = nullptr;
  147. std::unique_ptr<TestAppListClient> app_list_client_;
  148. AshTestColorGenerator icon_color_generator_{/*default_color=*/SK_ColorRED};
  149. };
  150. } // namespace ash
  151. #endif // ASH_APP_LIST_TEST_APP_LIST_TEST_HELPER_H_