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

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

Issue 2280483002: Add FlushForTesting to InterfacePtr and Binding. (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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 void Multiply(double value, const base::Closure& closure) { 73 void Multiply(double value, const base::Closure& closure) {
74 calculator_->Multiply( 74 calculator_->Multiply(
75 value, 75 value,
76 base::Bind(&MathCalculatorUI::Output, base::Unretained(this), closure)); 76 base::Bind(&MathCalculatorUI::Output, base::Unretained(this), closure));
77 } 77 }
78 78
79 double GetOutput() const { return output_; } 79 double GetOutput() const { return output_; }
80 80
81 math::CalculatorPtr& GetInterfacePtr() { return calculator_; }
82
81 private: 83 private:
82 void Output(const base::Closure& closure, double output) { 84 void Output(const base::Closure& closure, double output) {
83 output_ = output; 85 output_ = output;
84 if (!closure.is_null()) 86 if (!closure.is_null())
85 closure.Run(); 87 closure.Run();
86 } 88 }
87 89
88 math::CalculatorPtr calculator_; 90 math::CalculatorPtr calculator_;
89 double output_; 91 double output_;
90 base::Closure closure_; 92 base::Closure closure_;
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 EXPECT_TRUE(FuseInterface(std::move(request), proxy.PassInterface())); 730 EXPECT_TRUE(FuseInterface(std::move(request), proxy.PassInterface()));
729 731
730 // Ping! 732 // Ping!
731 bool called = false; 733 bool called = false;
732 base::RunLoop loop; 734 base::RunLoop loop;
733 ptr->Ping(base::Bind(&SetFlagAndRunClosure, &called, loop.QuitClosure())); 735 ptr->Ping(base::Bind(&SetFlagAndRunClosure, &called, loop.QuitClosure()));
734 loop.Run(); 736 loop.Run();
735 EXPECT_TRUE(called); 737 EXPECT_TRUE(called);
736 } 738 }
737 739
740 void Fail() {
741 FAIL() << "Unexpected connection error";
742 }
743
744 TEST_F(InterfacePtrTest, FlushForTesting) {
745 math::CalculatorPtr calc;
746 MathCalculatorImpl calc_impl(GetProxy(&calc));
747 calc.set_connection_error_handler(base::Bind(&Fail));
748
749 MathCalculatorUI calculator_ui(std::move(calc));
750
751 calculator_ui.Add(2.0, base::Bind(&base::DoNothing));
752 calculator_ui.GetInterfacePtr().FlushForTesting();
753 EXPECT_EQ(2.0, calculator_ui.GetOutput());
754
755 calculator_ui.Multiply(5.0, base::Bind(&base::DoNothing));
756 calculator_ui.GetInterfacePtr().FlushForTesting();
757
758 EXPECT_EQ(10.0, calculator_ui.GetOutput());
759 }
760
761 void SetBool(bool* value) {
762 *value = true;
763 }
764
765 TEST_F(InterfacePtrTest, FlushForTestingWithClosedPeer) {
766 math::CalculatorPtr calc;
767 GetProxy(&calc);
768 bool called = false;
769 calc.set_connection_error_handler(base::Bind(&SetBool, &called));
770 calc.FlushForTesting();
771 EXPECT_TRUE(called);
772 calc.FlushForTesting();
773 }
774
738 } // namespace 775 } // namespace
739 } // namespace test 776 } // namespace test
740 } // namespace mojo 777 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/binding_unittest.cc ('k') | mojo/public/cpp/bindings/tests/multiplex_router_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698