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

Side by Side Diff: mojo/public/cpp/bindings/tests/router_unittest.cc

Issue 1535943002: Convert Pass()→std::move() in //mojo/public/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Regenerate correctly 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "mojo/public/cpp/bindings/lib/router.h"
6
7 #include <utility>
8
5 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
6 #include "mojo/message_pump/message_pump_mojo.h" 10 #include "mojo/message_pump/message_pump_mojo.h"
7 #include "mojo/public/cpp/bindings/lib/router.h"
8 #include "mojo/public/cpp/bindings/tests/message_queue.h" 11 #include "mojo/public/cpp/bindings/tests/message_queue.h"
9 #include "mojo/public/cpp/bindings/tests/router_test_util.h" 12 #include "mojo/public/cpp/bindings/tests/router_test_util.h"
10 #include "mojo/public/cpp/system/macros.h" 13 #include "mojo/public/cpp/system/macros.h"
11 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
12 15
13 namespace mojo { 16 namespace mojo {
14 namespace test { 17 namespace test {
15 namespace { 18 namespace {
16 19
17 class RouterTest : public testing::Test { 20 class RouterTest : public testing::Test {
(...skipping 10 matching lines...) Expand all
28 31
29 protected: 32 protected:
30 ScopedMessagePipeHandle handle0_; 33 ScopedMessagePipeHandle handle0_;
31 ScopedMessagePipeHandle handle1_; 34 ScopedMessagePipeHandle handle1_;
32 35
33 private: 36 private:
34 base::MessageLoop loop_; 37 base::MessageLoop loop_;
35 }; 38 };
36 39
37 TEST_F(RouterTest, BasicRequestResponse) { 40 TEST_F(RouterTest, BasicRequestResponse) {
38 internal::Router router0(handle0_.Pass(), internal::FilterChain()); 41 internal::Router router0(std::move(handle0_), internal::FilterChain());
39 internal::Router router1(handle1_.Pass(), internal::FilterChain()); 42 internal::Router router1(std::move(handle1_), internal::FilterChain());
40 43
41 ResponseGenerator generator; 44 ResponseGenerator generator;
42 router1.set_incoming_receiver(&generator); 45 router1.set_incoming_receiver(&generator);
43 46
44 Message request; 47 Message request;
45 AllocRequestMessage(1, "hello", &request); 48 AllocRequestMessage(1, "hello", &request);
46 49
47 MessageQueue message_queue; 50 MessageQueue message_queue;
48 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue)); 51 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
49 52
(...skipping 18 matching lines...) Expand all
68 71
69 EXPECT_FALSE(message_queue.IsEmpty()); 72 EXPECT_FALSE(message_queue.IsEmpty());
70 73
71 message_queue.Pop(&response); 74 message_queue.Pop(&response);
72 75
73 EXPECT_EQ(std::string("hello again world!"), 76 EXPECT_EQ(std::string("hello again world!"),
74 std::string(reinterpret_cast<const char*>(response.payload()))); 77 std::string(reinterpret_cast<const char*>(response.payload())));
75 } 78 }
76 79
77 TEST_F(RouterTest, BasicRequestResponse_Synchronous) { 80 TEST_F(RouterTest, BasicRequestResponse_Synchronous) {
78 internal::Router router0(handle0_.Pass(), internal::FilterChain()); 81 internal::Router router0(std::move(handle0_), internal::FilterChain());
79 internal::Router router1(handle1_.Pass(), internal::FilterChain()); 82 internal::Router router1(std::move(handle1_), internal::FilterChain());
80 83
81 ResponseGenerator generator; 84 ResponseGenerator generator;
82 router1.set_incoming_receiver(&generator); 85 router1.set_incoming_receiver(&generator);
83 86
84 Message request; 87 Message request;
85 AllocRequestMessage(1, "hello", &request); 88 AllocRequestMessage(1, "hello", &request);
86 89
87 MessageQueue message_queue; 90 MessageQueue message_queue;
88 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue)); 91 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
89 92
(...skipping 20 matching lines...) Expand all
110 113
111 EXPECT_FALSE(message_queue.IsEmpty()); 114 EXPECT_FALSE(message_queue.IsEmpty());
112 115
113 message_queue.Pop(&response); 116 message_queue.Pop(&response);
114 117
115 EXPECT_EQ(std::string("hello again world!"), 118 EXPECT_EQ(std::string("hello again world!"),
116 std::string(reinterpret_cast<const char*>(response.payload()))); 119 std::string(reinterpret_cast<const char*>(response.payload())));
117 } 120 }
118 121
119 TEST_F(RouterTest, RequestWithNoReceiver) { 122 TEST_F(RouterTest, RequestWithNoReceiver) {
120 internal::Router router0(handle0_.Pass(), internal::FilterChain()); 123 internal::Router router0(std::move(handle0_), internal::FilterChain());
121 internal::Router router1(handle1_.Pass(), internal::FilterChain()); 124 internal::Router router1(std::move(handle1_), internal::FilterChain());
122 125
123 // Without an incoming receiver set on router1, we expect router0 to observe 126 // Without an incoming receiver set on router1, we expect router0 to observe
124 // an error as a result of sending a message. 127 // an error as a result of sending a message.
125 128
126 Message request; 129 Message request;
127 AllocRequestMessage(1, "hello", &request); 130 AllocRequestMessage(1, "hello", &request);
128 131
129 MessageQueue message_queue; 132 MessageQueue message_queue;
130 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue)); 133 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
131 134
132 PumpMessages(); 135 PumpMessages();
133 136
134 EXPECT_TRUE(router0.encountered_error()); 137 EXPECT_TRUE(router0.encountered_error());
135 EXPECT_TRUE(router1.encountered_error()); 138 EXPECT_TRUE(router1.encountered_error());
136 EXPECT_TRUE(message_queue.IsEmpty()); 139 EXPECT_TRUE(message_queue.IsEmpty());
137 } 140 }
138 141
139 // Tests Router using the LazyResponseGenerator. The responses will not be 142 // Tests Router using the LazyResponseGenerator. The responses will not be
140 // sent until after the requests have been accepted. 143 // sent until after the requests have been accepted.
141 TEST_F(RouterTest, LazyResponses) { 144 TEST_F(RouterTest, LazyResponses) {
142 internal::Router router0(handle0_.Pass(), internal::FilterChain()); 145 internal::Router router0(std::move(handle0_), internal::FilterChain());
143 internal::Router router1(handle1_.Pass(), internal::FilterChain()); 146 internal::Router router1(std::move(handle1_), internal::FilterChain());
144 147
145 LazyResponseGenerator generator; 148 LazyResponseGenerator generator;
146 router1.set_incoming_receiver(&generator); 149 router1.set_incoming_receiver(&generator);
147 150
148 Message request; 151 Message request;
149 AllocRequestMessage(1, "hello", &request); 152 AllocRequestMessage(1, "hello", &request);
150 153
151 MessageQueue message_queue; 154 MessageQueue message_queue;
152 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue)); 155 router0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
153 PumpMessages(); 156 PumpMessages();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 EXPECT_FALSE(message_queue.IsEmpty()); 190 EXPECT_FALSE(message_queue.IsEmpty());
188 message_queue.Pop(&response); 191 message_queue.Pop(&response);
189 EXPECT_EQ(std::string("hello again world!"), 192 EXPECT_EQ(std::string("hello again world!"),
190 std::string(reinterpret_cast<const char*>(response.payload()))); 193 std::string(reinterpret_cast<const char*>(response.payload())));
191 } 194 }
192 195
193 // Tests that if the receiving application destroys the responder_ without 196 // Tests that if the receiving application destroys the responder_ without
194 // sending a response, then we trigger connection error at both sides. Moreover, 197 // sending a response, then we trigger connection error at both sides. Moreover,
195 // both sides still appear to have a valid message pipe handle bound. 198 // both sides still appear to have a valid message pipe handle bound.
196 TEST_F(RouterTest, MissingResponses) { 199 TEST_F(RouterTest, MissingResponses) {
197 internal::Router router0(handle0_.Pass(), internal::FilterChain()); 200 internal::Router router0(std::move(handle0_), internal::FilterChain());
198 bool error_handler_called0 = false; 201 bool error_handler_called0 = false;
199 router0.set_connection_error_handler( 202 router0.set_connection_error_handler(
200 [&error_handler_called0]() { error_handler_called0 = true; }); 203 [&error_handler_called0]() { error_handler_called0 = true; });
201 204
202 internal::Router router1(handle1_.Pass(), internal::FilterChain()); 205 internal::Router router1(std::move(handle1_), internal::FilterChain());
203 bool error_handler_called1 = false; 206 bool error_handler_called1 = false;
204 router1.set_connection_error_handler( 207 router1.set_connection_error_handler(
205 [&error_handler_called1]() { error_handler_called1 = true; }); 208 [&error_handler_called1]() { error_handler_called1 = true; });
206 209
207 LazyResponseGenerator generator; 210 LazyResponseGenerator generator;
208 router1.set_incoming_receiver(&generator); 211 router1.set_incoming_receiver(&generator);
209 212
210 Message request; 213 Message request;
211 AllocRequestMessage(1, "hello", &request); 214 AllocRequestMessage(1, "hello", &request);
212 215
(...skipping 24 matching lines...) Expand all
237 EXPECT_TRUE(router1.is_valid()); 240 EXPECT_TRUE(router1.is_valid());
238 } 241 }
239 242
240 TEST_F(RouterTest, LateResponse) { 243 TEST_F(RouterTest, LateResponse) {
241 // Test that things won't blow up if we try to send a message to a 244 // Test that things won't blow up if we try to send a message to a
242 // MessageReceiver, which was given to us via AcceptWithResponder, 245 // MessageReceiver, which was given to us via AcceptWithResponder,
243 // after the router has gone away. 246 // after the router has gone away.
244 247
245 LazyResponseGenerator generator; 248 LazyResponseGenerator generator;
246 { 249 {
247 internal::Router router0(handle0_.Pass(), internal::FilterChain()); 250 internal::Router router0(std::move(handle0_), internal::FilterChain());
248 internal::Router router1(handle1_.Pass(), internal::FilterChain()); 251 internal::Router router1(std::move(handle1_), internal::FilterChain());
249 252
250 router1.set_incoming_receiver(&generator); 253 router1.set_incoming_receiver(&generator);
251 254
252 Message request; 255 Message request;
253 AllocRequestMessage(1, "hello", &request); 256 AllocRequestMessage(1, "hello", &request);
254 257
255 MessageQueue message_queue; 258 MessageQueue message_queue;
256 router0.AcceptWithResponder(&request, 259 router0.AcceptWithResponder(&request,
257 new MessageAccumulator(&message_queue)); 260 new MessageAccumulator(&message_queue));
258 261
259 PumpMessages(); 262 PumpMessages();
260 263
261 EXPECT_TRUE(generator.has_responder()); 264 EXPECT_TRUE(generator.has_responder());
262 } 265 }
263 266
264 EXPECT_FALSE(generator.responder_is_valid()); 267 EXPECT_FALSE(generator.responder_is_valid());
265 generator.CompleteWithResponse(); // This should end up doing nothing. 268 generator.CompleteWithResponse(); // This should end up doing nothing.
266 } 269 }
267 270
268 } // namespace 271 } // namespace
269 } // namespace test 272 } // namespace test
270 } // namespace mojo 273 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/request_response_unittest.cc ('k') | mojo/public/cpp/bindings/tests/sample_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698