Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: chrome/test/base/mojo_test_connector.cc

Issue 2118083002: ShellClient -> Service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mus2
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/public/test/test_launcher.h" 16 #include "content/public/test/test_launcher.h"
17 #include "mojo/edk/embedder/embedder.h" 17 #include "mojo/edk/embedder/embedder.h"
18 #include "mojo/edk/embedder/platform_channel_pair.h" 18 #include "mojo/edk/embedder/platform_channel_pair.h"
19 #include "mojo/edk/embedder/process_delegate.h" 19 #include "mojo/edk/embedder/process_delegate.h"
20 #include "mojo/public/cpp/bindings/interface_request.h" 20 #include "mojo/public/cpp/bindings/interface_request.h"
21 #include "services/catalog/store.h" 21 #include "services/catalog/store.h"
22 #include "services/shell/background/tests/test_catalog_store.h" 22 #include "services/shell/background/tests/test_catalog_store.h"
23 #include "services/shell/native_runner_delegate.h" 23 #include "services/shell/native_runner_delegate.h"
24 #include "services/shell/public/cpp/connector.h" 24 #include "services/shell/public/cpp/connector.h"
25 #include "services/shell/public/cpp/shell_client.h" 25 #include "services/shell/public/cpp/service.h"
26 #include "services/shell/public/cpp/shell_connection.h" 26 #include "services/shell/public/cpp/shell_connection.h"
27 #include "services/shell/runner/common/client_util.h" 27 #include "services/shell/runner/common/client_util.h"
28 #include "services/shell/runner/common/switches.h" 28 #include "services/shell/runner/common/switches.h"
29 #include "services/shell/shell.h" 29 #include "services/shell/shell.h"
30 #include "services/shell/switches.h" 30 #include "services/shell/switches.h"
31 31
32 using shell::mojom::ShellClient; 32 using shell::mojom::Service;
33 using shell::mojom::ShellClientPtr; 33 using shell::mojom::ServicePtr;
34 34
35 namespace { 35 namespace {
36 36
37 const char kTestRunnerName[] = "mojo:test-runner"; 37 const char kTestRunnerName[] = "mojo:test-runner";
38 const char kTestName[] = "exe:chrome"; 38 const char kTestName[] = "exe:chrome";
39 39
40 // Returns the Dictionary value of |parent| under the specified key, creating 40 // Returns the Dictionary value of |parent| under the specified key, creating
41 // and adding as necessary. 41 // and adding as necessary.
42 base::DictionaryValue* EnsureDictionary(base::DictionaryValue* parent, 42 base::DictionaryValue* EnsureDictionary(base::DictionaryValue* parent,
43 const char* key) { 43 const char* key) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 test_launch_options->inherit_handles = true; 95 test_launch_options->inherit_handles = true;
96 test_launch_options->handles_to_inherit = &handle_passing_info_; 96 test_launch_options->handles_to_inherit = &handle_passing_info_;
97 #if defined(OFFICIAL_BUILD) 97 #if defined(OFFICIAL_BUILD)
98 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; 98 CHECK(false) << "Launching mojo process with inherit_handles is insecure!";
99 #endif 99 #endif
100 #elif defined(OS_POSIX) 100 #elif defined(OS_POSIX)
101 test_launch_options->fds_to_remap = &handle_passing_info_; 101 test_launch_options->fds_to_remap = &handle_passing_info_;
102 #else 102 #else
103 #error "Unsupported" 103 #error "Unsupported"
104 #endif 104 #endif
105 shell::mojom::ShellClientPtr client = 105 shell::mojom::ServicePtr service =
106 shell::PassShellClientRequestOnCommandLine(command_line, child_token_); 106 shell::PassServiceRequestOnCommandLine(command_line, child_token_);
107 107
108 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); 108 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams);
109 params->set_source(shell::CreateShellIdentity()); 109 params->set_source(shell::CreateShellIdentity());
110 params->set_target( 110 params->set_target(
111 shell::Identity(kTestName, shell::mojom::kRootUserID, instance)); 111 shell::Identity(kTestName, shell::mojom::kRootUserID, instance));
112 112
113 shell::mojom::ClientProcessConnectionPtr client_process_connection = 113 shell::mojom::ClientProcessConnectionPtr client_process_connection =
114 shell::mojom::ClientProcessConnection::New(); 114 shell::mojom::ClientProcessConnection::New();
115 client_process_connection->shell_client = 115 client_process_connection->service =
116 client.PassInterface().PassHandle(); 116 service.PassInterface().PassHandle();
117 client_process_connection->pid_receiver_request = 117 client_process_connection->pid_receiver_request =
118 mojo::GetProxy(&pid_receiver_).PassMessagePipe(); 118 mojo::GetProxy(&pid_receiver_).PassMessagePipe();
119 params->set_client_process_connection(std::move(client_process_connection)); 119 params->set_client_process_connection(std::move(client_process_connection));
120 shell->Connect(std::move(params)); 120 shell->Connect(std::move(params));
121 } 121 }
122 122
123 // Called after the test process has launched. Completes the registration done 123 // Called after the test process has launched. Completes the registration done
124 // in Connect(). 124 // in Connect().
125 void ChildProcessLaunched(base::ProcessHandle handle, base::ProcessId pid) { 125 void ChildProcessLaunched(base::ProcessHandle handle, base::ProcessId pid) {
126 pid_receiver_->SetPID(pid); 126 pid_receiver_->SetPID(pid);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 DISALLOW_COPY_AND_ASSIGN(MojoTestState); 219 DISALLOW_COPY_AND_ASSIGN(MojoTestState);
220 }; 220 };
221 221
222 } // namespace 222 } // namespace
223 223
224 // static 224 // static
225 const char MojoTestConnector::kTestSwitch[] = "is_test"; 225 const char MojoTestConnector::kTestSwitch[] = "is_test";
226 226
227 MojoTestConnector::MojoTestConnector() {} 227 MojoTestConnector::MojoTestConnector() {}
228 228
229 shell::mojom::ShellClientRequest MojoTestConnector::Init() { 229 shell::mojom::ServiceRequest MojoTestConnector::Init() {
230 std::unique_ptr<shell::BackgroundShell::InitParams> init_params( 230 std::unique_ptr<shell::BackgroundShell::InitParams> init_params(
231 new shell::BackgroundShell::InitParams); 231 new shell::BackgroundShell::InitParams);
232 init_params->catalog_store = BuildTestCatalogStore(); 232 init_params->catalog_store = BuildTestCatalogStore();
233 // When running in single_process mode chrome initializes the edk. 233 // When running in single_process mode chrome initializes the edk.
234 init_params->init_edk = !base::CommandLine::ForCurrentProcess()->HasSwitch( 234 init_params->init_edk = !base::CommandLine::ForCurrentProcess()->HasSwitch(
235 content::kSingleProcessTestsFlag); 235 content::kSingleProcessTestsFlag);
236 background_shell_.Init(std::move(init_params)); 236 background_shell_.Init(std::move(init_params));
237 return background_shell_.CreateShellClientRequest(kTestRunnerName); 237 return background_shell_.CreateServiceRequest(kTestRunnerName);
238 } 238 }
239 239
240 MojoTestConnector::~MojoTestConnector() {} 240 MojoTestConnector::~MojoTestConnector() {}
241 241
242 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest( 242 std::unique_ptr<content::TestState> MojoTestConnector::PrepareForTest(
243 base::CommandLine* command_line, 243 base::CommandLine* command_line,
244 base::TestLauncher::LaunchOptions* test_launch_options) { 244 base::TestLauncher::LaunchOptions* test_launch_options) {
245 std::unique_ptr<MojoTestState> test_state( 245 std::unique_ptr<MojoTestState> test_state(
246 new MojoTestState(&background_shell_)); 246 new MojoTestState(&background_shell_));
247 test_state->Init(command_line, test_launch_options); 247 test_state->Init(command_line, test_launch_options);
248 return std::move(test_state); 248 return std::move(test_state);
249 } 249 }
OLDNEW
« no previous file with comments | « chrome/test/base/mojo_test_connector.h ('k') | chromecast/browser/cast_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698