chromium/components/metrics/stability_metrics_helper_unittest.cc

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

#include "components/metrics/stability_metrics_helper.h"

#include <memory>

#include "base/process/kill.h"
#include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/prefs/testing_pref_service.h"
#include "extensions/buildflags/buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/system_profile.pb.h"

namespace metrics {

namespace {

enum RendererType {};

class StabilityMetricsHelperTest : public testing::Test {};

}  // namespace

#if BUILDFLAG(IS_IOS)
TEST_F(StabilityMetricsHelperTest, LogRendererCrash) {
  StabilityMetricsHelper helper(prefs());
  base::HistogramTester histogram_tester;

  helper.LogRendererCrash();

  constexpr int kDummyExitCode = 105;
  histogram_tester.ExpectUniqueSample("CrashExitCodes.Renderer", kDummyExitCode,
                                      1);
  histogram_tester.ExpectBucketCount("BrowserRenderProcessHost.ChildCrashes",
                                     RENDERER_TYPE_RENDERER, 1);
  histogram_tester.ExpectBucketCount("Stability.Counts2",
                                     StabilityEventType::kRendererCrash, 1);
  histogram_tester.ExpectBucketCount("Stability.Counts2",
                                     StabilityEventType::kExtensionCrash, 0);
}
#elif !BUILDFLAG(IS_ANDROID)
TEST_F(StabilityMetricsHelperTest, LogRendererCrash) {}
#endif

// Note: ENABLE_EXTENSIONS is set to false in Android
#if BUILDFLAG(ENABLE_EXTENSIONS)
TEST_F(StabilityMetricsHelperTest, LogRendererCrashEnableExtensions) {}
#endif  // BUILDFLAG(ENABLE_EXTENSIONS)

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
// Verifies that "Stability.RendererAbnormalTermination2.*" histograms are
// correctly recorded by `LogRendererCrash`.
TEST_F(StabilityMetricsHelperTest, RendererAbnormalTerminationCount) {}
#endif  // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)

}  // namespace metrics