#ifndef CHROME_UPDATER_TEST_INTEGRATION_TESTS_IMPL_H_
#define CHROME_UPDATER_TEST_INTEGRATION_TESTS_IMPL_H_
#include <map>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/process/process_iterator.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/updater/test/server.h"
#include "chrome/updater/update_service.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include <wrl/client.h>
#include "chrome/updater/app/server/win/updater_legacy_idl.h"
#endif
class GURL;
namespace base {
class CommandLine;
class Value;
class Version;
}
namespace updater {
enum class UpdaterScope;
struct RegistrationRequest;
}
namespace wireless_android_enterprise_devicemanagement {
class OmahaSettingsClientProto;
}
namespace updater::test {
enum class AppBundleWebCreateMode { … };
struct AppUpdateExpectation { … };
base::FilePath GetSetupExecutablePath();
std::set<base::FilePath::StringType> GetTestProcessNames();
#if BUILDFLAG(IS_WIN)
class VersionProcessFilter : public base::ProcessFilter {
public:
VersionProcessFilter();
bool Includes(const base::ProcessEntry& entry) const override;
private:
const base::Version this_version_;
const base::Version older_version_;
};
#endif
void CleanProcesses();
void ExpectCleanProcesses();
void PrintFile(const base::FilePath& file);
std::vector<base::FilePath> GetUpdaterLogFilesInTmp();
void PrintLog(UpdaterScope scope);
void Clean(UpdaterScope scope);
void ExpectClean(UpdaterScope scope);
void EnterTestMode(const GURL& update_url,
const GURL& crash_upload_url,
const GURL& device_management_url,
const GURL& app_logo_url,
const base::TimeDelta& idle_timeout);
void ExitTestMode(UpdaterScope scope);
void SetGroupPolicies(const base::Value::Dict& values);
void SetPlatformPolicies(const base::Value::Dict& values);
void SetMachineManaged(bool is_managed_device);
void ExpectNoCrashes(UpdaterScope scope);
void CopyLog(const base::FilePath& src_dir, const std::string& infix);
void ExpectInstalled(UpdaterScope scope);
void Install(UpdaterScope scope, const base::Value::List& switches);
void InstallUpdaterAndApp(UpdaterScope scope,
const std::string& app_id,
bool is_silent_install,
const std::string& tag,
const std::string& child_window_text_to_find,
bool always_launch_cmd,
bool verify_app_logo_loaded,
bool expect_success,
bool wait_for_the_installer);
void ExpectVersionActive(UpdaterScope scope, const std::string& version);
void ExpectVersionNotActive(UpdaterScope scope, const std::string& version);
void Uninstall(UpdaterScope scope);
void RunWake(UpdaterScope scope, int exit_code);
void RunWakeAll(UpdaterScope scope);
void RunWakeActive(UpdaterScope scope, int exit_code);
void RunCrashMe(UpdaterScope scope);
void RunServer(UpdaterScope scope, int exit_code, bool internal);
void Update(UpdaterScope scope,
const std::string& app_id,
const std::string& install_data_index);
void CheckForUpdate(UpdaterScope scope, const std::string& app_id);
void UpdateAll(UpdaterScope scope);
void InstallAppViaService(UpdaterScope scope,
const std::string& app_id,
const base::Value::Dict& expected_final_values);
void GetAppStates(UpdaterScope updater_scope,
const base::Value::Dict& expected_app_states);
void DeleteFile(UpdaterScope scope, const base::FilePath& path);
void DeleteUpdaterDirectory(UpdaterScope scope);
void DeleteActiveUpdaterExecutable(UpdaterScope scope);
void Run(UpdaterScope scope,
base::CommandLine command_line,
int* exit_code = nullptr);
void ExpectCliResult(base::CommandLine command_line,
bool elevate,
std::optional<std::string> want_stdout,
std::optional<int> want_exit_code);
std::optional<base::FilePath> GetInstalledExecutablePath(UpdaterScope scope);
void SetupFakeUpdaterLowerVersion(UpdaterScope scope);
base::FilePath GetRealUpdaterLowerVersionPath();
void SetupRealUpdaterLowerVersion(UpdaterScope scope);
void SetupFakeUpdaterHigherVersion(UpdaterScope scope);
void ExpectCandidateUninstalled(UpdaterScope scope);
void SetActive(UpdaterScope scope, const std::string& app_id);
void ExpectActive(UpdaterScope scope, const std::string& app_id);
void ExpectNotActive(UpdaterScope scope, const std::string& app_id);
void SetExistenceCheckerPath(UpdaterScope scope,
const std::string& app_id,
const base::FilePath& path);
void SetServerStarts(UpdaterScope scope, int value);
void FillLog(UpdaterScope scope);
void ExpectLogRotated(UpdaterScope scope);
void ExpectRegistered(UpdaterScope scope, const std::string& app_id);
void ExpectNotRegistered(UpdaterScope scope, const std::string& app_id);
void ExpectAppTag(UpdaterScope scope,
const std::string& app_id,
const std::string& tag);
void SetAppTag(UpdaterScope scope,
const std::string& app_id,
const std::string& tag);
void ExpectAppVersion(UpdaterScope scope,
const std::string& app_id,
const base::Version& version);
void RegisterApp(UpdaterScope scope, const RegistrationRequest& registration);
void RegisterAppByValue(UpdaterScope scope,
const base::Value::Dict& registration_data);
[[nodiscard]] bool WaitForUpdaterExit();
#if BUILDFLAG(IS_WIN)
void ExpectInterfacesRegistered(UpdaterScope scope);
void ExpectMarshalInterfaceSucceeds(UpdaterScope scope);
void ExpectLegacyUpdate3WebSucceeds(
UpdaterScope scope,
const std::string& app_id,
AppBundleWebCreateMode app_bundle_web_create_mode,
int expected_final_state,
int expected_error_code,
bool cancel_when_downloading);
void ExpectLegacyProcessLauncherSucceeds(UpdaterScope scope);
void ExpectLegacyAppCommandWebSucceeds(UpdaterScope scope,
const std::string& app_id,
const std::string& command_id,
const base::Value::List& parameters,
int expected_exit_code);
void ExpectPolicyStatusValues(
Microsoft::WRL::ComPtr<IPolicyStatusValue> policy_status_value,
const std::wstring& expected_source,
const std::wstring& expected_value,
VARIANT_BOOL expected_has_conflict);
void ExpectLegacyPolicyStatusSucceeds(UpdaterScope scope);
void InvokeTestServiceFunction(const std::string& function_name,
const base::Value::Dict& arguments);
void RunUninstallCmdLine(UpdaterScope scope);
void RunHandoff(UpdaterScope scope, const std::string& app_id);
#endif
int CountDirectoryFiles(const base::FilePath& dir);
void ExpectSelfUpdateSequence(UpdaterScope scope, ScopedServer* test_server);
void ExpectPing(UpdaterScope scope,
ScopedServer* test_server,
int event_type,
std::optional<GURL> target_url);
void ExpectAppCommandPing(UpdaterScope scope,
ScopedServer* test_server,
const std::string& appid,
const std::string& appcommandid,
int errorcode,
int eventresult,
int event_type,
const base::Version& version);
void ExpectUpdateCheckRequest(UpdaterScope scope, ScopedServer* test_server);
void ExpectUpdateCheckSequence(UpdaterScope scope,
ScopedServer* test_server,
const std::string& app_id,
UpdateService::Priority priority,
const base::Version& from_version,
const base::Version& to_version);
void ExpectUpdateSequence(UpdaterScope scope,
ScopedServer* test_server,
const std::string& app_id,
const std::string& install_data_index,
UpdateService::Priority priority,
const base::Version& from_version,
const base::Version& to_version,
bool do_fault_injection);
void ExpectUpdateSequenceBadHash(UpdaterScope scope,
ScopedServer* test_server,
const std::string& app_id,
const std::string& install_data_index,
UpdateService::Priority priority,
const base::Version& from_version,
const base::Version& to_version);
void ExpectInstallSequence(UpdaterScope scope,
ScopedServer* test_server,
const std::string& app_id,
const std::string& install_data_index,
UpdateService::Priority priority,
const base::Version& from_version,
const base::Version& to_version,
bool do_fault_injection);
void ExpectAppsUpdateSequence(UpdaterScope scope,
ScopedServer* test_server,
const base::Value::Dict& request_attributes,
const std::vector<AppUpdateExpectation>& apps);
void StressUpdateService(UpdaterScope scope);
void CallServiceUpdate(UpdaterScope updater_scope,
const std::string& app_id,
const std::string& install_data_index,
bool same_version_update_allowed);
void SetupFakeLegacyUpdater(UpdaterScope scope);
#if BUILDFLAG(IS_WIN)
void RunFakeLegacyUpdater(UpdaterScope scope);
void CloseInstallCompleteDialog(const std::wstring& child_window_text_to_find,
bool verify_app_logo_loaded = false);
#endif
#if BUILDFLAG(IS_MAC)
void PrivilegedHelperInstall(UpdaterScope scope);
void DeleteLegacyUpdater(UpdaterScope scope);
void ExpectPrepareToRunBundleSuccess(const base::FilePath& bundle_path);
#endif
void ExpectLegacyUpdaterMigrated(UpdaterScope scope);
void RunRecoveryComponent(UpdaterScope scope,
const std::string& app_id,
const base::Version& version);
void SetLastChecked(UpdaterScope scope, const base::Time& time);
void ExpectLastChecked(UpdaterScope scope);
void ExpectLastStarted(UpdaterScope scope);
void InstallApp(UpdaterScope scope,
const std::string& app_id,
const base::Version& version);
void UninstallApp(UpdaterScope scope, const std::string& app_id);
void RunOfflineInstall(UpdaterScope scope,
bool is_legacy_install,
bool is_silent_install);
void RunOfflineInstallOsNotSupported(UpdaterScope scope,
bool is_legacy_install,
bool is_silent_install);
base::CommandLine MakeElevated(base::CommandLine command_line);
void DMPushEnrollmentToken(const std::string& enrollment_token);
void DMDeregisterDevice(UpdaterScope scope);
void DMCleanup(UpdaterScope scope);
void ExpectDeviceManagementRegistrationRequest(
ScopedServer* test_server,
const std::string& enrollment_token,
const std::string& dm_token);
void ExpectDeviceManagementPolicyFetchRequest(
ScopedServer* test_server,
const std::string& dm_token,
const ::wireless_android_enterprise_devicemanagement::
OmahaSettingsClientProto& omaha_settings,
bool first_request = true,
bool rotate_public_key = false,
std::optional<GURL> target_url = std::nullopt);
void ExpectDeviceManagementPolicyFetchWithNewPublicKeyRequest(
ScopedServer* test_server,
const std::string& dm_token,
const ::wireless_android_enterprise_devicemanagement::
OmahaSettingsClientProto& omaha_settings);
void ExpectDeviceManagementTokenDeletionRequest(ScopedServer* test_server,
const std::string& dm_token,
bool invalidate_token);
void ExpectDeviceManagementPolicyValidationRequest(ScopedServer* test_server,
const std::string& dm_token);
void ExpectProxyPacScriptRequest(ScopedServer* test_server);
#if BUILDFLAG(IS_MAC)
void ExpectKSAdminResult(UpdaterScope scope,
bool elevate,
const std::map<std::string, std::string>& switches,
std::optional<std::string> want_stdout,
std::optional<int> want_exit_code);
void ExpectKSAdminFetchTag(UpdaterScope scope,
bool elevate,
const std::string& product_id,
const base::FilePath& xc_path,
std::optional<UpdaterScope> store_flag,
std::optional<std::string> want_tag);
#endif
}
#endif