2016-11-16 21:24:13 +01:00
|
|
|
// Copyright 2016 The Chromium Embedded Framework Authors. Postions copyright
|
|
|
|
// 2012 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.
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_suite.h"
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2022-08-03 02:51:02 +02:00
|
|
|
#include "include/base/cef_logging.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "include/cef_file_util.h"
|
2022-08-03 02:51:02 +02:00
|
|
|
#include "include/test/cef_test_helpers.h"
|
2021-04-07 00:09:45 +02:00
|
|
|
#include "include/wrapper/cef_scoped_temp_dir.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
2021-06-24 22:52:37 +02:00
|
|
|
#include "tests/gtest/teamcity/include/teamcity_gtest.h"
|
2022-08-03 02:51:02 +02:00
|
|
|
#include "tests/shared/browser/resource_util.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/common/client_switches.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
namespace {
|
2014-07-15 00:18:51 +02:00
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
CefTestSuite* g_test_suite = nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
#if defined(OS_WIN)
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
// From base/process/launch_win.cc.
|
|
|
|
void RouteStdioToConsole(bool create_console_if_not_found) {
|
|
|
|
// Don't change anything if stdout or stderr already point to a
|
|
|
|
// valid stream.
|
|
|
|
//
|
|
|
|
// If we are running under Buildbot or under Cygwin's default
|
|
|
|
// terminal (mintty), stderr and stderr will be pipe handles. In
|
|
|
|
// that case, we don't want to open CONOUT$, because its output
|
|
|
|
// likely does not go anywhere.
|
|
|
|
//
|
|
|
|
// We don't use GetStdHandle() to check stdout/stderr here because
|
|
|
|
// it can return dangling IDs of handles that were never inherited
|
|
|
|
// by this process. These IDs could have been reused by the time
|
|
|
|
// this function is called. The CRT checks the validity of
|
|
|
|
// stdout/stderr on startup (before the handle IDs can be reused).
|
|
|
|
// _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was
|
|
|
|
// invalid.
|
|
|
|
if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
|
|
|
|
unsigned int result = GetLastError();
|
|
|
|
// Was probably already attached.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (result == ERROR_ACCESS_DENIED) {
|
2016-11-16 21:24:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-16 21:24:13 +01:00
|
|
|
// Don't bother creating a new console for each child process if the
|
|
|
|
// parent process is invalid (eg: crashed).
|
2023-01-02 23:59:03 +01:00
|
|
|
if (result == ERROR_GEN_FAILURE) {
|
2016-11-16 21:24:13 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-11-16 21:24:13 +01:00
|
|
|
if (create_console_if_not_found) {
|
|
|
|
// Make a new console if attaching to parent fails with any other error.
|
|
|
|
// It should be ERROR_INVALID_HANDLE at this point, which means the
|
|
|
|
// browser was likely not started from a console.
|
|
|
|
AllocConsole();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arbitrary byte count to use when buffering output lines. More
|
|
|
|
// means potential waste, less means more risk of interleaved
|
|
|
|
// log-lines in output.
|
|
|
|
enum { kOutputBufferSize = 64 * 1024 };
|
|
|
|
|
|
|
|
if (freopen("CONOUT$", "w", stdout)) {
|
|
|
|
setvbuf(stdout, nullptr, _IOLBF, kOutputBufferSize);
|
|
|
|
// Overwrite FD 1 for the benefit of any code that uses this FD
|
|
|
|
// directly. This is safe because the CRT allocates FDs 0, 1 and
|
|
|
|
// 2 at startup even if they don't have valid underlying Windows
|
|
|
|
// handles. This means we won't be overwriting an FD created by
|
|
|
|
// _open() after startup.
|
|
|
|
_dup2(_fileno(stdout), 1);
|
|
|
|
}
|
|
|
|
if (freopen("CONOUT$", "w", stderr)) {
|
|
|
|
setvbuf(stderr, nullptr, _IOLBF, kOutputBufferSize);
|
|
|
|
_dup2(_fileno(stderr), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix all cout, wcout, cin, wcin, cerr, wcerr, clog and wclog.
|
|
|
|
std::ios::sync_with_stdio();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(OS_WIN)
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CefTestSuite::CefTestSuite(int argc, char** argv)
|
2024-01-20 18:00:09 +01:00
|
|
|
: argc_(argc), argv_(argc, argv) {
|
2016-11-16 21:24:13 +01:00
|
|
|
g_test_suite = this;
|
|
|
|
|
|
|
|
// Keep a representation of the original command-line.
|
|
|
|
command_line_ = CefCommandLine::CreateCommandLine();
|
2012-04-03 03:34:16 +02:00
|
|
|
#if defined(OS_WIN)
|
2016-11-16 21:24:13 +01:00
|
|
|
command_line_->InitFromString(::GetCommandLineW());
|
|
|
|
#else
|
|
|
|
command_line_->InitFromArgv(argc, argv);
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif
|
2021-04-07 00:09:45 +02:00
|
|
|
|
|
|
|
if (!command_line_->HasSwitch("type")) {
|
|
|
|
// Initialize in the main process only.
|
|
|
|
root_cache_path_ =
|
|
|
|
command_line_->GetSwitchValue(client::switches::kCachePath);
|
|
|
|
if (root_cache_path_.empty()) {
|
|
|
|
CefScopedTempDir temp_dir;
|
|
|
|
CHECK(temp_dir.CreateUniqueTempDir());
|
|
|
|
root_cache_path_ = temp_dir.Take();
|
|
|
|
RegisterTempDirectory(root_cache_path_);
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
CefTestSuite::~CefTestSuite() {
|
|
|
|
g_test_suite = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// static
|
2016-11-16 21:24:13 +01:00
|
|
|
CefTestSuite* CefTestSuite::GetInstance() {
|
|
|
|
return g_test_suite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefTestSuite::InitMainProcess() {
|
|
|
|
PreInitialize();
|
|
|
|
|
|
|
|
// This will modify |argc_| and |argv_|.
|
|
|
|
testing::InitGoogleTest(&argc_, argv_.array());
|
2021-06-24 22:52:37 +02:00
|
|
|
|
|
|
|
if (jetbrains::teamcity::underTeamcity()) {
|
|
|
|
auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
|
|
|
|
listeners.Append(
|
|
|
|
new jetbrains::teamcity::TeamcityGoogleTestEventListener());
|
|
|
|
}
|
2016-11-16 21:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't add additional code to this method. Instead add it to Initialize().
|
|
|
|
int CefTestSuite::Run() {
|
|
|
|
Initialize();
|
|
|
|
retval_ = RUN_ALL_TESTS();
|
|
|
|
Shutdown();
|
|
|
|
return retval_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefTestSuite::GetSettings(CefSettings& settings) const {
|
2024-04-30 03:09:17 +02:00
|
|
|
#if !defined(DISABLE_ALLOY_BOOTSTRAP)
|
|
|
|
// Enable the Chrome runtime. See issue #2969 for details.
|
2020-09-25 03:40:47 +02:00
|
|
|
settings.chrome_runtime =
|
|
|
|
command_line_->HasSwitch(client::switches::kEnableChromeRuntime);
|
2024-04-30 03:09:17 +02:00
|
|
|
#endif
|
2020-09-25 03:40:47 +02:00
|
|
|
|
2021-04-07 00:09:45 +02:00
|
|
|
CefString(&settings.cache_path) = root_cache_path_;
|
|
|
|
CefString(&settings.root_cache_path) = root_cache_path_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Always expose the V8 gc() function to give tests finer-grained control over
|
|
|
|
// memory management.
|
|
|
|
std::string javascript_flags = "--expose-gc";
|
2012-06-12 17:53:39 +02:00
|
|
|
// Value of kJavascriptFlags switch.
|
2012-04-03 03:34:16 +02:00
|
|
|
std::string other_javascript_flags =
|
2016-11-16 21:24:13 +01:00
|
|
|
command_line_->GetSwitchValue("js-flags");
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!other_javascript_flags.empty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
javascript_flags += " " + other_javascript_flags;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
CefString(&settings.javascript_flags) = javascript_flags;
|
2012-11-02 19:16:28 +01:00
|
|
|
|
|
|
|
// Necessary for V8Test.OnUncaughtException tests.
|
|
|
|
settings.uncaught_exception_stack_size = 10;
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
// Necessary for the OSRTest tests.
|
|
|
|
settings.windowless_rendering_enabled = true;
|
2015-02-18 18:28:56 +01:00
|
|
|
|
|
|
|
// For Accept-Language test
|
|
|
|
CefString(&settings.accept_language_list) = CEF_SETTINGS_ACCEPT_LANGUAGE;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void CefTestSuite::RegisterTempDirectory(const CefString& directory) {
|
|
|
|
base::AutoLock lock_scope(temp_directories_lock_);
|
|
|
|
temp_directories_.push_back(directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefTestSuite::DeleteTempDirectories() {
|
|
|
|
base::AutoLock lock_scope(temp_directories_lock_);
|
2024-01-20 18:00:09 +01:00
|
|
|
for (const auto& temp_directory : temp_directories_) {
|
|
|
|
CefDeleteFile(temp_directory, true);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
temp_directories_.clear();
|
|
|
|
}
|
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
void CefTestSuite::PreInitialize() {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
testing::GTEST_FLAG(catch_exceptions) = false;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
// Enable termination on heap corruption.
|
|
|
|
// Ignore the result code. Supported starting with XP SP3 and Vista.
|
2020-01-15 14:34:01 +01:00
|
|
|
HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);
|
2016-11-16 21:24:13 +01:00
|
|
|
#endif
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2021-02-23 21:08:33 +01:00
|
|
|
#if defined(OS_LINUX)
|
2016-11-16 21:24:13 +01:00
|
|
|
// When calling native char conversion functions (e.g wrctomb) we need to
|
|
|
|
// have the locale set. In the absence of such a call the "C" locale is the
|
|
|
|
// default. In the gtk code (below) gtk_init() implicitly sets a locale.
|
|
|
|
setlocale(LC_ALL, "");
|
2021-02-23 21:08:33 +01:00
|
|
|
#endif // defined(OS_LINUX)
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-11-16 21:24:13 +01:00
|
|
|
// Don't add additional code to this function. Instead add it to Initialize().
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2016-11-16 21:24:13 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefTestSuite::Initialize() {
|
2016-11-16 21:24:13 +01:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
RouteStdioToConsole(true);
|
|
|
|
#endif // defined(OS_WIN)
|
2022-08-03 02:51:02 +02:00
|
|
|
|
|
|
|
#if !defined(CEF_TESTS_IN_SRC_DIRECTORY)
|
|
|
|
// Configure the directory that contains test data resources.
|
|
|
|
std::string resource_dir;
|
|
|
|
bool result = client::GetResourceDir(resource_dir);
|
|
|
|
CHECK(result && !resource_dir.empty());
|
|
|
|
CefSetDataDirectoryForTests(resource_dir);
|
|
|
|
#endif // !defined(CEF_TESTS_IN_SRC_DIRECTORY)
|
2017-05-17 11:29:28 +02:00
|
|
|
}
|
2016-11-16 21:24:13 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefTestSuite::Shutdown() {}
|