| OLD | NEW |
| 1 // Copyright 2014 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/layout_test/layout_test_browser_main.h" | 5 #include "content/shell/browser/layout_test/layout_test_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" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // 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. |
| 86 base::ThreadRestrictions::ScopedAllowIO allow_io; | 86 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 87 if (net::FileURLToFilePath(test_url, &local_path)) | 87 if (net::FileURLToFilePath(test_url, &local_path)) |
| 88 *current_working_directory = local_path.DirName(); | 88 *current_working_directory = local_path.DirName(); |
| 89 else | 89 else |
| 90 base::GetCurrentDirectory(current_working_directory); | 90 base::GetCurrentDirectory(current_working_directory); |
| 91 } | 91 } |
| 92 return test_url; | 92 return test_url; |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool GetNextTest(const CommandLine::StringVector& args, | 95 bool GetNextTest(const base::CommandLine::StringVector& args, |
| 96 size_t* position, | 96 size_t* position, |
| 97 std::string* test) { | 97 std::string* test) { |
| 98 if (*position >= args.size()) | 98 if (*position >= args.size()) |
| 99 return false; | 99 return false; |
| 100 if (args[*position] == FILE_PATH_LITERAL("-")) | 100 if (args[*position] == FILE_PATH_LITERAL("-")) |
| 101 return !!std::getline(std::cin, *test, '\n'); | 101 return !!std::getline(std::cin, *test, '\n'); |
| 102 #if defined(OS_WIN) | 102 #if defined(OS_WIN) |
| 103 *test = base::WideToUTF8(args[(*position)++]); | 103 *test = base::WideToUTF8(args[(*position)++]); |
| 104 #else | 104 #else |
| 105 *test = args[(*position)++]; | 105 *test = args[(*position)++]; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 int RunTests(const scoped_ptr<content::BrowserMainRunner>& main_runner) { | 150 int RunTests(const scoped_ptr<content::BrowserMainRunner>& main_runner) { |
| 151 content::WebKitTestController test_controller; | 151 content::WebKitTestController test_controller; |
| 152 { | 152 { |
| 153 // We're outside of the message loop here, and this is a test. | 153 // We're outside of the message loop here, and this is a test. |
| 154 base::ThreadRestrictions::ScopedAllowIO allow_io; | 154 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 155 base::FilePath temp_path; | 155 base::FilePath temp_path; |
| 156 base::GetTempDir(&temp_path); | 156 base::GetTempDir(&temp_path); |
| 157 test_controller.SetTempPath(temp_path); | 157 test_controller.SetTempPath(temp_path); |
| 158 } | 158 } |
| 159 std::string test_string; | 159 std::string test_string; |
| 160 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs(); | 160 base::CommandLine::StringVector args = |
| 161 base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 161 size_t command_line_position = 0; | 162 size_t command_line_position = 0; |
| 162 bool ran_at_least_once = false; | 163 bool ran_at_least_once = false; |
| 163 | 164 |
| 164 std::cout << "#READY\n"; | 165 std::cout << "#READY\n"; |
| 165 std::cout.flush(); | 166 std::cout.flush(); |
| 166 | 167 |
| 167 while (GetNextTest(args, &command_line_position, &test_string)) { | 168 while (GetNextTest(args, &command_line_position, &test_string)) { |
| 168 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) | 169 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) |
| 169 break; | 170 break; |
| 170 } | 171 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 187 } // namespace | 188 } // namespace |
| 188 | 189 |
| 189 // Main routine for running as the Browser process. | 190 // Main routine for running as the Browser process. |
| 190 int LayoutTestBrowserMain( | 191 int LayoutTestBrowserMain( |
| 191 const content::MainFunctionParams& parameters, | 192 const content::MainFunctionParams& parameters, |
| 192 const scoped_ptr<content::BrowserMainRunner>& main_runner) { | 193 const scoped_ptr<content::BrowserMainRunner>& main_runner) { |
| 193 base::ScopedTempDir browser_context_path_for_layout_tests; | 194 base::ScopedTempDir browser_context_path_for_layout_tests; |
| 194 | 195 |
| 195 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); | 196 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); |
| 196 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); | 197 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); |
| 197 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 198 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 198 switches::kContentShellDataPath, | 199 switches::kContentShellDataPath, |
| 199 browser_context_path_for_layout_tests.path().MaybeAsASCII()); | 200 browser_context_path_for_layout_tests.path().MaybeAsASCII()); |
| 200 | 201 |
| 201 #if defined(OS_ANDROID) | 202 #if defined(OS_ANDROID) |
| 202 content::EnsureInitializeForAndroidLayoutTests(); | 203 content::EnsureInitializeForAndroidLayoutTests(); |
| 203 #endif | 204 #endif |
| 204 | 205 |
| 205 int exit_code = main_runner->Initialize(parameters); | 206 int exit_code = main_runner->Initialize(parameters); |
| 206 DCHECK_LT(exit_code, 0) | 207 DCHECK_LT(exit_code, 0) |
| 207 << "BrowserMainRunner::Initialize failed in LayoutTestBrowserMain"; | 208 << "BrowserMainRunner::Initialize failed in LayoutTestBrowserMain"; |
| 208 | 209 |
| 209 if (exit_code >= 0) | 210 if (exit_code >= 0) |
| 210 return exit_code; | 211 return exit_code; |
| 211 | 212 |
| 212 if (CommandLine::ForCurrentProcess()->HasSwitch( | 213 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 213 switches::kCheckLayoutTestSysDeps)) { | 214 switches::kCheckLayoutTestSysDeps)) { |
| 214 base::MessageLoop::current()->PostTask(FROM_HERE, | 215 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 215 base::MessageLoop::QuitClosure()); | 216 base::MessageLoop::QuitClosure()); |
| 216 main_runner->Run(); | 217 main_runner->Run(); |
| 217 content::Shell::CloseAllWindows(); | 218 content::Shell::CloseAllWindows(); |
| 218 main_runner->Shutdown(); | 219 main_runner->Shutdown(); |
| 219 return 0; | 220 return 0; |
| 220 } | 221 } |
| 221 | 222 |
| 222 exit_code = RunTests(main_runner); | 223 exit_code = RunTests(main_runner); |
| 223 | 224 |
| 224 #if !defined(OS_ANDROID) | 225 #if !defined(OS_ANDROID) |
| 225 main_runner->Shutdown(); | 226 main_runner->Shutdown(); |
| 226 #endif | 227 #endif |
| 227 | 228 |
| 228 return exit_code; | 229 return exit_code; |
| 229 } | 230 } |
| OLD | NEW |