This source file includes following definitions.
- SetUpCommandLine
- OpenTabs
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include <string>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test_utils.h"
#include "net/base/net_util.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"
class MetricsServiceBrowserTest : public InProcessBrowserTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kMetricsRecordingOnly);
}
void OpenTabs() {
const int kBrowserTestFlags =
ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION;
base::FilePath test_directory;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_directory));
base::FilePath page1_path = test_directory.AppendASCII("title2.html");
ui_test_utils::NavigateToURLWithDisposition(
browser(),
net::FilePathToFileURL(page1_path),
NEW_FOREGROUND_TAB,
kBrowserTestFlags);
base::FilePath page2_path = test_directory.AppendASCII("iframe.html");
ui_test_utils::NavigateToURLWithDisposition(
browser(),
net::FilePathToFileURL(page2_path),
NEW_FOREGROUND_TAB,
kBrowserTestFlags);
}
};
class MetricsServiceReportingTest : public InProcessBrowserTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(switches::kEnableMetricsReportingForTesting);
}
};
IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CloseRenderersNormally) {
OpenTabs();
const PrefService* prefs = g_browser_process->local_state();
EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount));
EXPECT_EQ(3, prefs->GetInteger(prefs::kStabilityPageLoadCount));
EXPECT_EQ(0, prefs->GetInteger(prefs::kStabilityRendererCrashCount));
}
#if defined(OS_LINUX)
#define MAYBE_CrashRenderers DISABLED_CrashRenderers
#else
#define MAYBE_CrashRenderers CrashRenderers
#endif
IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, MAYBE_CrashRenderers) {
OpenTabs();
content::RenderProcessHostWatcher observer(
browser()->tab_strip_model()->GetActiveWebContents(),
content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
ui_test_utils::NavigateToURL(browser(), GURL(content::kChromeUICrashURL));
observer.Wait();
const PrefService* prefs = g_browser_process->local_state();
while (!prefs->GetInteger(prefs::kStabilityRendererCrashCount)) {
content::RunAllPendingInMessageLoop();
}
EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityLaunchCount));
EXPECT_EQ(4, prefs->GetInteger(prefs::kStabilityPageLoadCount));
EXPECT_EQ(1, prefs->GetInteger(prefs::kStabilityRendererCrashCount));
}
IN_PROC_BROWSER_TEST_F(MetricsServiceBrowserTest, CheckLowEntropySourceUsed) {
ASSERT_TRUE(g_browser_process->metrics_service());
EXPECT_EQ(MetricsService::LAST_ENTROPY_LOW,
g_browser_process->metrics_service()->entropy_source_returned());
}
IN_PROC_BROWSER_TEST_F(MetricsServiceReportingTest,
CheckHighEntropySourceUsed) {
ASSERT_TRUE(g_browser_process->metrics_service());
EXPECT_EQ(MetricsService::LAST_ENTROPY_HIGH,
g_browser_process->metrics_service()->entropy_source_returned());
}