OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 // Suppose this is instantiated in a process that has pipe1_. | |
yzshen1
2016/08/31 17:06:47
I guess this is an outdated comment (here and else
Sam McNally
2016/09/01 00:44:37
Done.
| |
750 MathCalculatorUI calculator_ui(std::move(calc)); | |
751 | |
752 calculator_ui.Add(2.0, base::Bind(&base::DoNothing)); | |
753 calculator_ui.GetInterfacePtr().FlushForTesting(); | |
754 EXPECT_EQ(2.0, calculator_ui.GetOutput()); | |
755 | |
756 calculator_ui.Multiply(5.0, base::Bind(&base::DoNothing)); | |
757 calculator_ui.GetInterfacePtr().FlushForTesting(); | |
758 | |
759 EXPECT_EQ(10.0, calculator_ui.GetOutput()); | |
760 } | |
761 | |
762 void SetBool(bool* value) { | |
763 *value = true; | |
764 } | |
765 | |
766 TEST_F(InterfacePtrTest, FlushForTestingWithClosedPeer) { | |
767 math::CalculatorPtr calc; | |
768 GetProxy(&calc); | |
769 bool called = false; | |
770 calc.set_connection_error_handler(base::Bind(&SetBool, &called)); | |
771 calc.FlushForTesting(); | |
772 EXPECT_TRUE(called); | |
773 calc.FlushForTesting(); | |
774 } | |
775 | |
738 } // namespace | 776 } // namespace |
739 } // namespace test | 777 } // namespace test |
740 } // namespace mojo | 778 } // namespace mojo |
OLD | NEW |