1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Tests the MetricsService stat recording to make sure that the numbers are
// what we expect.
#include <string>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/test/test_timeouts.h"
#include "base/threading/platform_thread.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/prefs/pref_service_mock_builder.h"
#include "chrome/browser/prefs/pref_value_store.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/json_pref_store.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "content/common/notification_service.h"
#include "net/base/net_util.h"
class MetricsServiceTest : public UITest {
public:
MetricsServiceTest() : UITest() {
// We need to show the window so web content type tabs load.
show_window_ = true;
}
// Open a few tabs of random content
void OpenTabs() {
scoped_refptr<BrowserProxy> window = automation()->GetBrowserWindow(0);
ASSERT_TRUE(window.get());
FilePath page1_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &page1_path));
page1_path = page1_path.AppendASCII("title2.html");
ASSERT_TRUE(window->AppendTab(net::FilePathToFileURL(page1_path)));
FilePath page2_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &page2_path));
page2_path = page2_path.AppendASCII("iframe.html");
ASSERT_TRUE(window->AppendTab(net::FilePathToFileURL(page2_path)));
}
// Get a PrefService whose contents correspond to the Local State file
// that was saved by the app as it closed. The caller takes ownership of the
// returned PrefService object.
PrefService* GetLocalState() {
FilePath path = user_data_dir().Append(chrome::kLocalStateFilename);
return PrefServiceMockBuilder().WithUserFilePrefs(path).Create();
}
#if defined(OS_WIN)
// This is not really Windows-specific, the transition is just being done
// in stages, and Windows is first. See below for more info.
// TODO(phajdan.jr): Remove #ifdef after fixing http://crbug.com/61062.
private:
NotificationService notification_service_;
#endif
};
#if defined(OS_MACOSX)
// Flaky across all Mac bots: http://crbug.com/92635
#define MAYBE_CloseRenderersNormally FLAKY_CloseRenderersNormally
#else
#define MAYBE_CloseRenderersNormally CloseRenderersNormally
#endif
TEST_F(MetricsServiceTest, MAYBE_CloseRenderersNormally) {
OpenTabs();
QuitBrowser();
scoped_ptr<PrefService> local_state(GetLocalState());
local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
local_state->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
local_state->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0);
local_state->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0);
EXPECT_TRUE(local_state->GetBoolean(prefs::kStabilityExitedCleanly));
EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityLaunchCount));
#if defined(TOUCH_UI)
// The keyboard page loads for touchui.
EXPECT_EQ(4, local_state->GetInteger(prefs::kStabilityPageLoadCount));
#else
EXPECT_EQ(3, local_state->GetInteger(prefs::kStabilityPageLoadCount));
#endif
EXPECT_EQ(0, local_state->GetInteger(prefs::kStabilityRendererCrashCount));
}
TEST_F(MetricsServiceTest, DISABLED_CrashRenderers) {
// This doesn't make sense to test in single process mode.
if (ProxyLauncher::in_process_renderer())
return;
OpenTabs();
{
// Limit the lifetime of various automation proxies used here. We must
// destroy them before calling QuitBrowser.
scoped_refptr<BrowserProxy> window = automation()->GetBrowserWindow(0);
ASSERT_TRUE(window.get());
// Kill the process for one of the tabs.
scoped_refptr<TabProxy> tab(window->GetTab(1));
ASSERT_TRUE(tab.get());
// We can get crash dumps on Windows always, Linux when breakpad is
// enabled, and all platforms for official Google Chrome builds.
#if defined(OS_WIN) || defined(USE_LINUX_BREAKPAD) || \
defined(GOOGLE_CHROME_BUILD)
expected_crashes_ = 1;
#endif
ASSERT_TRUE(tab->NavigateToURLAsync(GURL(chrome::kAboutCrashURL)));
}
// Give the browser a chance to notice the crashed tab.
base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
QuitBrowser();
scoped_ptr<PrefService> local_state(GetLocalState());
local_state->RegisterBooleanPref(prefs::kStabilityExitedCleanly, true);
local_state->RegisterIntegerPref(prefs::kStabilityLaunchCount, 0);
local_state->RegisterIntegerPref(prefs::kStabilityPageLoadCount, 0);
local_state->RegisterIntegerPref(prefs::kStabilityRendererCrashCount, 0);
EXPECT_TRUE(local_state->GetBoolean(prefs::kStabilityExitedCleanly));
EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityLaunchCount));
#if defined(TOUCH_UI)
// The keyboard page loads for touchui.
EXPECT_EQ(5, local_state->GetInteger(prefs::kStabilityPageLoadCount));
#else
EXPECT_EQ(4, local_state->GetInteger(prefs::kStabilityPageLoadCount));
#endif
EXPECT_EQ(1, local_state->GetInteger(prefs::kStabilityRendererCrashCount));
}
|