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