#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 { … };
}
#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
#if BUILDFLAG(ENABLE_EXTENSIONS)
TEST_F(StabilityMetricsHelperTest, LogRendererCrashEnableExtensions) { … }
#endif
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
TEST_F(StabilityMetricsHelperTest, RendererAbnormalTerminationCount) { … }
#endif
}