OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 ~RequestResponseTest() override { base::RunLoop().RunUntilIdle(); } | 88 ~RequestResponseTest() override { base::RunLoop().RunUntilIdle(); } |
89 | 89 |
90 void PumpMessages() { base::RunLoop().RunUntilIdle(); } | 90 void PumpMessages() { base::RunLoop().RunUntilIdle(); } |
91 | 91 |
92 private: | 92 private: |
93 base::MessageLoop loop_; | 93 base::MessageLoop loop_; |
94 }; | 94 }; |
95 | 95 |
96 TEST_F(RequestResponseTest, EchoString) { | 96 TEST_F(RequestResponseTest, EchoString) { |
97 sample::ProviderPtr provider; | 97 sample::ProviderPtr provider; |
98 ProviderImpl provider_impl(GetProxy(&provider)); | 98 ProviderImpl provider_impl(MakeRequest(&provider)); |
99 | 99 |
100 std::string buf; | 100 std::string buf; |
101 base::RunLoop run_loop; | 101 base::RunLoop run_loop; |
102 provider->EchoString("hello", | 102 provider->EchoString("hello", |
103 base::Bind(&RecordString, &buf, run_loop.QuitClosure())); | 103 base::Bind(&RecordString, &buf, run_loop.QuitClosure())); |
104 | 104 |
105 run_loop.Run(); | 105 run_loop.Run(); |
106 | 106 |
107 EXPECT_EQ(std::string("hello"), buf); | 107 EXPECT_EQ(std::string("hello"), buf); |
108 } | 108 } |
109 | 109 |
110 TEST_F(RequestResponseTest, EchoStrings) { | 110 TEST_F(RequestResponseTest, EchoStrings) { |
111 sample::ProviderPtr provider; | 111 sample::ProviderPtr provider; |
112 ProviderImpl provider_impl(GetProxy(&provider)); | 112 ProviderImpl provider_impl(MakeRequest(&provider)); |
113 | 113 |
114 std::string buf; | 114 std::string buf; |
115 base::RunLoop run_loop; | 115 base::RunLoop run_loop; |
116 provider->EchoStrings("hello", " world", base::Bind(&RecordStrings, &buf, | 116 provider->EchoStrings("hello", " world", base::Bind(&RecordStrings, &buf, |
117 run_loop.QuitClosure())); | 117 run_loop.QuitClosure())); |
118 | 118 |
119 run_loop.Run(); | 119 run_loop.Run(); |
120 | 120 |
121 EXPECT_EQ(std::string("hello world"), buf); | 121 EXPECT_EQ(std::string("hello world"), buf); |
122 } | 122 } |
123 | 123 |
124 TEST_F(RequestResponseTest, EchoMessagePipeHandle) { | 124 TEST_F(RequestResponseTest, EchoMessagePipeHandle) { |
125 sample::ProviderPtr provider; | 125 sample::ProviderPtr provider; |
126 ProviderImpl provider_impl(GetProxy(&provider)); | 126 ProviderImpl provider_impl(MakeRequest(&provider)); |
127 | 127 |
128 MessagePipe pipe2; | 128 MessagePipe pipe2; |
129 base::RunLoop run_loop; | 129 base::RunLoop run_loop; |
130 provider->EchoMessagePipeHandle( | 130 provider->EchoMessagePipeHandle( |
131 std::move(pipe2.handle1), | 131 std::move(pipe2.handle1), |
132 base::Bind(&WriteToMessagePipe, "hello", run_loop.QuitClosure())); | 132 base::Bind(&WriteToMessagePipe, "hello", run_loop.QuitClosure())); |
133 | 133 |
134 run_loop.Run(); | 134 run_loop.Run(); |
135 | 135 |
136 std::string value; | 136 std::string value; |
137 ReadTextMessage(pipe2.handle0.get(), &value); | 137 ReadTextMessage(pipe2.handle0.get(), &value); |
138 | 138 |
139 EXPECT_EQ(std::string("hello"), value); | 139 EXPECT_EQ(std::string("hello"), value); |
140 } | 140 } |
141 | 141 |
142 TEST_F(RequestResponseTest, EchoEnum) { | 142 TEST_F(RequestResponseTest, EchoEnum) { |
143 sample::ProviderPtr provider; | 143 sample::ProviderPtr provider; |
144 ProviderImpl provider_impl(GetProxy(&provider)); | 144 ProviderImpl provider_impl(MakeRequest(&provider)); |
145 | 145 |
146 sample::Enum value; | 146 sample::Enum value; |
147 base::RunLoop run_loop; | 147 base::RunLoop run_loop; |
148 provider->EchoEnum(sample::Enum::VALUE, | 148 provider->EchoEnum(sample::Enum::VALUE, |
149 base::Bind(&RecordEnum, &value, run_loop.QuitClosure())); | 149 base::Bind(&RecordEnum, &value, run_loop.QuitClosure())); |
150 run_loop.Run(); | 150 run_loop.Run(); |
151 | 151 |
152 EXPECT_EQ(sample::Enum::VALUE, value); | 152 EXPECT_EQ(sample::Enum::VALUE, value); |
153 } | 153 } |
154 | 154 |
155 } // namespace | 155 } // namespace |
156 } // namespace test | 156 } // namespace test |
157 } // namespace mojo | 157 } // namespace mojo |
OLD | NEW |