| 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 "chrome/test/base/mojo_test_connector.h" | 5 #include "chrome/test/base/mojo_test_connector.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "services/shell/runner/common/switches.h" | 28 #include "services/shell/runner/common/switches.h" |
| 29 #include "services/shell/service_manager.h" | 29 #include "services/shell/service_manager.h" |
| 30 #include "services/shell/switches.h" | 30 #include "services/shell/switches.h" |
| 31 | 31 |
| 32 using shell::mojom::Service; | 32 using shell::mojom::Service; |
| 33 using shell::mojom::ServicePtr; | 33 using shell::mojom::ServicePtr; |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 const char kTestRunnerName[] = "exe:mash_browser_tests"; | 37 const char kTestRunnerName[] = "exe:mash_browser_tests"; |
| 38 const char kTestName[] = "exe:chrome"; | 38 const char kTestName[] = "service:content_browser"; |
| 39 | 39 |
| 40 // BackgroundTestState maintains all the state necessary to bind the test to | 40 // BackgroundTestState maintains all the state necessary to bind the test to |
| 41 // mojo. This class is only used on the thread created by BackgroundShell. | 41 // mojo. This class is only used on the thread created by BackgroundShell. |
| 42 class BackgroundTestState { | 42 class BackgroundTestState { |
| 43 public: | 43 public: |
| 44 BackgroundTestState() : child_token_(mojo::edk::GenerateRandomToken()) {} | 44 BackgroundTestState() : child_token_(mojo::edk::GenerateRandomToken()) {} |
| 45 ~BackgroundTestState() {} | 45 ~BackgroundTestState() {} |
| 46 | 46 |
| 47 // Prepares the command line and other setup for connecting the test to mojo. | 47 // Prepares the command line and other setup for connecting the test to mojo. |
| 48 // Must be paired with a call to ChildProcessLaunched(). | 48 // Must be paired with a call to ChildProcessLaunched(). |
| (...skipping 15 matching lines...) Expand all Loading... |
| 64 test_launch_options->fds_to_remap = &handle_passing_info_; | 64 test_launch_options->fds_to_remap = &handle_passing_info_; |
| 65 #else | 65 #else |
| 66 #error "Unsupported" | 66 #error "Unsupported" |
| 67 #endif | 67 #endif |
| 68 shell::mojom::ServicePtr service = | 68 shell::mojom::ServicePtr service = |
| 69 shell::PassServiceRequestOnCommandLine(command_line, child_token_); | 69 shell::PassServiceRequestOnCommandLine(command_line, child_token_); |
| 70 | 70 |
| 71 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); | 71 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); |
| 72 params->set_source(shell::CreateServiceManagerIdentity()); | 72 params->set_source(shell::CreateServiceManagerIdentity()); |
| 73 // Use the default instance name (which should be "browser"). Otherwise a | 73 // Use the default instance name (which should be "browser"). Otherwise a |
| 74 // service (e.g. ash) that connects to the default "exe:chrome" will spawn | 74 // service (e.g. ash) that connects to the default "service:content_browser" |
| 75 // a new instance. | 75 // will spawn a new instance. |
| 76 params->set_target(shell::Identity(kTestName, shell::mojom::kRootUserID)); | 76 params->set_target(shell::Identity(kTestName, shell::mojom::kRootUserID)); |
| 77 | 77 |
| 78 shell::mojom::ClientProcessConnectionPtr client_process_connection = | 78 shell::mojom::ClientProcessConnectionPtr client_process_connection = |
| 79 shell::mojom::ClientProcessConnection::New(); | 79 shell::mojom::ClientProcessConnection::New(); |
| 80 client_process_connection->service = | 80 client_process_connection->service = |
| 81 service.PassInterface().PassHandle(); | 81 service.PassInterface().PassHandle(); |
| 82 client_process_connection->pid_receiver_request = | 82 client_process_connection->pid_receiver_request = |
| 83 mojo::GetProxy(&pid_receiver_).PassMessagePipe(); | 83 mojo::GetProxy(&pid_receiver_).PassMessagePipe(); |
| 84 params->set_client_process_connection(std::move(client_process_connection)); | 84 params->set_client_process_connection(std::move(client_process_connection)); |
| 85 service_manager->Connect(std::move(params)); | 85 service_manager->Connect(std::move(params)); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 : public shell::NativeRunnerDelegate { | 202 : public shell::NativeRunnerDelegate { |
| 203 public: | 203 public: |
| 204 NativeRunnerDelegateImpl() {} | 204 NativeRunnerDelegateImpl() {} |
| 205 ~NativeRunnerDelegateImpl() override {} | 205 ~NativeRunnerDelegateImpl() override {} |
| 206 | 206 |
| 207 private: | 207 private: |
| 208 // shell::NativeRunnerDelegate: | 208 // shell::NativeRunnerDelegate: |
| 209 void AdjustCommandLineArgumentsForTarget( | 209 void AdjustCommandLineArgumentsForTarget( |
| 210 const shell::Identity& target, | 210 const shell::Identity& target, |
| 211 base::CommandLine* command_line) override { | 211 base::CommandLine* command_line) override { |
| 212 if (target.name() != "exe:chrome") { | 212 if (target.name() != kTestName) { |
| 213 if (target.name() == "exe:mash_browser_tests") | 213 if (target.name() == kTestRunnerName) |
| 214 RemoveMashFromBrowserTests(command_line); | 214 RemoveMashFromBrowserTests(command_line); |
| 215 command_line->AppendSwitch(MojoTestConnector::kMashApp); | 215 command_line->AppendSwitch(MojoTestConnector::kMashApp); |
| 216 return; | 216 return; |
| 217 } | 217 } |
| 218 | 218 |
| 219 base::CommandLine::StringVector argv(command_line->argv()); | 219 base::CommandLine::StringVector argv(command_line->argv()); |
| 220 auto iter = | 220 auto iter = |
| 221 std::find(argv.begin(), argv.end(), FILE_PATH_LITERAL("--run-in-mash")); | 221 std::find(argv.begin(), argv.end(), FILE_PATH_LITERAL("--run-in-mash")); |
| 222 if (iter != argv.end()) | 222 if (iter != argv.end()) |
| 223 argv.erase(iter); | 223 argv.erase(iter); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 250 MojoTestConnector::~MojoTestConnector() {} | 250 MojoTestConnector::~MojoTestConnector() {} |
| 251 | 251 |
| 252 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( | 252 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( |
| 253 base::CommandLine* command_line, | 253 base::CommandLine* command_line, |
| 254 base::TestLauncher::LaunchOptions* test_launch_options) { | 254 base::TestLauncher::LaunchOptions* test_launch_options) { |
| 255 std::unique_ptr<MojoTestState> test_state( | 255 std::unique_ptr<MojoTestState> test_state( |
| 256 new MojoTestState(&background_shell_)); | 256 new MojoTestState(&background_shell_)); |
| 257 test_state->Init(command_line, test_launch_options); | 257 test_state->Init(command_line, test_launch_options); |
| 258 return std::move(test_state); | 258 return std::move(test_state); |
| 259 } | 259 } |
| OLD | NEW |