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 161 162 163 164 165 166 167 168 169
|
// 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.
#include "ash/app_list/test_app_list_client.h"
#include <utility>
#include "ash/app_list/app_list_model_provider.h"
#include "ash/app_list/model/app_list_item.h"
#include "ash/public/cpp/app_list/app_list_controller.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "base/functional/bind.h"
#include "base/notimplemented.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "chromeos/ash/services/assistant/public/cpp/features.h"
#include "chromeos/ui/vector_icons/vector_icons.h"
#include "ui/base/themed_vector_icon.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image.h"
#include "ui/menus/simple_menu_model.h"
namespace ash {
namespace {
class FakeScopedIphSession : public ScopedIphSession {
public:
~FakeScopedIphSession() override = default;
void NotifyEvent(const std::string& event) override {}
};
} // namespace
TestAppListClient::TestAppListClient() = default;
TestAppListClient::~TestAppListClient() = default;
std::vector<AppListSearchControlCategory>
TestAppListClient::GetToggleableCategories() const {
return toggleable_categories_for_test_;
}
void TestAppListClient::StartZeroStateSearch(base::OnceClosure on_done,
base::TimeDelta timeout) {
start_zero_state_search_count_++;
if (run_zero_state_callback_immediately_) {
// Most unit tests generally expect the launcher to open immediately, so run
// the callback synchronously.
std::move(on_done).Run();
} else {
// Simulate production behavior, which collects the results asynchronously.
// Bounce through OnZeroStateSearchDone() to count calls, so that tests can
// assert that the callback happened.
base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&TestAppListClient::OnZeroStateSearchDone,
weak_factory_.GetWeakPtr(), std::move(on_done)),
base::Milliseconds(1));
}
}
void TestAppListClient::StartSearch(const std::u16string& trimmed_query) {
search_queries_.push_back(trimmed_query);
if (search_callback_)
search_callback_.Run(trimmed_query);
}
void TestAppListClient::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) {
last_opened_search_result_ = result_id;
}
void TestAppListClient::InvokeSearchResultAction(
const std::string& result_id,
SearchResultActionType action) {
invoked_result_actions_.emplace_back(result_id, action);
}
void TestAppListClient::ActivateItem(int profile_id,
const std::string& id,
int event_flags,
ash::AppListLaunchedFrom launched_from,
bool is_above_the_fold) {
activate_item_count_++;
activate_item_last_id_ = id;
if (is_above_the_fold) {
activate_item_above_the_fold_++;
} else {
activate_item_below_the_fold_++;
}
}
void TestAppListClient::GetContextMenuModel(
int profile_id,
const std::string& id,
AppListItemContext item_context,
GetContextMenuModelCallback callback) {
auto model = std::make_unique<ui::SimpleMenuModel>(/*delegate=*/nullptr);
model->AddItem(/*command_id=*/0, u"Menu item");
std::move(callback).Run(std::move(model));
}
AppListNotifier* TestAppListClient::GetNotifier() {
return nullptr;
}
void TestAppListClient::RecalculateWouldTriggerLauncherSearchIph() {}
std::unique_ptr<ScopedIphSession>
TestAppListClient::CreateLauncherSearchIphSession() {
return std::make_unique<FakeScopedIphSession>();
}
void TestAppListClient::LoadIcon(int profile_id, const std::string& app_id) {
loaded_icon_app_ids_.push_back(app_id);
}
std::vector<TestAppListClient::SearchResultActionId>
TestAppListClient::GetAndResetInvokedResultActions() {
std::vector<SearchResultActionId> result;
result.swap(invoked_result_actions_);
return result;
}
std::vector<std::u16string> TestAppListClient::GetAndResetPastSearchQueries() {
std::vector<std::u16string> result;
result.swap(search_queries_);
return result;
}
ash::AppListSortOrder TestAppListClient::GetPermanentSortingOrder() const {
NOTIMPLEMENTED();
return ash::AppListSortOrder::kCustom;
}
void TestAppListClient::OnZeroStateSearchDone(base::OnceClosure on_done) {
zero_state_search_done_count_++;
std::move(on_done).Run();
}
std::optional<bool> TestAppListClient::IsNewUser(
const AccountId& account_id) const {
return is_new_user_;
}
void TestAppListClient::RecordAppsDefaultVisibility(
const std::vector<std::string>& apps_above_the_fold,
const std::vector<std::string>& apps_below_the_fold,
bool is_apps_collections_page) {
items_above_the_fold_count_ = apps_above_the_fold.size();
items_below_the_fold_count_ = apps_below_the_fold.size();
}
bool TestAppListClient::HasReordered() {
return false;
}
gfx::Image TestAppListClient::GetGeminiIcon() {
// Use `kMahiSparkIcon` as a placeholder.
return gfx::Image(ui::ThemedVectorIcon(&chromeos::kMahiSparkIcon)
.GetImageSkia(gfx::kPlaceholderColor));
}
} // namespace ash
|