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

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

Issue 2318793002: Mojo C++ bindings: support disconnect with a reason. (Closed)
Patch Set: . Created 4 years, 3 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 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 // Note: This file tests both binding.h (mojo::Binding) and strong_binding.h 5 // Note: This file tests both binding.h (mojo::Binding) and strong_binding.h
6 // (mojo::StrongBinding). 6 // (mojo::StrongBinding).
7 7
8 #include "mojo/public/cpp/bindings/binding.h" 8 #include "mojo/public/cpp/bindings/binding.h"
9 9
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 Binding<sample::Service> binding(&impl, std::move(request)); 417 Binding<sample::Service> binding(&impl, std::move(request));
418 binding.set_connection_error_handler(SetFlagAndRunClosure(&called)); 418 binding.set_connection_error_handler(SetFlagAndRunClosure(&called));
419 ptr.reset(); 419 ptr.reset();
420 420
421 EXPECT_FALSE(called); 421 EXPECT_FALSE(called);
422 binding.FlushForTesting(); 422 binding.FlushForTesting();
423 EXPECT_TRUE(called); 423 EXPECT_TRUE(called);
424 binding.FlushForTesting(); 424 binding.FlushForTesting();
425 } 425 }
426 426
427 TEST_F(BindingTest, ConnectionErrorWithReason) {
428 sample::ServicePtr ptr;
429 auto request = GetProxy(&ptr);
430 ServiceImpl impl;
431 Binding<sample::Service> binding(&impl, std::move(request));
432
433 base::RunLoop run_loop;
434 binding.set_connection_error_with_reason_handler(base::Bind(
435 [](const base::Closure& quit_closure, uint32_t custom_reason,
436 const std::string& description) {
437 EXPECT_EQ(1234u, custom_reason);
438 EXPECT_EQ("hello", description);
439 quit_closure.Run();
440 },
441 run_loop.QuitClosure()));
442
443 ptr.ResetWithReason(1234u, "hello");
444
445 run_loop.Run();
446 }
447
427 // StrongBindingTest ----------------------------------------------------------- 448 // StrongBindingTest -----------------------------------------------------------
428 449
429 using StrongBindingTest = BindingTestBase; 450 using StrongBindingTest = BindingTestBase;
430 451
431 // Tests that destroying a mojo::StrongBinding closes the bound message pipe 452 // Tests that destroying a mojo::StrongBinding closes the bound message pipe
432 // handle but does *not* destroy the implementation object. 453 // handle but does *not* destroy the implementation object.
433 TEST_F(StrongBindingTest, DestroyClosesMessagePipe) { 454 TEST_F(StrongBindingTest, DestroyClosesMessagePipe) {
434 base::RunLoop run_loop; 455 base::RunLoop run_loop;
435 bool encountered_error = false; 456 bool encountered_error = false;
436 bool was_deleted = false; 457 bool was_deleted = false;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 540
520 EXPECT_FALSE(called); 541 EXPECT_FALSE(called);
521 EXPECT_FALSE(was_deleted); 542 EXPECT_FALSE(was_deleted);
522 ASSERT_TRUE(binding); 543 ASSERT_TRUE(binding);
523 binding->FlushForTesting(); 544 binding->FlushForTesting();
524 EXPECT_TRUE(called); 545 EXPECT_TRUE(called);
525 EXPECT_TRUE(was_deleted); 546 EXPECT_TRUE(was_deleted);
526 ASSERT_FALSE(binding); 547 ASSERT_FALSE(binding);
527 } 548 }
528 549
550 TEST_F(StrongBindingTest, ConnectionErrorWithReason) {
551 sample::ServicePtr ptr;
552 auto request = GetProxy(&ptr);
553 auto binding =
554 MakeStrongBinding(base::MakeUnique<ServiceImpl>(), std::move(request));
555 base::RunLoop run_loop;
556 binding->set_connection_error_with_reason_handler(base::Bind(
557 [](const base::Closure& quit_closure, uint32_t custom_reason,
558 const std::string& description) {
559 EXPECT_EQ(5678u, custom_reason);
560 EXPECT_EQ("hello", description);
561 quit_closure.Run();
562 },
563 run_loop.QuitClosure()));
564
565 ptr.ResetWithReason(5678u, "hello");
566
567 run_loop.Run();
568 }
569
529 } // namespace 570 } // namespace
530 } // mojo 571 } // mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/binding_set_unittest.cc ('k') | mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698