| 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 #ifndef MOJO_EDK_TEST_MOJO_TEST_BASE_H_ | 5 #ifndef MOJO_EDK_TEST_MOJO_TEST_BASE_H_ |
| 6 #define MOJO_EDK_TEST_MOJO_TEST_BASE_H_ | 6 #define MOJO_EDK_TEST_MOJO_TEST_BASE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace mojo { | 23 namespace mojo { |
| 24 namespace edk { | 24 namespace edk { |
| 25 namespace test { | 25 namespace test { |
| 26 | 26 |
| 27 class MojoTestBase : public testing::Test { | 27 class MojoTestBase : public testing::Test { |
| 28 public: | 28 public: |
| 29 MojoTestBase(); | 29 MojoTestBase(); |
| 30 ~MojoTestBase() override; | 30 ~MojoTestBase() override; |
| 31 | 31 |
| 32 using LaunchType = MultiprocessTestHelper::LaunchType; |
| 33 |
| 32 protected: | 34 protected: |
| 33 using HandlerCallback = base::Callback<void(ScopedMessagePipeHandle)>; | 35 using HandlerCallback = base::Callback<void(ScopedMessagePipeHandle)>; |
| 34 | 36 |
| 35 class ClientController { | 37 class ClientController { |
| 36 public: | 38 public: |
| 37 ClientController(const std::string& client_name, | 39 ClientController(const std::string& client_name, |
| 38 MojoTestBase* test, | 40 MojoTestBase* test, |
| 39 const ProcessErrorCallback& process_error_callback_); | 41 const ProcessErrorCallback& process_error_callback, |
| 42 LaunchType launch_type); |
| 40 ~ClientController(); | 43 ~ClientController(); |
| 41 | 44 |
| 42 MojoHandle pipe() const { return pipe_.get().value(); } | 45 MojoHandle pipe() const { return pipe_.get().value(); } |
| 43 | 46 |
| 44 int WaitForShutdown(); | 47 int WaitForShutdown(); |
| 45 | 48 |
| 46 private: | 49 private: |
| 47 friend class MojoTestBase; | 50 friend class MojoTestBase; |
| 48 | 51 |
| 49 #if !defined(OS_IOS) | 52 #if !defined(OS_IOS) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 static void CreateDataPipe(MojoHandle* producer, | 144 static void CreateDataPipe(MojoHandle* producer, |
| 142 MojoHandle* consumer, | 145 MojoHandle* consumer, |
| 143 size_t capacity); | 146 size_t capacity); |
| 144 | 147 |
| 145 // Writes data to a data pipe. | 148 // Writes data to a data pipe. |
| 146 static void WriteData(MojoHandle producer, const std::string& data); | 149 static void WriteData(MojoHandle producer, const std::string& data); |
| 147 | 150 |
| 148 // Reads data from a data pipe. | 151 // Reads data from a data pipe. |
| 149 static std::string ReadData(MojoHandle consumer, size_t size); | 152 static std::string ReadData(MojoHandle consumer, size_t size); |
| 150 | 153 |
| 154 void set_launch_type(LaunchType launch_type) { launch_type_ = launch_type; } |
| 155 |
| 151 private: | 156 private: |
| 152 friend class ClientController; | 157 friend class ClientController; |
| 153 | 158 |
| 154 std::vector<std::unique_ptr<ClientController>> clients_; | 159 std::vector<std::unique_ptr<ClientController>> clients_; |
| 155 | 160 |
| 156 ProcessErrorCallback process_error_callback_; | 161 ProcessErrorCallback process_error_callback_; |
| 157 | 162 |
| 163 LaunchType launch_type_ = LaunchType::CHILD; |
| 164 |
| 158 DISALLOW_COPY_AND_ASSIGN(MojoTestBase); | 165 DISALLOW_COPY_AND_ASSIGN(MojoTestBase); |
| 159 }; | 166 }; |
| 160 | 167 |
| 161 // Launches a new child process running the test client |client_name| connected | 168 // Launches a new child process running the test client |client_name| connected |
| 162 // to a new message pipe bound to |pipe_name|. |pipe_name| is automatically | 169 // to a new message pipe bound to |pipe_name|. |pipe_name| is automatically |
| 163 // closed on test teardown. | 170 // closed on test teardown. |
| 164 #define RUN_CHILD_ON_PIPE(client_name, pipe_name) \ | 171 #define RUN_CHILD_ON_PIPE(client_name, pipe_name) \ |
| 165 StartClientWithHandler( \ | 172 StartClientWithHandler( \ |
| 166 #client_name, \ | 173 #client_name, \ |
| 167 [&](MojoHandle pipe_name, int *expected_exit_code) { { | 174 [&](MojoHandle pipe_name, int *expected_exit_code) { { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 #else // !defined(OS_IOS) | 233 #else // !defined(OS_IOS) |
| 227 #define DEFINE_TEST_CLIENT_WITH_PIPE(client_name, test_base, pipe_name) | 234 #define DEFINE_TEST_CLIENT_WITH_PIPE(client_name, test_base, pipe_name) |
| 228 #define DEFINE_TEST_CLIENT_TEST_WITH_PIPE(client_name, test_base, pipe_name) | 235 #define DEFINE_TEST_CLIENT_TEST_WITH_PIPE(client_name, test_base, pipe_name) |
| 229 #endif // !defined(OS_IOS) | 236 #endif // !defined(OS_IOS) |
| 230 | 237 |
| 231 } // namespace test | 238 } // namespace test |
| 232 } // namespace edk | 239 } // namespace edk |
| 233 } // namespace mojo | 240 } // namespace mojo |
| 234 | 241 |
| 235 #endif // MOJO_EDK_TEST_MOJO_TEST_BASE_H_ | 242 #endif // MOJO_EDK_TEST_MOJO_TEST_BASE_H_ |
| OLD | NEW |