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

Side by Side Diff: blimp/engine/app/blimp_stability_metrics_provider_unittest.cc

Issue 2045073002: Export stability metrics to UMA from Blimp engine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/metrics/chrome_stability_metrics_provider.h" 5 #include "blimp/engine/app/blimp_stability_metrics_provider.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "chrome/test/base/testing_browser_process.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "chrome/test/base/testing_profile_manager.h"
11 #include "components/metrics/proto/system_profile.pb.h" 8 #include "components/metrics/proto/system_profile.pb.h"
12 #include "components/prefs/pref_service.h" 9 #include "components/prefs/pref_service.h"
13 #include "components/prefs/scoped_user_pref_update.h" 10 #include "components/prefs/scoped_user_pref_update.h"
14 #include "components/prefs/testing_pref_service.h" 11 #include "components/prefs/testing_pref_service.h"
15 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/child_process_data.h" 13 #include "content/public/browser/child_process_data.h"
17 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
19 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/site_instance.h" 19 #include "content/public/browser/site_instance.h"
22 #include "content/public/common/process_type.h" 20 #include "content/public/common/process_type.h"
23 #include "content/public/test/mock_render_process_host.h" 21 #include "content/public/test/mock_render_process_host.h"
24 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
25 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
26 24
27 #if defined(ENABLE_EXTENSIONS)
28 #include "extensions/browser/process_map.h"
29 #endif
30
31 namespace { 25 namespace {
32 26
33 class ChromeStabilityMetricsProviderTest : public testing::Test { 27 class BlimpStabilityMetricsProviderTest : public testing::Test {
34 protected: 28 protected:
35 ChromeStabilityMetricsProviderTest() : prefs_(new TestingPrefServiceSimple) { 29 BlimpStabilityMetricsProviderTest() : prefs_(new TestingPrefServiceSimple) {
36 metrics::StabilityMetricsHelper::RegisterPrefs(prefs()->registry()); 30 metrics::StabilityMetricsHelper::RegisterPrefs(prefs()->registry());
37 } 31 }
38 32
39 TestingPrefServiceSimple* prefs() { return prefs_.get(); } 33 TestingPrefServiceSimple* prefs() { return prefs_.get(); }
40 34
41 private: 35 private:
42 std::unique_ptr<TestingPrefServiceSimple> prefs_; 36 std::unique_ptr<TestingPrefServiceSimple> prefs_;
43 content::TestBrowserThreadBundle thread_bundle_; 37 content::TestBrowserThreadBundle thread_bundle_;
44 38
45 DISALLOW_COPY_AND_ASSIGN(ChromeStabilityMetricsProviderTest); 39 DISALLOW_COPY_AND_ASSIGN(BlimpStabilityMetricsProviderTest);
46 }; 40 };
47 41
48 } // namespace 42 } // namespace
49 43
50 TEST_F(ChromeStabilityMetricsProviderTest, BrowserChildProcessObserver) { 44 TEST_F(BlimpStabilityMetricsProviderTest, BrowserChildProcessObserver) {
51 ChromeStabilityMetricsProvider provider(prefs()); 45 BlimpStabilityMetricsProvider provider(prefs());
52 46
53 content::ChildProcessData child_process_data(content::PROCESS_TYPE_RENDERER); 47 content::ChildProcessData child_process_data(content::PROCESS_TYPE_RENDERER);
54 provider.BrowserChildProcessCrashed(child_process_data, 1); 48 provider.BrowserChildProcessCrashed(child_process_data, 1);
55 provider.BrowserChildProcessCrashed(child_process_data, 1); 49 provider.BrowserChildProcessCrashed(child_process_data, 1);
56 50
57 // Call ProvideStabilityMetrics to check that it will force pending tasks to 51 // Call ProvideStabilityMetrics to check that it will force pending tasks to
58 // be executed immediately. 52 // be executed immediately.
59 metrics::SystemProfileProto system_profile; 53 metrics::SystemProfileProto system_profile;
60 54
61 provider.ProvideStabilityMetrics(&system_profile); 55 provider.ProvideStabilityMetrics(&system_profile);
62 56
63 // Check current number of instances created. 57 // Check current number of instances created.
64 const metrics::SystemProfileProto_Stability& stability = 58 const metrics::SystemProfileProto_Stability& stability =
65 system_profile.stability(); 59 system_profile.stability();
66 60
67 EXPECT_EQ(2, stability.child_process_crash_count()); 61 EXPECT_EQ(2, stability.child_process_crash_count());
68 } 62 }
69 63
70 TEST_F(ChromeStabilityMetricsProviderTest, NotificationObserver) { 64 TEST_F(BlimpStabilityMetricsProviderTest, NotificationObserver) {
71 ChromeStabilityMetricsProvider provider(prefs()); 65 BlimpStabilityMetricsProvider provider(prefs());
72 std::unique_ptr<TestingProfileManager> profile_manager( 66 content::NotificationSource irrelevant_source =
73 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 67 content::Source<std::nullptr_t>(nullptr);
Wez 2016/06/10 23:50:10 nit: This looks strange - we need to specify nullp
xyzzyz 2016/06/17 20:16:58 Exactly: ../../blimp/engine/app/blimp_stability_m
maniscalco 2016/06/17 20:45:43 Should we just use AllSources here? https://cs.ch
Wez 2016/06/21 00:14:10 AllSources is just content::Source<void>(nullptr),
74 EXPECT_TRUE(profile_manager->SetUp());
75 68
76 // Owned by profile_manager. 69 // Load start should increase page load count.
77 TestingProfile* profile( 70 provider.Observe(
78 profile_manager->CreateTestingProfile("StabilityTestProfile")); 71 content::NOTIFICATION_LOAD_START, irrelevant_source,
79 72 content::NotificationService::NoDetails());
80 std::unique_ptr<content::MockRenderProcessHostFactory> rph_factory(
81 new content::MockRenderProcessHostFactory());
82 scoped_refptr<content::SiteInstance> site_instance(
83 content::SiteInstance::Create(profile));
84
85 // Owned by rph_factory.
86 content::RenderProcessHost* host(
87 rph_factory->CreateRenderProcessHost(profile, site_instance.get()));
88 73
89 // Crash and abnormal termination should increment renderer crash count. 74 // Crash and abnormal termination should increment renderer crash count.
90 content::RenderProcessHost::RendererClosedDetails crash_details( 75 content::RenderProcessHost::RendererClosedDetails crash_details(
91 base::TERMINATION_STATUS_PROCESS_CRASHED, 1); 76 base::TERMINATION_STATUS_PROCESS_CRASHED, 1);
92 provider.Observe( 77 provider.Observe(
93 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 78 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, irrelevant_source,
94 content::Source<content::RenderProcessHost>(host),
95 content::Details<content::RenderProcessHost::RendererClosedDetails>( 79 content::Details<content::RenderProcessHost::RendererClosedDetails>(
96 &crash_details)); 80 &crash_details));
97 81
98 content::RenderProcessHost::RendererClosedDetails term_details( 82 content::RenderProcessHost::RendererClosedDetails term_details(
99 base::TERMINATION_STATUS_ABNORMAL_TERMINATION, 1); 83 base::TERMINATION_STATUS_ABNORMAL_TERMINATION, 1);
100 provider.Observe( 84 provider.Observe(
101 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 85 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, irrelevant_source,
102 content::Source<content::RenderProcessHost>(host),
103 content::Details<content::RenderProcessHost::RendererClosedDetails>( 86 content::Details<content::RenderProcessHost::RendererClosedDetails>(
104 &term_details)); 87 &term_details));
105 88
106 // Kill does not increment renderer crash count. 89 // Kill does not increment renderer crash count.
107 content::RenderProcessHost::RendererClosedDetails kill_details( 90 content::RenderProcessHost::RendererClosedDetails kill_details(
108 base::TERMINATION_STATUS_PROCESS_WAS_KILLED, 1); 91 base::TERMINATION_STATUS_PROCESS_WAS_KILLED, 1);
109 provider.Observe( 92 provider.Observe(
110 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 93 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, irrelevant_source,
111 content::Source<content::RenderProcessHost>(host),
112 content::Details<content::RenderProcessHost::RendererClosedDetails>( 94 content::Details<content::RenderProcessHost::RendererClosedDetails>(
113 &kill_details)); 95 &kill_details));
114 96
115 // Failed launch increments failed launch count. 97 // Failed launch increments failed launch count.
116 content::RenderProcessHost::RendererClosedDetails failed_launch_details( 98 content::RenderProcessHost::RendererClosedDetails failed_launch_details(
117 base::TERMINATION_STATUS_LAUNCH_FAILED, 1); 99 base::TERMINATION_STATUS_LAUNCH_FAILED, 1);
118 provider.Observe( 100 provider.Observe(
119 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 101 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, irrelevant_source,
120 content::Source<content::RenderProcessHost>(host),
121 content::Details<content::RenderProcessHost::RendererClosedDetails>( 102 content::Details<content::RenderProcessHost::RendererClosedDetails>(
122 &failed_launch_details)); 103 &failed_launch_details));
123 104
124 metrics::SystemProfileProto system_profile; 105 metrics::SystemProfileProto system_profile;
125 106
126 // Call ProvideStabilityMetrics to check that it will force pending tasks to 107 // Call ProvideStabilityMetrics to check that it will force pending tasks to
127 // be executed immediately. 108 // be executed immediately.
128 provider.ProvideStabilityMetrics(&system_profile); 109 provider.ProvideStabilityMetrics(&system_profile);
129 110
111 EXPECT_EQ(1, system_profile.stability().page_load_count());
130 EXPECT_EQ(2, system_profile.stability().renderer_crash_count()); 112 EXPECT_EQ(2, system_profile.stability().renderer_crash_count());
131 EXPECT_EQ(1, system_profile.stability().renderer_failed_launch_count()); 113 EXPECT_EQ(1, system_profile.stability().renderer_failed_launch_count());
132 EXPECT_EQ(0, system_profile.stability().extension_renderer_crash_count()); 114 EXPECT_EQ(0, system_profile.stability().extension_renderer_crash_count());
133
134 #if defined(ENABLE_EXTENSIONS)
135 provider.ClearSavedStabilityMetrics();
136
137 // Owned by rph_factory.
138 content::RenderProcessHost* extension_host(
139 rph_factory->CreateRenderProcessHost(profile, site_instance.get()));
140
141 // Make the rph an extension rph.
142 extensions::ProcessMap::Get(profile)
143 ->Insert("1", extension_host->GetID(), site_instance->GetId());
144
145 // Crash and abnormal termination should increment extension crash count.
146 provider.Observe(
147 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
148 content::Source<content::RenderProcessHost>(extension_host),
149 content::Details<content::RenderProcessHost::RendererClosedDetails>(
150 &crash_details));
151
152 // Failed launch increments failed launch count.
153 provider.Observe(
154 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
155 content::Source<content::RenderProcessHost>(extension_host),
156 content::Details<content::RenderProcessHost::RendererClosedDetails>(
157 &failed_launch_details));
158
159 system_profile.Clear();
160 provider.ProvideStabilityMetrics(&system_profile);
161
162 EXPECT_EQ(0, system_profile.stability().renderer_crash_count());
163 EXPECT_EQ(1, system_profile.stability().extension_renderer_crash_count());
164 EXPECT_EQ(
165 1, system_profile.stability().extension_renderer_failed_launch_count());
166 #endif
167
168 profile_manager->DeleteAllTestingProfiles();
169 } 115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698