#include "chrome/updater/persisted_data.h"
#include <memory>
#include <string>
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/time/time.h"
#include "base/version.h"
#include "chrome/updater/activity.h"
#include "chrome/updater/registration_data.h"
#include "chrome/updater/test/test_scope.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/update_client/update_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "base/win/registry.h"
#include "chrome/updater/util/win_util.h"
#include "chrome/updater/win/win_constants.h"
#endif
namespace updater {
TEST(PersistedDataTest, Simple) { … }
TEST(PersistedDataTest, MixedCase) { … }
TEST(PersistedDataTest, SharedPref) { … }
TEST(PersistedDataTest, RemoveAppId) { … }
TEST(PersistedDataTest, RegisterApp_SetFirstActive) { … }
#if BUILDFLAG(IS_WIN)
TEST(PersistedDataTest, LastOSVersion) {
auto pref = std::make_unique<TestingPrefServiceSimple>();
update_client::RegisterPrefs(pref->registry());
RegisterPersistedDataPrefs(pref->registry());
auto metadata = base::MakeRefCounted<PersistedData>(
GetUpdaterScopeForTesting(), pref.get(), nullptr);
EXPECT_EQ(metadata->GetLastOSVersion(), std::nullopt);
metadata->SetLastOSVersion();
EXPECT_NE(metadata->GetLastOSVersion(), std::nullopt);
const OSVERSIONINFOEX metadata_os = metadata->GetLastOSVersion().value();
OSVERSIONINFOEX os = {};
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
EXPECT_TRUE(::GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&os)));
#pragma clang diagnostic pop
EXPECT_EQ(metadata_os.dwOSVersionInfoSize, os.dwOSVersionInfoSize);
EXPECT_EQ(metadata_os.dwMajorVersion, os.dwMajorVersion);
EXPECT_EQ(metadata_os.dwMinorVersion, os.dwMinorVersion);
EXPECT_EQ(metadata_os.dwBuildNumber, os.dwBuildNumber);
EXPECT_EQ(metadata_os.dwPlatformId, os.dwPlatformId);
EXPECT_STREQ(metadata_os.szCSDVersion, os.szCSDVersion);
EXPECT_EQ(metadata_os.wServicePackMajor, os.wServicePackMajor);
EXPECT_EQ(metadata_os.wServicePackMinor, os.wServicePackMinor);
EXPECT_EQ(metadata_os.wSuiteMask, os.wSuiteMask);
EXPECT_EQ(metadata_os.wProductType, os.wProductType);
}
TEST(PersistedDataTest, SetEulaRequired) {
auto pref = std::make_unique<TestingPrefServiceSimple>();
update_client::RegisterPrefs(pref->registry());
RegisterPersistedDataPrefs(pref->registry());
auto metadata = base::MakeRefCounted<PersistedData>(
GetUpdaterScopeForTesting(), pref.get(), nullptr);
EXPECT_FALSE(metadata->GetEulaRequired());
metadata->SetEulaRequired(true);
EXPECT_TRUE(metadata->GetEulaRequired());
DWORD eula_accepted = 0;
const HKEY root = UpdaterScopeToHKeyRoot(GetUpdaterScopeForTesting());
EXPECT_EQ(base::win::RegKey(root, UPDATER_KEY, Wow6432(KEY_READ))
.ReadValueDW(L"eulaaccepted", &eula_accepted),
ERROR_SUCCESS);
EXPECT_EQ(eula_accepted, 0ul);
metadata->SetEulaRequired(false);
EXPECT_FALSE(metadata->GetEulaRequired());
EXPECT_FALSE(base::win::RegKey(root, UPDATER_KEY, Wow6432(KEY_READ))
.HasValue(L"eulaaccepted"));
}
#endif
class PersistedDataRegistrationRequestTest : public ::testing::Test { … };
TEST_F(PersistedDataRegistrationRequestTest, RegistrationRequest) { … }
TEST_F(PersistedDataRegistrationRequestTest, RegistrationRequestPartial) { … }
}