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 #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" | 5 #include "base/command_line.h" |
15 #include "base/environment.h" | 6 #include "base/environment.h" |
16 #include "chrome/common/chrome_switches.h" | 7 #include "chrome/common/chrome_switches.h" |
| 8 #include "chrome/common/url_constants.h" |
17 #include "chrome/common/env_vars.h" | 9 #include "chrome/common/env_vars.h" |
18 #include "chrome/common/logging_chrome.h" | 10 #include "chrome/common/logging_chrome.h" |
19 #include "chrome/test/automation/automation_proxy.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "chrome/test/automation/browser_proxy.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
21 #include "chrome/test/ui/ui_test.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/web_contents.h" |
| 17 #include "googleurl/src/gurl.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
23 | 19 |
| 20 using content::RenderProcessHost; |
| 21 |
24 class ChromeLoggingTest : public testing::Test { | 22 class ChromeLoggingTest : public testing::Test { |
25 public: | 23 public: |
26 // Stores the current value of the log file name environment | 24 // Stores the current value of the log file name environment |
27 // variable and sets the variable to new_value. | 25 // variable and sets the variable to new_value. |
28 void SaveEnvironmentVariable(std::string new_value) { | 26 void SaveEnvironmentVariable(std::string new_value) { |
29 scoped_ptr<base::Environment> env(base::Environment::Create()); | 27 scoped_ptr<base::Environment> env(base::Environment::Create()); |
30 if (!env->GetVar(env_vars::kLogFileName, &environment_filename_)) | 28 if (!env->GetVar(env_vars::kLogFileName, &environment_filename_)) |
31 environment_filename_ = ""; | 29 environment_filename_ = ""; |
32 | 30 |
33 env->SetVar(env_vars::kLogFileName, new_value); | 31 env->SetVar(env_vars::kLogFileName, new_value); |
(...skipping 25 matching lines...) Expand all Loading... |
59 TEST_F(ChromeLoggingTest, EnvironmentLogFileName) { | 57 TEST_F(ChromeLoggingTest, EnvironmentLogFileName) { |
60 SaveEnvironmentVariable("test value"); | 58 SaveEnvironmentVariable("test value"); |
61 | 59 |
62 FilePath filename = logging::GetLogFileName(); | 60 FilePath filename = logging::GetLogFileName(); |
63 ASSERT_EQ(FilePath(FILE_PATH_LITERAL("test value")).value(), | 61 ASSERT_EQ(FilePath(FILE_PATH_LITERAL("test value")).value(), |
64 filename.value()); | 62 filename.value()); |
65 | 63 |
66 RestoreEnvironmentVariable(); | 64 RestoreEnvironmentVariable(); |
67 } | 65 } |
68 | 66 |
69 #if (defined(OS_LINUX) || defined(OS_ANDROID)) \ | 67 // Tests whether we correctly fail on browser crashes. |
70 && (!defined(NDEBUG) || !defined(USE_LINUX_BREAKPAD)) | 68 class RendererCrashTest : public InProcessBrowserTest, |
71 // On Linux in Debug mode, Chrome generates a SIGTRAP. | 69 public content::NotificationObserver{ |
72 // we do not catch SIGTRAPs, thus no crash dump. | 70 protected: |
73 // This also does not work if Breakpad is disabled. | 71 RendererCrashTest() : saw_crash_(false) {} |
74 #define EXPECTED_ASSERT_CRASHES 0 | |
75 #else | |
76 #define EXPECTED_ASSERT_CRASHES 1 | |
77 #endif | |
78 | 72 |
79 // Virtual keyboard build will start an extra renderer process (the extension | 73 virtual void Observe(int type, |
80 // process) for the virtual keyboard. | 74 const content::NotificationSource& source, |
81 #if defined(USE_VIRTUAL_KEYBOARD) | 75 const content::NotificationDetails& details) { |
82 #define EXPECTED_ASSERT_ERRORS 2 | 76 content::RenderProcessHost::RendererClosedDetails* process_details = |
83 #else | 77 content::Details< |
84 #define EXPECTED_ASSERT_ERRORS 1 | 78 content::RenderProcessHost::RendererClosedDetails>( |
85 #endif | 79 details).ptr(); |
| 80 base::TerminationStatus status = process_details->status; |
| 81 if (status == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 82 status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION) { |
| 83 saw_crash_ = true; |
| 84 } |
| 85 MessageLoopForUI::current()->Quit(); |
| 86 } |
86 | 87 |
87 #if !defined(NDEBUG) // We don't have assertions in release builds. | 88 bool saw_crash_; |
88 // Tests whether we correctly fail on renderer assertions during tests. | 89 content::NotificationRegistrar registrar_; |
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 }; | 90 }; |
99 | 91 |
100 // Launch the app in assertion test mode, then close the app. | 92 IN_PROC_BROWSER_TEST_F(RendererCrashTest, Crash) { |
101 #if defined(OS_WIN) | 93 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
102 // http://crbug.com/26715 | 94 content::NotificationService::AllSources()); |
103 #define Assertion DISABLED_Assertion | 95 ui_test_utils::NavigateToURLWithDisposition( |
104 #elif defined(OS_MACOSX) | 96 browser(), GURL(chrome::kChromeUICrashURL), CURRENT_TAB, 0); |
105 // Crash service doesn't exist for the Mac yet: http://crbug.com/45243 | 97 ui_test_utils::RunMessageLoop(); |
106 #define Assertion DISABLED_Assertion | 98 ASSERT_TRUE(saw_crash_); |
107 #endif | |
108 TEST_F(AssertionTest, Assertion) { | |
109 expected_errors_ = EXPECTED_ASSERT_ERRORS; | |
110 expected_crashes_ = EXPECTED_ASSERT_CRASHES; | |
111 } | 99 } |
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 } | |
OLD | NEW |