OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/process_util.h" |
| 10 |
| 11 #include "chrome/test/browser/browser_test_runner.h" |
| 12 #include "chrome/test/unit/chrome_test_suite.h" |
| 13 |
| 14 // This version of the browser test launcher forks a new process for each test |
| 15 // it runs. |
| 16 |
| 17 namespace { |
| 18 |
| 19 const wchar_t* const kGTestListTestsFlag = L"gtest_list_tests"; |
| 20 const wchar_t* const kChildProcessFlag = L"child"; |
| 21 |
| 22 class OutOfProcBrowserTestRunner : public browser_tests::BrowserTestRunner { |
| 23 public: |
| 24 OutOfProcBrowserTestRunner() { |
| 25 } |
| 26 |
| 27 virtual ~OutOfProcBrowserTestRunner() { |
| 28 } |
| 29 |
| 30 bool Init() { |
| 31 return true; |
| 32 } |
| 33 |
| 34 // Returns true if the test succeeded, false if it failed. |
| 35 bool RunTest(const std::string& test_name) { |
| 36 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 37 CommandLine new_cmd_line(cmd_line->argv()); |
| 38 new_cmd_line.AppendSwitchWithValue(L"gtest_filter", ASCIIToWide(test_name)); |
| 39 new_cmd_line.AppendSwitch(kChildProcessFlag); |
| 40 |
| 41 base::ProcessHandle process_handle; |
| 42 bool r = base::LaunchApp(new_cmd_line, false, false, &process_handle); |
| 43 if (!r) |
| 44 return false; |
| 45 |
| 46 int exit_code = 0; |
| 47 r = base::WaitForExitCode(process_handle, &exit_code); |
| 48 if (!r) |
| 49 return false; |
| 50 |
| 51 return exit_code == 0; |
| 52 } |
| 53 |
| 54 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(OutOfProcBrowserTestRunner); |
| 56 }; |
| 57 |
| 58 class OutOfProcBrowserTestRunnerFactory |
| 59 : public browser_tests::BrowserTestRunnerFactory { |
| 60 public: |
| 61 OutOfProcBrowserTestRunnerFactory() { } |
| 62 |
| 63 virtual browser_tests::BrowserTestRunner* CreateBrowserTestRunner() const { |
| 64 return new OutOfProcBrowserTestRunner(); |
| 65 } |
| 66 |
| 67 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(OutOfProcBrowserTestRunnerFactory); |
| 69 }; |
| 70 |
| 71 } // namespace |
| 72 |
| 73 int main(int argc, char** argv) { |
| 74 CommandLine::Init(argc, argv); |
| 75 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 76 |
| 77 if (command_line->HasSwitch(kChildProcessFlag)) |
| 78 return ChromeTestSuite(argc, argv).Run(); |
| 79 |
| 80 if (command_line->HasSwitch(kGTestListTestsFlag)) |
| 81 return ChromeTestSuite(argc, argv).Run(); |
| 82 |
| 83 OutOfProcBrowserTestRunnerFactory test_runner_factory; |
| 84 return browser_tests::RunTests(test_runner_factory) ? 0 : 1; |
| 85 } |
OLD | NEW |