OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "chrome/browser/metrics/chrome_stability_metrics_provider.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 "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_source.h" | |
16 #include "content/public/browser/notification_types.h" | |
17 #include "content/public/browser/render_process_host.h" | |
18 #include "content/public/common/process_type.h" | |
19 #include "content/public/test/mock_render_process_host.h" | |
20 #include "content/public/test/test_browser_thread_bundle.h" | |
21 #include "extensions/browser/extensions_test.h" | |
22 #include "testing/gtest/include/gtest/gtest.h" | |
23 | |
24 using namespace content; | |
Alexei Svitkine (slow)
2015/08/31 15:12:26
Nit: In metrics/ code, we prefer not to have using
Will Harris
2015/08/31 18:18:35
Done.
| |
25 | |
26 namespace { | |
27 | |
28 // Must be subclass of ExtensionsTest - see https://crbug.com/395820 | |
29 class ChromeStabilityMetricsProviderTest : public extensions::ExtensionsTest { | |
30 protected: | |
31 ChromeStabilityMetricsProviderTest() : prefs_(new TestingPrefServiceSimple) { | |
32 ChromeStabilityMetricsProvider::RegisterPrefs(prefs()->registry()); | |
33 } | |
34 | |
35 TestingPrefServiceSimple* prefs() { return prefs_.get(); } | |
36 | |
37 private: | |
38 scoped_ptr<TestingPrefServiceSimple> prefs_; | |
39 | |
40 DISALLOW_COPY_AND_ASSIGN(ChromeStabilityMetricsProviderTest); | |
41 }; | |
42 | |
43 } // namespace | |
44 | |
45 TEST_F(ChromeStabilityMetricsProviderTest, BrowserChildProcessObserver) { | |
46 TestBrowserThreadBundle thread_bundle; | |
Alexei Svitkine (slow)
2015/08/31 15:12:26
Nit: This can be a member of the test harness clas
Will Harris
2015/08/31 18:18:35
Done.
| |
47 ChromeStabilityMetricsProvider provider(prefs()); | |
48 | |
49 ChildProcessData child_process_data(PROCESS_TYPE_RENDERER); | |
50 provider.BrowserChildProcessCrashed(child_process_data, 1); | |
51 provider.BrowserChildProcessCrashed(child_process_data, 1); | |
52 | |
53 // Call ProvideStabilityMetrics to check that it will force pending tasks to | |
54 // be executed immediately. | |
55 metrics::SystemProfileProto system_profile; | |
56 | |
57 provider.ProvideStabilityMetrics(&system_profile); | |
58 | |
59 // Check current number of instances created. | |
60 const metrics::SystemProfileProto_Stability& stability = | |
61 system_profile.stability(); | |
62 | |
63 EXPECT_EQ(stability.child_process_crash_count(), 2); | |
Alexei Svitkine (slow)
2015/08/31 15:12:26
Nit: Expected value should be on the left. Please
Will Harris
2015/08/31 18:18:35
Done.
| |
64 } | |
65 | |
66 TEST_F(ChromeStabilityMetricsProviderTest, NotificationObserver) { | |
67 TestBrowserThreadBundle thread_bundle; | |
68 ChromeStabilityMetricsProvider provider(prefs()); | |
69 MockRenderProcessHost host(browser_context()); | |
70 | |
71 // Crash and abnormal termination should increment renderer crash count. | |
72 RenderProcessHost::RendererClosedDetails crash_details( | |
73 base::TERMINATION_STATUS_PROCESS_CRASHED, 1); | |
74 provider.Observe( | |
75 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(&host), | |
76 Details<RenderProcessHost::RendererClosedDetails>(&crash_details)); | |
77 | |
78 RenderProcessHost::RendererClosedDetails term_details( | |
79 base::TERMINATION_STATUS_ABNORMAL_TERMINATION, 1); | |
80 provider.Observe( | |
81 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(&host), | |
82 Details<RenderProcessHost::RendererClosedDetails>(&term_details)); | |
83 | |
84 // Kill does not increment renderer crash count. | |
85 RenderProcessHost::RendererClosedDetails kill_details( | |
86 base::TERMINATION_STATUS_PROCESS_WAS_KILLED, 1); | |
87 provider.Observe( | |
88 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(&host), | |
89 Details<RenderProcessHost::RendererClosedDetails>(&kill_details)); | |
90 | |
91 metrics::SystemProfileProto system_profile; | |
92 | |
93 // Call ProvideStabilityMetrics to check that it will force pending tasks to | |
94 // be executed immediately. | |
95 provider.ProvideStabilityMetrics(&system_profile); | |
96 | |
97 const metrics::SystemProfileProto_Stability& stability = | |
98 system_profile.stability(); | |
99 | |
100 EXPECT_EQ(stability.renderer_crash_count(), 2); | |
101 } | |
OLD | NEW |