#include "components/metrics/stability_metrics_provider.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/metrics/stability_metrics_helper.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/system_profile.pb.h"
namespace metrics {
class StabilityMetricsProviderTest : public testing::Test { … };
TEST_F(StabilityMetricsProviderTest, ProvideStabilityMetrics) { … }
TEST_F(StabilityMetricsProviderTest, RecordStabilityMetrics) { … }
#if BUILDFLAG(IS_WIN)
namespace {
class TestingStabilityMetricsProvider : public StabilityMetricsProvider {
public:
TestingStabilityMetricsProvider(PrefService* local_state,
base::Time unclean_session_time)
: StabilityMetricsProvider(local_state),
unclean_session_time_(unclean_session_time) {}
bool IsUncleanSystemSession(base::Time last_live_timestamp) override {
return last_live_timestamp == unclean_session_time_;
}
private:
const base::Time unclean_session_time_;
};
}
TEST_F(StabilityMetricsProviderTest, RecordSystemCrashMetrics) {
base::HistogramTester histogram_tester;
{
base::Time unclean_time = base::Time::Now();
TestingStabilityMetricsProvider recorder(&prefs_, unclean_time);
recorder.LogCrash(unclean_time);
recorder.LogCrash(unclean_time - base::Minutes(1));
}
{
StabilityMetricsProvider stability_provider(&prefs_);
MetricsProvider* provider = &stability_provider;
SystemProfileProto system_profile;
provider->ProvideStabilityMetrics(&system_profile);
histogram_tester.ExpectUniqueSample("Stability.Counts2",
StabilityEventType::kBrowserCrash, 2);
histogram_tester.ExpectTotalCount("Stability.Internals.SystemCrashCount",
1);
}
}
#endif
}