Index: chrome/browser/metrics/chrome_stability_metrics_provider_unittest.cc |
diff --git a/chrome/browser/metrics/chrome_stability_metrics_provider_unittest.cc b/chrome/browser/metrics/chrome_stability_metrics_provider_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..acf39c426323d28b9e141460ee1088128ca4fcc7 |
--- /dev/null |
+++ b/chrome/browser/metrics/chrome_stability_metrics_provider_unittest.cc |
@@ -0,0 +1,101 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/metrics/chrome_stability_metrics_provider.h" |
+ |
+#include "base/basictypes.h" |
+#include "base/prefs/pref_service.h" |
+#include "base/prefs/scoped_user_pref_update.h" |
+#include "base/prefs/testing_pref_service.h" |
+#include "components/metrics/proto/system_profile.pb.h" |
+#include "content/public/browser/browser_context.h" |
+#include "content/public/browser/child_process_data.h" |
+#include "content/public/browser/notification_details.h" |
+#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/notification_types.h" |
+#include "content/public/browser/render_process_host.h" |
+#include "content/public/common/process_type.h" |
+#include "content/public/test/mock_render_process_host.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+#include "extensions/browser/extensions_test.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+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.
|
+ |
+namespace { |
+ |
+// Must be subclass of ExtensionsTest - see https://crbug.com/395820 |
+class ChromeStabilityMetricsProviderTest : public extensions::ExtensionsTest { |
+ protected: |
+ ChromeStabilityMetricsProviderTest() : prefs_(new TestingPrefServiceSimple) { |
+ ChromeStabilityMetricsProvider::RegisterPrefs(prefs()->registry()); |
+ } |
+ |
+ TestingPrefServiceSimple* prefs() { return prefs_.get(); } |
+ |
+ private: |
+ scoped_ptr<TestingPrefServiceSimple> prefs_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ChromeStabilityMetricsProviderTest); |
+}; |
+ |
+} // namespace |
+ |
+TEST_F(ChromeStabilityMetricsProviderTest, BrowserChildProcessObserver) { |
+ 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.
|
+ ChromeStabilityMetricsProvider provider(prefs()); |
+ |
+ ChildProcessData child_process_data(PROCESS_TYPE_RENDERER); |
+ provider.BrowserChildProcessCrashed(child_process_data, 1); |
+ provider.BrowserChildProcessCrashed(child_process_data, 1); |
+ |
+ // Call ProvideStabilityMetrics to check that it will force pending tasks to |
+ // be executed immediately. |
+ metrics::SystemProfileProto system_profile; |
+ |
+ provider.ProvideStabilityMetrics(&system_profile); |
+ |
+ // Check current number of instances created. |
+ const metrics::SystemProfileProto_Stability& stability = |
+ system_profile.stability(); |
+ |
+ 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.
|
+} |
+ |
+TEST_F(ChromeStabilityMetricsProviderTest, NotificationObserver) { |
+ TestBrowserThreadBundle thread_bundle; |
+ ChromeStabilityMetricsProvider provider(prefs()); |
+ MockRenderProcessHost host(browser_context()); |
+ |
+ // Crash and abnormal termination should increment renderer crash count. |
+ RenderProcessHost::RendererClosedDetails crash_details( |
+ base::TERMINATION_STATUS_PROCESS_CRASHED, 1); |
+ provider.Observe( |
+ NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(&host), |
+ Details<RenderProcessHost::RendererClosedDetails>(&crash_details)); |
+ |
+ RenderProcessHost::RendererClosedDetails term_details( |
+ base::TERMINATION_STATUS_ABNORMAL_TERMINATION, 1); |
+ provider.Observe( |
+ NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(&host), |
+ Details<RenderProcessHost::RendererClosedDetails>(&term_details)); |
+ |
+ // Kill does not increment renderer crash count. |
+ RenderProcessHost::RendererClosedDetails kill_details( |
+ base::TERMINATION_STATUS_PROCESS_WAS_KILLED, 1); |
+ provider.Observe( |
+ NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(&host), |
+ Details<RenderProcessHost::RendererClosedDetails>(&kill_details)); |
+ |
+ metrics::SystemProfileProto system_profile; |
+ |
+ // Call ProvideStabilityMetrics to check that it will force pending tasks to |
+ // be executed immediately. |
+ provider.ProvideStabilityMetrics(&system_profile); |
+ |
+ const metrics::SystemProfileProto_Stability& stability = |
+ system_profile.stability(); |
+ |
+ EXPECT_EQ(stability.renderer_crash_count(), 2); |
+} |