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

Unified Diff: mojo/public/bindings/tests/router_unittest.cc

Issue 198343002: Mojo: request/response bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/bindings/tests/router_unittest.cc
diff --git a/mojo/public/bindings/tests/router_unittest.cc b/mojo/public/bindings/tests/router_unittest.cc
index 79dc28a685a6fddfebe237306ea687a443b2e2af..92f5fa73ff641ef59591ce01efffae603682cf7d 100644
--- a/mojo/public/bindings/tests/router_unittest.cc
+++ b/mojo/public/bindings/tests/router_unittest.cc
@@ -34,11 +34,11 @@ void AllocResponseMessage(uint32_t name, const char* text,
class MessageAccumulator : public MessageReceiver {
public:
- MessageAccumulator() {
+ explicit MessageAccumulator(internal::MessageQueue* queue) : queue_(queue) {
}
virtual bool Accept(Message* message) MOJO_OVERRIDE {
- queue_.Push(message);
+ queue_->Push(message);
return true;
}
@@ -47,16 +47,8 @@ class MessageAccumulator : public MessageReceiver {
return false;
}
- bool IsEmpty() const {
- return queue_.IsEmpty();
- }
-
- void Pop(Message* message) {
- queue_.Pop(message);
- }
-
private:
- internal::MessageQueue queue_;
+ internal::MessageQueue* queue_;
};
class ResponseGenerator : public MessageReceiver {
@@ -79,12 +71,22 @@ class ResponseGenerator : public MessageReceiver {
MessageReceiver* responder) {
Message response;
AllocResponseMessage(name, "world", request_id, &response);
- return responder->Accept(&response);
+
+ bool result = responder->Accept(&response);
+ delete responder;
+ return result;
}
};
class LazyResponseGenerator : public ResponseGenerator {
public:
+ LazyResponseGenerator() : responder_(NULL), name_(0), request_id_(0) {
+ }
+
+ virtual ~LazyResponseGenerator() {
+ delete responder_;
+ }
+
virtual bool AcceptWithResponder(Message* message, MessageReceiver* responder)
MOJO_OVERRIDE {
name_ = message->name();
@@ -141,15 +143,15 @@ TEST_F(RouterTest, BasicRequestResponse) {
Message request;
AllocRequestMessage(1, "hello", &request);
- MessageAccumulator accumulator;
- router0.AcceptWithResponder(&request, &accumulator);
+ internal::MessageQueue message_queue;
+ router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
PumpMessages();
- EXPECT_FALSE(accumulator.IsEmpty());
+ EXPECT_FALSE(message_queue.IsEmpty());
Message response;
- accumulator.Pop(&response);
+ message_queue.Pop(&response);
EXPECT_EQ(std::string("world"),
std::string(reinterpret_cast<const char*>(response.payload())));
@@ -165,14 +167,14 @@ TEST_F(RouterTest, RequestWithNoReceiver) {
Message request;
AllocRequestMessage(1, "hello", &request);
- MessageAccumulator accumulator;
- router0.AcceptWithResponder(&request, &accumulator);
+ internal::MessageQueue message_queue;
+ router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
PumpMessages();
EXPECT_TRUE(router0.encountered_error());
EXPECT_TRUE(router1.encountered_error());
- EXPECT_TRUE(accumulator.IsEmpty());
+ EXPECT_TRUE(message_queue.IsEmpty());
}
TEST_F(RouterTest, LateResponse) {
@@ -190,8 +192,9 @@ TEST_F(RouterTest, LateResponse) {
Message request;
AllocRequestMessage(1, "hello", &request);
- MessageAccumulator accumulator;
- router0.AcceptWithResponder(&request, &accumulator);
+ internal::MessageQueue message_queue;
+ router0.AcceptWithResponder(&request,
+ new MessageAccumulator(&message_queue));
PumpMessages();
« no previous file with comments | « mojo/public/bindings/tests/request_response_unittest.cc ('k') | mojo/public/bindings/tests/sample_interfaces.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698