Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 <algorithm> | |
| 6 | |
| 7 #include "base/at_exit.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/debug/debugger.h" | |
| 10 #include "base/process/launch.h" | |
| 11 #include "base/sys_info.h" | |
| 12 #include "chrome/test/base/chrome_test_launcher.h" | |
| 13 #include "chrome/test/base/chrome_test_suite.h" | |
| 14 #include "chrome/test/base/mojo_test_connector.h" | |
| 15 #include "content/public/common/mojo_shell_connection.h" | |
| 16 #include "content/public/test/test_launcher.h" | |
| 17 #include "mojo/shell/public/cpp/connector.h" | |
| 18 #include "mojo/shell/public/cpp/shell_client.h" | |
| 19 #include "mojo/shell/public/cpp/shell_connection.h" | |
| 20 #include "mojo/shell/runner/common/switches.h" | |
| 21 #include "mojo/shell/runner/host/child_process.h" | |
| 22 #include "mojo/shell/runner/init.h" | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 void ConnectToDefaultApps(mojo::Connector* connector) { | |
| 27 connector->Connect("mojo:mash_session"); | |
| 28 } | |
| 29 | |
| 30 // Used to setup the command line for passing a mojo channel to tests. | |
| 31 class MashTestLauncherDelegate : public ChromeTestLauncherDelegate { | |
| 32 public: | |
| 33 explicit MashTestLauncherDelegate(ChromeTestSuiteRunner* runner) | |
| 34 : ChromeTestLauncherDelegate(runner) {} | |
| 35 ~MashTestLauncherDelegate() override {} | |
| 36 | |
| 37 MojoTestConnector* GetMojoTestConnector() { | |
| 38 if (!mojo_test_connector_) | |
| 39 mojo_test_connector_.reset(new MojoTestConnector); | |
| 40 return mojo_test_connector_.get(); | |
| 41 } | |
| 42 | |
| 43 private: | |
| 44 // ChromeTestLauncherDelegate: | |
| 45 scoped_ptr<content::TestState> PreRunTest( | |
| 46 base::CommandLine* command_line, | |
| 47 base::TestLauncher::LaunchOptions* test_launch_options) override { | |
| 48 if (!mojo_test_connector_) { | |
| 49 mojo_test_connector_.reset(new MojoTestConnector); | |
| 50 shell_client_.reset(new mojo::ShellClient); | |
| 51 shell_connection_.reset(new mojo::ShellConnection( | |
| 52 shell_client_.get(), mojo_test_connector_->Init())); | |
| 53 ConnectToDefaultApps(shell_connection_->connector()); | |
| 54 } | |
| 55 return GetMojoTestConnector()->PrepareForTest(command_line, | |
| 56 test_launch_options); | |
| 57 } | |
| 58 | |
| 59 scoped_ptr<MojoTestConnector> mojo_test_connector_; | |
| 60 scoped_ptr<mojo::ShellClient> shell_client_; | |
| 61 scoped_ptr<mojo::ShellConnection> shell_connection_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(MashTestLauncherDelegate); | |
| 64 }; | |
| 65 | |
| 66 void CreateMojoShellConnection(MashTestLauncherDelegate* delegate) { | |
| 67 const bool is_external_shell = true; | |
| 68 content::MojoShellConnection::Create(delegate->GetMojoTestConnector()->Init(), | |
| 69 is_external_shell); | |
| 70 ConnectToDefaultApps(content::MojoShellConnection::Get()->GetConnector()); | |
| 71 } | |
| 72 | |
| 73 } // namespace | |
| 74 | |
| 75 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) { | |
| 76 base::CommandLine::Init(argc, argv); | |
| 77 const base::CommandLine& command_line = | |
| 78 *base::CommandLine::ForCurrentProcess(); | |
| 79 if (!command_line.HasSwitch("run-in-mash")) | |
| 80 return false; | |
| 81 | |
| 82 if (command_line.HasSwitch(switches::kChildProcess) && | |
| 83 !command_line.HasSwitch(MojoTestConnector::kTestSwitch)) { | |
| 84 base::AtExitManager at_exit; | |
| 85 mojo::shell::InitializeLogging(); | |
| 86 mojo::shell::WaitForDebuggerIfNecessary(); | |
| 87 #if !defined(OFFICIAL_BUILD) && defined(OS_WIN) | |
| 88 base::RouteStdioToConsole(false); | |
| 89 #endif | |
| 90 *exit_code = mojo::shell::ChildProcessMain(); | |
| 91 return true; | |
| 92 } | |
| 93 | |
| 94 int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); | |
| 95 ChromeTestSuiteRunner runner; | |
| 96 MashTestLauncherDelegate delegate(&runner); | |
| 97 // --single_process and no primoridal pipe token indicate we were run directly | |
| 98 // from the command line. In this case we have to start up MojoShellConnection | |
| 99 // as though we were embedded. | |
| 100 content::MojoShellConnection::Factory shell_connection_factory; | |
|
Ben Goodger (Google)
2016/03/19 03:24:53
nit: indent
sky
2016/03/21 16:44:42
Done.
| |
| 101 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) && | |
| 102 !command_line.HasSwitch(switches::kPrimordialPipeToken)) { | |
| 103 shell_connection_factory = base::Bind(&CreateMojoShellConnection, | |
| 104 &delegate); | |
| 105 content::MojoShellConnection::SetFactoryForTest(&shell_connection_factory); | |
| 106 } | |
| 107 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); | |
| 108 return true; | |
| 109 } | |
| OLD | NEW |