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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 // Write the exit code to registry. | 49 // Write the exit code to registry. |
50 ULONG result = key.WriteValue(key_name.c_str(), exit_code); | 50 ULONG result = key.WriteValue(key_name.c_str(), exit_code); |
51 ASSERT_EQ(result, ERROR_SUCCESS); | 51 ASSERT_EQ(result, ERROR_SUCCESS); |
52 } | 52 } |
53 | 53 |
54 size_t ExitCodeRegistryPathValueCount() { | 54 size_t ExitCodeRegistryPathValueCount() { |
55 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); | 55 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); |
56 return key.GetValueCount(); | 56 return key.GetValueCount(); |
57 } | 57 } |
58 | 58 |
59 void AddExitFunnelEvent(int pid, const base::char16* name, int64 value) { | |
60 base::string16 key_name = | |
61 base::StringPrintf(L"%ls\\%d-%d", kRegistryPath, pid, pid); | |
erikwright (departed)
2014/12/11 15:00:46
Why dup the writing? You're testing (and overly co
Sigurður Ásgeirsson
2014/12/12 16:21:40
There's really not enough code there to worry abou
| |
62 | |
63 base::win::RegKey key(HKEY_CURRENT_USER, key_name.c_str(), KEY_WRITE); | |
64 ASSERT_EQ(key.WriteValue(name, &value, sizeof(value), REG_QWORD), | |
65 ERROR_SUCCESS); | |
66 } | |
67 | |
59 protected: | 68 protected: |
60 registry_util::RegistryOverrideManager override_manager_; | 69 registry_util::RegistryOverrideManager override_manager_; |
61 base::HistogramTester histogram_tester_; | 70 base::HistogramTester histogram_tester_; |
62 }; | 71 }; |
63 | 72 |
64 } // namespace | 73 } // namespace |
65 | 74 |
66 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) { | 75 TEST_F(WatcherMetricsProviderWinTest, RecordsStabilityHistogram) { |
67 // Record multiple success exits. | 76 // Record multiple success exits. |
68 for (size_t i = 0; i < 11; ++i) | 77 for (size_t i = 0; i < 11; ++i) |
(...skipping 27 matching lines...) Expand all Loading... | |
96 WatcherMetricsProviderWin provider(kRegistryPath); | 105 WatcherMetricsProviderWin provider(kRegistryPath); |
97 | 106 |
98 provider.ProvideStabilityMetrics(NULL); | 107 provider.ProvideStabilityMetrics(NULL); |
99 histogram_tester_.ExpectUniqueSample( | 108 histogram_tester_.ExpectUniqueSample( |
100 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); | 109 WatcherMetricsProviderWin::kBrowserExitCodeHistogramName, 0, 11); |
101 | 110 |
102 // Verify that the reported values are gone. | 111 // Verify that the reported values are gone. |
103 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1); | 112 EXPECT_EQ(ExitCodeRegistryPathValueCount(), 1); |
104 } | 113 } |
105 | 114 |
115 TEST_F(WatcherMetricsProviderWinTest, RecordsExitFunnel) { | |
116 // Record an exit funnel - note the recorded times are in microseconds, | |
117 // but the reporting is in milliseconds, hence the times 1000. | |
118 AddExitFunnelEvent(100, L"One", 1000 * 1000); | |
119 AddExitFunnelEvent(100, L"Two", 1010 * 1000); | |
120 AddExitFunnelEvent(100, L"Three", 990 * 1000); | |
121 | |
122 WatcherMetricsProviderWin provider(kRegistryPath); | |
123 | |
124 provider.ProvideStabilityMetrics(NULL); | |
erikwright (departed)
2014/12/11 15:00:46
Testing that the histograms are actually written i
Sigurður Ásgeirsson
2014/12/12 16:21:40
I added some testing to verify that the metrics pr
| |
125 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Three", 0, 1); | |
126 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.One", 10, 1); | |
127 histogram_tester_.ExpectUniqueSample("Stability.ExitFunnel.Two", 20, 1); | |
128 | |
129 // Make sure the subkey is deleted on reporting. | |
130 base::win::RegistryKeyIterator it(HKEY_CURRENT_USER, kRegistryPath); | |
131 ASSERT_EQ(it.SubkeyCount(), 0); | |
132 } | |
133 | |
106 } // namespace browser_watcher | 134 } // namespace browser_watcher |
OLD | NEW |