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