app_list_test_view_delegate.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // Copyright 2013 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_APP_LIST_TEST_VIEW_DELEGATE_H_
  5. #define ASH_APP_LIST_APP_LIST_TEST_VIEW_DELEGATE_H_
  6. #include <stddef.h>
  7. #include <map>
  8. #include <memory>
  9. #include <string>
  10. #include <utility>
  11. #include <vector>
  12. #include "ash/app_list/app_list_model_provider.h"
  13. #include "ash/app_list/app_list_view_delegate.h"
  14. #include "ash/app_list/model/app_list_test_model.h"
  15. #include "ash/app_list/model/search/search_model.h"
  16. #include "ash/public/cpp/app_list/app_list_types.h"
  17. #include "base/callback_forward.h"
  18. #include "base/compiler_specific.h"
  19. #include "ui/base/models/simple_menu_model.h"
  20. namespace ash {
  21. namespace test {
  22. class AppListTestModel;
  23. // A concrete AppListViewDelegate for unit tests.
  24. class AppListTestViewDelegate : public AppListViewDelegate,
  25. public ui::SimpleMenuModel::Delegate {
  26. public:
  27. AppListTestViewDelegate();
  28. AppListTestViewDelegate(const AppListTestViewDelegate&) = delete;
  29. AppListTestViewDelegate& operator=(const AppListTestViewDelegate&) = delete;
  30. ~AppListTestViewDelegate() override;
  31. int dismiss_count() const { return dismiss_count_; }
  32. int open_search_result_count() const { return open_search_result_count_; }
  33. int open_assistant_ui_count() const { return open_assistant_ui_count_; }
  34. std::map<size_t, int>& open_search_result_counts() {
  35. return open_search_result_counts_;
  36. }
  37. int show_wallpaper_context_menu_count() const {
  38. return show_wallpaper_context_menu_count_;
  39. }
  40. // Sets the number of apps that the model will be created with the next time
  41. // SetProfileByPath() is called.
  42. void set_next_profile_app_count(int apps) { next_profile_app_count_ = apps; }
  43. // Sets whether the search engine is Google or not.
  44. void SetSearchEngineIsGoogle(bool is_google);
  45. // Set whether tablet mode is enabled.
  46. void SetIsTabletModeEnabled(bool is_tablet_mode);
  47. // Set whether the suggested content info should be shown.
  48. void SetShouldShowSuggestedContentInfo(bool should_show);
  49. // AppListViewDelegate overrides:
  50. bool KeyboardTraversalEngaged() override;
  51. void StartAssistant() override {}
  52. void StartSearch(const std::u16string& raw_query) override {}
  53. void StartZeroStateSearch(base::OnceClosure callback,
  54. base::TimeDelta timeout) override;
  55. void OpenSearchResult(const std::string& result_id,
  56. int event_flags,
  57. ash::AppListLaunchedFrom launched_from,
  58. ash::AppListLaunchType launch_type,
  59. int suggestion_index,
  60. bool launch_as_default) override;
  61. void InvokeSearchResultAction(const std::string& result_id,
  62. SearchResultActionType action) override {}
  63. void GetSearchResultContextMenuModel(
  64. const std::string& result_id,
  65. GetContextMenuModelCallback callback) override;
  66. void ViewShown(int64_t display_id) override {}
  67. void DismissAppList() override;
  68. void ViewClosing() override {}
  69. const std::vector<SkColor>& GetWallpaperProminentColors() override;
  70. void ActivateItem(const std::string& id,
  71. int event_flags,
  72. ash::AppListLaunchedFrom launched_from) override;
  73. void GetContextMenuModel(const std::string& id,
  74. AppListItemContext item_context,
  75. GetContextMenuModelCallback callback) override;
  76. ui::ImplicitAnimationObserver* GetAnimationObserver(
  77. ash::AppListViewState target_state) override;
  78. void ShowWallpaperContextMenu(const gfx::Point& onscreen_location,
  79. ui::MenuSourceType source_type) override;
  80. bool CanProcessEventsOnApplistViews() override;
  81. bool ShouldDismissImmediately() override;
  82. int GetTargetYForAppListHide(aura::Window* root_window) override;
  83. ash::AssistantViewDelegate* GetAssistantViewDelegate() override;
  84. void OnSearchResultVisibilityChanged(const std::string& id,
  85. bool visibility) override;
  86. void MaybeIncreaseSuggestedContentInfoShownCount() override;
  87. bool IsAssistantAllowedAndEnabled() const override;
  88. bool ShouldShowSuggestedContentInfo() const override;
  89. void MarkSuggestedContentInfoDismissed() override;
  90. void OnStateTransitionAnimationCompleted(
  91. AppListViewState state,
  92. bool was_animation_interrupted) override;
  93. AppListState GetCurrentAppListPage() const override;
  94. void OnAppListPageChanged(AppListState page) override;
  95. AppListViewState GetAppListViewState() const override;
  96. void OnViewStateChanged(AppListViewState state) override;
  97. void GetAppLaunchedMetricParams(
  98. AppLaunchedMetricParams* metric_params) override;
  99. gfx::Rect SnapBoundsToDisplayEdge(const gfx::Rect& bounds) override;
  100. int GetShelfSize() override;
  101. bool AppListTargetVisibility() const override;
  102. bool IsInTabletMode() override;
  103. AppListNotifier* GetNotifier() override;
  104. int AdjustAppListViewScrollOffset(int offset, ui::EventType type) override;
  105. void LoadIcon(const std::string& app_id) override {}
  106. bool HasValidProfile() const override;
  107. bool ShouldHideContinueSection() const override;
  108. void SetHideContinueSection(bool hide) override;
  109. void CommitTemporarySortOrder() override {}
  110. // Do a bulk replacement of the items in the model.
  111. void ReplaceTestModel(int item_count);
  112. AppListTestModel* ReleaseTestModel() { return model_.release(); }
  113. AppListTestModel* GetTestModel() { return model_.get(); }
  114. SearchModel* ReleaseTestSearchModel() { return search_model_.release(); }
  115. private:
  116. void RecordAppLaunched(ash::AppListLaunchedFrom launched_from);
  117. // ui::SimpleMenuModel::Delegate overrides:
  118. bool IsCommandIdChecked(int command_id) const override;
  119. bool IsCommandIdEnabled(int command_id) const override;
  120. void ExecuteCommand(int command_id, int event_flags) override;
  121. int dismiss_count_ = 0;
  122. int open_search_result_count_ = 0;
  123. int open_assistant_ui_count_ = 0;
  124. int next_profile_app_count_ = 0;
  125. int show_wallpaper_context_menu_count_ = 0;
  126. AppListState app_list_page_ = AppListState::kInvalidState;
  127. AppListViewState app_list_view_state_ = AppListViewState::kClosed;
  128. bool is_tablet_mode_ = false;
  129. bool should_show_suggested_content_info_ = false;
  130. std::map<size_t, int> open_search_result_counts_;
  131. AppListModelProvider model_provider_;
  132. std::unique_ptr<AppListTestModel> model_;
  133. std::unique_ptr<SearchModel> search_model_;
  134. std::vector<SkColor> wallpaper_prominent_colors_;
  135. };
  136. } // namespace test
  137. } // namespace ash
  138. #endif // ASH_APP_LIST_APP_LIST_TEST_VIEW_DELEGATE_H_