#include "chrome/install_static/install_modes.h"
#include <windows.h>
#include <cguid.h>
#include "base/compiler_specific.h"
#include "base/strings/string_util.h"
#include "chrome/install_static/buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::Eq;
using ::testing::Gt;
using ::testing::Le;
using ::testing::Ne;
using ::testing::Not;
using ::testing::ResultOf;
using ::testing::StrEq;
using ::testing::StrNe;
namespace install_static {
namespace {
MATCHER(ContainsIllegalProgIdChar, "") {
const wchar_t* scan = arg;
wchar_t c;
while ((c = *UNSAFE_TODO(scan++)) != 0) {
if (!base::IsAsciiAlphaNumeric(c) && c != L'.') {
return true;
}
}
return false;
}
}
TEST(InstallModes, VerifyModes) {
ASSERT_THAT(kInstallModes.size(), Gt(0));
for (size_t i = 0; i < kInstallModes.size(); ++i) {
const InstallConstants& mode = kInstallModes[i];
ASSERT_THAT(mode.index, Eq(i));
if (i == 0)
ASSERT_THAT(mode.install_switch, StrEq(""));
else
ASSERT_THAT(mode.install_switch, StrNe(""));
if (i == 0)
ASSERT_THAT(mode.install_suffix, StrEq(L""));
else
ASSERT_THAT(mode.install_suffix, StrNe(L""));
if (i == 0)
ASSERT_THAT(mode.logo_suffix, StrEq(L""));
else
ASSERT_THAT(mode.logo_suffix, StrNe(L""));
#if BUILDFLAG(USE_GOOGLE_UPDATE_INTEGRATION)
ASSERT_THAT(mode.app_guid, StrNe(L""));
#else
ASSERT_THAT(mode.app_guid, StrEq(L""));
#endif
ASSERT_THAT(mode.base_app_name, StrNe(L""));
ASSERT_THAT(mode.base_app_id, StrNe(L""));
ASSERT_THAT(mode.base_app_id, Not(ContainsIllegalProgIdChar()));
ASSERT_THAT(mode.browser_prog_id_prefix, StrNe(L""));
ASSERT_THAT(lstrlen(mode.browser_prog_id_prefix), Le(11));
ASSERT_THAT(mode.browser_prog_id_prefix, Not(ContainsIllegalProgIdChar()));
ASSERT_THAT(*mode.browser_prog_id_prefix, ResultOf(iswdigit, Eq(0)));
ASSERT_THAT(mode.pdf_prog_id_prefix, StrNe(L""));
ASSERT_THAT(lstrlen(mode.pdf_prog_id_prefix), Le(11));
ASSERT_THAT(mode.pdf_prog_id_prefix, Not(ContainsIllegalProgIdChar()));
ASSERT_THAT(*mode.pdf_prog_id_prefix, ResultOf(iswdigit, Eq(0)));
ASSERT_THAT(mode.browser_prog_id_description, StrNe(L""));
ASSERT_THAT(mode.pdf_prog_id_description, StrNe(L""));
ASSERT_THAT(mode.active_setup_guid, StrNe(L""));
ASSERT_THAT(mode.toast_activator_clsid, Ne(CLSID_NULL));
ASSERT_THAT(mode.elevator_clsid, Ne(CLSID_NULL));
ASSERT_THAT(mode.elevator_iid, Ne(CLSID_NULL));
ASSERT_THAT(mode.html_doc_icon_resource_index, Ne(0));
ASSERT_THAT(mode.pdf_doc_icon_resource_index, Ne(0));
#if !BUILDFLAG(USE_GOOGLE_UPDATE_INTEGRATION)
ASSERT_THAT(mode.channel_strategy, Eq(ChannelStrategy::UNSUPPORTED));
#endif
}
}
TEST(InstallModes, GetClientsKeyPath) {
constexpr wchar_t kAppGuid[] = L"test";
#if BUILDFLAG(USE_GOOGLE_UPDATE_INTEGRATION)
ASSERT_THAT(GetClientsKeyPath(kAppGuid),
StrEq(L"Software\\Google\\Update\\Clients\\test"));
#else
ASSERT_THAT(GetClientsKeyPath(kAppGuid),
StrEq(std::wstring(L"Software\\").append(kProductPathName)));
#endif
}
TEST(InstallModes, GetClientStateKeyPath) {
constexpr wchar_t kAppGuid[] = L"test";
#if BUILDFLAG(USE_GOOGLE_UPDATE_INTEGRATION)
ASSERT_THAT(GetClientStateKeyPath(kAppGuid),
StrEq(L"Software\\Google\\Update\\ClientState\\test"));
#else
ASSERT_THAT(GetClientStateKeyPath(kAppGuid),
StrEq(std::wstring(L"Software\\").append(kProductPathName)));
#endif
}
TEST(InstallModes, GetClientStateMediumKeyPath) {
constexpr wchar_t kAppGuid[] = L"test";
#if BUILDFLAG(USE_GOOGLE_UPDATE_INTEGRATION)
ASSERT_THAT(GetClientStateMediumKeyPath(kAppGuid),
StrEq(L"Software\\Google\\Update\\ClientStateMedium\\test"));
#else
ASSERT_THAT(GetClientStateMediumKeyPath(kAppGuid),
StrEq(std::wstring(L"Software\\").append(kProductPathName)));
#endif
}
}