File: app_list_test_view_delegate.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (160 lines) | stat: -rw-r--r-- 6,810 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_APP_LIST_APP_LIST_TEST_VIEW_DELEGATE_H_
#define ASH_APP_LIST_APP_LIST_TEST_VIEW_DELEGATE_H_

#include <stddef.h>

#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "ash/app_list/app_list_model_provider.h"
#include "ash/app_list/app_list_view_delegate.h"
#include "ash/app_list/model/app_list_test_model.h"
#include "ash/app_list/model/search/search_model.h"
#include "ash/app_list/quick_app_access_model.h"
#include "ash/public/cpp/app_list/app_list_client.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "base/functional/callback_forward.h"
#include "chromeos/ash/services/assistant/public/cpp/assistant_enums.h"
#include "ui/base/mojom/menu_source_type.mojom-forward.h"
#include "ui/menus/simple_menu_model.h"

namespace ash {
namespace test {

class AppListTestModel;

// A concrete AppListViewDelegate for unit tests.
class AppListTestViewDelegate : public AppListViewDelegate,
                                public ui::SimpleMenuModel::Delegate {
 public:
  AppListTestViewDelegate();

  AppListTestViewDelegate(const AppListTestViewDelegate&) = delete;
  AppListTestViewDelegate& operator=(const AppListTestViewDelegate&) = delete;

  ~AppListTestViewDelegate() override;

  int dismiss_count() const { return dismiss_count_; }
  int open_search_result_count() const { return open_search_result_count_; }
  std::map<size_t, int>& open_search_result_counts() {
    return open_search_result_counts_;
  }
  int show_wallpaper_context_menu_count() const {
    return show_wallpaper_context_menu_count_;
  }

  // Sets the number of apps that the model will be created with the next time
  // SetProfileByPath() is called.
  void set_next_profile_app_count(int apps) { next_profile_app_count_ = apps; }

  // Sets whether the search engine is Google or not.
  void SetSearchEngineIsGoogle(bool is_google);

  // Set whether tablet mode is enabled.
  void SetIsTabletModeEnabled(bool is_tablet_mode);

  // AppListViewDelegate overrides:
  bool KeyboardTraversalEngaged() override;
  void StartAssistant(assistant::AssistantEntryPoint entry_point) override {}
  void EndAssistant(assistant::AssistantExitPoint exit_point) override {}
  std::vector<AppListSearchControlCategory> GetToggleableCategories()
      const override;
  void StartSearch(const std::u16string& raw_query) override {}
  void StartZeroStateSearch(base::OnceClosure callback,
                            base::TimeDelta timeout) override;
  void OpenSearchResult(const std::string& result_id,
                        int event_flags,
                        ash::AppListLaunchedFrom launched_from,
                        ash::AppListLaunchType launch_type,
                        int suggestion_index,
                        bool launch_as_default) override;
  void InvokeSearchResultAction(const std::string& result_id,
                                SearchResultActionType action) override {}
  void ViewShown(int64_t display_id) override {}
  void DismissAppList() override;
  void ViewClosing() override {}
  void ActivateItem(const std::string& id,
                    int event_flags,
                    ash::AppListLaunchedFrom launched_from,
                    bool is_app_above_the_fold) override;
  void GetContextMenuModel(const std::string& id,
                           AppListItemContext item_context,
                           GetContextMenuModelCallback callback) override;
  void ShowWallpaperContextMenu(const gfx::Point& onscreen_location,
                                ui::mojom::MenuSourceType source_type) override;
  bool CanProcessEventsOnApplistViews() override;
  bool ShouldDismissImmediately() override;
  ash::AssistantViewDelegate* GetAssistantViewDelegate() override;
  void OnSearchResultVisibilityChanged(const std::string& id,
                                       bool visibility) override;
  bool IsAssistantAllowedAndEnabled() const override;
  void OnStateTransitionAnimationCompleted(
      AppListViewState state,
      bool was_animation_interrupted) override;
  AppListState GetCurrentAppListPage() const override;
  void OnAppListPageChanged(AppListState page) override;
  AppListViewState GetAppListViewState() const override;
  void OnViewStateChanged(AppListViewState state) override;
  void GetAppLaunchedMetricParams(
      AppLaunchedMetricParams* metric_params) override;
  gfx::Rect SnapBoundsToDisplayEdge(const gfx::Rect& bounds) override;
  int GetShelfSize() override;
  int GetSystemShelfInsetsInTabletMode() override;
  bool AppListTargetVisibility() const override;
  bool IsInTabletMode() const override;
  AppListNotifier* GetNotifier() override;
  std::unique_ptr<ScopedIphSession> CreateLauncherSearchIphSession() override;
  void LoadIcon(const std::string& app_id) override {}
  bool HasValidProfile() const override;
  bool ShouldHideContinueSection() const override;
  void SetHideContinueSection(bool hide) override;
  bool IsCategoryEnabled(AppListSearchControlCategory category) override;
  void SetCategoryEnabled(AppListSearchControlCategory category,
                          bool enabled) override {}
  void RecordAppsDefaultVisibility(
      const std::vector<std::string>& apps_above_the_fold,
      const std::vector<std::string>& apps_below_the_fold,
      bool is_apps_collections_page) override {}

  // Do a bulk replacement of the items in the model.
  void ReplaceTestModel(int item_count);

  AppListTestModel* ReleaseTestModel() { return model_.release(); }
  AppListTestModel* GetTestModel() { return model_.get(); }

  SearchModel* ReleaseTestSearchModel() { return search_model_.release(); }
  SearchModel* GetTestSearchModel() { return search_model_.get(); }

 private:
  void RecordAppLaunched(ash::AppListLaunchedFrom launched_from);

  // ui::SimpleMenuModel::Delegate overrides:
  bool IsCommandIdChecked(int command_id) const override;
  bool IsCommandIdEnabled(int command_id) const override;
  void ExecuteCommand(int command_id, int event_flags) override;

  int dismiss_count_ = 0;
  int open_search_result_count_ = 0;
  int next_profile_app_count_ = 0;
  int show_wallpaper_context_menu_count_ = 0;
  AppListState app_list_page_ = AppListState::kInvalidState;
  AppListViewState app_list_view_state_ = AppListViewState::kClosed;
  bool is_tablet_mode_ = false;
  std::map<size_t, int> open_search_result_counts_;
  AppListModelProvider model_provider_;
  std::unique_ptr<AppListTestModel> model_;
  std::unique_ptr<SearchModel> search_model_;
  std::unique_ptr<QuickAppAccessModel> quick_app_access_model_;
};

}  // namespace test
}  // namespace ash

#endif  // ASH_APP_LIST_APP_LIST_TEST_VIEW_DELEGATE_H_