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

Side by Side Diff: chrome/browser/metrics/chrome_stability_metrics_provider_unittest.cc

Issue 1321313002: Revert of Add tests for Chrome Stability Metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 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 namespace {
25
26 // Must be subclass of ExtensionsTest - see https://crbug.com/395820
27 class ChromeStabilityMetricsProviderTest : public extensions::ExtensionsTest {
28 protected:
29 ChromeStabilityMetricsProviderTest() : prefs_(new TestingPrefServiceSimple) {
30 ChromeStabilityMetricsProvider::RegisterPrefs(prefs()->registry());
31 }
32
33 TestingPrefServiceSimple* prefs() { return prefs_.get(); }
34
35 private:
36 scoped_ptr<TestingPrefServiceSimple> prefs_;
37 content::TestBrowserThreadBundle thread_bundle_;
38
39 DISALLOW_COPY_AND_ASSIGN(ChromeStabilityMetricsProviderTest);
40 };
41
42 } // namespace
43
44 TEST_F(ChromeStabilityMetricsProviderTest, BrowserChildProcessObserver) {
45 ChromeStabilityMetricsProvider 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(ChromeStabilityMetricsProviderTest, NotificationObserver) {
65 ChromeStabilityMetricsProvider provider(prefs());
66 content::MockRenderProcessHost host(browser_context());
67
68 // Crash and abnormal termination should increment renderer crash count.
69 content::RenderProcessHost::RendererClosedDetails crash_details(
70 base::TERMINATION_STATUS_PROCESS_CRASHED, 1);
71 provider.Observe(
72 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
73 content::Source<content::RenderProcessHost>(&host),
74 content::Details<content::RenderProcessHost::RendererClosedDetails>(
75 &crash_details));
76
77 content::RenderProcessHost::RendererClosedDetails term_details(
78 base::TERMINATION_STATUS_ABNORMAL_TERMINATION, 1);
79 provider.Observe(
80 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
81 content::Source<content::RenderProcessHost>(&host),
82 content::Details<content::RenderProcessHost::RendererClosedDetails>(
83 &term_details));
84
85 // Kill does not increment renderer crash count.
86 content::RenderProcessHost::RendererClosedDetails kill_details(
87 base::TERMINATION_STATUS_PROCESS_WAS_KILLED, 1);
88 provider.Observe(
89 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
90 content::Source<content::RenderProcessHost>(&host),
91 content::Details<content::RenderProcessHost::RendererClosedDetails>(
92 &kill_details));
93
94 metrics::SystemProfileProto system_profile;
95
96 // Call ProvideStabilityMetrics to check that it will force pending tasks to
97 // be executed immediately.
98 provider.ProvideStabilityMetrics(&system_profile);
99
100 const metrics::SystemProfileProto_Stability& stability =
101 system_profile.stability();
102
103 EXPECT_EQ(2, stability.renderer_crash_count());
104 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_stability_metrics_provider.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698