OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/shell/browser/shell_browser_main.h" | 5 #include "content/shell/browser/shell_browser_main.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #if defined(OS_ANDROID) | 60 #if defined(OS_ANDROID) |
61 if (content::GetTestUrlForAndroid(path_or_url, &test_url)) | 61 if (content::GetTestUrlForAndroid(path_or_url, &test_url)) |
62 return test_url; | 62 return test_url; |
63 #endif | 63 #endif |
64 | 64 |
65 test_url = GURL(path_or_url); | 65 test_url = GURL(path_or_url); |
66 if (!(test_url.is_valid() && test_url.has_scheme())) { | 66 if (!(test_url.is_valid() && test_url.has_scheme())) { |
67 // We're outside of the message loop here, and this is a test. | 67 // We're outside of the message loop here, and this is a test. |
68 base::ThreadRestrictions::ScopedAllowIO allow_io; | 68 base::ThreadRestrictions::ScopedAllowIO allow_io; |
69 #if defined(OS_WIN) | 69 #if defined(OS_WIN) |
70 std::wstring wide_path_or_url = | 70 base::FilePath::StringType wide_path_or_url = |
71 base::SysNativeMBToWide(path_or_url); | 71 base::SysNativeMBToWide(path_or_url); |
72 base::FilePath local_file(wide_path_or_url); | 72 base::FilePath local_file(wide_path_or_url); |
73 #else | 73 #else |
74 base::FilePath local_file(path_or_url); | 74 base::FilePath local_file(path_or_url); |
75 #endif | 75 #endif |
76 if (!base::PathExists(local_file)) { | 76 if (!base::PathExists(local_file)) { |
77 local_file = content::GetWebKitRootDirFilePath() | 77 local_file = content::GetWebKitRootDirFilePath() |
78 .Append(FILE_PATH_LITERAL("LayoutTests")).Append(local_file); | 78 .Append(FILE_PATH_LITERAL("LayoutTests")) |
| 79 .Append(local_file); |
79 } | 80 } |
80 test_url = net::FilePathToFileURL(base::MakeAbsoluteFilePath(local_file)); | 81 test_url = net::FilePathToFileURL(base::MakeAbsoluteFilePath(local_file)); |
81 } | 82 } |
82 base::FilePath local_path; | 83 base::FilePath local_path; |
83 if (current_working_directory) { | 84 if (current_working_directory) { |
84 // We're outside of the message loop here, and this is a test. | 85 // We're outside of the message loop here, and this is a test. |
85 base::ThreadRestrictions::ScopedAllowIO allow_io; | 86 base::ThreadRestrictions::ScopedAllowIO allow_io; |
86 if (net::FileURLToFilePath(test_url, &local_path)) | 87 if (net::FileURLToFilePath(test_url, &local_path)) |
87 *current_working_directory = local_path.DirName(); | 88 *current_working_directory = local_path.DirName(); |
88 else | 89 else |
(...skipping 21 matching lines...) Expand all Loading... |
110 bool* ran_at_least_once, | 111 bool* ran_at_least_once, |
111 const scoped_ptr<content::BrowserMainRunner>& main_runner) { | 112 const scoped_ptr<content::BrowserMainRunner>& main_runner) { |
112 if (test_string.empty()) | 113 if (test_string.empty()) |
113 return true; | 114 return true; |
114 if (test_string == "QUIT") | 115 if (test_string == "QUIT") |
115 return false; | 116 return false; |
116 | 117 |
117 bool enable_pixel_dumps; | 118 bool enable_pixel_dumps; |
118 std::string pixel_hash; | 119 std::string pixel_hash; |
119 base::FilePath cwd; | 120 base::FilePath cwd; |
120 GURL test_url = GetURLForLayoutTest( | 121 GURL test_url = |
121 test_string, &cwd, &enable_pixel_dumps, &pixel_hash); | 122 GetURLForLayoutTest(test_string, &cwd, &enable_pixel_dumps, &pixel_hash); |
122 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( | 123 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( |
123 test_url, cwd, enable_pixel_dumps, pixel_hash)) { | 124 test_url, cwd, enable_pixel_dumps, pixel_hash)) { |
124 return false; | 125 return false; |
125 } | 126 } |
126 | 127 |
127 *ran_at_least_once = true; | 128 *ran_at_least_once = true; |
128 #if defined(OS_ANDROID) | 129 #if defined(OS_ANDROID) |
129 // The message loop on Android is provided by the system, and does not | 130 // The message loop on Android is provided by the system, and does not |
130 // offer a blocking Run() method. For layout tests, use a nested loop | 131 // offer a blocking Run() method. For layout tests, use a nested loop |
131 // together with a base::RunLoop so it can block until a QuitClosure. | 132 // together with a base::RunLoop so it can block until a QuitClosure. |
(...skipping 10 matching lines...) Expand all Loading... |
142 // There will be left-over tasks in the queue for Android because the | 143 // There will be left-over tasks in the queue for Android because the |
143 // main window is being destroyed. Run them before starting the next test. | 144 // main window is being destroyed. Run them before starting the next test. |
144 base::MessageLoop::current()->RunUntilIdle(); | 145 base::MessageLoop::current()->RunUntilIdle(); |
145 #endif | 146 #endif |
146 return true; | 147 return true; |
147 } | 148 } |
148 | 149 |
149 } // namespace | 150 } // namespace |
150 | 151 |
151 // Main routine for running as the Browser process. | 152 // Main routine for running as the Browser process. |
152 int ShellBrowserMain( | 153 int LayoutTestBrowserMain( |
153 const content::MainFunctionParams& parameters, | 154 const content::MainFunctionParams& parameters, |
154 const scoped_ptr<content::BrowserMainRunner>& main_runner) { | 155 const scoped_ptr<content::BrowserMainRunner>& main_runner) { |
155 bool layout_test_mode = | |
156 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); | |
157 base::ScopedTempDir browser_context_path_for_layout_tests; | 156 base::ScopedTempDir browser_context_path_for_layout_tests; |
158 | 157 |
159 if (layout_test_mode) { | 158 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); |
160 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); | 159 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); |
161 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); | 160 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
162 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 161 switches::kContentShellDataPath, |
163 switches::kContentShellDataPath, | 162 browser_context_path_for_layout_tests.path().MaybeAsASCII()); |
164 browser_context_path_for_layout_tests.path().MaybeAsASCII()); | |
165 | 163 |
166 #if defined(OS_ANDROID) | 164 #if defined(OS_ANDROID) |
167 content::EnsureInitializeForAndroidLayoutTests(); | 165 content::EnsureInitializeForAndroidLayoutTests(); |
168 #endif | 166 #endif |
169 } | |
170 | 167 |
171 int exit_code = main_runner->Initialize(parameters); | 168 int exit_code = main_runner->Initialize(parameters); |
172 DCHECK_LT(exit_code, 0) | 169 DCHECK_LT(exit_code, 0) |
173 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; | 170 << "BrowserMainRunner::Initialize failed in LayoutTestBrowserMain"; |
174 | 171 |
175 if (exit_code >= 0) | 172 if (exit_code >= 0) |
176 return exit_code; | 173 return exit_code; |
177 | 174 |
178 if (CommandLine::ForCurrentProcess()->HasSwitch( | 175 if (CommandLine::ForCurrentProcess()->HasSwitch( |
179 switches::kCheckLayoutTestSysDeps)) { | 176 switches::kCheckLayoutTestSysDeps)) { |
180 base::MessageLoop::current()->PostTask(FROM_HERE, | 177 base::MessageLoop::current()->PostTask(FROM_HERE, |
181 base::MessageLoop::QuitClosure()); | 178 base::MessageLoop::QuitClosure()); |
182 main_runner->Run(); | 179 main_runner->Run(); |
183 content::Shell::CloseAllWindows(); | 180 content::Shell::CloseAllWindows(); |
184 main_runner->Shutdown(); | 181 main_runner->Shutdown(); |
185 return 0; | 182 return 0; |
186 } | 183 } |
187 | 184 |
188 if (layout_test_mode) { | 185 content::WebKitTestController test_controller; |
189 content::WebKitTestController test_controller; | 186 { |
190 { | 187 // We're outside of the message loop here, and this is a test. |
191 // We're outside of the message loop here, and this is a test. | 188 base::ThreadRestrictions::ScopedAllowIO allow_io; |
192 base::ThreadRestrictions::ScopedAllowIO allow_io; | 189 base::FilePath temp_path; |
193 base::FilePath temp_path; | 190 base::GetTempDir(&temp_path); |
194 base::GetTempDir(&temp_path); | 191 test_controller.SetTempPath(temp_path); |
195 test_controller.SetTempPath(temp_path); | 192 } |
196 } | 193 std::string test_string; |
197 std::string test_string; | 194 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs(); |
198 CommandLine::StringVector args = | 195 size_t command_line_position = 0; |
199 CommandLine::ForCurrentProcess()->GetArgs(); | 196 bool ran_at_least_once = false; |
200 size_t command_line_position = 0; | |
201 bool ran_at_least_once = false; | |
202 | 197 |
203 std::cout << "#READY\n"; | 198 std::cout << "#READY\n"; |
204 std::cout.flush(); | 199 std::cout.flush(); |
205 | 200 |
206 while (GetNextTest(args, &command_line_position, &test_string)) { | 201 while (GetNextTest(args, &command_line_position, &test_string)) { |
207 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) | 202 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) |
208 break; | 203 break; |
209 } | 204 } |
210 if (!ran_at_least_once) { | 205 if (!ran_at_least_once) { |
211 base::MessageLoop::current()->PostTask(FROM_HERE, | 206 base::MessageLoop::current()->PostTask(FROM_HERE, |
212 base::MessageLoop::QuitClosure()); | 207 base::MessageLoop::QuitClosure()); |
213 main_runner->Run(); | 208 main_runner->Run(); |
214 } | 209 } |
215 | 210 |
216 #if defined(OS_ANDROID) | 211 #if defined(OS_ANDROID) |
217 // Android should only execute Shutdown() here when running layout tests. | 212 // Android should only execute Shutdown() here when running layout tests. |
218 main_runner->Shutdown(); | |
219 #endif | |
220 | |
221 exit_code = 0; | |
222 } | |
223 | |
224 #if !defined(OS_ANDROID) | |
225 if (!layout_test_mode) | |
226 exit_code = main_runner->Run(); | |
227 | |
228 main_runner->Shutdown(); | 213 main_runner->Shutdown(); |
229 #endif | 214 #endif |
230 | 215 |
| 216 exit_code = 0; |
| 217 |
| 218 #if !defined(OS_ANDROID) |
| 219 main_runner->Shutdown(); |
| 220 #endif |
| 221 |
231 return exit_code; | 222 return exit_code; |
232 } | 223 } |
OLD | NEW |