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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_APP_LIST_ARC_ARC_APP_TEST_H_
#define CHROME_BROWSER_ASH_APP_LIST_ARC_ARC_APP_TEST_H_
#include <memory>
#include <string>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
#include "chromeos/ash/experiences/arc/mojom/app.mojom-forward.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/scoped_user_manager.h"
namespace arc {
namespace mojom {
class AppInfo;
}
class ArcPlayStoreEnabledPreferenceHandler;
class ArcServiceManager;
class ArcSessionManager;
class FakeAppInstance;
class FakeCompatibilityModeInstance;
class FakeIntentHelperHost;
class FakeIntentHelperInstance;
} // namespace arc
namespace user_manager {
class User;
}
class ArcAppListPrefs;
class Profile;
// Helper class to initialize arc bridge to work with arc apps in unit tests.
class ArcAppTest {
public:
enum UserManagerMode {
kDoNothing,
kCreate,
};
explicit ArcAppTest(
UserManagerMode user_manager_mode = UserManagerMode::kCreate);
ArcAppTest(const ArcAppTest&) = delete;
ArcAppTest& operator=(const ArcAppTest&) = delete;
virtual ~ArcAppTest();
void SetUp(Profile* profile);
void TearDown();
// Public methods to modify AppInstance for unit_tests.
void StopArcInstance();
void RestartArcInstance();
void SetUpIntentHelper();
static std::string GetAppId(const arc::mojom::AppInfo& app_info);
static std::string GetAppId(const arc::mojom::ShortcutInfo& shortcut);
// Helper that clones packages info array.
static std::vector<arc::mojom::ArcPackageInfoPtr> ClonePackages(
const std::vector<arc::mojom::ArcPackageInfoPtr>& packages);
// Helper that clones app info array.
static std::vector<arc::mojom::AppInfoPtr> CloneApps(
const std::vector<arc::mojom::AppInfoPtr>& apps);
const std::vector<arc::mojom::ArcPackageInfoPtr>& fake_packages() const {
return fake_packages_;
}
// Adds package info and takes ownership.
void AddPackage(arc::mojom::ArcPackageInfoPtr package);
// Replaces package if a package with this package name exists.
void UpdatePackage(arc::mojom::ArcPackageInfoPtr package);
void RemovePackage(const std::string& package_name);
void WaitForDefaultApps();
void WaitForRemoveAllApps();
// The 0th item is sticky but not the followings.
const std::vector<arc::mojom::AppInfoPtr>& fake_apps() const {
return fake_apps_;
}
const std::vector<arc::mojom::AppInfoPtr>& fake_default_apps() const {
return fake_default_apps_;
}
const std::vector<arc::mojom::ShortcutInfo>& fake_shortcuts() const {
return fake_shortcuts_;
}
arc::FakeAppInstance* app_instance() { return app_instance_.get(); }
arc::FakeCompatibilityModeInstance* compatibility_mode_instance() {
return compatibility_mode_instance_.get();
}
arc::FakeIntentHelperInstance* intent_helper_instance() {
return intent_helper_instance_.get();
}
ArcAppListPrefs* arc_app_list_prefs() { return arc_app_list_pref_; }
arc::ArcSessionManager* arc_session_manager() {
return arc_session_manager_.get();
}
arc::ArcServiceManager* arc_service_manager() {
return arc_service_manager_.get();
}
void set_wait_default_apps(bool wait_default_apps) {
wait_default_apps_ = wait_default_apps;
}
void set_activate_arc_on_start(bool activate_arc_on_start) {
activate_arc_on_start_ = activate_arc_on_start;
}
void set_persist_service_manager(bool persist_service_manager) {
persist_service_manager_ = persist_service_manager;
}
void set_start_app_service_publisher(bool start_app_service_publisher) {
start_app_service_publisher_ = start_app_service_publisher;
}
void set_initialize_real_intent_helper_bridge(bool value) {
initialize_real_intent_helper_bridge_ = value;
}
void set_wait_compatibility_mode(bool value) {
wait_compatibility_mode_ = value;
}
private:
const user_manager::User* CreateUserAndLogin();
bool FindPackage(const std::string& package_name);
void CreateFakeAppsAndPackages();
// Unowned pointer.
raw_ptr<Profile> profile_ = nullptr;
raw_ptr<ArcAppListPrefs, DanglingUntriaged> arc_app_list_pref_ = nullptr;
bool wait_default_apps_ = true;
// If set to true ARC would be automatically enabled on test start up.
bool activate_arc_on_start_ = true;
// Whether arc service manager should be destroyed when this object gets torn
// down.
bool persist_service_manager_ = false;
// Whether the ArcApps AppService publisher should be started during
// initialization.
bool start_app_service_publisher_ = true;
// If set to true, the real ArcIntentHelperBridge is initialized on test start
// up.
bool initialize_real_intent_helper_bridge_ = false;
bool wait_compatibility_mode_ = false;
std::unique_ptr<session_manager::SessionManager> session_manager_;
std::unique_ptr<arc::ArcServiceManager> arc_service_manager_;
std::unique_ptr<arc::ArcSessionManager> arc_session_manager_;
std::unique_ptr<arc::ArcPlayStoreEnabledPreferenceHandler>
arc_play_store_enabled_preference_handler_;
std::unique_ptr<arc::FakeAppInstance> app_instance_;
std::unique_ptr<arc::FakeCompatibilityModeInstance>
compatibility_mode_instance_;
std::unique_ptr<arc::FakeIntentHelperHost> intent_helper_host_;
std::unique_ptr<arc::FakeIntentHelperInstance> intent_helper_instance_;
user_manager::TypedScopedUserManager<ash::FakeChromeUserManager>
fake_user_manager_;
std::vector<arc::mojom::AppInfoPtr> fake_apps_;
std::vector<arc::mojom::AppInfoPtr> fake_default_apps_;
std::vector<arc::mojom::ArcPackageInfoPtr> fake_packages_;
std::vector<arc::mojom::ShortcutInfo> fake_shortcuts_;
bool concierge_client_initialized_ = false;
};
#endif // CHROME_BROWSER_ASH_APP_LIST_ARC_ARC_APP_TEST_H_
|