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

Side by Side Diff: components/metrics/stability_metrics_helper_unittest.cc

Issue 1366643002: Extract guts of ChromeStabilityMetricsProvider into helper class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/metrics/stability_metrics_helper.h"
6
7 #include "base/basictypes.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/prefs/testing_pref_service.h"
11 #include "components/metrics/proto/system_profile.pb.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace metrics {
15
16 namespace {
17
18 class StabilityMetricsHelperTest : public testing::Test {
19 protected:
20 StabilityMetricsHelperTest() : prefs_(new TestingPrefServiceSimple) {
21 StabilityMetricsHelper::RegisterPrefs(prefs()->registry());
22 }
23
24 TestingPrefServiceSimple* prefs() { return prefs_.get(); }
25
26 private:
27 scoped_ptr<TestingPrefServiceSimple> prefs_;
28
29 DISALLOW_COPY_AND_ASSIGN(StabilityMetricsHelperTest);
30 };
31
32 } // namespace
33
34 TEST_F(StabilityMetricsHelperTest, BrowserChildProcessCrashed) {
35 StabilityMetricsHelper helper(prefs());
36
37 helper.BrowserChildProcessCrashed();
38 helper.BrowserChildProcessCrashed();
39
40 // Call ProvideStabilityMetrics to check that it will force pending tasks to
41 // be executed immediately.
42 metrics::SystemProfileProto system_profile;
43
44 helper.ProvideStabilityMetrics(&system_profile);
45
46 // Check current number of instances created.
47 const metrics::SystemProfileProto_Stability& stability =
48 system_profile.stability();
49
50 EXPECT_EQ(2, stability.child_process_crash_count());
51 }
52
53 TEST_F(StabilityMetricsHelperTest, LogRendererCrash) {
54 StabilityMetricsHelper helper(prefs());
55
56 // Crash and abnormal termination should increment renderer crash count.
57 helper.LogRendererCrash(false, base::TERMINATION_STATUS_PROCESS_CRASHED, 1);
58
59 helper.LogRendererCrash(false, base::TERMINATION_STATUS_ABNORMAL_TERMINATION,
60 1);
61
62 // Kill does not increment renderer crash count.
63 helper.LogRendererCrash(false, base::TERMINATION_STATUS_PROCESS_WAS_KILLED,
64 1);
65
66 // Failed launch increments failed launch count.
67 helper.LogRendererCrash(false, base::TERMINATION_STATUS_LAUNCH_FAILED, 1);
68
69 metrics::SystemProfileProto system_profile;
70
71 // Call ProvideStabilityMetrics to check that it will force pending tasks to
72 // be executed immediately.
73 helper.ProvideStabilityMetrics(&system_profile);
74
75 EXPECT_EQ(2, system_profile.stability().renderer_crash_count());
76 EXPECT_EQ(1, system_profile.stability().renderer_failed_launch_count());
77 EXPECT_EQ(0, system_profile.stability().extension_renderer_crash_count());
78
79 helper.ClearSavedStabilityMetrics();
80
81 // Crash and abnormal termination should increment extension crash count.
82 helper.LogRendererCrash(true, base::TERMINATION_STATUS_PROCESS_CRASHED, 1);
83
84 // Failed launch increments extension failed launch count.
85 helper.LogRendererCrash(true, base::TERMINATION_STATUS_LAUNCH_FAILED, 1);
86
87 system_profile.Clear();
88 helper.ProvideStabilityMetrics(&system_profile);
89
90 EXPECT_EQ(0, system_profile.stability().renderer_crash_count());
91 EXPECT_EQ(1, system_profile.stability().extension_renderer_crash_count());
92 EXPECT_EQ(
93 1, system_profile.stability().extension_renderer_failed_launch_count());
94 }
95
96 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/stability_metrics_helper.cc ('k') | components/metrics/system_memory_stats_recorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698