#include <stddef.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/memory/ref_counted_memory.h"
#include "base/metrics/histogram_macros.h"
#include "base/path_service.h"
#include "base/process/process_handle.h"
#include "base/profiler/module_cache.h"
#include "base/run_loop.h"
#include "base/strings/pattern.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/run_until.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_proto_loader.h"
#include "base/test/trace_event_analyzer.h"
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/named_trigger.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "content/browser/devtools/protocol/devtools_protocol_test_support.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/tracing/background_tracing_active_scenario.h"
#include "content/browser/tracing/background_tracing_manager_impl.h"
#include "content/browser/tracing/background_tracing_rule.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/background_tracing_test_support.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "net/dns/mock_host_resolver.h"
#include "services/tracing/perfetto/privacy_filtering_check.h"
#include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h"
#include "services/tracing/public/cpp/trace_startup_config.h"
#include "services/tracing/public/cpp/tracing_features.h"
#include "third_party/perfetto/include/perfetto/ext/trace_processor/export_json.h"
#include "third_party/perfetto/include/perfetto/trace_processor/trace_processor_storage.h"
#include "third_party/re2/src/re2/re2.h"
#include "third_party/zlib/google/compression_utils.h"
#include "third_party/zlib/zlib.h"
TraceLog;
namespace content {
namespace {
_;
constexpr char kDefaultCategories[] = …;
class TestStartupPreferenceManagerImpl
: public BackgroundTracingManagerImpl::PreferenceManager { … };
class TestBackgroundTracingHelper
: public BackgroundTracingManager::EnabledStateTestObserver,
public perfetto::trace_processor::json::OutputWriter { … };
perfetto::protos::gen::ChromeFieldTracingConfig ParseFieldTracingConfigFromText(
const std::string& proto_text) { … }
}
class BackgroundTracingManagerBrowserTest : public ContentBrowserTest { … };
std::unique_ptr<BackgroundTracingConfig> CreatePreemptiveConfig() { … }
std::unique_ptr<BackgroundTracingConfig> CreateReactiveConfig() { … }
std::unique_ptr<BackgroundTracingConfig> CreateSystemConfig() { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
AddPresetScenarios) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
EnablePresetScenariosWhileTracing) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
StartUploadScenario) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
StartInvalidScenario) { … }
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_NotAllowlistedArgsStripped …
#else
#define MAYBE_NotAllowlistedArgsStripped …
#endif
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
MAYBE_NotAllowlistedArgsStripped) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
StartOtherScenario) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
StartNestedScenario) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReceiveTraceFinalContentsOnTrigger) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
CallTriggersMoreThanOnceOnlyGatherOnce) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
LegacyNotAllowlistedArgsStripped) { … }
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_TracingRenderFrameHostImplDtor …
#else
#define MAYBE_TracingRenderFrameHostImplDtor …
#endif
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
MAYBE_TracingRenderFrameHostImplDtor) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
DISABLED_EarlyTraceEventsInTrace) { … }
#if BUILDFLAG(IS_LINUX) && defined(THREAD_SANITIZER)
#define MAYBE_TraceMetadataInTrace …
#else
#define MAYBE_TraceMetadataInTrace …
#endif
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
MAYBE_TraceMetadataInTrace) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
DISABLED_CrashWhenSubprocessWithoutArgumentFilter) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
CallMultipleTriggersOnlyGatherOnce) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
CallPreemptiveTriggerWithDelay) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
CannotTriggerWithoutScenarioSet) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
DoesNotTriggerWithWrongHandle) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
DoesNotTriggerWithInvalidHandle) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
PreemptiveNotTriggerWithZeroChance) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReactiveNotTriggerWithZeroChance) { … }
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && defined(THREAD_SANITIZER)
#define MAYBE_ReceiveTraceSucceedsOnHigherHistogramSample …
#else
#define MAYBE_ReceiveTraceSucceedsOnHigherHistogramSample …
#endif
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
MAYBE_ReceiveTraceSucceedsOnHigherHistogramSample) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_CustomConfig …
#else
#define MAYBE_CustomConfig …
#endif
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
MAYBE_CustomConfig) { … }
void DummyFunc() { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
DISABLED_EndToEndStackSampling) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReceiveReactiveTraceSucceedsOnHigherHistogramSample) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReceiveTraceFailsOnLowerHistogramSample) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReceiveTraceFailsOnHigherHistogramSample) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReceiveTraceSucceedsOnUpperReferenceValue) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReceiveTraceSucceedsOnLowerReferenceValue) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReceiveReactiveTraceSucceedsOnSingleEnumValue) { … }
IN_PROC_BROWSER_TEST_F(
BackgroundTracingManagerBrowserTest,
SetActiveScenarioWithReceiveCallbackFailsWithInvalidPreemptiveConfig) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
ReactiveTimeoutTermination) { … }
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
SetupStartupTracing) { … }
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID)
#define MAYBE_RunStartupTracing …
#else
#define MAYBE_RunStartupTracing …
#endif
IN_PROC_BROWSER_TEST_F(BackgroundTracingManagerBrowserTest,
MAYBE_RunStartupTracing) { … }
namespace {
class ProtoBackgroundTracingTest : public DevToolsProtocolTest { … };
}
IN_PROC_BROWSER_TEST_F(ProtoBackgroundTracingTest,
DevtoolsInterruptsBackgroundTracing) { … }
IN_PROC_BROWSER_TEST_F(ProtoBackgroundTracingTest, ProtoTraceReceived) { … }
IN_PROC_BROWSER_TEST_F(ProtoBackgroundTracingTest, ReceiveCallback) { … }
}