OLD | NEW |
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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 private: | 134 private: |
135 base::MessageLoop loop_; | 135 base::MessageLoop loop_; |
136 }; | 136 }; |
137 | 137 |
138 // Tests that the InterfacePtr and the Binding can communicate with each | 138 // Tests that the InterfacePtr and the Binding can communicate with each |
139 // other normally. | 139 // other normally. |
140 TEST_F(BindingCallbackTest, Basic) { | 140 TEST_F(BindingCallbackTest, Basic) { |
141 // Create the ServerImpl and the Binding. | 141 // Create the ServerImpl and the Binding. |
142 InterfaceImpl server_impl; | 142 InterfaceImpl server_impl; |
143 Binding<sample::Provider> binding(&server_impl, GetProxy(&interface_ptr_)); | 143 Binding<sample::Provider> binding(&server_impl, MakeRequest(&interface_ptr_)); |
144 | 144 |
145 // Initialize the test values. | 145 // Initialize the test values. |
146 server_impl.resetLastServerValueSeen(); | 146 server_impl.resetLastServerValueSeen(); |
147 last_client_callback_value_seen_ = 0; | 147 last_client_callback_value_seen_ = 0; |
148 | 148 |
149 // Invoke the Echo method. | 149 // Invoke the Echo method. |
150 base::RunLoop run_loop, run_loop2; | 150 base::RunLoop run_loop, run_loop2; |
151 server_impl.set_closure(run_loop.QuitClosure()); | 151 server_impl.set_closure(run_loop.QuitClosure()); |
152 interface_ptr_->EchoInt( | 152 interface_ptr_->EchoInt( |
153 7, | 153 7, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 | 193 |
194 // Tests that running the Callback after the Binding has been deleted | 194 // Tests that running the Callback after the Binding has been deleted |
195 // results in a clean failure. | 195 // results in a clean failure. |
196 TEST_F(BindingCallbackTest, DeleteBindingThenRunCallback) { | 196 TEST_F(BindingCallbackTest, DeleteBindingThenRunCallback) { |
197 // Create the ServerImpl. | 197 // Create the ServerImpl. |
198 InterfaceImpl server_impl; | 198 InterfaceImpl server_impl; |
199 base::RunLoop run_loop; | 199 base::RunLoop run_loop; |
200 { | 200 { |
201 // Create the binding in an inner scope so it can be deleted first. | 201 // Create the binding in an inner scope so it can be deleted first. |
202 Binding<sample::Provider> binding(&server_impl, GetProxy(&interface_ptr_)); | 202 Binding<sample::Provider> binding(&server_impl, |
| 203 MakeRequest(&interface_ptr_)); |
203 interface_ptr_.set_connection_error_handler(run_loop.QuitClosure()); | 204 interface_ptr_.set_connection_error_handler(run_loop.QuitClosure()); |
204 | 205 |
205 // Initialize the test values. | 206 // Initialize the test values. |
206 server_impl.resetLastServerValueSeen(); | 207 server_impl.resetLastServerValueSeen(); |
207 last_client_callback_value_seen_ = 0; | 208 last_client_callback_value_seen_ = 0; |
208 | 209 |
209 // Invoke the Echo method. | 210 // Invoke the Echo method. |
210 base::RunLoop run_loop2; | 211 base::RunLoop run_loop2; |
211 server_impl.set_closure(run_loop2.QuitClosure()); | 212 server_impl.set_closure(run_loop2.QuitClosure()); |
212 interface_ptr_->EchoInt( | 213 interface_ptr_->EchoInt( |
(...skipping 24 matching lines...) Expand all Loading... |
237 EXPECT_TRUE(interface_ptr_.encountered_error()); | 238 EXPECT_TRUE(interface_ptr_.encountered_error()); |
238 } | 239 } |
239 | 240 |
240 // Tests that deleting a Callback without running it after the corresponding | 241 // Tests that deleting a Callback without running it after the corresponding |
241 // binding has already been deleted does not result in a crash. | 242 // binding has already been deleted does not result in a crash. |
242 TEST_F(BindingCallbackTest, DeleteBindingThenDeleteCallback) { | 243 TEST_F(BindingCallbackTest, DeleteBindingThenDeleteCallback) { |
243 // Create the ServerImpl. | 244 // Create the ServerImpl. |
244 InterfaceImpl server_impl; | 245 InterfaceImpl server_impl; |
245 { | 246 { |
246 // Create the binding in an inner scope so it can be deleted first. | 247 // Create the binding in an inner scope so it can be deleted first. |
247 Binding<sample::Provider> binding(&server_impl, GetProxy(&interface_ptr_)); | 248 Binding<sample::Provider> binding(&server_impl, |
| 249 MakeRequest(&interface_ptr_)); |
248 | 250 |
249 // Initialize the test values. | 251 // Initialize the test values. |
250 server_impl.resetLastServerValueSeen(); | 252 server_impl.resetLastServerValueSeen(); |
251 last_client_callback_value_seen_ = 0; | 253 last_client_callback_value_seen_ = 0; |
252 | 254 |
253 // Invoke the Echo method. | 255 // Invoke the Echo method. |
254 base::RunLoop run_loop; | 256 base::RunLoop run_loop; |
255 server_impl.set_closure(run_loop.QuitClosure()); | 257 server_impl.set_closure(run_loop.QuitClosure()); |
256 interface_ptr_->EchoInt( | 258 interface_ptr_->EchoInt( |
257 7, | 259 7, |
(...skipping 10 matching lines...) Expand all Loading... |
268 // cause a problem because the insfrastructure can detect that the | 270 // cause a problem because the insfrastructure can detect that the |
269 // binding has already been destroyed and the pipe is closed. | 271 // binding has already been destroyed and the pipe is closed. |
270 server_impl.DeleteCallback(); | 272 server_impl.DeleteCallback(); |
271 } | 273 } |
272 | 274 |
273 // Tests that closing a Binding allows us to delete a callback | 275 // Tests that closing a Binding allows us to delete a callback |
274 // without running it without encountering a crash. | 276 // without running it without encountering a crash. |
275 TEST_F(BindingCallbackTest, CloseBindingBeforeDeletingCallback) { | 277 TEST_F(BindingCallbackTest, CloseBindingBeforeDeletingCallback) { |
276 // Create the ServerImpl and the Binding. | 278 // Create the ServerImpl and the Binding. |
277 InterfaceImpl server_impl; | 279 InterfaceImpl server_impl; |
278 Binding<sample::Provider> binding(&server_impl, GetProxy(&interface_ptr_)); | 280 Binding<sample::Provider> binding(&server_impl, MakeRequest(&interface_ptr_)); |
279 | 281 |
280 // Initialize the test values. | 282 // Initialize the test values. |
281 server_impl.resetLastServerValueSeen(); | 283 server_impl.resetLastServerValueSeen(); |
282 last_client_callback_value_seen_ = 0; | 284 last_client_callback_value_seen_ = 0; |
283 | 285 |
284 // Invoke the Echo method. | 286 // Invoke the Echo method. |
285 base::RunLoop run_loop; | 287 base::RunLoop run_loop; |
286 server_impl.set_closure(run_loop.QuitClosure()); | 288 server_impl.set_closure(run_loop.QuitClosure()); |
287 interface_ptr_->EchoInt( | 289 interface_ptr_->EchoInt( |
288 7, | 290 7, |
(...skipping 14 matching lines...) Expand all Loading... |
303 | 305 |
304 // Check that the client has still not seen the correct value. | 306 // Check that the client has still not seen the correct value. |
305 EXPECT_EQ(0, last_client_callback_value_seen_); | 307 EXPECT_EQ(0, last_client_callback_value_seen_); |
306 } | 308 } |
307 | 309 |
308 // Tests that deleting a Callback without using it before the | 310 // Tests that deleting a Callback without using it before the |
309 // Binding has been destroyed or closed results in a DCHECK. | 311 // Binding has been destroyed or closed results in a DCHECK. |
310 TEST_F(BindingCallbackTest, DeleteCallbackBeforeBindingDeathTest) { | 312 TEST_F(BindingCallbackTest, DeleteCallbackBeforeBindingDeathTest) { |
311 // Create the ServerImpl and the Binding. | 313 // Create the ServerImpl and the Binding. |
312 InterfaceImpl server_impl; | 314 InterfaceImpl server_impl; |
313 Binding<sample::Provider> binding(&server_impl, GetProxy(&interface_ptr_)); | 315 Binding<sample::Provider> binding(&server_impl, MakeRequest(&interface_ptr_)); |
314 | 316 |
315 // Initialize the test values. | 317 // Initialize the test values. |
316 server_impl.resetLastServerValueSeen(); | 318 server_impl.resetLastServerValueSeen(); |
317 last_client_callback_value_seen_ = 0; | 319 last_client_callback_value_seen_ = 0; |
318 | 320 |
319 // Invoke the Echo method. | 321 // Invoke the Echo method. |
320 base::RunLoop run_loop; | 322 base::RunLoop run_loop; |
321 server_impl.set_closure(run_loop.QuitClosure()); | 323 server_impl.set_closure(run_loop.QuitClosure()); |
322 interface_ptr_->EchoInt( | 324 interface_ptr_->EchoInt( |
323 7, | 325 7, |
(...skipping 13 matching lines...) Expand all Loading... |
337 regex.clear(); | 339 regex.clear(); |
338 #endif // OS_WIN | 340 #endif // OS_WIN |
339 EXPECT_DEATH_IF_SUPPORTED(server_impl.DeleteCallback(), regex.c_str()); | 341 EXPECT_DEATH_IF_SUPPORTED(server_impl.DeleteCallback(), regex.c_str()); |
340 #endif // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && | 342 #endif // (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && |
341 // !defined(OS_ANDROID) | 343 // !defined(OS_ANDROID) |
342 } | 344 } |
343 | 345 |
344 } // namespace | 346 } // namespace |
345 } // namespace test | 347 } // namespace test |
346 } // namespace mojo | 348 } // namespace mojo |
OLD | NEW |