OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "mojo/public/cpp/bindings/message.h" |
| 11 |
| 12 namespace mojo { |
| 13 namespace test { |
| 14 |
| 15 class MessageQueue; |
| 16 |
| 17 void AllocRequestMessage(uint32_t name, const char* text, Message* message); |
| 18 void AllocResponseMessage(uint32_t name, |
| 19 const char* text, |
| 20 uint64_t request_id, |
| 21 Message* message); |
| 22 |
| 23 class MessageAccumulator : public MessageReceiver { |
| 24 public: |
| 25 explicit MessageAccumulator(MessageQueue* queue); |
| 26 |
| 27 bool Accept(Message* message) override; |
| 28 |
| 29 private: |
| 30 MessageQueue* queue_; |
| 31 }; |
| 32 |
| 33 class ResponseGenerator : public MessageReceiverWithResponderStatus { |
| 34 public: |
| 35 ResponseGenerator(); |
| 36 |
| 37 bool Accept(Message* message) override; |
| 38 |
| 39 bool AcceptWithResponder(Message* message, |
| 40 MessageReceiverWithStatus* responder) override; |
| 41 |
| 42 bool SendResponse(uint32_t name, |
| 43 uint64_t request_id, |
| 44 const char* request_string, |
| 45 MessageReceiver* responder); |
| 46 }; |
| 47 |
| 48 class LazyResponseGenerator : public ResponseGenerator { |
| 49 public: |
| 50 LazyResponseGenerator(); |
| 51 |
| 52 ~LazyResponseGenerator() override; |
| 53 |
| 54 bool AcceptWithResponder(Message* message, |
| 55 MessageReceiverWithStatus* responder) override; |
| 56 |
| 57 bool has_responder() const { return !!responder_; } |
| 58 |
| 59 bool responder_is_valid() const { return responder_->IsValid(); } |
| 60 |
| 61 // Sends the response and delete the responder. |
| 62 void CompleteWithResponse() { Complete(true); } |
| 63 |
| 64 // Deletes the responder without sending a response. |
| 65 void CompleteWithoutResponse() { Complete(false); } |
| 66 |
| 67 private: |
| 68 // Completes the request handling by deleting responder_. Optionally |
| 69 // also sends a response. |
| 70 void Complete(bool send_response); |
| 71 |
| 72 MessageReceiverWithStatus* responder_; |
| 73 uint32_t name_; |
| 74 uint64_t request_id_; |
| 75 std::string request_string_; |
| 76 }; |
| 77 |
| 78 } // namespace test |
| 79 } // namespace mojo |
| 80 |
| 81 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ |
OLD | NEW |