mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Add support for running unit tests without multi-threaded message loop mode (issue #338).
- Mac: Fix unit test expectations. - Mac: cef_time_t.day_of_week is not supported. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@448 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -3,48 +3,163 @@
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "test_suite.h"
|
||||
#include "include/cef_app.h"
|
||||
#include "../cefclient/cefclient_switches.h"
|
||||
#include "base/command_line.h"
|
||||
#include "build/build_config.h"
|
||||
#include "base/threading/platform_thread.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/test/test_suite.h"
|
||||
|
||||
CefTestSuite::CefTestSuite(int argc, char** argv) : TestSuite(argc, argv) {
|
||||
#if defined(OS_MACOSX)
|
||||
#include "base/file_path.h"
|
||||
#include "base/i18n/icu_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/process_util.h"
|
||||
#include "base/test/test_timeouts.h"
|
||||
#endif
|
||||
|
||||
CommandLine* CefTestSuite::commandline_ = NULL;
|
||||
|
||||
CefTestSuite::CefTestSuite(int argc, char** argv)
|
||||
: TestSuite(argc, argv) {
|
||||
}
|
||||
|
||||
void CefTestSuite::Initialize() {
|
||||
TestSuite::Initialize();
|
||||
|
||||
CefSettings settings;
|
||||
settings.multi_threaded_message_loop = true;
|
||||
|
||||
std::string cache_path;
|
||||
if (GetCachePath(cache_path)) {
|
||||
// Set the cache_path value.
|
||||
CefString(&settings.cache_path).FromASCII(cache_path.c_str());
|
||||
// static
|
||||
void CefTestSuite::InitCommandLine(int argc, const char* const* argv)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
CefInitialize(settings, NULL);
|
||||
commandline_ = new CommandLine(CommandLine::NO_PROGRAM);
|
||||
#if defined(OS_WIN)
|
||||
commandline_->ParseFromString(::GetCommandLineW());
|
||||
#elif defined(OS_POSIX)
|
||||
commandline_->InitFromArgv(argc, argv);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CefTestSuite::Shutdown() {
|
||||
// Delay a bit so that the system has a chance to finish destroying windows
|
||||
// before CefShutdown() checks for memory leaks.
|
||||
base::PlatformThread::Sleep(500);
|
||||
// static
|
||||
void CefTestSuite::GetSettings(CefSettings& settings) {
|
||||
#if defined(OS_WIN)
|
||||
settings.multi_threaded_message_loop =
|
||||
commandline_->HasSwitch(cefclient::kMultiThreadedMessageLoop);
|
||||
#endif
|
||||
|
||||
CefShutdown();
|
||||
TestSuite::Shutdown();
|
||||
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);
|
||||
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
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());
|
||||
|
||||
CefString(&settings.javascript_flags) =
|
||||
commandline_->GetSwitchValueASCII(cefclient::kJavascriptFlags);
|
||||
}
|
||||
|
||||
// static
|
||||
bool CefTestSuite::GetCachePath(std::string& path) {
|
||||
CommandLine* command_line = CommandLine::ForCurrentProcess();
|
||||
DCHECK(commandline_);
|
||||
|
||||
if (command_line->HasSwitch("cache_path")) {
|
||||
if (commandline_->HasSwitch(cefclient::kCachePath)) {
|
||||
// Set the cache_path value.
|
||||
path = command_line->GetSwitchValueASCII("cache_path");
|
||||
path = commandline_->GetSwitchValueASCII(cefclient::kCachePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
void CefTestSuite::Initialize() {
|
||||
// The below code is copied from base/test/test_suite.cc to avoid calling
|
||||
// RegisterMockCrApp() on Mac.
|
||||
|
||||
// Initialize logging.
|
||||
FilePath exe;
|
||||
PathService::Get(base::FILE_EXE, &exe);
|
||||
FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log"));
|
||||
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);
|
||||
|
||||
CHECK(base::EnableInProcessStackDumping());
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
icu_util::Initialize();
|
||||
|
||||
CatchMaybeTests();
|
||||
ResetCommandLine();
|
||||
|
||||
TestTimeouts::Initialize();
|
||||
}
|
||||
#endif // defined(OS_MACOSX)
|
||||
|
||||
Reference in New Issue
Block a user