test_app_list_client.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_CLIENT_H_
  5. #define ASH_APP_LIST_TEST_APP_LIST_CLIENT_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. #include "ash/public/cpp/app_list/app_list_client.h"
  12. #include "ash/public/cpp/app_list/app_list_types.h"
  13. #include "base/memory/weak_ptr.h"
  14. namespace ash {
  15. // A test implementation of AppListClient that records function call counts.
  16. class TestAppListClient : public AppListClient {
  17. public:
  18. TestAppListClient();
  19. TestAppListClient(const TestAppListClient&) = delete;
  20. TestAppListClient& operator=(const TestAppListClient&) = delete;
  21. ~TestAppListClient() override;
  22. // AppListClient:
  23. void OnAppListControllerDestroyed() override {}
  24. void StartZeroStateSearch(base::OnceClosure on_done,
  25. base::TimeDelta timeout) override;
  26. void StartSearch(const std::u16string& trimmed_query) override;
  27. void OpenSearchResult(int profile_id,
  28. const std::string& result_id,
  29. int event_flags,
  30. AppListLaunchedFrom launched_from,
  31. AppListLaunchType launch_type,
  32. int suggestion_index,
  33. bool launch_as_default) override;
  34. void InvokeSearchResultAction(const std::string& result_id,
  35. SearchResultActionType action) override;
  36. void GetSearchResultContextMenuModel(
  37. const std::string& result_id,
  38. GetContextMenuModelCallback callback) override;
  39. void ViewClosing() override {}
  40. void ViewShown(int64_t display_id) override {}
  41. void ActivateItem(int profile_id,
  42. const std::string& id,
  43. int event_flags,
  44. ash::AppListLaunchedFrom launched_from) override;
  45. void GetContextMenuModel(int profile_id,
  46. const std::string& id,
  47. AppListItemContext item_context,
  48. GetContextMenuModelCallback callback) override;
  49. void OnAppListVisibilityWillChange(bool visible) override {}
  50. void OnAppListVisibilityChanged(bool visible) override {}
  51. void OnSearchResultVisibilityChanged(const std::string& id,
  52. bool visibility) override {}
  53. void OnQuickSettingsChanged(
  54. const std::string& setting_name,
  55. const std::map<std::string, int>& values) override {}
  56. AppListNotifier* GetNotifier() override;
  57. void LoadIcon(int profile_id, const std::string& app_id) override {}
  58. ash::AppListSortOrder GetPermanentSortingOrder() const override;
  59. void CommitTemporarySortOrder() override;
  60. int start_zero_state_search_count() const {
  61. return start_zero_state_search_count_;
  62. }
  63. void set_run_zero_state_callback_immediately(bool value) {
  64. run_zero_state_callback_immediately_ = value;
  65. }
  66. int zero_state_search_done_count() const {
  67. return zero_state_search_done_count_;
  68. }
  69. // Returns the number of AppItems that have been activated. These items could
  70. // live in search, RecentAppsView, or ScrollableAppsGridView.
  71. int activate_item_count() const { return activate_item_count_; }
  72. // Returns the ID of the last activated AppItem.
  73. std::string activate_item_last_id() const { return activate_item_last_id_; }
  74. // Returns the ID of the last opened SearchResult.
  75. std::string last_opened_search_result() const {
  76. return last_opened_search_result_;
  77. }
  78. using SearchResultActionId = std::pair<std::string, int>;
  79. std::vector<SearchResultActionId> GetAndResetInvokedResultActions();
  80. // Returns the list of search queries that were requested.
  81. // This clears the list of tracked queries - if the method gets called
  82. // consecutively, the second call will not return queries returned returned by
  83. // the first call.
  84. std::vector<std::u16string> GetAndResetPastSearchQueries();
  85. private:
  86. // Called in response to StartZeroStateSearch() when
  87. // `run_zero_state_callback_immediately_` is false. Counts calls via
  88. // `zero_state_done_count_` then invokes `on_done`.
  89. void OnZeroStateSearchDone(base::OnceClosure on_done);
  90. int start_zero_state_search_count_ = 0;
  91. bool run_zero_state_callback_immediately_ = true;
  92. int zero_state_search_done_count_ = 0;
  93. std::vector<std::u16string> search_queries_;
  94. std::vector<SearchResultActionId> invoked_result_actions_;
  95. int activate_item_count_ = 0;
  96. std::string activate_item_last_id_;
  97. std::string last_opened_search_result_;
  98. base::WeakPtrFactory<TestAppListClient> weak_factory_{this};
  99. };
  100. } // namespace ash
  101. #endif // ASH_APP_LIST_TEST_APP_LIST_CLIENT_H_