OLD | NEW |
| (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 "blimp/engine/app/blimp_stability_metrics_provider.h" | |
6 | |
7 #include "base/macros.h" | |
8 #include "components/metrics/proto/system_profile.pb.h" | |
9 #include "components/prefs/pref_service.h" | |
10 #include "components/prefs/scoped_user_pref_update.h" | |
11 #include "components/prefs/testing_pref_service.h" | |
12 #include "content/public/browser/browser_context.h" | |
13 #include "content/public/browser/child_process_data.h" | |
14 #include "content/public/browser/notification_details.h" | |
15 #include "content/public/browser/notification_service.h" | |
16 #include "content/public/browser/notification_source.h" | |
17 #include "content/public/browser/notification_types.h" | |
18 #include "content/public/browser/render_process_host.h" | |
19 #include "content/public/browser/site_instance.h" | |
20 #include "content/public/common/process_type.h" | |
21 #include "content/public/test/mock_render_process_host.h" | |
22 #include "content/public/test/test_browser_thread_bundle.h" | |
23 #include "testing/gtest/include/gtest/gtest.h" | |
24 | |
25 namespace { | |
26 | |
27 class BlimpStabilityMetricsProviderTest : public testing::Test { | |
28 protected: | |
29 BlimpStabilityMetricsProviderTest() : prefs_(new TestingPrefServiceSimple) { | |
30 metrics::StabilityMetricsHelper::RegisterPrefs(prefs()->registry()); | |
31 } | |
32 | |
33 TestingPrefServiceSimple* prefs() { return prefs_.get(); } | |
34 | |
35 private: | |
36 std::unique_ptr<TestingPrefServiceSimple> prefs_; | |
37 content::TestBrowserThreadBundle thread_bundle_; | |
38 | |
39 DISALLOW_COPY_AND_ASSIGN(BlimpStabilityMetricsProviderTest); | |
40 }; | |
41 | |
42 } // namespace | |
43 | |
44 TEST_F(BlimpStabilityMetricsProviderTest, BrowserChildProcessObserver) { | |
45 BlimpStabilityMetricsProvider provider(prefs()); | |
46 | |
47 content::ChildProcessData child_process_data(content::PROCESS_TYPE_RENDERER); | |
48 provider.BrowserChildProcessCrashed(child_process_data, 1); | |
49 provider.BrowserChildProcessCrashed(child_process_data, 1); | |
50 | |
51 // Call ProvideStabilityMetrics to check that it will force pending tasks to | |
52 // be executed immediately. | |
53 metrics::SystemProfileProto system_profile; | |
54 | |
55 provider.ProvideStabilityMetrics(&system_profile); | |
56 | |
57 // Check current number of instances created. | |
58 const metrics::SystemProfileProto_Stability& stability = | |
59 system_profile.stability(); | |
60 | |
61 EXPECT_EQ(2, stability.child_process_crash_count()); | |
62 } | |
63 | |
64 TEST_F(BlimpStabilityMetricsProviderTest, NotificationObserver) { | |
65 BlimpStabilityMetricsProvider provider(prefs()); | |
66 content::NotificationSource irrelevant_source = | |
67 content::Source<std::nullptr_t>(nullptr); | |
68 | |
69 // Load start should increase page load count. | |
70 provider.Observe( | |
71 content::NOTIFICATION_LOAD_START, irrelevant_source, | |
72 content::NotificationService::NoDetails()); | |
73 | |
74 // Crash and abnormal termination should increment renderer crash count. | |
75 content::RenderProcessHost::RendererClosedDetails crash_details( | |
76 base::TERMINATION_STATUS_PROCESS_CRASHED, 1); | |
77 provider.Observe( | |
78 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, irrelevant_source, | |
79 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
80 &crash_details)); | |
81 | |
82 content::RenderProcessHost::RendererClosedDetails term_details( | |
83 base::TERMINATION_STATUS_ABNORMAL_TERMINATION, 1); | |
84 provider.Observe( | |
85 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, irrelevant_source, | |
86 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
87 &term_details)); | |
88 | |
89 // Kill does not increment renderer crash count. | |
90 content::RenderProcessHost::RendererClosedDetails kill_details( | |
91 base::TERMINATION_STATUS_PROCESS_WAS_KILLED, 1); | |
92 provider.Observe( | |
93 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, irrelevant_source, | |
94 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
95 &kill_details)); | |
96 | |
97 // Failed launch increments failed launch count. | |
98 content::RenderProcessHost::RendererClosedDetails failed_launch_details( | |
99 base::TERMINATION_STATUS_LAUNCH_FAILED, 1); | |
100 provider.Observe( | |
101 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, irrelevant_source, | |
102 content::Details<content::RenderProcessHost::RendererClosedDetails>( | |
103 &failed_launch_details)); | |
104 | |
105 metrics::SystemProfileProto system_profile; | |
106 | |
107 // Call ProvideStabilityMetrics to check that it will force pending tasks to | |
108 // be executed immediately. | |
109 provider.ProvideStabilityMetrics(&system_profile); | |
110 | |
111 EXPECT_EQ(1, system_profile.stability().page_load_count()); | |
112 EXPECT_EQ(2, system_profile.stability().renderer_crash_count()); | |
113 EXPECT_EQ(1, system_profile.stability().renderer_failed_launch_count()); | |
114 EXPECT_EQ(0, system_profile.stability().extension_renderer_crash_count()); | |
115 } | |
OLD | NEW |