| 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> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/process/memory.h" | 15 #include "base/process/memory.h" |
| 16 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | |
| 23 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
| 25 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 26 #include "components/metrics/metrics_pref_names.h" | 25 #include "components/metrics/metrics_pref_names.h" |
| 26 #include "components/metrics/metrics_switches.h" |
| 27 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| 28 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 29 #include "net/base/filename_util.h" | 29 #include "net/base/filename_util.h" |
| 30 #include "services/service_manager/embedder/switches.h" | 30 #include "services/service_manager/embedder/switches.h" |
| 31 #include "ui/base/window_open_disposition.h" | 31 #include "ui/base/window_open_disposition.h" |
| 32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 33 | 33 |
| 34 #if defined(OS_POSIX) | 34 #if defined(OS_POSIX) |
| 35 #include <sys/wait.h> | 35 #include <sys/wait.h> |
| 36 #endif | 36 #endif |
| (...skipping 28 matching lines...) Expand all Loading... |
| 65 // code is recorded. | 65 // code is recorded. |
| 66 // | 66 // |
| 67 // TODO(isherman): We should also verify that | 67 // TODO(isherman): We should also verify that |
| 68 // metrics::prefs::kStabilityExitedCleanly is set correctly after each of these | 68 // metrics::prefs::kStabilityExitedCleanly is set correctly after each of these |
| 69 // tests, but this preference isn't set until the browser exits... it's not | 69 // tests, but this preference isn't set until the browser exits... it's not |
| 70 // clear to me how to test that. | 70 // clear to me how to test that. |
| 71 class MetricsServiceBrowserTest : public InProcessBrowserTest { | 71 class MetricsServiceBrowserTest : public InProcessBrowserTest { |
| 72 public: | 72 public: |
| 73 void SetUpCommandLine(base::CommandLine* command_line) override { | 73 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 74 // Enable the metrics service for testing (in recording-only mode). | 74 // Enable the metrics service for testing (in recording-only mode). |
| 75 command_line->AppendSwitch(switches::kMetricsRecordingOnly); | 75 command_line->AppendSwitch(metrics::switches::kMetricsRecordingOnly); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Open three tabs then navigate to |crashy_url| and wait for the renderer to | 78 // Open three tabs then navigate to |crashy_url| and wait for the renderer to |
| 79 // crash. | 79 // crash. |
| 80 void OpenTabsAndNavigateToCrashyUrl(const std::string& crashy_url) { | 80 void OpenTabsAndNavigateToCrashyUrl(const std::string& crashy_url) { |
| 81 // Opens three tabs. | 81 // Opens three tabs. |
| 82 OpenThreeTabs(); | 82 OpenThreeTabs(); |
| 83 | 83 |
| 84 // Kill the process for one of the tabs by navigating to |crashy_url|. | 84 // Kill the process for one of the tabs by navigating to |crashy_url|. |
| 85 content::RenderProcessHostWatcher observer( | 85 content::RenderProcessHostWatcher observer( |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 #endif | 221 #endif |
| 222 | 222 |
| 223 // Exit codes are recorded after being passed through std::abs see | 223 // Exit codes are recorded after being passed through std::abs see |
| 224 // MapCrashExitCodeForHistogram. | 224 // MapCrashExitCodeForHistogram. |
| 225 histogram_tester.ExpectUniqueSample("CrashExitCodes.Renderer", | 225 histogram_tester.ExpectUniqueSample("CrashExitCodes.Renderer", |
| 226 std::abs(expected_exit_code), 1); | 226 std::abs(expected_exit_code), 1); |
| 227 | 227 |
| 228 histogram_tester.ExpectUniqueSample("Tabs.SadTab.OomCreated", 1, 1); | 228 histogram_tester.ExpectUniqueSample("Tabs.SadTab.OomCreated", 1, 1); |
| 229 } | 229 } |
| 230 #endif // OS_WIN && !ADDRESS_SANITIZER | 230 #endif // OS_WIN && !ADDRESS_SANITIZER |
| OLD | NEW |