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 "chrome/browser/metrics/metrics_service.h" |
| 9 |
8 #include <string> | 10 #include <string> |
9 | 11 |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
12 #include "base/path_service.h" | 14 #include "base/path_service.h" |
13 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/metrics/metrics_service.h" | |
16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
24 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
25 #include "net/base/filename_util.h" | 26 #include "net/base/filename_util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
51 | 52 |
52 base::FilePath page2_path = test_directory.AppendASCII("iframe.html"); | 53 base::FilePath page2_path = test_directory.AppendASCII("iframe.html"); |
53 ui_test_utils::NavigateToURLWithDisposition( | 54 ui_test_utils::NavigateToURLWithDisposition( |
54 browser(), | 55 browser(), |
55 net::FilePathToFileURL(page2_path), | 56 net::FilePathToFileURL(page2_path), |
56 NEW_FOREGROUND_TAB, | 57 NEW_FOREGROUND_TAB, |
57 kBrowserTestFlags); | 58 kBrowserTestFlags); |
58 } | 59 } |
59 }; | 60 }; |
60 | 61 |
61 class MetricsServiceReportingTest : public InProcessBrowserTest { | |
62 public: | |
63 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
64 // Enable the metrics service for testing (in the full mode). | |
65 command_line->AppendSwitch(switches::kEnableMetricsReportingForTesting); | |
66 } | |
67 }; | |
68 | |
69 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CloseRenderersNormally) { | 62 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CloseRenderersNormally) { |
70 OpenTabs(); | 63 OpenTabs(); |
71 | 64 |
72 // Verify that the expected stability metrics were recorded. | 65 // Verify that the expected stability metrics were recorded. |
73 const PrefService* prefs = g_browser_process->local_state(); | 66 const PrefService* prefs = g_browser_process->local_state(); |
74 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount)); | 67 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount)); |
75 EXPECT_EQ(3, prefs->GetInteger(prefs::kStabilityPageLoadCount)); | 68 EXPECT_EQ(3, prefs->GetInteger(prefs::kStabilityPageLoadCount)); |
76 EXPECT_EQ(0, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); | 69 EXPECT_EQ(0, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); |
77 // TODO(isherman): We should also verify that prefs::kStabilityExitedCleanly | 70 // TODO(isherman): We should also verify that prefs::kStabilityExitedCleanly |
78 // is set to true, but this preference isn't set until the browser | 71 // is set to true, but this preference isn't set until the browser |
(...skipping 29 matching lines...) Expand all Loading... |
108 | 101 |
109 // Verify that the expected stability metrics were recorded. | 102 // Verify that the expected stability metrics were recorded. |
110 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount)); | 103 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount)); |
111 EXPECT_EQ(4, prefs->GetInteger(prefs::kStabilityPageLoadCount)); | 104 EXPECT_EQ(4, prefs->GetInteger(prefs::kStabilityPageLoadCount)); |
112 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); | 105 EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityRendererCrashCount)); |
113 // TODO(isherman): We should also verify that prefs::kStabilityExitedCleanly | 106 // TODO(isherman): We should also verify that prefs::kStabilityExitedCleanly |
114 // is set to true, but this preference isn't set until the browser | 107 // is set to true, but this preference isn't set until the browser |
115 // exits... it's not clear to me how to test that. | 108 // exits... it's not clear to me how to test that. |
116 } | 109 } |
117 | 110 |
118 IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CheckLowEntropySourceUsed) { | |
119 // Since MetricsService is only in recording mode, and is not reporting, | |
120 // check that the low entropy source is returned at some point. | |
121 ASSERT_TRUE(g_browser_process->metrics_service()); | |
122 EXPECT_EQ(MetricsService::LAST_ENTROPY_LOW, | |
123 g_browser_process->metrics_service()->entropy_source_returned()); | |
124 } | |
125 | |
126 IN_PROC_BROWSER_TEST_F(MetricsServiceReportingTest, | |
127 CheckHighEntropySourceUsed) { | |
128 // Since the full metrics service runs in this test, we expect that | |
129 // MetricsService returns the full entropy source at some point during | |
130 // BrowserMain startup. | |
131 ASSERT_TRUE(g_browser_process->metrics_service()); | |
132 EXPECT_EQ(MetricsService::LAST_ENTROPY_HIGH, | |
133 g_browser_process->metrics_service()->entropy_source_returned()); | |
134 } | |
OLD | NEW |