chromium/content/public/test/browser_test_base.cc

// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/public/test/browser_test_base.h"

#include <fcntl.h>
#include <stddef.h>

#include <iostream>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/base_switches.h"
#include "base/callback_list.h"
#include "base/command_line.h"
#include "base/debug/stack_trace.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/system/sys_info.h"
#include "base/task/current_thread.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/bind.h"
#include "base/test/scoped_run_loop_timeout.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/trace_event/typed_macros.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
#include "components/tracing/common/tracing_switches.h"
#include "components/variations/variations_ids_provider.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/network_service_instance_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/scheduler/browser_task_executor.h"
#include "content/browser/startup_data_impl.h"
#include "content/browser/startup_helper.h"
#include "content/browser/storage_partition_impl.h"
#include "content/browser/tracing/background_tracing_manager_impl.h"
#include "content/browser/tracing/memory_instrumentation_util.h"
#include "content/browser/tracing/startup_tracing_controller.h"
#include "content/browser/tracing/tracing_controller_impl.h"
#include "content/public/app/content_main.h"
#include "content/public/app/initialize_mojo_core.h"
#include "content/public/browser/browser_main_parts.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/network_service_util.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_client.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/main_function_params.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/test_utils.h"
#include "content/test/content_browser_consistency_checker.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/config/gpu_switches.h"
#include "media/base/media_switches.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "net/dns/mock_host_resolver.h"
#include "net/dns/public/dns_over_https_server_config.h"
#include "net/dns/public/secure_dns_mode.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_service_test.mojom.h"
#include "services/tracing/public/cpp/trace_startup.h"
#include "ui/base/ui_base_features.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/display_switches.h"
#include "ui/gfx/animation/animation_test_api.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_switches.h"

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "ui/platform_window/common/platform_window_defaults.h"  // nogncheck
#endif

#if BUILDFLAG(IS_ANDROID)
#include "base/android/task_scheduler/post_task_android.h"
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"  // nogncheck
#include "content/app/content_main_runner_impl.h"
#include "content/app/mojo/mojo_init.h"
#include "content/app/mojo_ipc_support.h"
#include "content/public/app/content_main_delegate.h"
#include "content/public/common/content_paths.h"
#include "testing/android/native_test/native_browser_test_support.h"
#include "ui/base/ui_base_paths.h"
#endif

#if BUILDFLAG(IS_MAC)
#include "content/browser/sandbox_parameters_mac.h"
#include "net/test/test_data_directory.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/test/event_generator_delegate_mac.h"
#endif

#if BUILDFLAG(IS_POSIX)
#include "base/process/process_handle.h"
#endif

#if defined(USE_AURA)
#include "content/browser/compositor/image_transport_factory.h"
#include "ui/aura/test/event_generator_delegate_aura.h"  // nogncheck
#endif

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "base/files/scoped_file.h"
#include "chromeos/crosapi/cpp/crosapi_constants.h"  // nogncheck
#include "chromeos/startup/browser_params_proxy.h"
#include "chromeos/startup/startup_switches.h"  // nogncheck
#include "mojo/public/cpp/platform/socket_utils_posix.h"
#endif

#if BUILDFLAG(IS_FUCHSIA)
#include "base/fuchsia/system_info.h"
#include "ui/platform_window/fuchsia/initialize_presenter_api_view.h"
#endif  // BUILDFLAG(IS_FUCHSIA)

#if BUILDFLAG(IS_WIN)
#include <shlobj.h>

#include "base/files/file_util.h"
#include "base/test/test_reg_util_win.h"
#endif  // BUILDFLAG(IS_WIN)

namespace content {

namespace {

// Whether an instance of BrowserTestBase has already been created in this
// process. Browser tests should each be run in a new process.
bool g_instance_already_created =;

#if BUILDFLAG(IS_POSIX)
// On SIGSEGV or SIGTERM (sent by the runner on timeouts), dump a stack trace
// (to make debugging easier) and also exit with a known error code (so that
// the test framework considers this a failure -- http://crbug.com/57578).
// Note: We only want to do this in the browser process, and not forked
// processes. That might lead to hangs because of locks inside the OS.
// See http://crbug.com/141302.
int g_browser_process_pid;

// A shutdown function set on signal callback registration.
base::OnceCallback<void(int)> ShutdownHandler;

void SignalHandler(int signal) {}
#endif  // BUILDFLAG(IS_POSIX)

void RunTaskOnRendererThread(base::OnceClosure task,
                             base::OnceClosure quit_task) {}

enum class TraceBasenameType {};

std::string GetDefaultTraceBasename(TraceBasenameType type) {}

// See SetInitialWebContents comment for more information.
class InitialNavigationObserver : public WebContentsObserver {};

}  // namespace

BrowserTestBase::BrowserTestBase() {}

BrowserTestBase::~BrowserTestBase() {}

void BrowserTestBase::SetUp() {}

void BrowserTestBase::TearDown() {}

bool BrowserTestBase::UseProductionQuotaSettings() {}

void BrowserTestBase::SimulateNetworkServiceCrash() {}

void BrowserTestBase::IgnoreNetworkServiceCrashes() {}

#if BUILDFLAG(IS_ANDROID)
void BrowserTestBase::WaitUntilJavaIsReady(
    base::OnceClosure quit_closure,
    const base::TimeDelta& wait_retry_left) {
  CHECK_GE(wait_retry_left.InMilliseconds(), 0)
      << "WaitUntilJavaIsReady() timed out.";

  if (testing::android::JavaAsyncStartupTasksCompleteForBrowserTests()) {
    std::move(quit_closure).Run();
    return;
  }

  base::TimeDelta retry_interval = base::Milliseconds(100);
  base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
      FROM_HERE,
      base::BindOnce(&BrowserTestBase::WaitUntilJavaIsReady,
                     base::Unretained(this), std::move(quit_closure),
                     wait_retry_left - retry_interval),
      retry_interval);
  return;
}
#endif

void BrowserTestBase::ProxyRunTestOnMainThreadLoop() {}

void BrowserTestBase::SetAllowNetworkAccessToHostResolutions() {}

void BrowserTestBase::SetReplaceSystemDnsConfig() {}

void BrowserTestBase::SetTestDohConfig(net::SecureDnsMode secure_dns_mode,
                                       net::DnsOverHttpsConfig config) {}

void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) {}

void BrowserTestBase::PostTaskToInProcessRendererAndWait(
    base::OnceClosure task) {}

void BrowserTestBase::EnablePixelOutput(float force_device_scale_factor) {}

void BrowserTestBase::UseSoftwareCompositing() {}

void BrowserTestBase::SetInitialWebContents(WebContents* web_contents) {}

void BrowserTestBase::AssertThatNetworkServiceDidNotCrash() {}

void BrowserTestBase::ForceInitializeNetworkProcess() {}

void BrowserTestBase::InitializeNetworkProcess() {}

void BrowserTestBase::CreatedBrowserMainPartsImpl(
    BrowserMainParts* browser_main_parts) {}

ContentMainDelegate* BrowserTestBase::GetOptionalContentMainDelegateOverride() {}

}  // namespace content