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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 kBrowserTestFlags); | 55 kBrowserTestFlags); |
56 } | 56 } |
57 }; | 57 }; |
58 | 58 |
59 IN_PROC_BROWSER_TEST_F(MetricsServiceTest, CloseRenderersNormally) { | 59 IN_PROC_BROWSER_TEST_F(MetricsServiceTest, CloseRenderersNormally) { |
60 OpenTabs(); | 60 OpenTabs(); |
61 | 61 |
62 // Verify that the expected stability metrics were recorded. | 62 // Verify that the expected stability metrics were recorded. |
63 const PrefService* prefs = g_browser_process->local_state(); | 63 const PrefService* prefs = g_browser_process->local_state(); |
64 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount)); | 64 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount)); |
65 #if defined(USE_VIRTUAL_KEYBOARD) | |
66 // The keyboard page loads. | |
67 EXPECT_EQ(4, prefs->GetInteger(prefs::kStabilityPageLoadCount)); | |
68 #else | |
69 EXPECT_EQ(3, prefs->GetInteger(prefs::kStabilityPageLoadCount)); | 65 EXPECT_EQ(3, prefs->GetInteger(prefs::kStabilityPageLoadCount)); |
70 #endif | |
71 EXPECT_EQ(0, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); | 66 EXPECT_EQ(0, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); |
72 // TODO(isherman): We should also verify that prefs::kStabilityExitedCleanly | 67 // TODO(isherman): We should also verify that prefs::kStabilityExitedCleanly |
73 // is set to true, but this preference isn't set until the browser | 68 // is set to true, but this preference isn't set until the browser |
74 // exits... it's not clear to me how to test that. | 69 // exits... it's not clear to me how to test that. |
75 } | 70 } |
76 | 71 |
77 IN_PROC_BROWSER_TEST_F(MetricsServiceTest, CrashRenderers) { | 72 IN_PROC_BROWSER_TEST_F(MetricsServiceTest, CrashRenderers) { |
78 OpenTabs(); | 73 OpenTabs(); |
79 | 74 |
80 // Kill the process for one of the tabs. | 75 // Kill the process for one of the tabs. |
81 ui_test_utils::WindowedNotificationObserver observer( | 76 ui_test_utils::WindowedNotificationObserver observer( |
82 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 77 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
83 content::NotificationService::AllSources()); | 78 content::NotificationService::AllSources()); |
84 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); | 79 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); |
85 observer.Wait(); | 80 observer.Wait(); |
86 | 81 |
87 // The MetricsService listens for the same notification, so the |observer| | 82 // The MetricsService listens for the same notification, so the |observer| |
88 // might finish waiting before the MetricsService has a chance to process the | 83 // might finish waiting before the MetricsService has a chance to process the |
89 // notification. To avoid racing here, we repeatedly run the message loop | 84 // notification. To avoid racing here, we repeatedly run the message loop |
90 // until the MetricsService catches up. This should happen "real soon now", | 85 // until the MetricsService catches up. This should happen "real soon now", |
91 // since the notification is posted to all observers essentially | 86 // since the notification is posted to all observers essentially |
92 // simultaneously... so busy waiting here shouldn't be too bad. | 87 // simultaneously... so busy waiting here shouldn't be too bad. |
93 const PrefService* prefs = g_browser_process->local_state(); | 88 const PrefService* prefs = g_browser_process->local_state(); |
94 while (!prefs->GetInteger(prefs::kStabilityRendererCrashCount)) { | 89 while (!prefs->GetInteger(prefs::kStabilityRendererCrashCount)) { |
95 ui_test_utils::RunAllPendingInMessageLoop(); | 90 ui_test_utils::RunAllPendingInMessageLoop(); |
96 } | 91 } |
97 | 92 |
98 // Verify that the expected stability metrics were recorded. | 93 // Verify that the expected stability metrics were recorded. |
99 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount)); | 94 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount)); |
100 #if defined(USE_VIRTUAL_KEYBOARD) | |
101 // The keyboard page loads. | |
102 EXPECT_EQ(5, prefs->GetInteger(prefs::kStabilityPageLoadCount)); | |
103 #else | |
104 EXPECT_EQ(4, prefs->GetInteger(prefs::kStabilityPageLoadCount)); | 95 EXPECT_EQ(4, prefs->GetInteger(prefs::kStabilityPageLoadCount)); |
105 #endif | |
106 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); | 96 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); |
107 // TODO(isherman): We should also verify that prefs::kStabilityExitedCleanly | 97 // TODO(isherman): We should also verify that prefs::kStabilityExitedCleanly |
108 // is set to true, but this preference isn't set until the browser | 98 // is set to true, but this preference isn't set until the browser |
109 // exits... it's not clear to me how to test that. | 99 // exits... it's not clear to me how to test that. |
110 } | 100 } |
OLD | NEW |