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

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

Issue 2344343002: Wire in postmortem report collection (Closed)
Patch Set: Merge 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>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } // namespace 80 } // namespace
81 81
82 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) { 82 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) {
83 // Record multiple success exits. 83 // Record multiple success exits.
84 for (size_t i = 0; i < 11; ++i) 84 for (size_t i = 0; i < 11; ++i)
85 AddProcessExitCode(false, 0); 85 AddProcessExitCode(false, 0);
86 86
87 // Record a single failure. 87 // Record a single failure.
88 AddProcessExitCode(false, 100); 88 AddProcessExitCode(false, 100);
89 89
90 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get()); 90 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(),
91 base::FilePath(), test_task_runner_.get());
91 92
92 provider.ProvideStabilityMetrics(NULL); 93 provider.ProvideStabilityMetrics(NULL);
93 histogram_tester_.ExpectBucketCount( 94 histogram_tester_.ExpectBucketCount(
94 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 95 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
95 histogram_tester_.ExpectBucketCount( 96 histogram_tester_.ExpectBucketCount(
96 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1); 97 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1);
97 histogram_tester_.ExpectTotalCount( 98 histogram_tester_.ExpectTotalCount(
98 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12); 99 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12);
99 100
100 // Verify that the reported values are gone. 101 // Verify that the reported values are gone.
101 EXPECT_EQ(0u, ExitCodeRegistryPathValueCount()); 102 EXPECT_EQ(0u, ExitCodeRegistryPathValueCount());
102 } 103 }
103 104
104 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) { 105 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) {
105 // Record multiple success exits. 106 // Record multiple success exits.
106 for (size_t i = 0; i < 11; ++i) 107 for (size_t i = 0; i < 11; ++i)
107 AddProcessExitCode(i, 0); 108 AddProcessExitCode(i, 0);
108 109
109 // Record own process as STILL_ACTIVE. 110 // Record own process as STILL_ACTIVE.
110 AddProcessExitCode(true, STILL_ACTIVE); 111 AddProcessExitCode(true, STILL_ACTIVE);
111 112
112 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get()); 113 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(),
114 base::FilePath(), test_task_runner_.get());
113 115
114 provider.ProvideStabilityMetrics(NULL); 116 provider.ProvideStabilityMetrics(NULL);
115 histogram_tester_.ExpectUniqueSample( 117 histogram_tester_.ExpectUniqueSample(
116 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 118 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
117 119
118 // Verify that the reported values are gone. 120 // Verify that the reported values are gone.
119 EXPECT_EQ(1u, ExitCodeRegistryPathValueCount()); 121 EXPECT_EQ(1u, ExitCodeRegistryPathValueCount());
120 } 122 }
121 123
122 TEST_F(WatcherMetricsProviderWinTest, DeletesRecordedExitFunnelEvents) { 124 TEST_F(WatcherMetricsProviderWinTest, DeletesRecordedExitFunnelEvents) {
123 // Record an exit funnel and make sure the registry is cleaned up on 125 // Record an exit funnel and make sure the registry is cleaned up on
124 // reporting, without recording any events. 126 // reporting, without recording any events.
125 AddExitFunnelEvent(100, L"One", 1000 * 1000); 127 AddExitFunnelEvent(100, L"One", 1000 * 1000);
126 AddExitFunnelEvent(101, L"Two", 1010 * 1000); 128 AddExitFunnelEvent(101, L"Two", 1010 * 1000);
127 AddExitFunnelEvent(102, L"Three", 990 * 1000); 129 AddExitFunnelEvent(102, L"Three", 990 * 1000);
128 130
129 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); 131 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
130 EXPECT_EQ(3u, it.SubkeyCount()); 132 EXPECT_EQ(3u, it.SubkeyCount());
131 133
132 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get()); 134 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(),
135 base::FilePath(), test_task_runner_.get());
133 136
134 provider.ProvideStabilityMetrics(NULL); 137 provider.ProvideStabilityMetrics(NULL);
135 // Make sure the exit funnel events are no longer recorded in histograms. 138 // Make sure the exit funnel events are no longer recorded in histograms.
136 EXPECT_TRUE( 139 EXPECT_TRUE(
137 histogram_tester_.GetAllSamples("Stability.ExitFunnel.One").empty()); 140 histogram_tester_.GetAllSamples("Stability.ExitFunnel.One").empty());
138 EXPECT_TRUE( 141 EXPECT_TRUE(
139 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Two").empty()); 142 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Two").empty());
140 EXPECT_TRUE( 143 EXPECT_TRUE(
141 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Three").empty()); 144 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Three").empty());
142 145
(...skipping 13 matching lines...) Expand all
156 AddProcessExitCode(false, 100); 159 AddProcessExitCode(false, 100);
157 160
158 // Record an exit funnel. 161 // Record an exit funnel.
159 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now())); 162 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now()));
160 163
161 AddExitFunnelEvent(100, L"One", 1000 * 1000); 164 AddExitFunnelEvent(100, L"One", 1000 * 1000);
162 AddExitFunnelEvent(101, L"Two", 1010 * 1000); 165 AddExitFunnelEvent(101, L"Two", 1010 * 1000);
163 AddExitFunnelEvent(102, L"Three", 990 * 1000); 166 AddExitFunnelEvent(102, L"Three", 990 * 1000);
164 167
165 // Make like the user is opted out of reporting. 168 // Make like the user is opted out of reporting.
166 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get()); 169 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(),
170 base::FilePath(), test_task_runner_.get());
167 provider.OnRecordingDisabled(); 171 provider.OnRecordingDisabled();
168 172
169 base::win::RegKey key; 173 base::win::RegKey key;
170 { 174 {
171 // The deletion should be scheduled to the test_task_runner, and not happen 175 // The deletion should be scheduled to the test_task_runner, and not happen
172 // immediately. 176 // immediately.
173 ASSERT_EQ(ERROR_SUCCESS, 177 ASSERT_EQ(ERROR_SUCCESS,
174 key.Open(HKEY_CURRENT_USER, kRegistryPath, KEY_READ)); 178 key.Open(HKEY_CURRENT_USER, kRegistryPath, KEY_READ));
175 } 179 }
176 180
(...skipping 10 matching lines...) Expand all
187 for (size_t i = 0; i < 200; ++i) { 191 for (size_t i = 0; i < 200; ++i) {
188 AddExitFunnelEvent(i, L"One", 10); 192 AddExitFunnelEvent(i, L"One", 10);
189 AddExitFunnelEvent(i, L"Two", 10); 193 AddExitFunnelEvent(i, L"Two", 10);
190 } 194 }
191 195
192 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); 196 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
193 EXPECT_EQ(200u, it.SubkeyCount()); 197 EXPECT_EQ(200u, it.SubkeyCount());
194 198
195 { 199 {
196 // Make like the user is opted out of reporting. 200 // Make like the user is opted out of reporting.
197 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get()); 201 WatcherMetricsProviderWin provider(kRegistryPath, base::FilePath(),
202 base::FilePath(),
203 test_task_runner_.get());
198 provider.OnRecordingDisabled(); 204 provider.OnRecordingDisabled();
199 // Flush the task(s). 205 // Flush the task(s).
200 test_task_runner_->RunPendingTasks(); 206 test_task_runner_->RunPendingTasks();
201 } 207 }
202 208
203 // We expect only 100 of the funnels have been scrubbed. 209 // We expect only 100 of the funnels have been scrubbed.
204 EXPECT_EQ(100u, it.SubkeyCount()); 210 EXPECT_EQ(100u, it.SubkeyCount());
205 } 211 }
206 212
207 } // namespace browser_watcher 213 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « components/browser_watcher/watcher_metrics_provider_win.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698