Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: components/browser_watcher/watcher_metrics_provider_win_unittest.cc

Issue 2372633002: Use the correct product/version for postmortem reports (Closed)
Patch Set: Direct access to GetExecutableVersionDetails via ChromePostmortemReportCollector Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/browser_watcher/watcher_metrics_provider_win.h" 5 #include "components/browser_watcher/watcher_metrics_provider_win.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cstdlib> 10 #include <cstdlib>
11 11
12 #include "base/memory/ptr_util.h"
12 #include "base/process/process_handle.h" 13 #include "base/process/process_handle.h"
13 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/test/histogram_tester.h" 16 #include "base/test/histogram_tester.h"
16 #include "base/test/test_reg_util_win.h" 17 #include "base/test/test_reg_util_win.h"
17 #include "base/test/test_simple_task_runner.h" 18 #include "base/test/test_simple_task_runner.h"
18 #include "base/win/registry.h" 19 #include "base/win/registry.h"
19 #include "components/browser_watcher/exit_funnel_win.h" 20 #include "components/browser_watcher/exit_funnel_win.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 ASSERT_EQ(key.WriteValue(name, &value, sizeof(value), REG_QWORD), 71 ASSERT_EQ(key.WriteValue(name, &value, sizeof(value), REG_QWORD),
71 ERROR_SUCCESS); 72 ERROR_SUCCESS);
72 } 73 }
73 74
74 protected: 75 protected:
75 registry_util::RegistryOverrideManager override_manager_; 76 registry_util::RegistryOverrideManager override_manager_;
76 base::HistogramTester histogram_tester_; 77 base::HistogramTester histogram_tester_;
77 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner_; 78 scoped_refptr<base::TestSimpleTaskRunner> test_task_runner_;
78 }; 79 };
79 80
81 class PostmortemReportCollectorForTest : public PostmortemReportCollector {
82 public:
83 PostmortemReportCollectorForTest()
84 : PostmortemReportCollector(),
85 product_name_("TestProduct"),
86 version_number_("TestVersionNumber"),
87 channel_name_("TestChannel") {}
88 ~PostmortemReportCollectorForTest() override = default;
89
90 const std::string& GetProductName() override { return product_name_; }
91 const std::string& GetProductVersion() override { return version_number_; }
92 const std::string& GetProductChannel() override { return channel_name_; }
93
94 private:
95 std::string product_name_;
96 std::string version_number_;
97 std::string channel_name_;
98
99 DISALLOW_COPY_AND_ASSIGN(PostmortemReportCollectorForTest);
100 };
101
80 } // namespace 102 } // namespace
81 103
82 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) { 104 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) {
83 // Record multiple success exits. 105 // Record multiple success exits.
84 for (size_t i = 0; i < 11; ++i) 106 for (size_t i = 0; i < 11; ++i)
85 AddProcessExitCode(false, 0); 107 AddProcessExitCode(false, 0);
86 108
87 // Record a single failure. 109 // Record a single failure.
88 AddProcessExitCode(false, 100); 110 AddProcessExitCode(false, 100);
89 111
90 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(), 112 WatcherMetricsProviderWin provider(
91 base::FilePath(), test_task_runner_.get()); 113 kRegistryPath, base::FilePath(), base::FilePath(),
114 base::WrapUnique(new PostmortemReportCollectorForTest()),
115 test_task_runner_.get());
92 116
93 provider.ProvideStabilityMetrics(NULL); 117 provider.ProvideStabilityMetrics(NULL);
94 histogram_tester_.ExpectBucketCount( 118 histogram_tester_.ExpectBucketCount(
95 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 119 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
96 histogram_tester_.ExpectBucketCount( 120 histogram_tester_.ExpectBucketCount(
97 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1); 121 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1);
98 histogram_tester_.ExpectTotalCount( 122 histogram_tester_.ExpectTotalCount(
99 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12); 123 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12);
100 124
101 // Verify that the reported values are gone. 125 // Verify that the reported values are gone.
102 EXPECT_EQ(0u, ExitCodeRegistryPathValueCount()); 126 EXPECT_EQ(0u, ExitCodeRegistryPathValueCount());
103 } 127 }
104 128
105 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) { 129 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) {
106 // Record multiple success exits. 130 // Record multiple success exits.
107 for (size_t i = 0; i < 11; ++i) 131 for (size_t i = 0; i < 11; ++i)
108 AddProcessExitCode(i, 0); 132 AddProcessExitCode(i, 0);
109 133
110 // Record own process as STILL_ACTIVE. 134 // Record own process as STILL_ACTIVE.
111 AddProcessExitCode(true, STILL_ACTIVE); 135 AddProcessExitCode(true, STILL_ACTIVE);
112 136
113 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(), 137 WatcherMetricsProviderWin provider(
114 base::FilePath(), test_task_runner_.get()); 138 kRegistryPath, base::FilePath(), base::FilePath(),
139 base::WrapUnique(new PostmortemReportCollectorForTest()),
140 test_task_runner_.get());
115 141
116 provider.ProvideStabilityMetrics(NULL); 142 provider.ProvideStabilityMetrics(NULL);
117 histogram_tester_.ExpectUniqueSample( 143 histogram_tester_.ExpectUniqueSample(
118 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 144 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
119 145
120 // Verify that the reported values are gone. 146 // Verify that the reported values are gone.
121 EXPECT_EQ(1u, ExitCodeRegistryPathValueCount()); 147 EXPECT_EQ(1u, ExitCodeRegistryPathValueCount());
122 } 148 }
123 149
124 TEST_F(WatcherMetricsProviderWinTest, DeletesRecordedExitFunnelEvents) { 150 TEST_F(WatcherMetricsProviderWinTest, DeletesRecordedExitFunnelEvents) {
125 // Record an exit funnel and make sure the registry is cleaned up on 151 // Record an exit funnel and make sure the registry is cleaned up on
126 // reporting, without recording any events. 152 // reporting, without recording any events.
127 AddExitFunnelEvent(100, L"One", 1000 * 1000); 153 AddExitFunnelEvent(100, L"One", 1000 * 1000);
128 AddExitFunnelEvent(101, L"Two", 1010 * 1000); 154 AddExitFunnelEvent(101, L"Two", 1010 * 1000);
129 AddExitFunnelEvent(102, L"Three", 990 * 1000); 155 AddExitFunnelEvent(102, L"Three", 990 * 1000);
130 156
131 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); 157 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
132 EXPECT_EQ(3u, it.SubkeyCount()); 158 EXPECT_EQ(3u, it.SubkeyCount());
133 159
134 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(), 160 WatcherMetricsProviderWin provider(
135 base::FilePath(), test_task_runner_.get()); 161 kRegistryPath, base::FilePath(), base::FilePath(),
162 base::WrapUnique(new PostmortemReportCollectorForTest()),
163 test_task_runner_.get());
136 164
137 provider.ProvideStabilityMetrics(NULL); 165 provider.ProvideStabilityMetrics(NULL);
138 // Make sure the exit funnel events are no longer recorded in histograms. 166 // Make sure the exit funnel events are no longer recorded in histograms.
139 EXPECT_TRUE( 167 EXPECT_TRUE(
140 histogram_tester_.GetAllSamples("Stability.ExitFunnel.One").empty()); 168 histogram_tester_.GetAllSamples("Stability.ExitFunnel.One").empty());
141 EXPECT_TRUE( 169 EXPECT_TRUE(
142 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Two").empty()); 170 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Two").empty());
143 EXPECT_TRUE( 171 EXPECT_TRUE(
144 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Three").empty()); 172 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Three").empty());
145 173
(...skipping 13 matching lines...) Expand all
159 AddProcessExitCode(false, 100); 187 AddProcessExitCode(false, 100);
160 188
161 // Record an exit funnel. 189 // Record an exit funnel.
162 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now())); 190 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now()));
163 191
164 AddExitFunnelEvent(100, L"One", 1000 * 1000); 192 AddExitFunnelEvent(100, L"One", 1000 * 1000);
165 AddExitFunnelEvent(101, L"Two", 1010 * 1000); 193 AddExitFunnelEvent(101, L"Two", 1010 * 1000);
166 AddExitFunnelEvent(102, L"Three", 990 * 1000); 194 AddExitFunnelEvent(102, L"Three", 990 * 1000);
167 195
168 // Make like the user is opted out of reporting. 196 // Make like the user is opted out of reporting.
169 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(), 197 WatcherMetricsProviderWin provider(
170 base::FilePath(), test_task_runner_.get()); 198 kRegistryPath, base::FilePath(), base::FilePath(),
199 base::WrapUnique(new PostmortemReportCollectorForTest()),
200 test_task_runner_.get());
171 provider.OnRecordingDisabled(); 201 provider.OnRecordingDisabled();
172 202
173 base::win::RegKey key; 203 base::win::RegKey key;
174 { 204 {
175 // The deletion should be scheduled to the test_task_runner, and not happen 205 // The deletion should be scheduled to the test_task_runner, and not happen
176 // immediately. 206 // immediately.
177 ASSERT_EQ(ERROR_SUCCESS, 207 ASSERT_EQ(ERROR_SUCCESS,
178 key.Open(HKEY_CURRENT_USER, kRegistryPath, KEY_READ)); 208 key.Open(HKEY_CURRENT_USER, kRegistryPath, KEY_READ));
179 } 209 }
180 210
(...skipping 10 matching lines...) Expand all
191 for (size_t i = 0; i < 200; ++i) { 221 for (size_t i = 0; i < 200; ++i) {
192 AddExitFunnelEvent(i, L"One", 10); 222 AddExitFunnelEvent(i, L"One", 10);
193 AddExitFunnelEvent(i, L"Two", 10); 223 AddExitFunnelEvent(i, L"Two", 10);
194 } 224 }
195 225
196 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); 226 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
197 EXPECT_EQ(200u, it.SubkeyCount()); 227 EXPECT_EQ(200u, it.SubkeyCount());
198 228
199 { 229 {
200 // Make like the user is opted out of reporting. 230 // Make like the user is opted out of reporting.
201 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(), 231 WatcherMetricsProviderWin provider(
202 base::FilePath(), 232 kRegistryPath, base::FilePath(), base::FilePath(),
203 test_task_runner_.get()); 233 base::WrapUnique(new PostmortemReportCollectorForTest()),
234 test_task_runner_.get());
204 provider.OnRecordingDisabled(); 235 provider.OnRecordingDisabled();
205 // Flush the task(s). 236 // Flush the task(s).
206 test_task_runner_->RunPendingTasks(); 237 test_task_runner_->RunPendingTasks();
207 } 238 }
208 239
209 // We expect only 100 of the funnels have been scrubbed. 240 // We expect only 100 of the funnels have been scrubbed.
210 EXPECT_EQ(100u, it.SubkeyCount()); 241 EXPECT_EQ(100u, it.SubkeyCount());
211 } 242 }
212 243
213 } // namespace browser_watcher 244 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698