chromium/chrome/browser/extensions/api/tab_capture/tab_capture_performancetest.cc

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

#include <cmath>
#include <string_view>

#include "base/command_line.h"
#include "base/containers/flat_map.h"
#include "base/files/file_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/trace_event_analyzer.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/api/tab_capture/tab_capture_performance_test_base.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_launcher_utils.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/tracing.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "extensions/common/switches.h"
#include "extensions/test/extension_test_message_listener.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_result_reporter.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/gl/gl_switches.h"

namespace {

// Number of events to trim from the beginning and end. These events don't
// contribute anything toward stable measurements: A brief moment of startup
// "jank" is acceptable, and shutdown may result in missing events (since
// render widget draws may stop before capture stops).
constexpr int kTrimEvents =;  // 1 sec at 24fps, or 0.4 sec at 60 fps.

// Minimum number of events required for a reasonable analysis.
constexpr int kMinDataPointsForFullRun =;  // ~5 sec at 24fps.

// Minimum number of events required for data analysis in a non-performance run.
constexpr int kMinDataPointsForQuickRun =;

constexpr char kMetricPrefixTabCapture[] =;
constexpr char kMetricCaptureMs[] =;
constexpr char kMetricCaptureFailRatePercent[] =;
constexpr char kMetricCaptureLatencyMs[] =;
constexpr char kMetricRendererFrameDrawMs[] =;

constexpr char kEventCapture[] =;
constexpr char kEventSuffixFailRate[] =;
constexpr char kEventSuffixLatency[] =;
constexpr char kEventCommitAndDrawCompositorFrame[] =;
const base::flat_map<std::string, std::string> kEventToMetricMap(
    {});

perf_test::PerfResultReporter SetUpTabCaptureReporter(
    const std::string& story) {}

std::string GetMetricFromEventName(const std::string& event_name) {}

// A convenience macro to run a gtest expectation in the "full performance run"
// setting, or else a warning that something is not being entirely tested in the
// "CQ run" setting. This is required because the test runs in the CQ may not be
// long enough to collect sufficient tracing data; and, unfortunately, there's
// nothing we can do about that.
#define EXPECT_FOR_PERFORMANCE_RUN(expr)

enum TestFlags {};

// Perfetto trace events should have a "success" that is either on
// the beginning or end event.
bool EventWasSuccessful(const trace_analyzer::TraceEvent* event) {}
class TabCapturePerformanceTest : public TabCapturePerformanceTestBase,
                                  public testing::WithParamInterface<int> {};

}  // namespace

#if BUILDFLAG(IS_CHROMEOS)
// Using MSAN on ChromeOS causes problems due to its hardware OpenGL library.
// Failing on ChromeOS Lacros as well.
#define MAYBE_Performance
#elif BUILDFLAG(IS_MAC)
// TODO(crbug.com/1235358): Flaky on Mac 10.11
#define MAYBE_Performance
#elif BUILDFLAG(IS_LINUX) && defined(ADDRESS_SANITIZER)
// TODO(crbug.com/40214499): Flaky on Linux ASAN
#define MAYBE_Performance
#else
#define MAYBE_Performance
#endif
IN_PROC_BROWSER_TEST_P(TabCapturePerformanceTest, MAYBE_Performance) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)

// On ChromeOS, software compositing is not an option.
INSTANTIATE_TEST_SUITE_P(All,
                         TabCapturePerformanceTest,
                         testing::Values(kUseGpu,
                                         kTestThroughWebRTC | kUseGpu));

#else

// Run everything on non-ChromeOS platforms.
INSTANTIATE_TEST_SUITE_P();

#endif  // BUILDFLAG(IS_CHROMEOS_ASH)