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

Side by Side Diff: mojo/edk/test/mojo_test_base.h

Issue 2043713004: Mojo: Add NotifyBadMessage API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no bindings Created 4 years, 6 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
« no previous file with comments | « mojo/edk/system/ports_message.h ('k') | mojo/edk/test/mojo_test_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 16 matching lines...) Expand all
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 protected: 32 protected:
33 using HandlerCallback = base::Callback<void(ScopedMessagePipeHandle)>; 33 using HandlerCallback = base::Callback<void(ScopedMessagePipeHandle)>;
34 34
35 class ClientController { 35 class ClientController {
36 public: 36 public:
37 ClientController(const std::string& client_name, MojoTestBase* test); 37 ClientController(const std::string& client_name,
38 MojoTestBase* test,
39 const ProcessErrorCallback& process_error_callback_);
38 ~ClientController(); 40 ~ClientController();
39 41
40 MojoHandle pipe() const { return pipe_.get().value(); } 42 MojoHandle pipe() const { return pipe_.get().value(); }
41 43
42 int WaitForShutdown(); 44 int WaitForShutdown();
43 45
44 private: 46 private:
45 friend class MojoTestBase; 47 friend class MojoTestBase;
46 48
47 #if !defined(OS_IOS) 49 #if !defined(OS_IOS)
48 MultiprocessTestHelper helper_; 50 MultiprocessTestHelper helper_;
49 #endif 51 #endif
50 ScopedMessagePipeHandle pipe_; 52 ScopedMessagePipeHandle pipe_;
51 bool was_shutdown_ = false; 53 bool was_shutdown_ = false;
52 54
53 DISALLOW_COPY_AND_ASSIGN(ClientController); 55 DISALLOW_COPY_AND_ASSIGN(ClientController);
54 }; 56 };
55 57
58 // Set the callback to handle bad messages received from test client
59 // processes. This can be set to a different callback before starting each
60 // client.
61 void set_process_error_callback(const ProcessErrorCallback& callback) {
62 process_error_callback_ = callback;
63 }
64
56 ClientController& StartClient(const std::string& client_name); 65 ClientController& StartClient(const std::string& client_name);
57 66
58 template <typename HandlerFunc> 67 template <typename HandlerFunc>
59 void StartClientWithHandler(const std::string& client_name, 68 void StartClientWithHandler(const std::string& client_name,
60 HandlerFunc handler) { 69 HandlerFunc handler) {
61 int expected_exit_code = 0; 70 int expected_exit_code = 0;
62 ClientController& c = StartClient(client_name); 71 ClientController& c = StartClient(client_name);
63 handler(c.pipe(), &expected_exit_code); 72 handler(c.pipe(), &expected_exit_code);
64 EXPECT_EQ(expected_exit_code, c.WaitForShutdown()); 73 EXPECT_EQ(expected_exit_code, c.WaitForShutdown());
65 } 74 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 static void WriteData(MojoHandle producer, const std::string& data); 146 static void WriteData(MojoHandle producer, const std::string& data);
138 147
139 // Reads data from a data pipe. 148 // Reads data from a data pipe.
140 static std::string ReadData(MojoHandle consumer, size_t size); 149 static std::string ReadData(MojoHandle consumer, size_t size);
141 150
142 private: 151 private:
143 friend class ClientController; 152 friend class ClientController;
144 153
145 std::vector<std::unique_ptr<ClientController>> clients_; 154 std::vector<std::unique_ptr<ClientController>> clients_;
146 155
156 ProcessErrorCallback process_error_callback_;
157
147 DISALLOW_COPY_AND_ASSIGN(MojoTestBase); 158 DISALLOW_COPY_AND_ASSIGN(MojoTestBase);
148 }; 159 };
149 160
150 // Launches a new child process running the test client |client_name| connected 161 // Launches a new child process running the test client |client_name| connected
151 // to a new message pipe bound to |pipe_name|. |pipe_name| is automatically 162 // to a new message pipe bound to |pipe_name|. |pipe_name| is automatically
152 // closed on test teardown. 163 // closed on test teardown.
153 #define RUN_CHILD_ON_PIPE(client_name, pipe_name) \ 164 #define RUN_CHILD_ON_PIPE(client_name, pipe_name) \
154 StartClientWithHandler( \ 165 StartClientWithHandler( \
155 #client_name, \ 166 #client_name, \
156 [&](MojoHandle pipe_name, int *expected_exit_code) { { 167 [&](MojoHandle pipe_name, int *expected_exit_code) { {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 #else // !defined(OS_IOS) 226 #else // !defined(OS_IOS)
216 #define DEFINE_TEST_CLIENT_WITH_PIPE(client_name, test_base, pipe_name) 227 #define DEFINE_TEST_CLIENT_WITH_PIPE(client_name, test_base, pipe_name)
217 #define DEFINE_TEST_CLIENT_TEST_WITH_PIPE(client_name, test_base, pipe_name) 228 #define DEFINE_TEST_CLIENT_TEST_WITH_PIPE(client_name, test_base, pipe_name)
218 #endif // !defined(OS_IOS) 229 #endif // !defined(OS_IOS)
219 230
220 } // namespace test 231 } // namespace test
221 } // namespace edk 232 } // namespace edk
222 } // namespace mojo 233 } // namespace mojo
223 234
224 #endif // MOJO_EDK_TEST_MOJO_TEST_BASE_H_ 235 #endif // MOJO_EDK_TEST_MOJO_TEST_BASE_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/ports_message.h ('k') | mojo/edk/test/mojo_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698