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

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

Issue 2258523003: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 5 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 scoped_refptr<MultiplexRouter> router1_; 58 scoped_refptr<MultiplexRouter> router1_;
59 ScopedInterfaceEndpointHandle endpoint0_; 59 ScopedInterfaceEndpointHandle endpoint0_;
60 ScopedInterfaceEndpointHandle endpoint1_; 60 ScopedInterfaceEndpointHandle endpoint1_;
61 61
62 private: 62 private:
63 base::MessageLoop loop_; 63 base::MessageLoop loop_;
64 }; 64 };
65 65
66 TEST_F(MultiplexRouterTest, BasicRequestResponse) { 66 TEST_F(MultiplexRouterTest, BasicRequestResponse) {
67 InterfaceEndpointClient client0(std::move(endpoint0_), nullptr, 67 InterfaceEndpointClient client0(std::move(endpoint0_), nullptr,
68 base::WrapUnique(new PassThroughFilter()), 68 base::MakeUnique<PassThroughFilter>(), false,
69 false, base::ThreadTaskRunnerHandle::Get()); 69 base::ThreadTaskRunnerHandle::Get());
70 ResponseGenerator generator; 70 ResponseGenerator generator;
71 InterfaceEndpointClient client1(std::move(endpoint1_), &generator, 71 InterfaceEndpointClient client1(std::move(endpoint1_), &generator,
72 base::WrapUnique(new PassThroughFilter()), 72 base::MakeUnique<PassThroughFilter>(), false,
73 false, base::ThreadTaskRunnerHandle::Get()); 73 base::ThreadTaskRunnerHandle::Get());
74 74
75 Message request; 75 Message request;
76 AllocRequestMessage(1, "hello", &request); 76 AllocRequestMessage(1, "hello", &request);
77 77
78 MessageQueue message_queue; 78 MessageQueue message_queue;
79 base::RunLoop run_loop; 79 base::RunLoop run_loop;
80 client0.AcceptWithResponder( 80 client0.AcceptWithResponder(
81 &request, 81 &request,
82 new MessageAccumulator(&message_queue, run_loop.QuitClosure())); 82 new MessageAccumulator(&message_queue, run_loop.QuitClosure()));
83 83
(...skipping 21 matching lines...) Expand all
105 EXPECT_FALSE(message_queue.IsEmpty()); 105 EXPECT_FALSE(message_queue.IsEmpty());
106 106
107 message_queue.Pop(&response); 107 message_queue.Pop(&response);
108 108
109 EXPECT_EQ(std::string("hello again world!"), 109 EXPECT_EQ(std::string("hello again world!"),
110 std::string(reinterpret_cast<const char*>(response.payload()))); 110 std::string(reinterpret_cast<const char*>(response.payload())));
111 } 111 }
112 112
113 TEST_F(MultiplexRouterTest, BasicRequestResponse_Synchronous) { 113 TEST_F(MultiplexRouterTest, BasicRequestResponse_Synchronous) {
114 InterfaceEndpointClient client0(std::move(endpoint0_), nullptr, 114 InterfaceEndpointClient client0(std::move(endpoint0_), nullptr,
115 base::WrapUnique(new PassThroughFilter()), 115 base::MakeUnique<PassThroughFilter>(), false,
116 false, base::ThreadTaskRunnerHandle::Get()); 116 base::ThreadTaskRunnerHandle::Get());
117 ResponseGenerator generator; 117 ResponseGenerator generator;
118 InterfaceEndpointClient client1(std::move(endpoint1_), &generator, 118 InterfaceEndpointClient client1(std::move(endpoint1_), &generator,
119 base::WrapUnique(new PassThroughFilter()), 119 base::MakeUnique<PassThroughFilter>(), false,
120 false, base::ThreadTaskRunnerHandle::Get()); 120 base::ThreadTaskRunnerHandle::Get());
121 121
122 Message request; 122 Message request;
123 AllocRequestMessage(1, "hello", &request); 123 AllocRequestMessage(1, "hello", &request);
124 124
125 MessageQueue message_queue; 125 MessageQueue message_queue;
126 client0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue)); 126 client0.AcceptWithResponder(&request, new MessageAccumulator(&message_queue));
127 127
128 router1_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE); 128 router1_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE);
129 router0_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE); 129 router0_->WaitForIncomingMessage(MOJO_DEADLINE_INDEFINITE);
130 130
(...skipping 18 matching lines...) Expand all
149 EXPECT_FALSE(message_queue.IsEmpty()); 149 EXPECT_FALSE(message_queue.IsEmpty());
150 150
151 message_queue.Pop(&response); 151 message_queue.Pop(&response);
152 152
153 EXPECT_EQ(std::string("hello again world!"), 153 EXPECT_EQ(std::string("hello again world!"),
154 std::string(reinterpret_cast<const char*>(response.payload()))); 154 std::string(reinterpret_cast<const char*>(response.payload())));
155 } 155 }
156 156
157 TEST_F(MultiplexRouterTest, RequestWithNoReceiver) { 157 TEST_F(MultiplexRouterTest, RequestWithNoReceiver) {
158 InterfaceEndpointClient client0(std::move(endpoint0_), nullptr, 158 InterfaceEndpointClient client0(std::move(endpoint0_), nullptr,
159 base::WrapUnique(new PassThroughFilter()), 159 base::MakeUnique<PassThroughFilter>(), false,
160 false, base::ThreadTaskRunnerHandle::Get()); 160 base::ThreadTaskRunnerHandle::Get());
161 InterfaceEndpointClient client1(std::move(endpoint1_), nullptr, 161 InterfaceEndpointClient client1(std::move(endpoint1_), nullptr,
162 base::WrapUnique(new PassThroughFilter()), 162 base::MakeUnique<PassThroughFilter>(), false,
163 false, base::ThreadTaskRunnerHandle::Get()); 163 base::ThreadTaskRunnerHandle::Get());
164 164
165 // Without an incoming receiver set on client1, we expect client0 to observe 165 // Without an incoming receiver set on client1, we expect client0 to observe
166 // an error as a result of sending a message. 166 // an error as a result of sending a message.
167 167
168 Message request; 168 Message request;
169 AllocRequestMessage(1, "hello", &request); 169 AllocRequestMessage(1, "hello", &request);
170 170
171 MessageQueue message_queue; 171 MessageQueue message_queue;
172 base::RunLoop run_loop, run_loop2; 172 base::RunLoop run_loop, run_loop2;
173 client0.set_connection_error_handler(run_loop.QuitClosure()); 173 client0.set_connection_error_handler(run_loop.QuitClosure());
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 308
309 TEST_F(MultiplexRouterTest, LateResponse) { 309 TEST_F(MultiplexRouterTest, LateResponse) {
310 // Test that things won't blow up if we try to send a message to a 310 // Test that things won't blow up if we try to send a message to a
311 // MessageReceiver, which was given to us via AcceptWithResponder, 311 // MessageReceiver, which was given to us via AcceptWithResponder,
312 // after the router has gone away. 312 // after the router has gone away.
313 313
314 base::RunLoop run_loop; 314 base::RunLoop run_loop;
315 LazyResponseGenerator generator(run_loop.QuitClosure()); 315 LazyResponseGenerator generator(run_loop.QuitClosure());
316 { 316 {
317 InterfaceEndpointClient client0(std::move(endpoint0_), nullptr, 317 InterfaceEndpointClient client0(std::move(endpoint0_), nullptr,
318 base::WrapUnique(new PassThroughFilter()), 318 base::MakeUnique<PassThroughFilter>(),
319 false, base::ThreadTaskRunnerHandle::Get()); 319 false, base::ThreadTaskRunnerHandle::Get());
320 InterfaceEndpointClient client1(std::move(endpoint1_), &generator, 320 InterfaceEndpointClient client1(std::move(endpoint1_), &generator,
321 base::WrapUnique(new PassThroughFilter()), 321 base::MakeUnique<PassThroughFilter>(),
322 false, base::ThreadTaskRunnerHandle::Get()); 322 false, base::ThreadTaskRunnerHandle::Get());
323 323
324 Message request; 324 Message request;
325 AllocRequestMessage(1, "hello", &request); 325 AllocRequestMessage(1, "hello", &request);
326 326
327 MessageQueue message_queue; 327 MessageQueue message_queue;
328 client0.AcceptWithResponder(&request, 328 client0.AcceptWithResponder(&request,
329 new MessageAccumulator(&message_queue)); 329 new MessageAccumulator(&message_queue));
330 330
331 run_loop.Run(); 331 run_loop.Run();
332 332
333 EXPECT_TRUE(generator.has_responder()); 333 EXPECT_TRUE(generator.has_responder());
334 } 334 }
335 335
336 EXPECT_FALSE(generator.responder_is_valid()); 336 EXPECT_FALSE(generator.responder_is_valid());
337 generator.CompleteWithResponse(); // This should end up doing nothing. 337 generator.CompleteWithResponse(); // This should end up doing nothing.
338 } 338 }
339 339
340 // TODO(yzshen): add more tests. 340 // TODO(yzshen): add more tests.
341 341
342 } // namespace 342 } // namespace
343 } // namespace test 343 } // namespace test
344 } // namespace mojo 344 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/router.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698