OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Tests the MetricsService stat recording to make sure that the numbers are | 5 // Tests the MetricsService stat recording to make sure that the numbers are |
6 // what we expect. | 6 // what we expect. |
7 | 7 |
8 #include "components/metrics/metrics_service.h" | 8 #include "components/metrics/metrics_service.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 kBrowserTestFlags); | 58 kBrowserTestFlags); |
59 } | 59 } |
60 }; | 60 }; |
61 | 61 |
62 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CloseRenderersNormally) { | 62 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CloseRenderersNormally) { |
63 OpenTabs(); | 63 OpenTabs(); |
64 | 64 |
65 // Verify that the expected stability metrics were recorded. | 65 // Verify that the expected stability metrics were recorded. |
66 const PrefService* prefs = g_browser_process->local_state(); | 66 const PrefService* prefs = g_browser_process->local_state(); |
67 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount)); | 67 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount)); |
68 EXPECT_EQ(3, prefs->GetInteger(prefs::kStabilityPageLoadCount)); | 68 EXPECT_EQ(3, prefs->GetInteger(metrics::prefs::kStabilityPageLoadCount)); |
69 EXPECT_EQ(0, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); | 69 EXPECT_EQ(0, prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)); |
70 // TODO(isherman): We should also verify that | 70 // TODO(isherman): We should also verify that |
71 // metrics::prefs::kStabilityExitedCleanly | 71 // metrics::prefs::kStabilityExitedCleanly |
72 // is set to true, but this preference isn't set until the browser | 72 // is set to true, but this preference isn't set until the browser |
73 // exits... it's not clear to me how to test that. | 73 // exits... it's not clear to me how to test that. |
74 } | 74 } |
75 | 75 |
76 // Flaky on Linux. See http://crbug.com/131094 | 76 // Flaky on Linux. See http://crbug.com/131094 |
77 // Child crashes fail the process on ASan (see crbug.com/411251, | 77 // Child crashes fail the process on ASan (see crbug.com/411251, |
78 // crbug.com/368525). | 78 // crbug.com/368525). |
79 #if defined(OS_LINUX) || defined(ADDRESS_SANITIZER) | 79 #if defined(OS_LINUX) || defined(ADDRESS_SANITIZER) |
(...skipping 11 matching lines...) Expand all Loading... |
91 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL)); | 91 ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL)); |
92 observer.Wait(); | 92 observer.Wait(); |
93 | 93 |
94 // The MetricsService listens for the same notification, so the |observer| | 94 // The MetricsService listens for the same notification, so the |observer| |
95 // might finish waiting before the MetricsService has a chance to process the | 95 // might finish waiting before the MetricsService has a chance to process the |
96 // notification. To avoid racing here, we repeatedly run the message loop | 96 // notification. To avoid racing here, we repeatedly run the message loop |
97 // until the MetricsService catches up. This should happen "real soon now", | 97 // until the MetricsService catches up. This should happen "real soon now", |
98 // since the notification is posted to all observers essentially | 98 // since the notification is posted to all observers essentially |
99 // simultaneously... so busy waiting here shouldn't be too bad. | 99 // simultaneously... so busy waiting here shouldn't be too bad. |
100 const PrefService* prefs = g_browser_process->local_state(); | 100 const PrefService* prefs = g_browser_process->local_state(); |
101 while (!prefs->GetInteger(prefs::kStabilityRendererCrashCount)) { | 101 while (!prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)) { |
102 content::RunAllPendingInMessageLoop(); | 102 content::RunAllPendingInMessageLoop(); |
103 } | 103 } |
104 | 104 |
105 // Verify that the expected stability metrics were recorded. | 105 // Verify that the expected stability metrics were recorded. |
106 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount)); | 106 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityLaunchCount)); |
107 EXPECT_EQ(4, prefs->GetInteger(prefs::kStabilityPageLoadCount)); | 107 EXPECT_EQ(4, prefs->GetInteger(metrics::prefs::kStabilityPageLoadCount)); |
108 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); | 108 EXPECT_EQ(1, prefs->GetInteger(metrics::prefs::kStabilityRendererCrashCount)); |
109 // TODO(isherman): We should also verify that | 109 // TODO(isherman): We should also verify that |
110 // metrics::prefs::kStabilityExitedCleanly | 110 // metrics::prefs::kStabilityExitedCleanly |
111 // is set to true, but this preference isn't set until the browser | 111 // is set to true, but this preference isn't set until the browser |
112 // exits... it's not clear to me how to test that. | 112 // exits... it's not clear to me how to test that. |
113 } | 113 } |
114 | 114 |
OLD | NEW |