2011-10-06 15:34:47 +02:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework 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-01-10 00:46:23 +01:00
|
|
|
#include "tests/unittests/test_suite.h"
|
2012-10-29 22:54:57 +01:00
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "tests/cefclient/cefclient_switches.h"
|
2011-10-06 15:34:47 +02:00
|
|
|
#include "base/command_line.h"
|
2011-12-30 21:55:16 +01:00
|
|
|
#include "base/logging.h"
|
2011-10-06 15:34:47 +02:00
|
|
|
#include "base/test/test_suite.h"
|
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
#if defined(OS_MACOSX)
|
2012-11-06 18:13:58 +01:00
|
|
|
#include "base/debug/stack_trace.h"
|
2013-03-13 19:14:36 +01:00
|
|
|
#include "base/files/file_path.h"
|
2011-12-30 21:55:16 +01:00
|
|
|
#include "base/i18n/icu_util.h"
|
|
|
|
#include "base/path_service.h"
|
|
|
|
#include "base/process_util.h"
|
|
|
|
#include "base/test/test_timeouts.h"
|
|
|
|
#endif
|
2011-10-06 15:34:47 +02:00
|
|
|
|
2012-10-29 22:54:57 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Return the int representation of the specified string.
|
|
|
|
int GetIntValue(const std::string& str) {
|
|
|
|
if (str.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return atoi(str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
CommandLine* CefTestSuite::commandline_ = NULL;
|
2011-10-06 15:34:47 +02:00
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
CefTestSuite::CefTestSuite(int argc, char** argv)
|
|
|
|
: TestSuite(argc, argv) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefTestSuite::InitCommandLine(int argc, const char* const* argv) {
|
2011-12-30 21:55:16 +01:00
|
|
|
if (commandline_) {
|
|
|
|
// If this is intentional, Reset() must be called first. If we are using
|
|
|
|
// the shared build mode, we have to share a single object across multiple
|
|
|
|
// shared libraries.
|
|
|
|
return;
|
2011-10-06 15:34:47 +02:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
commandline_ = new CommandLine(CommandLine::NO_PROGRAM);
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
commandline_->ParseFromString(::GetCommandLineW());
|
|
|
|
#elif defined(OS_POSIX)
|
|
|
|
commandline_->InitFromArgv(argc, argv);
|
|
|
|
#endif
|
2011-10-06 15:34:47 +02:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
// static
|
|
|
|
void CefTestSuite::GetSettings(CefSettings& settings) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
settings.multi_threaded_message_loop =
|
|
|
|
commandline_->HasSwitch(cefclient::kMultiThreadedMessageLoop);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CefString(&settings.cache_path) =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kCachePath);
|
|
|
|
CefString(&settings.user_agent) =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kUserAgent);
|
|
|
|
CefString(&settings.product_version) =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kProductVersion);
|
|
|
|
CefString(&settings.locale) =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kLocale);
|
|
|
|
CefString(&settings.log_file) =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kLogFile);
|
2011-10-06 15:34:47 +02:00
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
{
|
|
|
|
std::string str =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kLogSeverity);
|
|
|
|
bool invalid = false;
|
|
|
|
if (!str.empty()) {
|
|
|
|
if (str == cefclient::kLogSeverity_Verbose)
|
|
|
|
settings.log_severity = LOGSEVERITY_VERBOSE;
|
|
|
|
else if (str == cefclient::kLogSeverity_Info)
|
|
|
|
settings.log_severity = LOGSEVERITY_INFO;
|
|
|
|
else if (str == cefclient::kLogSeverity_Warning)
|
|
|
|
settings.log_severity = LOGSEVERITY_WARNING;
|
|
|
|
else if (str == cefclient::kLogSeverity_Error)
|
|
|
|
settings.log_severity = LOGSEVERITY_ERROR;
|
|
|
|
else if (str == cefclient::kLogSeverity_ErrorReport)
|
|
|
|
settings.log_severity = LOGSEVERITY_ERROR_REPORT;
|
|
|
|
else if (str == cefclient::kLogSeverity_Disable)
|
|
|
|
settings.log_severity = LOGSEVERITY_DISABLE;
|
|
|
|
else
|
|
|
|
invalid = true;
|
|
|
|
}
|
|
|
|
if (str.empty() || invalid) {
|
|
|
|
#ifdef NDEBUG
|
|
|
|
// Only log error messages and higher in release build.
|
|
|
|
settings.log_severity = LOGSEVERITY_ERROR;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 20:04:11 +01:00
|
|
|
settings.release_dcheck_enabled =
|
|
|
|
commandline_->HasSwitch(cefclient::kReleaseDcheckEnabled);
|
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
{
|
|
|
|
std::string str =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kGraphicsImpl);
|
|
|
|
if (!str.empty()) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
if (str == cefclient::kGraphicsImpl_Angle)
|
|
|
|
settings.graphics_implementation = ANGLE_IN_PROCESS;
|
|
|
|
else if (str == cefclient::kGraphicsImpl_AngleCmdBuffer)
|
|
|
|
settings.graphics_implementation = ANGLE_IN_PROCESS_COMMAND_BUFFER;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (str == cefclient::kGraphicsImpl_Desktop)
|
|
|
|
settings.graphics_implementation = DESKTOP_IN_PROCESS;
|
|
|
|
else if (str == cefclient::kGraphicsImpl_DesktopCmdBuffer)
|
|
|
|
settings.graphics_implementation = DESKTOP_IN_PROCESS_COMMAND_BUFFER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.local_storage_quota = atoi(commandline_->GetSwitchValueASCII(
|
|
|
|
cefclient::kLocalStorageQuota).c_str());
|
|
|
|
settings.session_storage_quota = atoi(commandline_->GetSwitchValueASCII(
|
|
|
|
cefclient::kSessionStorageQuota).c_str());
|
|
|
|
|
2012-01-19 20:12:15 +01:00
|
|
|
// Always expose the V8 gc() function to give tests finer-grained control over
|
|
|
|
// memory management.
|
|
|
|
std::string javascript_flags = "--expose-gc";
|
|
|
|
std::string other_javascript_flags =
|
2011-12-30 21:55:16 +01:00
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kJavascriptFlags);
|
2012-01-19 20:12:15 +01:00
|
|
|
if (!other_javascript_flags.empty())
|
|
|
|
javascript_flags += " " + other_javascript_flags;
|
|
|
|
CefString(&settings.javascript_flags) = javascript_flags;
|
2012-02-16 18:11:49 +01:00
|
|
|
|
2012-09-06 00:34:30 +02:00
|
|
|
CefString(&settings.resources_dir_path) =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kResourcesDirPath);
|
2012-02-16 18:11:49 +01:00
|
|
|
CefString(&settings.locales_dir_path) =
|
|
|
|
commandline_->GetSwitchValueASCII(cefclient::kLocalesDirPath);
|
|
|
|
|
|
|
|
settings.pack_loading_disabled =
|
|
|
|
commandline_->HasSwitch(cefclient::kPackLoadingDisabled);
|
2012-10-12 18:38:24 +02:00
|
|
|
|
|
|
|
// Necessary for V8Test.OnUncaughtException tests.
|
|
|
|
settings.uncaught_exception_stack_size = 10;
|
2012-10-29 22:54:57 +01:00
|
|
|
|
|
|
|
settings.context_safety_implementation = GetIntValue(
|
|
|
|
commandline_->GetSwitchValueASCII(
|
|
|
|
cefclient::kContextSafetyImplementation));
|
2011-10-06 15:34:47 +02:00
|
|
|
}
|
2011-11-02 20:50:00 +01:00
|
|
|
|
|
|
|
// static
|
|
|
|
bool CefTestSuite::GetCachePath(std::string& path) {
|
2011-12-30 21:55:16 +01:00
|
|
|
DCHECK(commandline_);
|
2011-11-02 20:50:00 +01:00
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
if (commandline_->HasSwitch(cefclient::kCachePath)) {
|
2011-11-02 20:50:00 +01:00
|
|
|
// Set the cache_path value.
|
2011-12-30 21:55:16 +01:00
|
|
|
path = commandline_->GetSwitchValueASCII(cefclient::kCachePath);
|
2011-11-02 20:50:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-30 21:55:16 +01:00
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
void CefTestSuite::Initialize() {
|
|
|
|
// The below code is copied from base/test/test_suite.cc to avoid calling
|
|
|
|
// RegisterMockCrApp() on Mac.
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
// Initialize logging.
|
2013-02-28 23:33:49 +01:00
|
|
|
base::FilePath exe;
|
2011-12-30 21:55:16 +01:00
|
|
|
PathService::Get(base::FILE_EXE, &exe);
|
2013-02-28 23:33:49 +01:00
|
|
|
base::FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log"));
|
2011-12-30 21:55:16 +01:00
|
|
|
logging::InitLogging(
|
|
|
|
log_filename.value().c_str(),
|
|
|
|
logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
|
|
|
|
logging::LOCK_LOG_FILE,
|
|
|
|
logging::DELETE_OLD_LOG_FILE,
|
|
|
|
logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
|
|
|
|
// We want process and thread IDs because we may have multiple processes.
|
|
|
|
// Note: temporarily enabled timestamps in an effort to catch bug 6361.
|
|
|
|
logging::SetLogItems(true, true, true, true);
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2012-11-06 18:13:58 +01:00
|
|
|
CHECK(base::debug::EnableInProcessStackDumping());
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
// In some cases, we do not want to see standard error dialogs.
|
|
|
|
if (!base::debug::BeingDebugged() &&
|
|
|
|
!CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) {
|
|
|
|
SuppressErrorDialogs();
|
|
|
|
base::debug::SetSuppressDebugUI(true);
|
|
|
|
logging::SetLogAssertHandler(UnitTestAssertHandler);
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
icu_util::Initialize();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
CatchMaybeTests();
|
|
|
|
ResetCommandLine();
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2011-12-30 21:55:16 +01:00
|
|
|
TestTimeouts::Initialize();
|
|
|
|
}
|
2012-01-10 00:46:23 +01:00
|
|
|
#endif // defined(OS_MACOSX)
|