#include "media/gpu/test/video_test_environment.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.h"
#include "build/build_config.h"
#include "media/gpu/buildflags.h"
#include "mojo/core/embedder/embedder.h"
#if BUILDFLAG(USE_VAAPI)
#include "media/gpu/vaapi/vaapi_wrapper.h"
#endif
#if BUILDFLAG(IS_OZONE)
#include "ui/ozone/public/ozone_platform.h"
#endif
namespace media {
namespace test {
VideoTestEnvironment::VideoTestEnvironment() : VideoTestEnvironment({}, {}) {}
VideoTestEnvironment::VideoTestEnvironment(
const std::vector<base::test::FeatureRef>& enabled_features,
const std::vector<base::test::FeatureRef>& disabled_features) {
mojo::core::Init();
logging::LoggingSettings settings;
settings.logging_dest =
logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
if (!logging::InitLogging(settings))
ADD_FAILURE();
TestTimeouts::Initialize();
task_environment_ = std::make_unique<base::test::TaskEnvironment>(
base::test::TaskEnvironment::MainThreadType::UI);
scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features);
#if BUILDFLAG(IS_OZONE)
LOG(WARNING) << "Initializing Ozone Platform...\n"
"If this hangs indefinitely please call 'stop ui' first!";
ui::OzonePlatform::InitParams params;
params.single_process = true;
ui::OzonePlatform::InitializeForUI(params);
ui::OzonePlatform::InitializeForGPU(params);
#endif
#if BUILDFLAG(USE_VAAPI)
media::VaapiWrapper::PreSandboxInitialization();
#endif
}
VideoTestEnvironment::~VideoTestEnvironment() = default;
void VideoTestEnvironment::TearDown() {
task_environment_->RunUntilIdle();
}
base::FilePath VideoTestEnvironment::GetTestOutputFilePath() const {
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
base::FilePath::StringType test_name;
base::FilePath::StringType test_suite_name;
#if BUILDFLAG(IS_WIN)
test_name = base::UTF8ToUTF16(test_info->name());
test_suite_name = base::UTF8ToUTF16(test_info->test_suite_name());
#else
test_name = test_info->name();
test_suite_name = test_info->test_suite_name();
#endif
return base::FilePath(test_suite_name).Append(test_name);
}
}
}