Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / browser_watcher / crash_reporting_metrics_win_unittest.cc
blob6d9fd2410282617ac9cf645f9c4727a91469854a
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/browser_watcher/crash_reporting_metrics_win.h"
7 #include "base/macros.h"
8 #include "base/strings/string16.h"
9 #include "base/win/registry.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace browser_watcher {
14 namespace {
16 const base::char16 test_root[] = L"TmpTmp";
18 class CrashReportingMetricsTest : public testing::Test {
19 protected:
20 CrashReportingMetricsTest() {}
22 void SetUp() override {
23 // Create a temporary key for testing
24 base::win::RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
25 key.DeleteKey(test_root);
26 ASSERT_NE(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, test_root, KEY_READ));
27 ASSERT_EQ(ERROR_SUCCESS, key.Create(HKEY_CURRENT_USER, test_root,
28 KEY_READ));
31 void TearDown() override {
32 // Clean up the temporary key
33 base::win::RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
34 ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(test_root));
37 base::string16 registry_path() {
38 return base::string16(test_root) + L"\\CrashReportingMetricsTest";
41 private:
42 DISALLOW_COPY_AND_ASSIGN(CrashReportingMetricsTest);
45 } // namespace
47 TEST_F(CrashReportingMetricsTest, BasicTest) {
48 CrashReportingMetrics::Values values =
49 CrashReportingMetrics(registry_path()).RetrieveAndResetMetrics();
50 EXPECT_EQ(0, values.crash_dump_attempts);
51 EXPECT_EQ(0, values.successful_crash_dumps);
52 EXPECT_EQ(0, values.failed_crash_dumps);
53 EXPECT_EQ(0, values.dump_without_crash_attempts);
54 EXPECT_EQ(0, values.successful_dumps_without_crash);
55 EXPECT_EQ(0, values.failed_dumps_without_crash);
57 CrashReportingMetrics writer(registry_path());
58 writer.RecordCrashDumpAttempt();
59 writer.RecordCrashDumpAttempt();
60 writer.RecordCrashDumpAttempt();
61 writer.RecordDumpWithoutCrashAttempt();
62 writer.RecordDumpWithoutCrashAttempt();
63 writer.RecordDumpWithoutCrashAttempt();
64 writer.RecordDumpWithoutCrashAttempt();
66 writer.RecordCrashDumpAttemptResult(true);
67 writer.RecordCrashDumpAttemptResult(false);
68 writer.RecordCrashDumpAttemptResult(false);
69 writer.RecordDumpWithoutCrashAttemptResult(true);
70 writer.RecordDumpWithoutCrashAttemptResult(true);
71 writer.RecordDumpWithoutCrashAttemptResult(true);
72 writer.RecordDumpWithoutCrashAttemptResult(false);
74 values = CrashReportingMetrics(registry_path()).RetrieveAndResetMetrics();
75 EXPECT_EQ(3, values.crash_dump_attempts);
76 EXPECT_EQ(1, values.successful_crash_dumps);
77 EXPECT_EQ(2, values.failed_crash_dumps);
78 EXPECT_EQ(4, values.dump_without_crash_attempts);
79 EXPECT_EQ(3, values.successful_dumps_without_crash);
80 EXPECT_EQ(1, values.failed_dumps_without_crash);
82 values = CrashReportingMetrics(registry_path()).RetrieveAndResetMetrics();
83 EXPECT_EQ(0, values.crash_dump_attempts);
84 EXPECT_EQ(0, values.successful_crash_dumps);
85 EXPECT_EQ(0, values.failed_crash_dumps);
86 EXPECT_EQ(0, values.dump_without_crash_attempts);
87 EXPECT_EQ(0, values.successful_dumps_without_crash);
88 EXPECT_EQ(0, values.failed_dumps_without_crash);
90 writer.RecordCrashDumpAttempt();
91 writer.RecordCrashDumpAttempt();
92 writer.RecordDumpWithoutCrashAttempt();
93 writer.RecordDumpWithoutCrashAttempt();
94 writer.RecordDumpWithoutCrashAttempt();
96 writer.RecordCrashDumpAttemptResult(true);
97 writer.RecordCrashDumpAttemptResult(true);
98 writer.RecordDumpWithoutCrashAttemptResult(true);
99 writer.RecordDumpWithoutCrashAttemptResult(false);
100 writer.RecordDumpWithoutCrashAttemptResult(false);
102 values = CrashReportingMetrics(registry_path()).RetrieveAndResetMetrics();
103 EXPECT_EQ(2, values.crash_dump_attempts);
104 EXPECT_EQ(2, values.successful_crash_dumps);
105 EXPECT_EQ(0, values.failed_crash_dumps);
106 EXPECT_EQ(3, values.dump_without_crash_attempts);
107 EXPECT_EQ(1, values.successful_dumps_without_crash);
108 EXPECT_EQ(2, values.failed_dumps_without_crash);
111 } // namespace browser_watcher