-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathtest_app_list_client.h
134 lines (112 loc) · 5.12 KB
/
test_app_list_client.h
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
// Copyright 2018 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_TEST_APP_LIST_CLIENT_H_
#define ASH_APP_LIST_TEST_APP_LIST_CLIENT_H_
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "ash/public/cpp/app_list/app_list_client.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "base/memory/weak_ptr.h"
namespace ash {
// A test implementation of AppListClient that records function call counts.
class TestAppListClient : public AppListClient {
public:
TestAppListClient();
TestAppListClient(const TestAppListClient&) = delete;
TestAppListClient& operator=(const TestAppListClient&) = delete;
~TestAppListClient() override;
// AppListClient:
void OnAppListControllerDestroyed() override {}
void StartZeroStateSearch(base::OnceClosure on_done,
base::TimeDelta timeout) override;
void StartSearch(const std::u16string& trimmed_query) override;
void OpenSearchResult(int profile_id,
const std::string& result_id,
int event_flags,
AppListLaunchedFrom launched_from,
AppListLaunchType launch_type,
int suggestion_index,
bool launch_as_default) override;
void InvokeSearchResultAction(const std::string& result_id,
SearchResultActionType action) override;
void ActivateItem(int profile_id,
const std::string& id,
int event_flags,
ash::AppListLaunchedFrom launched_from) override;
void GetContextMenuModel(int profile_id,
const std::string& id,
AppListItemContext item_context,
GetContextMenuModelCallback callback) override;
void OnAppListVisibilityWillChange(bool visible) override {}
void OnAppListVisibilityChanged(bool visible) override {}
void OnSearchResultVisibilityChanged(const std::string& id,
bool visibility) override {}
void OnQuickSettingsChanged(
const std::string& setting_name,
const std::map<std::string, int>& values) override {}
AppListNotifier* GetNotifier() override;
void RecalculateWouldTriggerLauncherSearchIph() override;
std::unique_ptr<ScopedIphSession> CreateLauncherSearchIphSession() override;
void OpenSearchBoxIphUrl() override;
void LoadIcon(int profile_id, const std::string& app_id) override;
ash::AppListSortOrder GetPermanentSortingOrder() const override;
void CommitTemporarySortOrder() override;
int start_zero_state_search_count() const {
return start_zero_state_search_count_;
}
void set_run_zero_state_callback_immediately(bool value) {
run_zero_state_callback_immediately_ = value;
}
int zero_state_search_done_count() const {
return zero_state_search_done_count_;
}
// Returns the number of AppItems that have been activated. These items could
// live in search, RecentAppsView, or ScrollableAppsGridView.
int activate_item_count() const { return activate_item_count_; }
// Returns the ID of the last activated AppItem.
std::string activate_item_last_id() const { return activate_item_last_id_; }
// Returns the ID of the last opened SearchResult.
std::string last_opened_search_result() const {
return last_opened_search_result_;
}
std::vector<std::string> load_icon_app_ids() const {
return loaded_icon_app_ids_;
}
using SearchResultActionId = std::pair<std::string, int>;
std::vector<SearchResultActionId> GetAndResetInvokedResultActions();
// Returns the list of search queries that were requested.
// This clears the list of tracked queries - if the method gets called
// consecutively, the second call will not return queries returned returned by
// the first call.
std::vector<std::u16string> GetAndResetPastSearchQueries();
using SearchCallback =
base::RepeatingCallback<void(const std::u16string& query)>;
void set_search_callback(SearchCallback callback) {
search_callback_ = std::move(callback);
}
private:
// Called in response to StartZeroStateSearch() when
// `run_zero_state_callback_immediately_` is false. Counts calls via
// `zero_state_done_count_` then invokes `on_done`.
void OnZeroStateSearchDone(base::OnceClosure on_done);
int start_zero_state_search_count_ = 0;
bool run_zero_state_callback_immediately_ = true;
int zero_state_search_done_count_ = 0;
std::vector<std::u16string> search_queries_;
std::vector<SearchResultActionId> invoked_result_actions_;
int activate_item_count_ = 0;
std::string activate_item_last_id_;
std::string last_opened_search_result_;
std::vector<std::string> loaded_icon_app_ids_;
// If not null, callback that will be run on each search request. It can be
// used by tests to inject results to search model in response to search
// queries.
SearchCallback search_callback_;
base::WeakPtrFactory<TestAppListClient> weak_factory_{this};
};
} // namespace ash
#endif // ASH_APP_LIST_TEST_APP_LIST_CLIENT_H_