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 <memory> |
| 6 |
5 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
6 #include "base/command_line.h" | 8 #include "base/command_line.h" |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
8 #include "base/process/process.h" | 10 #include "base/process/process.h" |
9 #include "mojo/public/cpp/bindings/binding_set.h" | 11 #include "mojo/public/cpp/bindings/binding_set.h" |
10 #include "services/shell/public/cpp/connection.h" | 12 #include "services/shell/public/cpp/connection.h" |
11 #include "services/shell/public/cpp/connector.h" | 13 #include "services/shell/public/cpp/connector.h" |
12 #include "services/shell/public/cpp/shell_client.h" | 14 #include "services/shell/public/cpp/shell_client.h" |
13 #include "services/shell/runner/child/test_native_main.h" | 15 #include "services/shell/runner/child/test_native_main.h" |
14 #include "services/shell/runner/init.h" | 16 #include "services/shell/runner/init.h" |
15 #include "services/shell/tests/connect/connect_test.mojom.h" | 17 #include "services/shell/tests/connect/connect_test.mojom.h" |
16 #include "services/shell/tests/util.h" | 18 #include "services/shell/tests/util.h" |
17 | 19 |
18 using mojo::shell::test::mojom::ClientProcessTest; | 20 using shell::test::mojom::ClientProcessTest; |
19 using mojo::shell::test::mojom::ClientProcessTestRequest; | 21 using shell::test::mojom::ClientProcessTestRequest; |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 class Driver : public mojo::ShellClient, | 25 class Driver : public shell::ShellClient, |
24 public mojo::InterfaceFactory<ClientProcessTest>, | 26 public shell::InterfaceFactory<ClientProcessTest>, |
25 public ClientProcessTest { | 27 public ClientProcessTest { |
26 public: | 28 public: |
27 Driver() {} | 29 Driver() {} |
28 ~Driver() override {} | 30 ~Driver() override {} |
29 | 31 |
30 private: | 32 private: |
31 // mojo::ShellClient: | 33 // shell::ShellClient: |
32 void Initialize(mojo::Connector* connector, const mojo::Identity& identity, | 34 void Initialize(shell::Connector* connector, |
| 35 const shell::Identity& identity, |
33 uint32_t id) override { | 36 uint32_t id) override { |
34 connector_ = connector; | 37 connector_ = connector; |
35 } | 38 } |
36 bool AcceptConnection(mojo::Connection* connection) override { | 39 bool AcceptConnection(shell::Connection* connection) override { |
37 connection->AddInterface<ClientProcessTest>(this); | 40 connection->AddInterface<ClientProcessTest>(this); |
38 return true; | 41 return true; |
39 } | 42 } |
40 bool ShellConnectionLost() override { | 43 bool ShellConnectionLost() override { |
41 // TODO(rockot): http://crbug.com/596621. Should be able to remove this | 44 // TODO(rockot): http://crbug.com/596621. Should be able to remove this |
42 // override entirely. | 45 // override entirely. |
43 _exit(1); | 46 _exit(1); |
44 } | 47 } |
45 | 48 |
46 // mojo::InterfaceFactory<ConnectTestService>: | 49 // shell::InterfaceFactory<ConnectTestService>: |
47 void Create(mojo::Connection* connection, | 50 void Create(shell::Connection* connection, |
48 ClientProcessTestRequest request) override { | 51 ClientProcessTestRequest request) override { |
49 bindings_.AddBinding(this, std::move(request)); | 52 bindings_.AddBinding(this, std::move(request)); |
50 } | 53 } |
51 | 54 |
52 // test::mojom::ClientProcessTest: | 55 // test::mojom::ClientProcessTest: |
53 void LaunchAndConnectToProcess( | 56 void LaunchAndConnectToProcess( |
54 const LaunchAndConnectToProcessCallback& callback) override { | 57 const LaunchAndConnectToProcessCallback& callback) override { |
55 base::Process process; | 58 base::Process process; |
56 scoped_ptr<mojo::Connection> connection = | 59 std::unique_ptr<shell::Connection> connection = |
57 mojo::shell::test::LaunchAndConnectToProcess( | 60 shell::test::LaunchAndConnectToProcess( |
58 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
59 "connect_test_exe.exe", | 62 "connect_test_exe.exe", |
60 #else | 63 #else |
61 "connect_test_exe", | 64 "connect_test_exe", |
62 #endif | 65 #endif |
63 mojo::Identity("exe:connect_test_exe", | 66 shell::Identity("exe:connect_test_exe", |
64 mojo::shell::mojom::kInheritUserID), | 67 shell::mojom::kInheritUserID), |
65 connector_, | 68 connector_, &process); |
66 &process); | |
67 callback.Run(static_cast<int32_t>(connection->GetResult()), | 69 callback.Run(static_cast<int32_t>(connection->GetResult()), |
68 mojo::shell::mojom::Identity::From( | 70 shell::mojom::Identity::From(connection->GetRemoteIdentity())); |
69 connection->GetRemoteIdentity())); | |
70 } | 71 } |
71 | 72 |
72 mojo::Connector* connector_ = nullptr; | 73 shell::Connector* connector_ = nullptr; |
73 mojo::BindingSet<ClientProcessTest> bindings_; | 74 mojo::BindingSet<ClientProcessTest> bindings_; |
74 | 75 |
75 DISALLOW_COPY_AND_ASSIGN(Driver); | 76 DISALLOW_COPY_AND_ASSIGN(Driver); |
76 }; | 77 }; |
77 | 78 |
78 } // namespace | 79 } // namespace |
79 | 80 |
80 int main(int argc, char** argv) { | 81 int main(int argc, char** argv) { |
81 base::AtExitManager at_exit; | 82 base::AtExitManager at_exit; |
82 base::CommandLine::Init(argc, argv); | 83 base::CommandLine::Init(argc, argv); |
83 | 84 |
84 mojo::shell::InitializeLogging(); | 85 shell::InitializeLogging(); |
85 | 86 |
86 Driver driver; | 87 Driver driver; |
87 return mojo::shell::TestNativeMain(&driver); | 88 return shell::TestNativeMain(&driver); |
88 } | 89 } |
OLD | NEW |