Commit 24b92bba authored by Joe Mason's avatar Joe Mason Committed by Commit Bot

Add generate_test_uws binary for use with chrome_cleaner

R=proberge@chromium.org

Bug: 1001604
Change-Id: Ia3be398a3340911ae0f3044188154e20c9567f80
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790284Reviewed-by: default avatarproberge <proberge@chromium.org>
Commit-Queue: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/master@{#694363}
parent 4d10ad60
...@@ -213,6 +213,7 @@ source_set("integration_test_sources") { ...@@ -213,6 +213,7 @@ source_set("integration_test_sources") {
sources = [ sources = [
"cleaner_test.cc", "cleaner_test.cc",
"generate_test_uws_test.cc",
"secure_dll_loading_test.cc", "secure_dll_loading_test.cc",
] ]
...@@ -239,6 +240,7 @@ source_set("integration_test_sources") { ...@@ -239,6 +240,7 @@ source_set("integration_test_sources") {
":empty_dll", ":empty_dll",
"//chrome/chrome_cleaner/executables:chrome_cleanup_tool", "//chrome/chrome_cleaner/executables:chrome_cleanup_tool",
"//chrome/chrome_cleaner/executables:software_reporter_tool", "//chrome/chrome_cleaner/executables:software_reporter_tool",
"//chrome/chrome_cleaner/tools:generate_test_uws",
] ]
} }
......
// Copyright 2019 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/base_paths_win.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/strings/string16.h"
#include "base/test/test_timeouts.h"
#include "chrome/chrome_cleaner/pup_data/test_uws.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
TEST(GenerateTestUwsTest, WriteTestUwS) {
// Ensure the expected output files don't exist.
base::FilePath start_menu_path;
ASSERT_TRUE(base::PathService::Get(base::DIR_START_MENU, &start_menu_path));
base::FilePath startup_dir =
start_menu_path.Append(STRING16_LITERAL("Startup"));
base::FilePath uws_file_a =
startup_dir.Append(chrome_cleaner::kTestUwsAFilename);
ASSERT_TRUE(base::DeleteFile(uws_file_a, /*recursive=*/false));
base::FilePath uws_file_b =
startup_dir.Append(chrome_cleaner::kTestUwsBFilename);
ASSERT_TRUE(base::DeleteFile(uws_file_b, /*recursive=*/false));
// Delete the output files on exit, including on early exit.
base::ScopedClosureRunner delete_uws_file_a(base::BindOnce(
base::IgnoreResult(&base::DeleteFile), uws_file_a, /*recursive=*/false));
base::ScopedClosureRunner delete_uws_file_b(base::BindOnce(
base::IgnoreResult(&base::DeleteFile), uws_file_b, /*recursive=*/false));
// Expect generate_test_uws to finish quickly with exit code 0 (success).
base::Process process(base::LaunchProcess(
STRING16_LITERAL("generate_test_uws.exe"), base::LaunchOptions()));
ASSERT_TRUE(process.IsValid());
int exit_code = -1;
bool exited_within_timeout = process.WaitForExitWithTimeout(
TestTimeouts::action_timeout(), &exit_code);
EXPECT_TRUE(exited_within_timeout);
EXPECT_EQ(exit_code, 0);
if (!exited_within_timeout)
process.Terminate(/*exit_code=*/-1, /*wait=*/false);
// Verify that generate_test_uws created the expected files.
std::string uws_file_contents_a;
EXPECT_TRUE(base::ReadFileToStringWithMaxSize(
uws_file_a, &uws_file_contents_a,
chrome_cleaner::kTestUwsAFileContentsSize))
<< uws_file_a;
EXPECT_EQ(uws_file_contents_a, chrome_cleaner::kTestUwsAFileContents);
std::string uws_file_contents_b;
EXPECT_TRUE(base::ReadFileToStringWithMaxSize(
uws_file_b, &uws_file_contents_b,
chrome_cleaner::kTestUwsBFileContentsSize))
<< uws_file_b;
EXPECT_EQ(uws_file_contents_b, chrome_cleaner::kTestUwsBFileContents);
}
} // namespace
# Copyright 2019 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.
# Nothing outside //chrome/chrome_cleaner can depend on these targets.
visibility = [ "//chrome/chrome_cleaner/*" ]
# We need at least one non-executable to prevent an "unused visibility
# declaration" warning.
source_set("generate_test_uws_src") {
sources = [
"generate_test_uws.cc",
]
deps = [
"//base:base",
"//chrome/chrome_cleaner/pup_data:test_uws",
]
}
executable("generate_test_uws") {
deps = [
":generate_test_uws_src",
"//build/win:default_exe_manifest",
]
}
// Copyright 2019 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/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/chrome_cleaner/pup_data/test_uws.h"
int main(int argc, char** argv) {
base::FilePath start_menu_folder;
CHECK(base::PathService::Get(base::DIR_START_MENU, &start_menu_folder));
base::FilePath startup_dir = start_menu_folder.Append(L"Startup");
base::FilePath google_test_a =
startup_dir.Append(chrome_cleaner::kTestUwsAFilename);
if (base::WriteFile(google_test_a, chrome_cleaner::kTestUwsAFileContents,
chrome_cleaner::kTestUwsAFileContentsSize) == -1) {
PLOG(ERROR) << "Failed to create test UwS at " << google_test_a;
return 1;
}
base::FilePath google_test_b =
startup_dir.Append(chrome_cleaner::kTestUwsBFilename);
if (base::WriteFile(google_test_b, chrome_cleaner::kTestUwsBFileContents,
chrome_cleaner::kTestUwsBFileContentsSize) == -1) {
PLOG(ERROR) << "Failed to create test UwS at " << google_test_b;
return 1;
}
LOG(INFO) << "Test UwS successfully generated in " << startup_dir;
return 0;
}
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