Chromium Code Reviews| 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/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" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 return false; | 140 return false; |
| 141 | 141 |
| 142 #if defined(OS_ANDROID) | 142 #if defined(OS_ANDROID) |
| 143 // 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 |
| 144 // 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. |
| 145 base::MessageLoop::current()->RunUntilIdle(); | 145 base::MessageLoop::current()->RunUntilIdle(); |
| 146 #endif | 146 #endif |
| 147 return true; | 147 return true; |
| 148 } | 148 } |
| 149 | 149 |
| 150 int RunTests(const scoped_ptr<content::BrowserMainRunner>& main_runner) { | |
| 151 content::WebKitTestController test_controller; | |
| 152 { | |
| 153 // We're outside of the message loop here, and this is a test. | |
| 154 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 155 base::FilePath temp_path; | |
| 156 base::GetTempDir(&temp_path); | |
| 157 test_controller.SetTempPath(temp_path); | |
| 158 } | |
| 159 std::string test_string; | |
| 160 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs(); | |
| 161 size_t command_line_position = 0; | |
| 162 bool ran_at_least_once = false; | |
| 163 | |
| 164 std::cout << "#READY\n"; | |
| 165 std::cout.flush(); | |
| 166 | |
| 167 while (GetNextTest(args, &command_line_position, &test_string)) { | |
| 168 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) | |
| 169 break; | |
| 170 } | |
| 171 if (!ran_at_least_once) { | |
| 172 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 173 base::MessageLoop::QuitClosure()); | |
| 174 main_runner->Run(); | |
| 175 } | |
| 176 | |
| 177 #if defined(OS_ANDROID) | |
| 178 // We need to execute 'main_runner->Shutdown()' before the test_controller | |
| 179 // destructs when running on Android, and after it destructs when running | |
| 180 // anywhere else. | |
| 181 main_runner->Shutdown(); | |
| 182 #endif | |
| 183 | |
| 184 return 0; | |
| 185 } | |
| 186 | |
| 150 } // namespace | 187 } // namespace |
| 151 | 188 |
| 152 // Main routine for running as the Browser process. | 189 // Main routine for running as the Browser process. |
| 153 int LayoutTestBrowserMain( | 190 int LayoutTestBrowserMain( |
| 154 const content::MainFunctionParams& parameters, | 191 const content::MainFunctionParams& parameters, |
| 155 const scoped_ptr<content::BrowserMainRunner>& main_runner) { | 192 const scoped_ptr<content::BrowserMainRunner>& main_runner) { |
| 156 base::ScopedTempDir browser_context_path_for_layout_tests; | 193 base::ScopedTempDir browser_context_path_for_layout_tests; |
| 157 | 194 |
| 158 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); | 195 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); |
| 159 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); | 196 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 175 if (CommandLine::ForCurrentProcess()->HasSwitch( | 212 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 176 switches::kCheckLayoutTestSysDeps)) { | 213 switches::kCheckLayoutTestSysDeps)) { |
| 177 base::MessageLoop::current()->PostTask(FROM_HERE, | 214 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 178 base::MessageLoop::QuitClosure()); | 215 base::MessageLoop::QuitClosure()); |
| 179 main_runner->Run(); | 216 main_runner->Run(); |
| 180 content::Shell::CloseAllWindows(); | 217 content::Shell::CloseAllWindows(); |
| 181 main_runner->Shutdown(); | 218 main_runner->Shutdown(); |
| 182 return 0; | 219 return 0; |
| 183 } | 220 } |
| 184 | 221 |
| 185 content::WebKitTestController test_controller; | 222 exit_code = RunTests(main_runner); |
|
Peter Beverloo
2014/10/18 09:17:58
Hmm. RunTests never returns anything that's non-ze
| |
| 186 { | |
| 187 // We're outside of the message loop here, and this is a test. | |
| 188 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 189 base::FilePath temp_path; | |
| 190 base::GetTempDir(&temp_path); | |
| 191 test_controller.SetTempPath(temp_path); | |
| 192 } | |
| 193 std::string test_string; | |
| 194 CommandLine::StringVector args = CommandLine::ForCurrentProcess()->GetArgs(); | |
| 195 size_t command_line_position = 0; | |
| 196 bool ran_at_least_once = false; | |
| 197 | |
| 198 std::cout << "#READY\n"; | |
| 199 std::cout.flush(); | |
| 200 | |
| 201 while (GetNextTest(args, &command_line_position, &test_string)) { | |
| 202 if (!RunOneTest(test_string, &ran_at_least_once, main_runner)) | |
| 203 break; | |
| 204 } | |
| 205 if (!ran_at_least_once) { | |
| 206 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 207 base::MessageLoop::QuitClosure()); | |
| 208 main_runner->Run(); | |
| 209 } | |
| 210 | |
| 211 #if defined(OS_ANDROID) | |
| 212 // Android should only execute Shutdown() here when running layout tests. | |
| 213 main_runner->Shutdown(); | |
| 214 #endif | |
| 215 | |
| 216 exit_code = 0; | |
| 217 | 223 |
| 218 #if !defined(OS_ANDROID) | 224 #if !defined(OS_ANDROID) |
| 219 main_runner->Shutdown(); | 225 main_runner->Shutdown(); |
| 220 #endif | 226 #endif |
| 221 | 227 |
| 222 return exit_code; | 228 return exit_code; |
| 223 } | 229 } |
| OLD | NEW |