| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/debugger.h" | 9 #include "base/debug/debugger.h" |
| 10 #include "base/i18n/icu_util.h" | 10 #include "base/i18n/icu_util.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 // ChromeTestLauncherDelegate: | 78 // ChromeTestLauncherDelegate: |
| 79 int RunTestSuite(int argc, char** argv) override { | 79 int RunTestSuite(int argc, char** argv) override { |
| 80 test_suite_.reset(new MashTestSuite(argc, argv)); | 80 test_suite_.reset(new MashTestSuite(argc, argv)); |
| 81 const int result = test_suite_->Run(); | 81 const int result = test_suite_->Run(); |
| 82 test_suite_.reset(); | 82 test_suite_.reset(); |
| 83 return result; | 83 return result; |
| 84 } | 84 } |
| 85 |
| 85 std::unique_ptr<content::TestState> PreRunTest( | 86 std::unique_ptr<content::TestState> PreRunTest( |
| 86 base::CommandLine* command_line, | 87 base::CommandLine* command_line, |
| 87 base::TestLauncher::LaunchOptions* test_launch_options) override { | 88 base::TestLauncher::LaunchOptions* test_launch_options) override { |
| 88 if (!mojo_test_connector_) { | 89 if (!mojo_test_connector_) { |
| 89 mojo_test_connector_ = base::MakeUnique<MojoTestConnector>(); | 90 mojo_test_connector_ = base::MakeUnique<MojoTestConnector>(); |
| 90 service_ = base::MakeUnique<mash::MashPackagedService>(); | 91 context_.reset(new service_manager::ServiceContext( |
| 91 service_->set_context(base::MakeUnique<service_manager::ServiceContext>( | 92 base::MakeUnique<mash::MashPackagedService>(), |
| 92 service_.get(), mojo_test_connector_->Init())); | 93 mojo_test_connector_->Init())); |
| 93 } | 94 } |
| 94 std::unique_ptr<content::TestState> test_state = | 95 std::unique_ptr<content::TestState> test_state = |
| 95 mojo_test_connector_->PrepareForTest(command_line, test_launch_options); | 96 mojo_test_connector_->PrepareForTest(command_line, test_launch_options); |
| 96 // Start default apps after chrome, as they may try to connect to chrome on | 97 // Start default apps after chrome, as they may try to connect to chrome on |
| 97 // startup. Attempt to connect once per test in case a previous test crashed | 98 // startup. Attempt to connect once per test in case a previous test crashed |
| 98 // mash_session. | 99 // mash_session. |
| 99 ConnectToDefaultApps(service_->connector()); | 100 ConnectToDefaultApps(context_->connector()); |
| 100 return test_state; | 101 return test_state; |
| 101 } | 102 } |
| 103 |
| 102 void OnDoneRunningTests() override { | 104 void OnDoneRunningTests() override { |
| 103 // We have to shutdown this state here, while an AtExitManager is still | 105 // We have to shutdown this state here, while an AtExitManager is still |
| 104 // valid. | 106 // valid. |
| 105 service_.reset(); | 107 context_.reset(); |
| 106 mojo_test_connector_.reset(); | 108 mojo_test_connector_.reset(); |
| 107 } | 109 } |
| 108 | 110 |
| 109 std::unique_ptr<MashTestSuite> test_suite_; | 111 std::unique_ptr<MashTestSuite> test_suite_; |
| 110 std::unique_ptr<MojoTestConnector> mojo_test_connector_; | 112 std::unique_ptr<MojoTestConnector> mojo_test_connector_; |
| 111 std::unique_ptr<mash::MashPackagedService> service_; | 113 std::unique_ptr<service_manager::ServiceContext> context_; |
| 112 | 114 |
| 113 DISALLOW_COPY_AND_ASSIGN(MashTestLauncherDelegate); | 115 DISALLOW_COPY_AND_ASSIGN(MashTestLauncherDelegate); |
| 114 }; | 116 }; |
| 115 | 117 |
| 116 std::unique_ptr<content::ServiceManagerConnection> | 118 std::unique_ptr<content::ServiceManagerConnection> |
| 117 CreateServiceManagerConnection(MashTestLauncherDelegate* delegate) { | 119 CreateServiceManagerConnection(MashTestLauncherDelegate* delegate) { |
| 118 std::unique_ptr<content::ServiceManagerConnection> connection( | 120 std::unique_ptr<content::ServiceManagerConnection> connection( |
| 119 content::ServiceManagerConnection::Create( | 121 content::ServiceManagerConnection::Create( |
| 120 delegate->GetMojoTestConnectorForSingleProcess()->Init(), | 122 delegate->GetMojoTestConnectorForSingleProcess()->Init(), |
| 121 base::ThreadTaskRunnerHandle::Get())); | 123 base::ThreadTaskRunnerHandle::Get())); |
| 122 connection->Start(); | 124 connection->Start(); |
| 123 ConnectToDefaultApps(connection->GetConnector()); | 125 ConnectToDefaultApps(connection->GetConnector()); |
| 124 return connection; | 126 return connection; |
| 125 } | 127 } |
| 126 | 128 |
| 127 void StartChildApp(service_manager::mojom::ServiceRequest service_request) { | 129 void StartChildApp(service_manager::mojom::ServiceRequest service_request) { |
| 128 base::MessageLoop message_loop(base::MessageLoop::TYPE_DEFAULT); | 130 base::MessageLoop message_loop(base::MessageLoop::TYPE_DEFAULT); |
| 129 base::RunLoop run_loop; | 131 base::RunLoop run_loop; |
| 130 mash::MashPackagedService service; | 132 service_manager::ServiceContext context( |
| 131 std::unique_ptr<service_manager::ServiceContext> context = | 133 base::MakeUnique<mash::MashPackagedService>(), |
| 132 base::MakeUnique<service_manager::ServiceContext>( | 134 std::move(service_request)); |
| 133 &service, std::move(service_request)); | 135 context.SetConnectionLostClosure(run_loop.QuitClosure()); |
| 134 context->SetConnectionLostClosure(run_loop.QuitClosure()); | |
| 135 service.set_context(std::move(context)); | |
| 136 run_loop.Run(); | 136 run_loop.Run(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace | 139 } // namespace |
| 140 | 140 |
| 141 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) { | 141 bool RunMashBrowserTests(int argc, char** argv, int* exit_code) { |
| 142 base::CommandLine::Init(argc, argv); | 142 base::CommandLine::Init(argc, argv); |
| 143 const base::CommandLine& command_line = | 143 const base::CommandLine& command_line = |
| 144 *base::CommandLine::ForCurrentProcess(); | 144 *base::CommandLine::ForCurrentProcess(); |
| 145 if (!command_line.HasSwitch("run-in-mash")) | 145 if (!command_line.HasSwitch("run-in-mash")) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) && | 177 if (command_line.HasSwitch(content::kSingleProcessTestsFlag) && |
| 178 !command_line.HasSwitch(switches::kPrimordialPipeToken)) { | 178 !command_line.HasSwitch(switches::kPrimordialPipeToken)) { |
| 179 service_manager_connection_factory = | 179 service_manager_connection_factory = |
| 180 base::Bind(&CreateServiceManagerConnection, &delegate); | 180 base::Bind(&CreateServiceManagerConnection, &delegate); |
| 181 content::ServiceManagerConnection::SetFactoryForTest( | 181 content::ServiceManagerConnection::SetFactoryForTest( |
| 182 &service_manager_connection_factory); | 182 &service_manager_connection_factory); |
| 183 } | 183 } |
| 184 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); | 184 *exit_code = LaunchChromeTests(default_jobs, &delegate, argc, argv); |
| 185 return true; | 185 return true; |
| 186 } | 186 } |
| OLD | NEW |