Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: chrome/common/logging_chrome_uitest.cc

Issue 10082001: Convert the logging ui_test to a browser_test. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "build/build_config.h"
6
7 #if defined(OS_WIN)
8 #include <windows.h>
9 #endif
10
11 #include <string>
12
13 #include "base/basictypes.h"
14 #include "base/command_line.h"
15 #include "base/environment.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/env_vars.h"
18 #include "chrome/common/logging_chrome.h"
19 #include "chrome/test/automation/automation_proxy.h"
20 #include "chrome/test/automation/browser_proxy.h"
21 #include "chrome/test/ui/ui_test.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 class ChromeLoggingTest : public testing::Test {
25 public:
26 // Stores the current value of the log file name environment
27 // variable and sets the variable to new_value.
28 void SaveEnvironmentVariable(std::string new_value) {
29 scoped_ptr<base::Environment> env(base::Environment::Create());
30 if (!env->GetVar(env_vars::kLogFileName, &environment_filename_))
31 environment_filename_ = "";
32
33 env->SetVar(env_vars::kLogFileName, new_value);
34 }
35
36 // Restores the value of the log file nave environment variable
37 // previously saved by SaveEnvironmentVariable().
38 void RestoreEnvironmentVariable() {
39 scoped_ptr<base::Environment> env(base::Environment::Create());
40 env->SetVar(env_vars::kLogFileName, environment_filename_);
41 }
42
43 private:
44 std::string environment_filename_; // Saves real environment value.
45 };
46
47 // Tests the log file name getter without an environment variable.
48 TEST_F(ChromeLoggingTest, LogFileName) {
49 SaveEnvironmentVariable("");
50
51 FilePath filename = logging::GetLogFileName();
52 ASSERT_NE(FilePath::StringType::npos,
53 filename.value().find(FILE_PATH_LITERAL("chrome_debug.log")));
54
55 RestoreEnvironmentVariable();
56 }
57
58 // Tests the log file name getter with an environment variable.
59 TEST_F(ChromeLoggingTest, EnvironmentLogFileName) {
60 SaveEnvironmentVariable("test value");
61
62 FilePath filename = logging::GetLogFileName();
63 ASSERT_EQ(FilePath(FILE_PATH_LITERAL("test value")).value(),
64 filename.value());
65
66 RestoreEnvironmentVariable();
67 }
68
69 #if (defined(OS_LINUX) || defined(OS_ANDROID)) \
70 && (!defined(NDEBUG) || !defined(USE_LINUX_BREAKPAD))
71 // On Linux in Debug mode, Chrome generates a SIGTRAP.
72 // we do not catch SIGTRAPs, thus no crash dump.
73 // This also does not work if Breakpad is disabled.
74 #define EXPECTED_ASSERT_CRASHES 0
75 #else
76 #define EXPECTED_ASSERT_CRASHES 1
77 #endif
78
79 // Virtual keyboard build will start an extra renderer process (the extension
80 // process) for the virtual keyboard.
81 #if defined(USE_VIRTUAL_KEYBOARD)
82 #define EXPECTED_ASSERT_ERRORS 2
83 #else
84 #define EXPECTED_ASSERT_ERRORS 1
85 #endif
86
87 #if !defined(NDEBUG) // We don't have assertions in release builds.
88 // Tests whether we correctly fail on renderer assertions during tests.
89 class AssertionTest : public UITest {
90 protected:
91 AssertionTest() {
92 #if defined(OS_WIN)
93 // TODO(phajdan.jr): Make crash notifications on launch work on Win.
94 wait_for_initial_loads_ = false;
95 #endif
96 launch_arguments_.AppendSwitch(switches::kRendererAssertTest);
97 }
98 };
99
100 // Launch the app in assertion test mode, then close the app.
101 #if defined(OS_WIN)
102 // http://crbug.com/26715
103 #define Assertion DISABLED_Assertion
104 #elif defined(OS_MACOSX)
105 // Crash service doesn't exist for the Mac yet: http://crbug.com/45243
106 #define Assertion DISABLED_Assertion
107 #endif
108 TEST_F(AssertionTest, Assertion) {
109 expected_errors_ = EXPECTED_ASSERT_ERRORS;
110 expected_crashes_ = EXPECTED_ASSERT_CRASHES;
111 }
112 #endif // !defined(NDEBUG)
113
114 #if !defined(GOOGLE_CHROME_BUILD)
115 // Only works on Linux in Release mode with CHROME_HEADLESS=1
116 class CheckFalseTest : public UITest {
117 protected:
118 CheckFalseTest() {
119 #if defined(OS_WIN)
120 // TODO(phajdan.jr): Make crash notifications on launch work on Win.
121 wait_for_initial_loads_ = false;
122 #endif
123 launch_arguments_.AppendSwitch(switches::kRendererCheckFalseTest);
124 }
125 };
126
127 #if defined(OS_WIN)
128 // http://crbug.com/38497
129 #define CheckFails DISABLED_CheckFails
130 #elif defined(OS_MACOSX)
131 // Crash service doesn't exist for the Mac yet: http://crbug.com/45243
132 #define CheckFails DISABLED_CheckFails
133 #endif
134 // Launch the app in assertion test mode, then close the app.
135 TEST_F(CheckFalseTest, CheckFails) {
136 expected_errors_ = EXPECTED_ASSERT_ERRORS;
137 expected_crashes_ = EXPECTED_ASSERT_CRASHES;
138 }
139 #endif // !defined(GOOGLE_CHROME_BUILD)
140
141 // Tests whether we correctly fail on browser crashes during UI Tests.
142 class RendererCrashTest : public UITest {
143 protected:
144 RendererCrashTest() {
145 #if defined(OS_WIN)
146 // TODO(phajdan.jr): Make crash notifications on launch work on Win.
147 wait_for_initial_loads_ = false;
148 #endif
149 launch_arguments_.AppendSwitch(switches::kRendererCrashTest);
150 }
151 };
152
153 #if (defined(OS_LINUX) || defined(OS_ANDROID)) && !defined(USE_LINUX_BREAKPAD)
154 // On Linux, do not expect a crash dump if Breakpad is disabled.
155 #define EXPECTED_CRASH_CRASHES 0
156 #else
157 #define EXPECTED_CRASH_CRASHES 1
158 #endif
159
160 #if defined(OS_MACOSX)
161 // Crash service doesn't exist for the Mac yet: http://crbug.com/45243
162 #define MAYBE_Crash DISABLED_Crash
163 #elif defined(OS_CHROMEOS)
164 #define MAYBE_Crash DISABLED_Crash
165 #else
166 #define MAYBE_Crash Crash
167 #endif
168 // Launch the app in renderer crash test mode, then close the app.
169 TEST_F(RendererCrashTest, MAYBE_Crash) {
170 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
171 ASSERT_TRUE(browser.get());
172 ASSERT_TRUE(browser->WaitForTabCountToBecome(1));
173 expected_crashes_ = EXPECTED_CRASH_CRASHES;
174 }
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698