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

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

Issue 1513043002: clang/win: Let remaining chromium_code targets build with -Wextra. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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 <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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 pid = rand(); 43 pid = rand();
44 } while (pid == static_cast<int>(base::GetCurrentProcId())); 44 } while (pid == static_cast<int>(base::GetCurrentProcId()));
45 } 45 }
46 46
47 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); 47 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE);
48 48
49 // Make up a unique key, starting with the given pid. 49 // Make up a unique key, starting with the given pid.
50 base::string16 key_name(base::StringPrintf(L"%d-%d", pid, rand())); 50 base::string16 key_name(base::StringPrintf(L"%d-%d", pid, rand()));
51 51
52 // Write the exit code to registry. 52 // Write the exit code to registry.
53 ULONG result = key.WriteValue(key_name.c_str(), exit_code); 53 LONG result = key.WriteValue(key_name.c_str(), exit_code);
54 ASSERT_EQ(result, ERROR_SUCCESS); 54 ASSERT_EQ(result, ERROR_SUCCESS);
55 } 55 }
56 56
57 size_t ExitCodeRegistryPathValueCount() { 57 size_t ExitCodeRegistryPathValueCount() {
58 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); 58 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_READ);
59 return key.GetValueCount(); 59 return key.GetValueCount();
60 } 60 }
61 61
62 void AddExitFunnelEvent(int pid, const base::char16* name, int64 value) { 62 void AddExitFunnelEvent(int pid, const base::char16* name, int64 value) {
63 base::string16 key_name = 63 base::string16 key_name =
(...skipping 24 matching lines...) Expand all
88 88
89 provider.ProvideStabilityMetrics(NULL); 89 provider.ProvideStabilityMetrics(NULL);
90 histogram_tester_.ExpectBucketCount( 90 histogram_tester_.ExpectBucketCount(
91 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 91 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
92 histogram_tester_.ExpectBucketCount( 92 histogram_tester_.ExpectBucketCount(
93 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1); 93 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 100, 1);
94 histogram_tester_.ExpectTotalCount( 94 histogram_tester_.ExpectTotalCount(
95 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12); 95 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 12);
96 96
97 // Verify that the reported values are gone. 97 // Verify that the reported values are gone.
98 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 0); 98 EXPECT_EQ(0u, ExitCodeRegistryPathValueCount());
99 } 99 }
100 100
101 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) { 101 TEST_F(WatcherMetricsProviderWinTest, DoesNotReportOwnProcessId) {
102 // Record multiple success exits. 102 // Record multiple success exits.
103 for (size_t i = 0; i < 11; ++i) 103 for (size_t i = 0; i < 11; ++i)
104 AddProcessExitCode(i, 0); 104 AddProcessExitCode(i, 0);
105 105
106 // Record own process as STILL_ACTIVE. 106 // Record own process as STILL_ACTIVE.
107 AddProcessExitCode(true, STILL_ACTIVE); 107 AddProcessExitCode(true, STILL_ACTIVE);
108 108
109 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get()); 109 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get());
110 110
111 provider.ProvideStabilityMetrics(NULL); 111 provider.ProvideStabilityMetrics(NULL);
112 histogram_tester_.ExpectUniqueSample( 112 histogram_tester_.ExpectUniqueSample(
113 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); 113 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11);
114 114
115 // Verify that the reported values are gone. 115 // Verify that the reported values are gone.
116 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1); 116 EXPECT_EQ(1u, ExitCodeRegistryPathValueCount());
117 } 117 }
118 118
119 TEST_F(WatcherMetricsProviderWinTest, DeletesRecordedExitFunnelEvents) { 119 TEST_F(WatcherMetricsProviderWinTest, DeletesRecordedExitFunnelEvents) {
120 // Record an exit funnel and make sure the registry is cleaned up on 120 // Record an exit funnel and make sure the registry is cleaned up on
121 // reporting, without recording any events. 121 // reporting, without recording any events.
122 AddExitFunnelEvent(100, L"One", 1000 * 1000); 122 AddExitFunnelEvent(100, L"One", 1000 * 1000);
123 AddExitFunnelEvent(101, L"Two", 1010 * 1000); 123 AddExitFunnelEvent(101, L"Two", 1010 * 1000);
124 AddExitFunnelEvent(102, L"Three", 990 * 1000); 124 AddExitFunnelEvent(102, L"Three", 990 * 1000);
125 125
126 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); 126 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
127 EXPECT_EQ(it.SubkeyCount(), 3); 127 EXPECT_EQ(3u, it.SubkeyCount());
128 128
129 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get()); 129 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get());
130 130
131 provider.ProvideStabilityMetrics(NULL); 131 provider.ProvideStabilityMetrics(NULL);
132 // Make sure the exit funnel events are no longer recorded in histograms. 132 // Make sure the exit funnel events are no longer recorded in histograms.
133 EXPECT_TRUE( 133 EXPECT_TRUE(
134 histogram_tester_.GetAllSamples("Stability.ExitFunnel.One").empty()); 134 histogram_tester_.GetAllSamples("Stability.ExitFunnel.One").empty());
135 EXPECT_TRUE( 135 EXPECT_TRUE(
136 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Two").empty()); 136 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Two").empty());
137 EXPECT_TRUE( 137 EXPECT_TRUE(
138 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Three").empty()); 138 histogram_tester_.GetAllSamples("Stability.ExitFunnel.Three").empty());
139 139
140 // Make sure the subkeys are deleted on reporting. 140 // Make sure the subkeys are deleted on reporting.
141 ASSERT_EQ(it.SubkeyCount(), 0); 141 ASSERT_EQ(0u, it.SubkeyCount());
142 } 142 }
143 143
144 TEST_F(WatcherMetricsProviderWinTest, DeletesExitcodeKeyWhenNotReporting) { 144 TEST_F(WatcherMetricsProviderWinTest, DeletesExitcodeKeyWhenNotReporting) {
145 // Test that the registry at kRegistryPath is deleted when reporting is 145 // Test that the registry at kRegistryPath is deleted when reporting is
146 // disabled. 146 // disabled.
147 ExitFunnel funnel; 147 ExitFunnel funnel;
148 148
149 // Record multiple success exits. 149 // Record multiple success exits.
150 for (size_t i = 0; i < 11; ++i) 150 for (size_t i = 0; i < 11; ++i)
151 AddProcessExitCode(false, 0); 151 AddProcessExitCode(false, 0);
(...skipping 28 matching lines...) Expand all
180 } 180 }
181 181
182 TEST_F(WatcherMetricsProviderWinTest, DeletesOnly100FunnelsAtATime) { 182 TEST_F(WatcherMetricsProviderWinTest, DeletesOnly100FunnelsAtATime) {
183 // Record 200 distinct exit funnels. 183 // Record 200 distinct exit funnels.
184 for (size_t i = 0; i < 200; ++i) { 184 for (size_t i = 0; i < 200; ++i) {
185 AddExitFunnelEvent(i, L"One", 10); 185 AddExitFunnelEvent(i, L"One", 10);
186 AddExitFunnelEvent(i, L"Two", 10); 186 AddExitFunnelEvent(i, L"Two", 10);
187 } 187 }
188 188
189 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); 189 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath);
190 EXPECT_EQ(it.SubkeyCount(), 200); 190 EXPECT_EQ(200u, it.SubkeyCount());
191 191
192 { 192 {
193 // Make like the user is opted out of reporting. 193 // Make like the user is opted out of reporting.
194 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get()); 194 WatcherMetricsProviderWin provider(kRegistryPath, test_task_runner_.get());
195 provider.OnRecordingDisabled(); 195 provider.OnRecordingDisabled();
196 // Flush the task(s). 196 // Flush the task(s).
197 test_task_runner_->RunPendingTasks(); 197 test_task_runner_->RunPendingTasks();
198 } 198 }
199 199
200 // We expect only 100 of the funnels have been scrubbed. 200 // We expect only 100 of the funnels have been scrubbed.
201 EXPECT_EQ(it.SubkeyCount(), 100); 201 EXPECT_EQ(100u, it.SubkeyCount());
202 } 202 }
203 203
204 } // namespace browser_watcher 204 } // namespace browser_watcher
OLDNEW
« no previous file with comments | « components/browser_watcher/exit_funnel_win_unittest.cc ('k') | components/crash/content/app/crash_keys_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698