OLD | NEW |
---|---|
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 <cstdlib> | 7 #include <cstdlib> |
8 | 8 |
9 #include "base/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) { | 76 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) { |
77 // Record multiple success exits. | 77 // Record multiple success exits. |
78 for (size_t i = 0; i < 11; ++i) | 78 for (size_t i = 0; i < 11; ++i) |
79 AddProcessExitCode(false, 0); | 79 AddProcessExitCode(false, 0); |
80 | 80 |
81 // Record a single failure. | 81 // Record a single failure. |
82 AddProcessExitCode(false, 100); | 82 AddProcessExitCode(false, 100); |
83 | 83 |
84 WatcherMetricsProviderWin provider(kRegistryPath); | 84 WatcherMetricsProviderWin provider(kRegistryPath, true); |
85 | 85 |
86 provider.ProvideStabilityMetrics(NULL); | 86 provider.ProvideStabilityMetrics(NULL); |
87 histogram_tester_.ExpectBucketCount( | 87 histogram_tester_.ExpectBucketCount( |
88 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); | 88 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); |
89 histogram_tester_.ExpectBucketCount( | 89 histogram_tester_.ExpectBucketCount( |
90 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1); | 90 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1); |
91 histogram_tester_.ExpectTotalCount( | 91 histogram_tester_.ExpectTotalCount( |
92 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12); | 92 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12); |
93 | 93 |
94 // Verify that the reported values are gone. | 94 // Verify that the reported values are gone. |
95 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 0); | 95 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 0); |
96 } | 96 } |
97 | 97 |
98 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) { | 98 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) { |
99 // Record multiple success exits. | 99 // Record multiple success exits. |
100 for (size_t i = 0; i < 11; ++i) | 100 for (size_t i = 0; i < 11; ++i) |
101 AddProcessExitCode(i, 0); | 101 AddProcessExitCode(i, 0); |
102 | 102 |
103 // Record own process as STILL_ACTIVE. | 103 // Record own process as STILL_ACTIVE. |
104 AddProcessExitCode(true, STILL_ACTIVE); | 104 AddProcessExitCode(true, STILL_ACTIVE); |
105 | 105 |
106 WatcherMetricsProviderWin provider(kRegistryPath); | 106 WatcherMetricsProviderWin provider(kRegistryPath, true); |
107 | 107 |
108 provider.ProvideStabilityMetrics(NULL); | 108 provider.ProvideStabilityMetrics(NULL); |
109 histogram_tester_.ExpectUniqueSample( | 109 histogram_tester_.ExpectUniqueSample( |
110 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); | 110 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); |
111 | 111 |
112 // Verify that the reported values are gone. | 112 // Verify that the reported values are gone. |
113 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1); | 113 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1); |
114 } | 114 } |
115 | 115 |
116 TEST_F(WatcherMetricsProviderWinTest, RecordsOrderedExitFunnelEvents) { | 116 TEST_F(WatcherMetricsProviderWinTest, RecordsOrderedExitFunnelEvents) { |
117 // Record an exit funnel with a given set of timings and check that the | 117 // Record an exit funnel with a given set of timings and check that the |
118 // ordering is correct on the reported histograms. | 118 // ordering is correct on the reported histograms. |
119 // Note the recorded times are in microseconds, but the reporting is in | 119 // Note the recorded times are in microseconds, but the reporting is in |
120 // milliseconds, hence the times 1000. | 120 // milliseconds, hence the times 1000. |
121 AddExitFunnelEvent(100, L"One", 1000 * 1000); | 121 AddExitFunnelEvent(100, L"One", 1000 * 1000); |
122 AddExitFunnelEvent(100, L"Two", 1010 * 1000); | 122 AddExitFunnelEvent(100, L"Two", 1010 * 1000); |
123 AddExitFunnelEvent(100, L"Three", 990 * 1000); | 123 AddExitFunnelEvent(100, L"Three", 990 * 1000); |
124 | 124 |
125 WatcherMetricsProviderWin provider(kRegistryPath); | 125 WatcherMetricsProviderWin provider(kRegistryPath, true); |
126 | 126 |
127 provider.ProvideStabilityMetrics(NULL); | 127 provider.ProvideStabilityMetrics(NULL); |
128 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Three", 0, 1); | 128 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Three", 0, 1); |
129 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.One", 10, 1); | 129 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.One", 10, 1); |
130 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Two", 20, 1); | 130 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Two", 20, 1); |
131 | 131 |
132 // Make sure the subkey is deleted on reporting. | 132 // Make sure the subkey is deleted on reporting. |
133 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); | 133 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); |
134 ASSERT_EQ(it.SubkeyCount(), 0); | 134 ASSERT_EQ(it.SubkeyCount(), 0); |
135 } | 135 } |
(...skipping 10 matching lines...) Expand all Loading... | |
146 // which tests can hopefully never open. | 146 // which tests can hopefully never open. |
147 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now())); | 147 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now())); |
148 | 148 |
149 // Each named event can only exist in a single copy. | 149 // Each named event can only exist in a single copy. |
150 ASSERT_TRUE(funnel.RecordEvent(L"One")); | 150 ASSERT_TRUE(funnel.RecordEvent(L"One")); |
151 ASSERT_TRUE(funnel.RecordEvent(L"One")); | 151 ASSERT_TRUE(funnel.RecordEvent(L"One")); |
152 ASSERT_TRUE(funnel.RecordEvent(L"One")); | 152 ASSERT_TRUE(funnel.RecordEvent(L"One")); |
153 ASSERT_TRUE(funnel.RecordEvent(L"Two")); | 153 ASSERT_TRUE(funnel.RecordEvent(L"Two")); |
154 ASSERT_TRUE(funnel.RecordEvent(L"Three")); | 154 ASSERT_TRUE(funnel.RecordEvent(L"Three")); |
155 | 155 |
156 WatcherMetricsProviderWin provider(kRegistryPath); | 156 WatcherMetricsProviderWin provider(kRegistryPath, true); |
157 | 157 |
158 provider.ProvideStabilityMetrics(NULL); | 158 provider.ProvideStabilityMetrics(NULL); |
159 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.One", 1); | 159 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.One", 1); |
160 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Two", 1); | 160 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Two", 1); |
161 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Three", 1); | 161 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Three", 1); |
162 | 162 |
163 // Make sure the subkey for the pseudo process has been deleted on reporting. | 163 // Make sure the subkey for the pseudo process has been deleted on reporting. |
164 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); | 164 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); |
165 ASSERT_EQ(it.SubkeyCount(), 1); | 165 ASSERT_EQ(it.SubkeyCount(), 1); |
166 } | 166 } |
167 | 167 |
168 TEST_F(WatcherMetricsProviderWinTest, ClearsExitFunnelWriteWhenNotReporting) { | |
169 // Test that the metrics provider picks up the writes from | |
Alexei Svitkine (slow)
2015/01/23 18:45:22
Incomplete sentence?
Sigurður Ásgeirsson
2015/01/23 18:48:43
Done.
| |
170 ExitFunnel funnel; | |
171 | |
172 // Events against our own process should not get reported. | |
173 ASSERT_TRUE(funnel.Init(kRegistryPath, base::GetCurrentProcessHandle())); | |
174 ASSERT_TRUE(funnel.RecordEvent(L"Forgetaboutit")); | |
175 | |
176 // Reset the funnel to a pseudo process. The PID 4 is the system process, | |
177 // which tests can hopefully never open. | |
178 ASSERT_TRUE(funnel.InitImpl(kRegistryPath, 4, base::Time::Now())); | |
179 | |
180 // Each named event can only exist in a single copy. | |
181 ASSERT_TRUE(funnel.RecordEvent(L"One")); | |
182 ASSERT_TRUE(funnel.RecordEvent(L"One")); | |
183 ASSERT_TRUE(funnel.RecordEvent(L"One")); | |
184 ASSERT_TRUE(funnel.RecordEvent(L"Two")); | |
185 ASSERT_TRUE(funnel.RecordEvent(L"Three")); | |
186 | |
187 // Turn off exit funnel reporting. | |
188 WatcherMetricsProviderWin provider(kRegistryPath, false); | |
189 | |
190 provider.ProvideStabilityMetrics(NULL); | |
191 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.One", 0); | |
192 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Two", 0); | |
193 histogram_tester_.ExpectTotalCount("Stability.ExitFunnel.Three", 0); | |
194 | |
195 // Make sure the subkey for the pseudo process has been deleted on reporting. | |
196 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); | |
197 ASSERT_EQ(it.SubkeyCount(), 1); | |
198 } | |
199 | |
168 } // namespace browser_watcher | 200 } // namespace browser_watcher |
OLD | NEW |