Commit 98a349ce authored by Joe Mason's avatar Joe Mason Committed by Commit Bot

Updates from internal chrome_cleaner repo

* Add a hook to override the command line of test_main.cc.
chrome_cleaner_unittests has an empty implementation. Other internal
test executables that use test_main.cc use this to add flags to the
commandline.

* Add more accessors to engine_resources.h to reduce hardcoding.

* Move the dummy engine resources and signatures to their own build
targets.

* Remove unused MatchingOptions::find_incomplete_matches.

* Remove unused StartScanning and StartCleanup methods in
MainDialogAPI.

* Make test binaries into console apps.

* Allow import_util.py to work outside the source tree.

* Cleanups to deps and includes.

* Alphabetize test/BUILD.gn so it can be diffed against the internal
version more easily during upstreaming.

R=csharp

Bug: 830892
Change-Id: I263aabf02a467df231e3c227ea6f01328b9212d3
Reviewed-on: https://chromium-review.googlesource.com/1207171Reviewed-by: default avatarChris Sharp <csharp@chromium.org>
Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Chris Sharp <csharp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589625}
parent ead1c24e
......@@ -7,6 +7,7 @@ import("//testing/test.gni")
test("chrome_cleaner_unittests") {
sources = [
"//chrome/chrome_cleaner/engines/dummy_engine_resources.cc",
"//chrome/chrome_cleaner/test/unit_test_override_command_line.cc",
"test/test_main.cc",
]
......@@ -22,6 +23,7 @@ test("chrome_cleaner_unittests") {
"//chrome/chrome_cleaner/os:cleaner_os",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/pup_data:dummy_signatures",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//chrome/chrome_cleaner/settings:settings_types",
"//chrome/chrome_cleaner/test:test_pup_data",
......
......@@ -7,7 +7,21 @@ source_set("resources") {
"engine_resources.h",
]
deps = [
"//base",
]
public_deps = [
"//chrome/chrome_cleaner/logging/proto:shared_data_proto",
]
}
source_set("dummy_resources") {
sources = [
"dummy_engine_resources.cc",
]
deps = [
":resources",
]
}
......@@ -6,6 +6,10 @@
namespace chrome_cleaner {
base::string16 GetTestStubFileName(Engine::Name engine) {
return base::string16();
}
std::string GetEngineVersion(Engine::Name engine) {
return std::string();
}
......@@ -14,4 +18,26 @@ int GetProtectedFilesDigestResourceId() {
return 0;
}
std::unordered_map<base::string16, int> GetEmbeddedLibraryResourceIds(
Engine::Name engine) {
return {};
}
int GetLibrariesDigestResourcesId(Engine::Name engine) {
return 0;
}
std::set<base::string16> GetLibrariesToLoad(Engine::Name engine) {
return {};
}
std::unordered_map<base::string16, base::string16> GetLibraryTestReplacements(
Engine::Name engine) {
return {};
}
std::vector<base::string16> GetDLLNames(Engine::Name engine) {
return {};
}
} // namespace chrome_cleaner
......@@ -5,12 +5,20 @@
#ifndef CHROME_CHROME_CLEANER_ENGINES_ENGINE_RESOURCES_H_
#define CHROME_CHROME_CLEANER_ENGINES_ENGINE_RESOURCES_H_
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include "base/strings/string16.h"
#include "chrome/chrome_cleaner/logging/proto/shared_data.pb.h"
namespace chrome_cleaner {
// Returns the name of the stub DLL to be used in testing and an empty string
// if there are none.
base::string16 GetTestStubFileName(Engine::Name engine);
// Returns string representation of the engine's version or an empty string if
// not available.
std::string GetEngineVersion(Engine::Name engine);
......@@ -20,6 +28,28 @@ std::string GetEngineVersion(Engine::Name engine);
// available.
int GetProtectedFilesDigestResourceId();
// Returns IDs of the "LIBRARY" resources for |engine| that are embedded into
// the executable.
std::unordered_map<base::string16, int> GetEmbeddedLibraryResourceIds(
Engine::Name engine);
// Returns ID of the "TEXT" resource that contains serialized FileDigests
// message (see file_digest.proto) of |engine| libraries.
int GetLibrariesDigestResourcesId(Engine::Name engine);
// Returns set of libraries that should be loaded for |engine|.
std::set<base::string16> GetLibrariesToLoad(Engine::Name engine);
// Returns a map of test library replacements. If during delayed loading a
// library is missing, it can be replaced by the corresponding library from the
// map. To be used in test builds only.
std::unordered_map<base::string16, base::string16> GetLibraryTestReplacements(
Engine::Name engine);
// Returns the names of the dlls that are used by the engine
// when there are no test replacements.
std::vector<base::string16> GetDLLNames(Engine::Name engine);
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_ENGINES_ENGINE_RESOURCES_H_
include_rules = [
"+components/chrome_cleaner",
"+net/traffic_annotation",
"+url",
]
......@@ -45,6 +45,18 @@ source_set("cleaner_pup_util") {
]
}
source_set("dummy_signatures") {
# This is not testonly because the real engine will be linked with these
# signatures when the private internal signatures are not available.
sources = [
"dummy_signatures.cc",
]
deps = [
":pup_data_base",
]
}
source_set("dynamic_pup") {
sources = [
"dynamic_pup.cc",
......
......@@ -7,14 +7,14 @@
namespace chrome_cleaner {
// An array of signatures that only contains the sentinel value and represents
// an empty array
// an empty array.
const PUPData::UwSSignature dummy_signatures[] = {
{PUPData::kInvalidUwSId, PUPData::FLAGS_NONE, nullptr,
PUPData::kMaxFilesToRemoveSmallUwS, kNoDisk, kNoRegistry,
kNoCustomMatcher}};
// While testing we will set up special signatures but we still can't have
// unitialized pointers to pass the DCHECKS during setup
// uninitialized pointers to pass the DCHECKS during setup.
const PUPData::UwSSignature* PUPData::kRemovedPUPs = dummy_signatures;
const PUPData::UwSSignature* PUPData::kPUPs = dummy_signatures;
const PUPData::UwSSignature* PUPData::kObservedPUPs = dummy_signatures;
......
......@@ -72,7 +72,6 @@ source_set("scanner") {
"//chrome/chrome_cleaner/chrome_utils:chrome_util_lib",
"//chrome/chrome_cleaner/constants:common_strings",
"//chrome/chrome_cleaner/logging:common",
"//chrome/chrome_cleaner/logging:logging_definitions",
"//chrome/chrome_cleaner/logging:scoped_timed_task_logger",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
......
......@@ -33,7 +33,6 @@
#include "base/time/time.h"
#include "base/win/registry.h"
#include "chrome/chrome_cleaner/constants/chrome_cleaner_switches.h"
#include "chrome/chrome_cleaner/logging/logging_definitions.h"
#include "chrome/chrome_cleaner/logging/logging_service_api.h"
#include "chrome/chrome_cleaner/logging/registry_logger.h"
#include "chrome/chrome_cleaner/logging/scoped_timed_task_logger.h"
......
include_rules = [
"+components/chrome_cleaner",
"+mojo/public",
]
......@@ -9,25 +9,21 @@
namespace chrome_cleaner {
// For the cleaner we should always perform full scan so we know exactly what is
// found, even for report only UwS, and we should always look for incomplete
// matches.
// found, even for report only UwS.
MatchingOptions DefaultCleanerMatchingOptions() {
MatchingOptions options;
options.set_only_one_footprint(false);
options.set_find_incomplete_matches(true);
return options;
}
// For the reporter, we should only perform a full scan if we report back to
// Google what files and registry entries were matched. Otherwise, we should
// stop looking as soon as any piece of the UwS is found, since we just care if
// it is present. In addition, we should never look for incomplete matches,
// since they will not be available anyway in logs.
// it is present.
MatchingOptions DefaultReporterMatchingOptions() {
MatchingOptions options;
options.set_only_one_footprint(
!Settings::GetInstance()->logs_collection_enabled());
options.set_find_incomplete_matches(false);
return options;
}
......
......@@ -14,13 +14,4 @@ void MatchingOptions::set_only_one_footprint(bool only_one_footprint) {
only_one_footprint_ = only_one_footprint;
}
bool MatchingOptions::find_incomplete_matches() const {
return find_incomplete_matches_;
}
void MatchingOptions::set_find_incomplete_matches(
bool find_incomplete_matches) {
find_incomplete_matches_ = find_incomplete_matches;
}
} // namespace chrome_cleaner
......@@ -12,12 +12,8 @@ class MatchingOptions {
bool only_one_footprint() const;
void set_only_one_footprint(bool only_one_footprint);
bool find_incomplete_matches() const;
void set_find_incomplete_matches(bool find_incomplete_matches);
private:
bool only_one_footprint_ = false;
bool find_incomplete_matches_ = false;
};
} // namespace chrome_cleaner
......
......@@ -30,6 +30,9 @@ String16EmbeddedNulls::String16EmbeddedNulls(const base::string16& str)
String16EmbeddedNulls::String16EmbeddedNulls(base::StringPiece16 str)
: String16EmbeddedNulls(str.data(), str.size()) {}
String16EmbeddedNulls::String16EmbeddedNulls(std::initializer_list<wchar_t> il)
: data_(il) {}
String16EmbeddedNulls::~String16EmbeddedNulls() = default;
String16EmbeddedNulls& String16EmbeddedNulls::operator=(
......
......@@ -29,6 +29,7 @@ class String16EmbeddedNulls {
explicit String16EmbeddedNulls(const std::vector<wchar_t>& str);
explicit String16EmbeddedNulls(const base::string16& str);
explicit String16EmbeddedNulls(base::StringPiece16 str);
explicit String16EmbeddedNulls(std::initializer_list<wchar_t> chars);
~String16EmbeddedNulls();
......@@ -43,6 +44,9 @@ class String16EmbeddedNulls {
const wchar_t* CastAsWCharArray() const;
const uint16_t* CastAsUInt16Array() const;
const std::vector<wchar_t>& data() const { return data_; }
std::vector<wchar_t>& data() { return data_; }
private:
std::vector<wchar_t> data_;
};
......
......@@ -6,6 +6,12 @@ shared_library("empty_dll") {
sources = [
"empty_dll.cc",
]
configs += [
# This is required to prevent this target from having to be rebuilt every
# time, even with the source files doesn't change.
"//base:base_win_linker_flags",
]
}
source_set("scoped_file") {
......@@ -19,12 +25,11 @@ source_set("scoped_file") {
]
}
source_set("test_strings") {
source_set("test_branding_header") {
testonly = true
sources = [
"test_strings.cc",
"test_strings.h",
"test_branding.h",
]
}
......@@ -52,6 +57,53 @@ source_set("test_executables") {
]
}
source_set("test_pup_data") {
testonly = true
sources = [
"test_pup_data.cc",
"test_pup_data.h",
"test_uws_catalog.cc",
"test_uws_catalog.h",
]
deps = [
"//base:base",
"//chrome/chrome_cleaner/logging/proto:shared_data_proto",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
"//chrome/chrome_cleaner/pup_data:dynamic_pup",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//chrome/chrome_cleaner/pup_data:test_uws",
"//testing/gtest",
]
}
source_set("test_scoped_service_handle") {
testonly = true
sources = [
"test_scoped_service_handle.cc",
"test_scoped_service_handle.h",
]
deps = [
":test_executables",
":test_strings",
"//base",
"//chrome/chrome_cleaner/os:cleaner_os",
"//chrome/chrome_cleaner/os:common_os",
]
}
source_set("test_strings") {
testonly = true
sources = [
"test_strings.cc",
"test_strings.h",
]
}
source_set("test_util") {
testonly = true
......@@ -104,54 +156,6 @@ source_set("test_util") {
]
}
source_set("test_scoped_service_handle") {
testonly = true
sources = [
"test_scoped_service_handle.cc",
"test_scoped_service_handle.h",
]
deps = [
":test_executables",
":test_strings",
"//base",
"//chrome/chrome_cleaner/os:cleaner_os",
"//chrome/chrome_cleaner/os:common_os",
]
}
source_set("test_branding_header") {
# This is NOT testonly because it's used by RegistryOverrideManager, which is
# shipped on official builds.
sources = [
"test_branding.h",
]
}
source_set("test_pup_data") {
testonly = true
sources = [
"test_pup_data.cc",
"test_pup_data.h",
"test_signatures.cc",
"test_uws_catalog.cc",
"test_uws_catalog.h",
]
deps = [
"//base:base",
"//chrome/chrome_cleaner/logging/proto:shared_data_proto",
"//chrome/chrome_cleaner/proto:shared_pup_enums_proto",
"//chrome/chrome_cleaner/pup_data:dynamic_pup",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//chrome/chrome_cleaner/pup_data:pup_data_base",
"//chrome/chrome_cleaner/pup_data:test_uws",
"//testing/gtest",
]
}
source_set("unittest_sources") {
testonly = true
......@@ -165,6 +169,7 @@ source_set("unittest_sources") {
"//base",
"//base/test:test_support",
"//chrome/chrome_cleaner/os:common_os",
"//testing/gmock",
"//testing/gtest",
]
}
......@@ -173,7 +178,6 @@ executable("test_process") {
testonly = true
sources = [
"//chrome/chrome_cleaner/engines/dummy_engine_resources.cc",
"test_process_main.cc",
]
......@@ -184,13 +188,11 @@ executable("test_process") {
"//base/test:test_support",
"//build/win:default_exe_manifest",
"//chrome/chrome_cleaner:other_executable_definitions",
"//chrome/chrome_cleaner/engines:dummy_resources",
"//chrome/chrome_cleaner/engines:resources",
"//chrome/chrome_cleaner/os:common_os",
"//chrome/chrome_cleaner/pup_data:dummy_signatures",
]
# Default entrypoint is main, console app. Change it to wWinMain, windowed.
configs -= [ "//build/config/win:console" ]
configs += [ "//build/config/win:windowed" ]
}
executable("test_service") {
......
......@@ -6,6 +6,8 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "base/win/scoped_com_initializer.h"
......@@ -51,6 +53,14 @@ class ChromeCleanerTestSuite : public base::TestSuite {
} // namespace
namespace chrome_cleaner {
// Gives each test executable a chance to modify |command_line|. Each
// executable must link with exactly one implementation of this.
void OverrideTestCommandLine(base::CommandLine* command_line);
} // namespace chrome_cleaner
int main(int argc, char** argv) {
// This must be executed as soon as possible to reduce the number of dlls that
// the code might try to load before we can lock things down.
......@@ -71,6 +81,9 @@ int main(int argc, char** argv) {
if (chrome_cleaner::Rebooter::IsPostReboot())
return 0;
chrome_cleaner::OverrideTestCommandLine(
base::CommandLine::ForCurrentProcess());
// ScopedCOMInitializer keeps COM initialized in a specific scope. We don't
// want to initialize it for sandboxed processes, so manage its lifetime with
// a unique_ptr, which will call ScopedCOMInitializer's destructor when it
......
......@@ -5,8 +5,6 @@
#ifndef CHROME_CHROME_CLEANER_TEST_TEST_NAME_HELPER_H_
#define CHROME_CHROME_CLEANER_TEST_TEST_NAME_HELPER_H_
#include <stdint.h>
#include <string>
#include "base/strings/string_util.h"
......
......@@ -27,7 +27,7 @@ constexpr base::char16 kLogFileExtension[] = L"log";
} // namespace
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
int main(int, char**) {
// This must be executed as soon as possible to reduce the number of dlls that
// the code might try to load before we can lock things down.
chrome_cleaner::EnableSecureDllLoading();
......
......@@ -6,6 +6,7 @@
#include "chrome/chrome_cleaner/os/disk_util.h"
#include "testing/gtest/include/gtest/gtest.h"
// The following include is needed to use EXPECT_NONFATAL_FAILURE.
#include "testing/gtest/include/gtest/gtest-spi.h"
......
// Copyright 2018 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/command_line.h"
namespace chrome_cleaner {
void OverrideTestCommandLine(base::CommandLine* command_line) {
// Do nothing.
}
} // namespace chrome_cleaner
......@@ -21,14 +21,17 @@ def AddImportPath(path):
def GetBuildDirectory(build_configuration):
"""Returns the path to the build directory relative to this file. Will assert
if not used from inside the source tree.
"""Returns the path to the build directory relative to this file.
Args:
build_configuration: name of the build configuration whose directory
should be looked up, e.g. 'Debug' or 'Release'.
Returns:
Path to the build directory or None if used from outside the source tree.
"""
assert(_InSourceTree())
if not _InSourceTree():
return None
return os.path.join(_ROOT_DIRECTORY, 'out', build_configuration)
......@@ -38,6 +41,7 @@ def AddProtosToPath(root_path):
Args:
root_path: root directory where the pyproto subdir is located.
"""
assert root_path is not None
# Add the root pyproto dir so Python packages under that dir (such as
# google.protobuf, which is built by //third_party/protobuf:py_proto) can be
# imported with fully-qualified package names. (eg. "from google.protobuf
......
......@@ -26,8 +26,6 @@ bool ChromeProxyMainDialog::Create() {
return true;
}
void ChromeProxyMainDialog::StartScanning() {}
void ChromeProxyMainDialog::NoPUPsFound() {
chrome_prompt_ipc_->PostPromptUserTask(
std::vector<base::FilePath>(), std::vector<base::string16>(),
......@@ -49,8 +47,6 @@ void ChromeProxyMainDialog::ConfirmCleanup(
base::SequencedTaskRunnerHandle::Get()));
}
void ChromeProxyMainDialog::StartCleanup(size_t num_pups) {}
void ChromeProxyMainDialog::CleanupDone(ResultCode cleanup_result) {
delegate()->OnClose();
}
......
......@@ -29,9 +29,7 @@ class ChromeProxyMainDialog : public MainDialogAPI {
// MainDialogAPI overrides.
bool Create() override;
void StartScanning() override;
void NoPUPsFound() override;
void StartCleanup(size_t num_pups) override;
void CleanupDone(ResultCode cleanup_result) override;
void Close() override;
......
......@@ -45,10 +45,6 @@ TEST_F(ChromeProxyMainDialogTest, Create) {
dialog_->Create();
}
TEST_F(ChromeProxyMainDialogTest, StartScanning) {
dialog_->StartScanning();
}
TEST_F(ChromeProxyMainDialogTest, NoPUPsFound) {
base::MessageLoopForUI ui_message_loop_;
......@@ -66,10 +62,6 @@ TEST_F(ChromeProxyMainDialogTest, NoPUPsFound) {
run_loop.Run();
}
TEST_F(ChromeProxyMainDialogTest, StartCleanup) {
dialog_->StartCleanup(10);
}
TEST_F(ChromeProxyMainDialogTest, CleanupDone) {
EXPECT_CALL(delegate_, OnClose()).Times(1);
dialog_->CleanupDone(RESULT_CODE_SUCCESS);
......
......@@ -38,15 +38,9 @@ class MainDialogAPI {
// Create the dialog. This must be called before any of the other methods.
virtual bool Create() = 0;
// Set the dialog to a "scanning in progress" state.
virtual void StartScanning() = 0;
// Show the "No PUPs found" message.
virtual void NoPUPsFound() = 0;
// Set the dialog to a "cleanup in progress" state.
virtual void StartCleanup(size_t num_pups) = 0;
// Set the dialog to the "done cleanup" state. The message to be displayed
// depends on the value of |cleanup_result|.
virtual void CleanupDone(ResultCode cleanup_result) = 0;
......
......@@ -19,8 +19,6 @@ bool SilentMainDialog::Create() {
return true;
}
void SilentMainDialog::StartScanning() {}
void SilentMainDialog::NoPUPsFound() {
delegate()->OnClose();
}
......@@ -32,8 +30,6 @@ void SilentMainDialog::ConfirmCleanup(
delegate()->AcceptedCleanup(true);
}
void SilentMainDialog::StartCleanup(size_t num_pups) {}
void SilentMainDialog::CleanupDone(ResultCode cleanup_result) {
delegate()->OnClose();
}
......
......@@ -25,9 +25,7 @@ class SilentMainDialog : public MainDialogAPI {
// MainDialogAPI overrides.
bool Create() override;
void StartScanning() override;
void NoPUPsFound() override;
void StartCleanup(size_t num_pups) override;
void CleanupDone(ResultCode cleanup_result) override;
void Close() override;
......
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