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

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

Powered by Google App Engine
This is Rietveld 408576698