Commit 178d53ff authored by grt's avatar grt Committed by Commit bot

Remove the tool to disable the outdated build detector for organic installs of Chrome.

It served its purpose and is no longer needed. This is a simple revert
of r414123, r413080, r412464, r411775, and r410031.

BUG=623986

Review-Url: https://codereview.chromium.org/2328493002
Cr-Commit-Position: refs/heads/master@{#417516}
parent 77548d02
...@@ -117,7 +117,6 @@ if (is_win) { ...@@ -117,7 +117,6 @@ if (is_win) {
] ]
if (target_cpu == "x86") { if (target_cpu == "x86") {
deps += [ "//chrome/tools/disable_outdated_build_detector" ]
if (is_clang) { if (is_clang) {
deps += [ "//courgette(//build/toolchain/win:clang_x64)" ] deps += [ "//courgette(//build/toolchain/win:clang_x64)" ]
} else { } else {
...@@ -716,10 +715,6 @@ group("gn_only") { ...@@ -716,10 +715,6 @@ group("gn_only") {
deps += [ "//components/proximity_auth:proximity_auth_unittests" ] deps += [ "//components/proximity_auth:proximity_auth_unittests" ]
} }
if (is_win && target_cpu == "x86") {
deps += [ "//chrome/tools/disable_outdated_build_detector" ]
}
if (is_win || is_linux) { if (is_win || is_linux) {
deps += [ deps += [
"//mash:all", "//mash:all",
......
...@@ -90,8 +90,6 @@ bool IsOrganic(const std::string& brand) { ...@@ -90,8 +90,6 @@ bool IsOrganic(const std::string& brand) {
} }
#endif #endif
// Changes to this list must be mirrored in
// chrome/tools/disable_outdated_build_detector/google_update_integration.cc.
const char* const kBrands[] = { const char* const kBrands[] = {
"CHCA", "CHCB", "CHCG", "CHCH", "CHCI", "CHCJ", "CHCK", "CHCL", "CHCA", "CHCB", "CHCG", "CHCH", "CHCI", "CHCJ", "CHCK", "CHCL",
"CHFO", "CHFT", "CHHS", "CHHM", "CHMA", "CHMB", "CHME", "CHMF", "CHFO", "CHFT", "CHHS", "CHHM", "CHMA", "CHMB", "CHME", "CHMF",
......
...@@ -609,24 +609,6 @@ FILES = [ ...@@ -609,24 +609,6 @@ FILES = [
'buildtype': ['dev', 'official'], 'buildtype': ['dev', 'official'],
'archive': 'chrome-win32-syms.zip', 'archive': 'chrome-win32-syms.zip',
}, },
# XP/Vista Probe.
{
'filename': 'disable_outdated_build_detector.exe',
'arch': ['32bit'],
'buildtype': ['official'],
'archive': 'disable_outdated_build_detector.exe',
'direct_archive': 1,
'filegroup': ['default', 'symsrc'],
'optional': ['official'],
},
{
'filename': 'disable_outdated_build_detector.exe.pdb',
'arch': ['32bit'],
'buildtype': ['official'],
'archive': 'disable_outdated_build_detector.exe.pdb',
'direct_archive': 1,
'optional': ['official'],
},
# PDB files for Syzygy modified binaries. Only add to this section if you # PDB files for Syzygy modified binaries. Only add to this section if you
# know what you're doing! The build configuration has to be modified to run # know what you're doing! The build configuration has to be modified to run
# Syzygy on the target in question before adding a staging dependency here! # Syzygy on the target in question before adding a staging dependency here!
......
# Copyright (c) 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//chrome/version.gni")
import("//testing/test.gni")
if (is_win) {
config("xp") {
# Target low-end CPUs on XP.
cflags = [ "/arch:IA32" ]
defines = [
"NTDDI_VERSION=0x05010200",
"WINVER=0x0501",
"_WIN32_WINNT=0x0501",
]
}
executable("disable_outdated_build_detector") {
sources = [
"disable_outdated_build_detector_main.cc",
]
configs -= [
"//build/config/win:console",
"//build/config/win:winver",
]
configs += [
"//build/config/win:windowed",
":xp",
]
deps = [
":disable_outdated_build_detector_exe_version",
":lib",
"//build/win:default_exe_manifest",
]
}
process_version("disable_outdated_build_detector_exe_version") {
template_file = "disable_outdated_build_detector_exe_version.rc.version"
output = "$target_gen_dir/disable_outdated_build_detector_exe_version.rc"
}
source_set("lib") {
sources = [
"constants.cc",
"constants.h",
"disable_outdated_build_detector.cc",
"disable_outdated_build_detector.h",
"google_update_integration.cc",
"google_update_integration.h",
]
configs -= [ "//build/config/win:winver" ]
configs += [ ":xp" ]
}
test("disable_outdated_build_detector_unittests") {
sources = [
"disable_outdated_build_detector_unittest.cc",
"google_update_integration_unittest.cc",
"run_all_unittests.cc",
]
deps = [
":lib",
"//base",
"//base/test:test_support",
"//chrome/installer/util:with_no_strings",
"//testing/gmock",
"//testing/gtest",
]
}
}
include_rules = [
"+chrome/installer/util",
]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/tools/disable_outdated_build_detector/constants.h"
namespace switches {
const wchar_t kMultiInstall[] = L"multi-install";
const wchar_t kSystemLevel[] = L"system-level";
} // namespace switches
namespace env {
// The presence of this environment variable with a value of 1 implies that the
// tool should run as a system installation regardless of what is on the command
// line.
const wchar_t kGoogleUpdateIsMachine[] = L"GoogleUpdateIsMachine";
} // namespace env
// The new brand to which organic installs will be switched.
const wchar_t kAOHY[] = L"AOHY";
// The names of registry values within a product's ClientState key.
const wchar_t kBrand[] = L"brand";
const wchar_t kInstallerResult[] = L"InstallerResult";
const wchar_t kInstallerError[] = L"InstallerError";
const wchar_t kInstallerExtraCode1[] = L"InstallerExtraCode1";
const wchar_t kUninstallArguments[] = L"UninstallArguments";
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_CONSTANTS_H_
#define CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_CONSTANTS_H_
#include <stdint.h>
namespace switches {
extern const wchar_t kMultiInstall[];
extern const wchar_t kSystemLevel[];
} // namespace switches
namespace env {
extern const wchar_t kGoogleUpdateIsMachine[];
} // namespace env
extern const wchar_t kAOHY[];
extern const wchar_t kBrand[];
extern const wchar_t kInstallerResult[];
extern const wchar_t kInstallerError[];
extern const wchar_t kInstallerExtraCode1[];
extern const wchar_t kUninstallArguments[];
// Values for the process exit code and for Google Update's InstallerError,
// both of which are of type DWORD (a 32-bit unsigned int). The codes start at
// 1000 so as to not collide with existing setup.exe and mini_installer.exe
// exit codes (found in chrome/installer/util/util_constants.h and
// chrome/installer/mini_installer/exit_code.h, respectively).
enum class ExitCode : uint32_t {
// Success exit codes.
BOTH_BRANDS_UPDATED = 1000, // Both Chrome and the Binaries were updated.
CHROME_BRAND_UPDATED = 1001, // Only Chrome's brand was updated.
NO_CHROME = 1002, // Chrome's ClientState key was not found.
NON_ORGANIC_BRAND = 1003, // A non-organic brand was found, no update.
// Failure exit codes.
UNKNOWN_FAILURE = 1010, // Never reported.
UNSUPPORTED_OS = 1011, // Client OS is Windows 7 or newer.
// For these failure modes, Google Update's ExtraCode1 field is populated with
// the Windows error code corresponding to the failed operation.
FAILED_OPENING_KEY = 1012, // RegOpenKeyEx failed.
FAILED_READING_BRAND = 1013, // RegQueryValueEx failed.
FAILED_WRITING_BRAND = 1014, // RegSetValueEx failed.
};
// Values defined by Google Update.
enum class InstallerResult : uint32_t {
FAILED_CUSTOM_ERROR = 1,
};
#endif // CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_CONSTANTS_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/tools/disable_outdated_build_detector/disable_outdated_build_detector.h"
#include <stdlib.h>
#include <algorithm>
#include <string>
#include "chrome/tools/disable_outdated_build_detector/google_update_integration.h"
namespace {
// A rudimentary switch finder that ignores prefixes (e.g., --, -, /).
bool HasSwitch(const wchar_t* command_line, const wchar_t* a_switch) {
if (!command_line || !*command_line)
return false;
const wchar_t* line_end =
command_line + std::char_traits<wchar_t>::length(command_line);
const wchar_t* switch_end =
a_switch + std::char_traits<wchar_t>::length(a_switch);
return std::search(command_line, line_end, a_switch, switch_end) != line_end;
}
// Reads the value named |value_name| from a registry key into |value|. The
// type in the registry is ignored. |value| is not modified in case of error.
// presubmit: allow wstring
uint32_t ReadString(HKEY key, const wchar_t* value_name, std::wstring* value) {
// Read the size of the value (in bytes).
uint32_t byte_length = 0;
uint32_t result = ::RegQueryValueEx(
key, value_name, nullptr /* lpReserved */, nullptr /* lpType */,
nullptr /* lpData */, reinterpret_cast<DWORD*>(&byte_length));
if (result != ERROR_SUCCESS)
return result;
if (!byte_length) {
value->resize(0);
return result;
}
// Handle odd sizes and missing string terminators.
size_t char_length = (byte_length + 3) / sizeof(wchar_t);
// presubmit: allow wstring
std::wstring buffer(char_length, L'\0');
byte_length = static_cast<uint32_t>(char_length * sizeof(wchar_t));
result = ::RegQueryValueEx(key, value_name, nullptr /* lpReserved */,
nullptr /* lpType */,
reinterpret_cast<uint8_t*>(&buffer[0]),
reinterpret_cast<DWORD*>(&byte_length));
if (result != ERROR_SUCCESS)
return result;
if (!byte_length) {
value->resize(0);
return result;
}
// Shrink the string to chop off the terminator.
if (!buffer[(byte_length - 1) / sizeof(wchar_t)])
buffer.resize((byte_length - 1) / sizeof(wchar_t));
else
buffer.resize((byte_length + 1) / sizeof(wchar_t));
value->swap(buffer);
return result;
}
// Returns true if the tool is to operate on a system-level Chrome on the basis
// of either the --system-level command line switch or the GoogleUpdateIsMachine
// environment variable.
bool IsSystemLevel(const wchar_t* command_line) {
if (HasSwitch(command_line, switches::kSystemLevel))
return true;
wchar_t buffer[2] = {};
return ::GetEnvironmentVariableW(env::kGoogleUpdateIsMachine, &buffer[0],
static_cast<DWORD>(_countof(buffer))) == 1 &&
buffer[0] == L'1';
}
// Returns true if Chrome is multi-install.
bool IsChromeMultiInstall(bool system_level) {
HKEY key = nullptr;
LONG result = OpenClientStateKey(system_level, App::CHROME_BROWSER, &key);
if (result != ERROR_SUCCESS)
return false;
// presubmit: allow wstring
std::wstring uninstall_arguments;
ReadString(key, kUninstallArguments, &uninstall_arguments);
::RegCloseKey(key);
return HasSwitch(uninstall_arguments.c_str(), switches::kMultiInstall);
}
// Disables the outdated build detector for |app|. On failures, |detail| will be
// populated with a Windows error code corresponding to the failure mode.
// Returns the exit code for the operation.
ExitCode DisableForApp(bool system_level, App app, uint32_t* detail) {
HKEY key = nullptr;
*detail = OpenClientStateKey(system_level, app, &key);
if (*detail == ERROR_FILE_NOT_FOUND)
return ExitCode::NO_CHROME;
if (*detail != ERROR_SUCCESS)
return ExitCode::FAILED_OPENING_KEY;
ExitCode exit_code = ExitCode::UNKNOWN_FAILURE;
// presubmit: allow wstring
std::wstring brand;
*detail = ReadString(key, kBrand, &brand);
if (*detail != ERROR_SUCCESS && *detail != ERROR_FILE_NOT_FOUND) {
exit_code = ExitCode::FAILED_READING_BRAND;
} else if (!IsOrganic(brand)) {
exit_code = ExitCode::NON_ORGANIC_BRAND;
} else {
*detail = ::RegSetValueEx(
key, kBrand, 0 /* Reserved */, REG_SZ,
reinterpret_cast<const uint8_t*>(&kAOHY[0]),
(std::char_traits<wchar_t>::length(kAOHY) + 1) * sizeof(wchar_t));
exit_code = *detail == ERROR_SUCCESS ? ExitCode::CHROME_BRAND_UPDATED
: ExitCode::FAILED_WRITING_BRAND;
}
::RegCloseKey(key);
return exit_code;
}
// Disables the outdated build detector for organic installs of Chrome by
// switching the install to the AOHY non-organic brand code. If Chrome's brand
// is modified and it is a multi-install Chrome, the binaries' brand code will
// likewise be modified. On failures, |detail| will be populated with a Windows
// error code corresponding to the failure mode. Returns the process exit code
// for the operation.
ExitCode DisableOutdatedBuildDetectorImpl(bool system_level, uint32_t* detail) {
// Update Chrome's brand code.
ExitCode exit_code = DisableForApp(system_level, App::CHROME_BROWSER, detail);
// If that succeeded and Chrome is multi-install, make a best-effort attempt
// to update the binaries' brand code.
if (exit_code == ExitCode::CHROME_BRAND_UPDATED &&
IsChromeMultiInstall(system_level)) {
ExitCode secondary_code =
DisableForApp(system_level, App::CHROME_BINARIES, detail);
if (secondary_code == ExitCode::CHROME_BRAND_UPDATED)
exit_code = ExitCode::BOTH_BRANDS_UPDATED;
}
return exit_code;
}
} // namespace
ExitCode DisableOutdatedBuildDetector(const wchar_t* command_line) {
const bool system_level = IsSystemLevel(command_line);
ResultInfo result_info = {
InstallerResult::FAILED_CUSTOM_ERROR, // installer_result
ExitCode::UNKNOWN_FAILURE, // installer_error
0 // installer_extra_code1
};
result_info.installer_error = DisableOutdatedBuildDetectorImpl(
system_level, &result_info.installer_extra_code1);
WriteResultInfo(system_level, result_info);
return result_info.installer_error;
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_DISABLE_OUTDATED_BUILD_DETECTOR_H_
#define CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_DISABLE_OUTDATED_BUILD_DETECTOR_H_
#include "chrome/tools/disable_outdated_build_detector/constants.h"
// Disables the outdated build detector for organic installs of Chrome by
// switching the install to the AOHY non-organic brand code. Operates on
// per-user Chrome unless |command_line| contains the "--system-level" switch,
// in which case it operates on per-machine Chrome. The result of the operation
// is written to the registry in Chrome's ClientState key in accordance with the
// Google Update installer result API. Returns the process exit code for the
// operation.
ExitCode DisableOutdatedBuildDetector(const wchar_t* command_line);
#endif // CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_DISABLE_OUTDATED_BUILD_DETECTOR_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <verrsrc.h>
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION @MAJOR@,@MINOR@,@BUILD@,@PATCH@
PRODUCTVERSION @MAJOR@,@MINOR@,@BUILD@,@PATCH@
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "@COMPANY_FULLNAME@"
VALUE "FileDescription", "disable_outdated_build_detector"
VALUE "FileVersion", "@MAJOR@.@MINOR@.@BUILD@.@PATCH@"
VALUE "InternalName", "disable_outdated_build_detector"
VALUE "LegalCopyright", "@COPYRIGHT@"
VALUE "ProductName", "disable_outdated_build_detector"
VALUE "ProductVersion", "@MAJOR@.@MINOR@.@BUILD@.@PATCH@"
VALUE "CompanyShortName", "@COMPANY_SHORTNAME@"
VALUE "ProductShortName", "disable_outdated_build_detector"
VALUE "LastChange", "@LASTCHANGE@"
VALUE "Official Build", "@OFFICIAL_BUILD@"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The main entrypoint for the tool that disables the outdated build detector
// for organic installs of Chrome on Windows XP and Vista. See
// disable_outdated_build_detector.h for more information.
#include <windows.h>
#include "chrome/tools/disable_outdated_build_detector/disable_outdated_build_detector.h"
namespace {
bool IsVistaOrOlder() {
OSVERSIONINFO version_info = {sizeof(version_info)};
return ::GetVersionEx(&version_info) && (version_info.dwMajorVersion < 6 ||
(version_info.dwMajorVersion == 6 &&
version_info.dwMinorVersion == 0));
}
} // namespace
int WINAPI wWinMain(HINSTANCE /* instance */,
HINSTANCE /* unused */,
wchar_t* command_line,
int /* command_show */) {
if (!IsVistaOrOlder())
return static_cast<int>(ExitCode::UNSUPPORTED_OS);
// For reasons, wWinMain returns an int rather than a DWORD. This value
// eventually makes its way to ExitProcess, which indeed takes an unsigned
// int.
return static_cast<int>(DisableOutdatedBuildDetector(command_line));
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/tools/disable_outdated_build_detector/disable_outdated_build_detector.h"
#include "base/environment.h"
#include "base/strings/string16.h"
#include "base/test/test_reg_util_win.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/util_constants.h"
#include "chrome/tools/disable_outdated_build_detector/constants.h"
#include "testing/gtest/include/gtest/gtest.h"
enum class ExecutionMode {
USER_LEVEL,
SYSTEM_LEVEL_SWITCH,
IS_MACHINE_ENV,
};
class DisableOutdatedBuildDetectorTest
: public ::testing::TestWithParam<ExecutionMode> {
protected:
DisableOutdatedBuildDetectorTest()
: chrome_distribution_(BrowserDistribution::GetSpecificDistribution(
BrowserDistribution::CHROME_BROWSER)),
binaries_distribution_(BrowserDistribution::GetSpecificDistribution(
BrowserDistribution::CHROME_BINARIES)),
execution_mode_(GetParam()),
root_(execution_mode_ == ExecutionMode::USER_LEVEL
? HKEY_CURRENT_USER
: HKEY_LOCAL_MACHINE) {
registry_override_manager_.OverrideRegistry(root_);
if (execution_mode_ == ExecutionMode::SYSTEM_LEVEL_SWITCH)
command_line_ = L"--system-level";
base::Environment::Create()->SetVar(
"GoogleUpdateIsMachine",
execution_mode_ == ExecutionMode::IS_MACHINE_ENV ? "1" : "0");
}
void FakeChrome(bool multi_install, const wchar_t* brand) {
base::win::RegKey key;
ASSERT_EQ(ERROR_SUCCESS,
key.Create(root_, chrome_distribution_->GetStateKey().c_str(),
KEY_ALL_ACCESS | KEY_WOW64_32KEY));
base::string16 uninstall_arguments(L"--uninstall");
if (multi_install)
uninstall_arguments += L"--chrome --multi-install";
if (brand)
ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"brand", brand));
ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"UninstallArguments",
uninstall_arguments.c_str()));
if (!multi_install)
return;
uninstall_arguments = L"--uninstall --multi-install";
ASSERT_EQ(ERROR_SUCCESS,
key.Create(root_, binaries_distribution_->GetStateKey().c_str(),
KEY_ALL_ACCESS | KEY_WOW64_32KEY));
if (brand)
ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"brand", brand));
ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"UninstallArguments",
uninstall_arguments.c_str()));
}
bool HasBrand(BrowserDistribution* dist) {
base::win::RegKey key(root_, dist->GetStateKey().c_str(),
KEY_QUERY_VALUE | KEY_WOW64_32KEY);
return key.Valid() && key.HasValue(L"brand");
}
base::string16 ReadBrand(BrowserDistribution* dist) {
base::win::RegKey key(root_, dist->GetStateKey().c_str(),
KEY_QUERY_VALUE | KEY_WOW64_32KEY);
base::string16 brand;
if (!key.Valid() || key.ReadValue(L"brand", &brand) != ERROR_SUCCESS)
return base::string16();
return brand;
}
// Verifies that |result|, |exit_code|, and |detail| are found in Chrome's
// ClientStateKey in the InstallerResult, InstallerError, and
// InstallerExtraCode1 values, respectively.
void ExpectResult(InstallerResult result,
ExitCode exit_code,
uint32_t detail) {
base::win::RegKey key(root_, chrome_distribution_->GetStateKey().c_str(),
KEY_QUERY_VALUE | KEY_WOW64_32KEY);
ASSERT_TRUE(key.Valid());
DWORD value = 0;
ASSERT_EQ(ERROR_SUCCESS,
key.ReadValueDW(installer::kInstallerResult, &value));
EXPECT_EQ(result, static_cast<InstallerResult>(value));
ASSERT_EQ(ERROR_SUCCESS,
key.ReadValueDW(installer::kInstallerError, &value));
EXPECT_EQ(exit_code, static_cast<ExitCode>(value));
if (detail) {
ASSERT_EQ(ERROR_SUCCESS,
key.ReadValueDW(installer::kInstallerExtraCode1, &value));
EXPECT_EQ(detail, value);
} else {
EXPECT_FALSE(key.HasValue(installer::kInstallerExtraCode1));
}
}
const wchar_t* command_line() const { return command_line_.c_str(); }
std::wstring command_line_;
BrowserDistribution* chrome_distribution_;
BrowserDistribution* binaries_distribution_;
private:
const ExecutionMode execution_mode_;
const HKEY root_;
registry_util::RegistryOverrideManager registry_override_manager_;
};
TEST_P(DisableOutdatedBuildDetectorTest, NoChrome) {
EXPECT_EQ(ExitCode::NO_CHROME, DisableOutdatedBuildDetector(command_line()));
}
TEST_P(DisableOutdatedBuildDetectorTest, SingleUnbrandedChrome) {
// Fake single-install Chrome's ClientState key with no brand.
FakeChrome(false /* single-install */, nullptr);
// Switch the brand.
EXPECT_EQ(ExitCode::NON_ORGANIC_BRAND,
DisableOutdatedBuildDetector(command_line()));
ExpectResult(InstallerResult::FAILED_CUSTOM_ERROR,
ExitCode::NON_ORGANIC_BRAND, ERROR_FILE_NOT_FOUND);
// Verify that there is still no brand.
EXPECT_FALSE(HasBrand(chrome_distribution_));
// And the binaries' ClientState key should not have been created.
EXPECT_FALSE(HasBrand(binaries_distribution_));
}
TEST_P(DisableOutdatedBuildDetectorTest, SingleOrganicChrome) {
// Fake single-install Chrome's ClientState key with an organic brand.
FakeChrome(false /* single-install */, L"GGLS");
// Switch the brand.
EXPECT_EQ(ExitCode::CHROME_BRAND_UPDATED,
DisableOutdatedBuildDetector(command_line()));
ExpectResult(InstallerResult::FAILED_CUSTOM_ERROR,
ExitCode::CHROME_BRAND_UPDATED, 0);
// Verify the new brand.
EXPECT_STREQ(L"AOHY", ReadBrand(chrome_distribution_).c_str());
// And the binaries' ClientState key should not have been created.
EXPECT_FALSE(HasBrand(binaries_distribution_));
}
TEST_P(DisableOutdatedBuildDetectorTest, SingleInOrganicChrome) {
static const wchar_t kBlorBrand[] = L"BLOR";
// Fake single-install Chrome's ClientState key with an inorganic brand.
FakeChrome(false /* single-install */, kBlorBrand);
// Switch the brand.
EXPECT_EQ(ExitCode::NON_ORGANIC_BRAND,
DisableOutdatedBuildDetector(command_line()));
ExpectResult(InstallerResult::FAILED_CUSTOM_ERROR,
ExitCode::NON_ORGANIC_BRAND, 0);
// Verify that the brand is unchanged.
EXPECT_STREQ(kBlorBrand, ReadBrand(chrome_distribution_).c_str());
// And the binaries' ClientState key should not have been created.
EXPECT_FALSE(HasBrand(binaries_distribution_));
}
TEST_P(DisableOutdatedBuildDetectorTest, MultiOrganicChrome) {
// Fake multi-install Chrome's ClientState key with an organic brand.
FakeChrome(true /* multi-install */, L"GGLS");
// Switch the brand.
EXPECT_EQ(ExitCode::BOTH_BRANDS_UPDATED,
DisableOutdatedBuildDetector(command_line()));
ExpectResult(InstallerResult::FAILED_CUSTOM_ERROR,
ExitCode::BOTH_BRANDS_UPDATED, 0);
// Verify the new brand in Chrome and the binaries.
EXPECT_STREQ(L"AOHY", ReadBrand(chrome_distribution_).c_str());
EXPECT_STREQ(L"AOHY", ReadBrand(binaries_distribution_).c_str());
}
TEST_P(DisableOutdatedBuildDetectorTest, MultiInOrganicChrome) {
static const wchar_t kBlorBrand[] = L"BLOR";
// Fake multi-install Chrome's ClientState key with an inorganic brand.
FakeChrome(true /* multi-install */, kBlorBrand);
// Switch the brand.
EXPECT_EQ(ExitCode::NON_ORGANIC_BRAND,
DisableOutdatedBuildDetector(command_line()));
ExpectResult(InstallerResult::FAILED_CUSTOM_ERROR,
ExitCode::NON_ORGANIC_BRAND, 0);
// Verify that the brand is unchanged in both apps.
EXPECT_STREQ(kBlorBrand, ReadBrand(chrome_distribution_).c_str());
EXPECT_STREQ(kBlorBrand, ReadBrand(binaries_distribution_).c_str());
}
INSTANTIATE_TEST_CASE_P(UserLevel,
DisableOutdatedBuildDetectorTest,
::testing::Values(ExecutionMode::USER_LEVEL));
INSTANTIATE_TEST_CASE_P(SystemLevelSwitch,
DisableOutdatedBuildDetectorTest,
::testing::Values(ExecutionMode::SYSTEM_LEVEL_SWITCH));
INSTANTIATE_TEST_CASE_P(IsMachineEnv,
DisableOutdatedBuildDetectorTest,
::testing::Values(ExecutionMode::IS_MACHINE_ENV));
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/tools/disable_outdated_build_detector/google_update_integration.h"
#include <stdlib.h>
#include <algorithm>
uint32_t OpenClientStateKey(bool system_level, App app, HKEY* key) {
#if defined(GOOGLE_CHROME_BUILD)
constexpr wchar_t kChromeAppGuid[] =
L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
constexpr wchar_t kBinariesAppGuid[] =
L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
// presubmit: allow wstring
std::wstring path(L"Software\\Google\\Update\\ClientState\\");
path += (app == App::CHROME_BINARIES ? kBinariesAppGuid : kChromeAppGuid);
#else
// presubmit: allow wstring
std::wstring path(app == App::CHROME_BINARIES ? L"Software\\Chromium Binaries"
: L"Software\\Chromium");
#endif
return ::RegOpenKeyEx(system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
path.c_str(), 0 /* ulOptions */,
KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WOW64_32KEY, key);
}
void WriteResultInfo(bool system_level, const ResultInfo& result_info) {
HKEY key = nullptr;
uint32_t result = OpenClientStateKey(system_level, App::CHROME_BROWSER, &key);
if (result != ERROR_SUCCESS)
return;
::RegSetValueEx(
key, kInstallerResult, 0 /* Reserved */, REG_DWORD,
reinterpret_cast<const uint8_t*>(&result_info.installer_result),
sizeof(DWORD));
::RegSetValueEx(
key, kInstallerError, 0 /* Reserved */, REG_DWORD,
reinterpret_cast<const uint8_t*>(&result_info.installer_error),
sizeof(DWORD));
if (result_info.installer_extra_code1) {
::RegSetValueEx(
key, kInstallerExtraCode1, 0 /* Reserved */, REG_DWORD,
reinterpret_cast<const uint8_t*>(&result_info.installer_extra_code1),
sizeof(DWORD));
} else {
::RegDeleteValue(key, kInstallerExtraCode1);
}
::RegCloseKey(key);
}
// Copied from chrome/browser/google/google_brand.cc.
// presubmit: allow wstring
bool IsOrganic(const std::wstring& brand) {
constexpr const wchar_t* kBrands[] = {
L"CHCA", L"CHCB", L"CHCG", L"CHCH", L"CHCI", L"CHCJ", L"CHCK", L"CHCL",
L"CHFO", L"CHFT", L"CHHS", L"CHHM", L"CHMA", L"CHMB", L"CHME", L"CHMF",
L"CHMG", L"CHMH", L"CHMI", L"CHMQ", L"CHMV", L"CHNB", L"CHNC", L"CHNG",
L"CHNH", L"CHNI", L"CHOA", L"CHOB", L"CHOC", L"CHON", L"CHOO", L"CHOP",
L"CHOQ", L"CHOR", L"CHOS", L"CHOT", L"CHOU", L"CHOX", L"CHOY", L"CHOZ",
L"CHPD", L"CHPE", L"CHPF", L"CHPG", L"ECBA", L"ECBB", L"ECDA", L"ECDB",
L"ECSA", L"ECSB", L"ECVA", L"ECVB", L"ECWA", L"ECWB", L"ECWC", L"ECWD",
L"ECWE", L"ECWF", L"EUBB", L"EUBC", L"GGLA", L"GGLS"};
const wchar_t* const* end = &kBrands[_countof(kBrands)];
const wchar_t* const* found = std::find(&kBrands[0], end, brand);
if (found != end)
return true;
return brand.size() > 3 && (std::equal(&brand[0], &brand[3], L"EUB") ||
std::equal(&brand[0], &brand[3], L"EUC") ||
std::equal(&brand[0], &brand[3], L"GGR"));
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_GOOGLE_UPDATE_INTEGRATION_H_
#define CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_GOOGLE_UPDATE_INTEGRATION_H_
#include <windows.h>
#include <stdint.h>
#include <string>
#include "chrome/tools/disable_outdated_build_detector/constants.h"
// A structure containing the values that comprise the Google Update installer
// result API.
struct ResultInfo {
InstallerResult installer_result;
ExitCode installer_error;
uint32_t installer_extra_code1;
};
// An identifier of an app's registration with Google Update.
enum class App {
CHROME_BROWSER,
CHROME_BINARIES,
};
// Opens the Google Update ClientState key in the registry for the app
// identified by |app| at |system_level|. Returns ERROR_SUCCESS or another
// Windows error value. On success, the caller is responsible for calling
// RegCloseKey.
uint32_t OpenClientStateKey(bool system_level, App app, HKEY* key);
// Writes the data in |result_info| into Chrome's ClientState key.
void WriteResultInfo(bool system_level, const ResultInfo& result_info);
// Returns |true| if |brand| represents an organic brand code.
// presubmit: allow wstring
bool IsOrganic(const std::wstring& brand);
#endif // CHROME_TOOLS_DISABLE_OUTDATED_BUILD_DETECTOR_GOOGLE_UPDATE_INTEGRATION_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/tools/disable_outdated_build_detector/google_update_integration.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
// Copied from chrome/browser/google/google_brand.cc.
const wchar_t* const kOrganicBrands[] = {
L"CHCA", L"CHCB", L"CHCG", L"CHCH", L"CHCI", L"CHCJ", L"CHCK", L"CHCL",
L"CHFO", L"CHFT", L"CHHS", L"CHHM", L"CHMA", L"CHMB", L"CHME", L"CHMF",
L"CHMG", L"CHMH", L"CHMI", L"CHMQ", L"CHMV", L"CHNB", L"CHNC", L"CHNG",
L"CHNH", L"CHNI", L"CHOA", L"CHOB", L"CHOC", L"CHON", L"CHOO", L"CHOP",
L"CHOQ", L"CHOR", L"CHOS", L"CHOT", L"CHOU", L"CHOX", L"CHOY", L"CHOZ",
L"CHPD", L"CHPE", L"CHPF", L"CHPG", L"ECBA", L"ECBB", L"ECDA", L"ECDB",
L"ECSA", L"ECSB", L"ECVA", L"ECVB", L"ECWA", L"ECWB", L"ECWC", L"ECWD",
L"ECWE", L"ECWF", L"EUBB", L"EUBC", L"GGLA", L"GGLS",
// EUB*
L"EUBQ",
// EUC*
L"EUCQ",
// GGR*
L"GGRQ",
};
} // namespace
// Test that all expected brands are considered organic.
class IsOrganicTest : public ::testing::TestWithParam<const wchar_t*> {};
TEST_P(IsOrganicTest, IsOrganicBrand) {
EXPECT_TRUE(IsOrganic(GetParam()));
}
INSTANTIATE_TEST_CASE_P(OrganicBrands,
IsOrganicTest,
::testing::ValuesIn(kOrganicBrands));
// Test that a smattering of non-organic brands are not considered organic.
class IsNotOrganicTest : public ::testing::TestWithParam<const wchar_t*> {};
TEST_P(IsNotOrganicTest, IsNotOrganicBrand) {
EXPECT_FALSE(IsOrganic(GetParam()));
}
INSTANTIATE_TEST_CASE_P(NonOrganicBrands,
IsNotOrganicTest,
::testing::Values(L"AOHY", L"YAKS", L""));
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/bind.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "build/build_config.h"
int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
...@@ -4652,12 +4652,6 @@ ...@@ -4652,12 +4652,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -4921,12 +4915,6 @@ ...@@ -4921,12 +4915,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -5184,12 +5172,6 @@ ...@@ -5184,12 +5172,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -6206,12 +6188,6 @@ ...@@ -6206,12 +6188,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -6671,12 +6647,6 @@ ...@@ -6671,12 +6647,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -6910,12 +6880,6 @@ ...@@ -6910,12 +6880,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -7173,12 +7137,6 @@ ...@@ -7173,12 +7137,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -7436,12 +7394,6 @@ ...@@ -7436,12 +7394,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -8470,12 +8422,6 @@ ...@@ -8470,12 +8422,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -9241,12 +9187,6 @@ ...@@ -9241,12 +9187,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
......
...@@ -1115,12 +1115,6 @@ ...@@ -1115,12 +1115,6 @@
}, },
"test": "device_unittests" "test": "device_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
...@@ -1585,12 +1579,6 @@ ...@@ -1585,12 +1579,6 @@
}, },
"test": "crypto_unittests" "test": "crypto_unittests"
}, },
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "disable_outdated_build_detector_unittests"
},
{ {
"swarming": { "swarming": {
"can_use_on_swarming_builders": true "can_use_on_swarming_builders": true
......
...@@ -274,10 +274,6 @@ ...@@ -274,10 +274,6 @@
"label": "//device:device_unittests", "label": "//device:device_unittests",
"type": "console_test_launcher", "type": "console_test_launcher",
}, },
"disable_outdated_build_detector_unittests": {
"label": "//chrome/tools/disable_outdated_build_detector:disable_outdated_build_detector_unittests",
"type": "console_test_launcher",
},
"display_unittests": { "display_unittests": {
"label": "//ui/display:display_unittests", "label": "//ui/display:display_unittests",
"type": "console_test_launcher", "type": "console_test_launcher",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment