| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 GURL test_url; | 59 GURL test_url; |
| 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 base::FilePath::StringType local_file_path(path_or_url); |
| 70 std::wstring wide_path_or_url = | 70 base::FilePath local_file(local_file_path); |
| 71 base::SysNativeMBToWide(path_or_url); | |
| 72 base::FilePath local_file(wide_path_or_url); | |
| 73 #else | |
| 74 base::FilePath local_file(path_or_url); | |
| 75 #endif | |
| 76 if (!base::PathExists(local_file)) { | 71 if (!base::PathExists(local_file)) { |
| 77 local_file = content::GetWebKitRootDirFilePath() | 72 local_file = content::GetWebKitRootDirFilePath() |
| 78 .Append(FILE_PATH_LITERAL("LayoutTests")).Append(local_file); | 73 .Append(FILE_PATH_LITERAL("LayoutTests")).Append(local_file); |
| 79 } | 74 } |
| 80 test_url = net::FilePathToFileURL(base::MakeAbsoluteFilePath(local_file)); | 75 test_url = net::FilePathToFileURL(base::MakeAbsoluteFilePath(local_file)); |
| 81 } | 76 } |
| 82 base::FilePath local_path; | 77 base::FilePath local_path; |
| 83 if (current_working_directory) { | 78 if (current_working_directory) { |
| 84 // We're outside of the message loop here, and this is a test. | 79 // We're outside of the message loop here, and this is a test. |
| 85 base::ThreadRestrictions::ScopedAllowIO allow_io; | 80 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // There will be left-over tasks in the queue for Android because the | 137 // 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. | 138 // main window is being destroyed. Run them before starting the next test. |
| 144 base::MessageLoop::current()->RunUntilIdle(); | 139 base::MessageLoop::current()->RunUntilIdle(); |
| 145 #endif | 140 #endif |
| 146 return true; | 141 return true; |
| 147 } | 142 } |
| 148 | 143 |
| 149 } // namespace | 144 } // namespace |
| 150 | 145 |
| 151 // Main routine for running as the Browser process. | 146 // Main routine for running as the Browser process. |
| 152 int ShellBrowserMain( | 147 int LayoutTestBrowserMain( |
| 153 const content::MainFunctionParams& parameters, | 148 const content::MainFunctionParams& parameters, |
| 154 const scoped_ptr<content::BrowserMainRunner>& main_runner) { | 149 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; | 150 base::ScopedTempDir browser_context_path_for_layout_tests; |
| 158 | 151 |
| 159 if (layout_test_mode) { | 152 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); |
| 160 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); | 153 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); |
| 161 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); | 154 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 162 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 155 switches::kContentShellDataPath, |
| 163 switches::kContentShellDataPath, | 156 browser_context_path_for_layout_tests.path().MaybeAsASCII()); |
| 164 browser_context_path_for_layout_tests.path().MaybeAsASCII()); | |
| 165 | 157 |
| 166 #if defined(OS_ANDROID) | 158 #if defined(OS_ANDROID) |
| 167 content::EnsureInitializeForAndroidLayoutTests(); | 159 content::EnsureInitializeForAndroidLayoutTests(); |
| 168 #endif | 160 #endif |
| 169 } | |
| 170 | 161 |
| 171 int exit_code = main_runner->Initialize(parameters); | 162 int exit_code = main_runner->Initialize(parameters); |
| 172 DCHECK_LT(exit_code, 0) | 163 DCHECK_LT(exit_code, 0) |
| 173 << "BrowserMainRunner::Initialize failed in ShellBrowserMain"; | 164 << "BrowserMainRunner::Initialize failed in LayoutTestBrowserMain"; |
| 174 | 165 |
| 175 if (exit_code >= 0) | 166 if (exit_code >= 0) |
| 176 return exit_code; | 167 return exit_code; |
| 177 | 168 |
| 178 if (CommandLine::ForCurrentProcess()->HasSwitch( | 169 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 179 switches::kCheckLayoutTestSysDeps)) { | 170 switches::kCheckLayoutTestSysDeps)) { |
| 180 base::MessageLoop::current()->PostTask(FROM_HERE, | 171 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 181 base::MessageLoop::QuitClosure()); | 172 base::MessageLoop::QuitClosure()); |
| 182 main_runner->Run(); | 173 main_runner->Run(); |
| 183 content::Shell::CloseAllWindows(); | 174 content::Shell::CloseAllWindows(); |
| 184 main_runner->Shutdown(); | 175 main_runner->Shutdown(); |
| 185 return 0; | 176 return 0; |
| 186 } | 177 } |
| 187 | 178 |
| 188 if (layout_test_mode) { | 179 content::WebKitTestController test_controller; |
| 189 content::WebKitTestController test_controller; | 180 { |
| 190 { | 181 // 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. | 182 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 192 base::ThreadRestrictions::ScopedAllowIO allow_io; | 183 base::FilePath temp_path; |
| 193 base::FilePath temp_path; | 184 base::GetTempDir(&temp_path); |
| 194 base::GetTempDir(&temp_path); | 185 test_controller.SetTempPath(temp_path); |
| 195 test_controller.SetTempPath(temp_path); | 186 } |
| 196 } | 187 std::string test_string; |
| 197 std::string test_string; | 188 CommandLine::StringVector args = |
| 198 CommandLine::StringVector args = | 189 CommandLine::ForCurrentProcess()->GetArgs(); |
| 199 CommandLine::ForCurrentProcess()->GetArgs(); | 190 size_t command_line_position = 0; |
| 200 size_t command_line_position = 0; | 191 bool ran_at_least_once = false; |
| 201 bool ran_at_least_once = false; | |
| 202 | 192 |
| 203 std::cout << "#READY\n"; | 193 std::cout << "#READY\n"; |
| 204 std::cout.flush(); | 194 std::cout.flush(); |
| 205 | 195 |
| 206 while (GetNextTest(args, &command_line_position, &test_string)) { | 196 while (GetNextTest(args, &command_line_position, &test_string)) { |
| 207 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) | 197 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) |
| 208 break; | 198 break; |
| 209 } | 199 } |
| 210 if (!ran_at_least_once) { | 200 if (!ran_at_least_once) { |
| 211 base::MessageLoop::current()->PostTask(FROM_HERE, | 201 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 212 base::MessageLoop::QuitClosure()); | 202 base::MessageLoop::QuitClosure()); |
| 213 main_runner->Run(); | 203 main_runner->Run(); |
| 214 } | 204 } |
| 215 | 205 |
| 216 #if defined(OS_ANDROID) | 206 #if defined(OS_ANDROID) |
| 217 // Android should only execute Shutdown() here when running layout tests. | 207 // 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(); | 208 main_runner->Shutdown(); |
| 229 #endif | 209 #endif |
| 230 | 210 |
| 211 exit_code = 0; |
| 212 |
| 213 #if !defined(OS_ANDROID) |
| 214 main_runner->Shutdown(); |
| 215 #endif |
| 216 |
| 231 return exit_code; | 217 return exit_code; |
| 232 } | 218 } |
| OLD | NEW |