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

Side by Side Diff: mojo/public/cpp/bindings/tests/router_test_util.h

Issue 1552983003: Fix a bunch of mojo_public_*_unittests with the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 11 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h"
12 #include "mojo/public/cpp/bindings/message.h" 13 #include "mojo/public/cpp/bindings/message.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace test { 16 namespace test {
16 17
17 class MessageQueue; 18 class MessageQueue;
18 19
19 void AllocRequestMessage(uint32_t name, const char* text, Message* message); 20 void AllocRequestMessage(uint32_t name, const char* text, Message* message);
20 void AllocResponseMessage(uint32_t name, 21 void AllocResponseMessage(uint32_t name,
21 const char* text, 22 const char* text,
22 uint64_t request_id, 23 uint64_t request_id,
23 Message* message); 24 Message* message);
24 25
25 class MessageAccumulator : public MessageReceiver { 26 class MessageAccumulator : public MessageReceiver {
26 public: 27 public:
27 explicit MessageAccumulator(MessageQueue* queue); 28 MessageAccumulator(MessageQueue* queue,
29 const base::Closure& closure = base::Closure());
30 ~MessageAccumulator() override;
28 31
29 bool Accept(Message* message) override; 32 bool Accept(Message* message) override;
30 33
31 private: 34 private:
32 MessageQueue* queue_; 35 MessageQueue* queue_;
36 base::Closure closure_;
33 }; 37 };
34 38
35 class ResponseGenerator : public MessageReceiverWithResponderStatus { 39 class ResponseGenerator : public MessageReceiverWithResponderStatus {
36 public: 40 public:
37 ResponseGenerator(); 41 ResponseGenerator();
38 42
39 bool Accept(Message* message) override; 43 bool Accept(Message* message) override;
40 44
41 bool AcceptWithResponder(Message* message, 45 bool AcceptWithResponder(Message* message,
42 MessageReceiverWithStatus* responder) override; 46 MessageReceiverWithStatus* responder) override;
43 47
44 bool SendResponse(uint32_t name, 48 bool SendResponse(uint32_t name,
45 uint64_t request_id, 49 uint64_t request_id,
46 const char* request_string, 50 const char* request_string,
47 MessageReceiver* responder); 51 MessageReceiver* responder);
48 }; 52 };
49 53
50 class LazyResponseGenerator : public ResponseGenerator { 54 class LazyResponseGenerator : public ResponseGenerator {
51 public: 55 public:
52 LazyResponseGenerator(); 56 explicit LazyResponseGenerator(
57 const base::Closure& closure = base::Closure());
53 58
54 ~LazyResponseGenerator() override; 59 ~LazyResponseGenerator() override;
55 60
56 bool AcceptWithResponder(Message* message, 61 bool AcceptWithResponder(Message* message,
57 MessageReceiverWithStatus* responder) override; 62 MessageReceiverWithStatus* responder) override;
58 63
59 bool has_responder() const { return !!responder_; } 64 bool has_responder() const { return !!responder_; }
60 65
61 bool responder_is_valid() const { return responder_->IsValid(); } 66 bool responder_is_valid() const { return responder_->IsValid(); }
62 67
68 void set_closure(const base::Closure& closure) { closure_ = closure; }
69
63 // Sends the response and delete the responder. 70 // Sends the response and delete the responder.
64 void CompleteWithResponse() { Complete(true); } 71 void CompleteWithResponse() { Complete(true); }
65 72
66 // Deletes the responder without sending a response. 73 // Deletes the responder without sending a response.
67 void CompleteWithoutResponse() { Complete(false); } 74 void CompleteWithoutResponse() { Complete(false); }
68 75
69 private: 76 private:
70 // Completes the request handling by deleting responder_. Optionally 77 // Completes the request handling by deleting responder_. Optionally
71 // also sends a response. 78 // also sends a response.
72 void Complete(bool send_response); 79 void Complete(bool send_response);
73 80
74 MessageReceiverWithStatus* responder_; 81 MessageReceiverWithStatus* responder_;
75 uint32_t name_; 82 uint32_t name_;
76 uint64_t request_id_; 83 uint64_t request_id_;
77 std::string request_string_; 84 std::string request_string_;
85 base::Closure closure_;
78 }; 86 };
79 87
80 } // namespace test 88 } // namespace test
81 } // namespace mojo 89 } // namespace mojo
82 90
83 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_ 91 #endif // MOJO_PUBLIC_CPP_BINDINGS_TESTS_ROUTER_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/request_response_unittest.cc ('k') | mojo/public/cpp/bindings/tests/router_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698