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 // 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 #include "mojo/public/cpp/bindings/strong_binding.h" | 9 #include "mojo/public/cpp/bindings/strong_binding.h" |
10 #include "mojo/public/cpp/environment/environment.h" | 10 #include "mojo/public/cpp/environment/environment.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 bool encountered_error = false; | 78 bool encountered_error = false; |
79 ServiceImpl impl; | 79 ServiceImpl impl; |
80 sample::ServicePtr ptr; | 80 sample::ServicePtr ptr; |
81 auto request = GetProxy(&ptr); | 81 auto request = GetProxy(&ptr); |
82 ptr.set_connection_error_handler( | 82 ptr.set_connection_error_handler( |
83 [&encountered_error]() { encountered_error = true; }); | 83 [&encountered_error]() { encountered_error = true; }); |
84 bool called = false; | 84 bool called = false; |
85 auto called_cb = [&called](int32_t result) { called = true; }; | 85 auto called_cb = [&called](int32_t result) { called = true; }; |
86 { | 86 { |
87 Binding<sample::Service> binding(&impl, request.Pass()); | 87 Binding<sample::Service> binding(&impl, request.Pass()); |
88 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 88 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
89 called_cb); | 89 called_cb); |
90 loop().RunUntilIdle(); | 90 loop().RunUntilIdle(); |
91 EXPECT_TRUE(called); | 91 EXPECT_TRUE(called); |
92 EXPECT_FALSE(encountered_error); | 92 EXPECT_FALSE(encountered_error); |
93 } | 93 } |
94 // Now that the Binding is out of scope we should detect an error on the other | 94 // Now that the Binding is out of scope we should detect an error on the other |
95 // end of the pipe. | 95 // end of the pipe. |
96 loop().RunUntilIdle(); | 96 loop().RunUntilIdle(); |
97 EXPECT_TRUE(encountered_error); | 97 EXPECT_TRUE(encountered_error); |
98 | 98 |
99 // And calls should fail. | 99 // And calls should fail. |
100 called = false; | 100 called = false; |
101 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 101 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
102 called_cb); | 102 called_cb); |
103 loop().RunUntilIdle(); | 103 loop().RunUntilIdle(); |
104 EXPECT_FALSE(called); | 104 EXPECT_FALSE(called); |
105 } | 105 } |
106 | 106 |
107 // Tests that the binding's connection error handler gets called when the other | 107 // Tests that the binding's connection error handler gets called when the other |
108 // end is closed. | 108 // end is closed. |
109 TEST_F(BindingTest, ConnectionError) { | 109 TEST_F(BindingTest, ConnectionError) { |
110 bool called = false; | 110 bool called = false; |
111 { | 111 { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 169 } |
170 | 170 |
171 // Tests that explicitly calling Unbind followed by rebinding works. | 171 // Tests that explicitly calling Unbind followed by rebinding works. |
172 TEST_F(BindingTest, Unbind) { | 172 TEST_F(BindingTest, Unbind) { |
173 ServiceImpl impl; | 173 ServiceImpl impl; |
174 sample::ServicePtr ptr; | 174 sample::ServicePtr ptr; |
175 Binding<sample::Service> binding(&impl, GetProxy(&ptr)); | 175 Binding<sample::Service> binding(&impl, GetProxy(&ptr)); |
176 | 176 |
177 bool called = false; | 177 bool called = false; |
178 auto called_cb = [&called](int32_t result) { called = true; }; | 178 auto called_cb = [&called](int32_t result) { called = true; }; |
179 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 179 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
180 called_cb); | 180 called_cb); |
181 loop().RunUntilIdle(); | 181 loop().RunUntilIdle(); |
182 EXPECT_TRUE(called); | 182 EXPECT_TRUE(called); |
183 | 183 |
184 called = false; | 184 called = false; |
185 auto request = binding.Unbind(); | 185 auto request = binding.Unbind(); |
186 EXPECT_FALSE(binding.is_bound()); | 186 EXPECT_FALSE(binding.is_bound()); |
187 // All calls should fail when not bound... | 187 // All calls should fail when not bound... |
188 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 188 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
189 called_cb); | 189 called_cb); |
190 loop().RunUntilIdle(); | 190 loop().RunUntilIdle(); |
191 EXPECT_FALSE(called); | 191 EXPECT_FALSE(called); |
192 | 192 |
193 called = false; | 193 called = false; |
194 binding.Bind(request.Pass()); | 194 binding.Bind(request.Pass()); |
195 EXPECT_TRUE(binding.is_bound()); | 195 EXPECT_TRUE(binding.is_bound()); |
196 // ...and should succeed again when the rebound. | 196 // ...and should succeed again when the rebound. |
197 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 197 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
198 called_cb); | 198 called_cb); |
199 loop().RunUntilIdle(); | 199 loop().RunUntilIdle(); |
200 EXPECT_TRUE(called); | 200 EXPECT_TRUE(called); |
201 } | 201 } |
202 | 202 |
203 class IntegerAccessorImpl : public sample::IntegerAccessor { | 203 class IntegerAccessorImpl : public sample::IntegerAccessor { |
204 public: | 204 public: |
205 IntegerAccessorImpl() {} | 205 IntegerAccessorImpl() {} |
206 ~IntegerAccessorImpl() override {} | 206 ~IntegerAccessorImpl() override {} |
207 | 207 |
208 private: | 208 private: |
209 // sample::IntegerAccessor implementation. | 209 // sample::IntegerAccessor implementation. |
210 void GetInteger(const GetIntegerCallback& callback) override { | 210 void GetInteger(const GetIntegerCallback& callback) override { |
211 callback.Run(1, sample::ENUM_VALUE); | 211 callback.Run(1, sample::Enum::VALUE); |
212 } | 212 } |
213 void SetInteger(int64_t data, sample::Enum type) override {} | 213 void SetInteger(int64_t data, sample::Enum type) override {} |
214 | 214 |
215 MOJO_DISALLOW_COPY_AND_ASSIGN(IntegerAccessorImpl); | 215 MOJO_DISALLOW_COPY_AND_ASSIGN(IntegerAccessorImpl); |
216 }; | 216 }; |
217 | 217 |
218 TEST_F(BindingTest, SetInterfacePtrVersion) { | 218 TEST_F(BindingTest, SetInterfacePtrVersion) { |
219 IntegerAccessorImpl impl; | 219 IntegerAccessorImpl impl; |
220 sample::IntegerAccessorPtr ptr; | 220 sample::IntegerAccessorPtr ptr; |
221 Binding<sample::IntegerAccessor> binding(&impl, &ptr); | 221 Binding<sample::IntegerAccessor> binding(&impl, &ptr); |
(...skipping 11 matching lines...) Expand all Loading... |
233 bool was_deleted = false; | 233 bool was_deleted = false; |
234 ServiceImpl impl(&was_deleted); | 234 ServiceImpl impl(&was_deleted); |
235 sample::ServicePtr ptr; | 235 sample::ServicePtr ptr; |
236 auto request = GetProxy(&ptr); | 236 auto request = GetProxy(&ptr); |
237 ptr.set_connection_error_handler( | 237 ptr.set_connection_error_handler( |
238 [&encountered_error]() { encountered_error = true; }); | 238 [&encountered_error]() { encountered_error = true; }); |
239 bool called = false; | 239 bool called = false; |
240 auto called_cb = [&called](int32_t result) { called = true; }; | 240 auto called_cb = [&called](int32_t result) { called = true; }; |
241 { | 241 { |
242 StrongBinding<sample::Service> binding(&impl, request.Pass()); | 242 StrongBinding<sample::Service> binding(&impl, request.Pass()); |
243 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 243 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
244 called_cb); | 244 called_cb); |
245 loop().RunUntilIdle(); | 245 loop().RunUntilIdle(); |
246 EXPECT_TRUE(called); | 246 EXPECT_TRUE(called); |
247 EXPECT_FALSE(encountered_error); | 247 EXPECT_FALSE(encountered_error); |
248 } | 248 } |
249 // Now that the StrongBinding is out of scope we should detect an error on the | 249 // Now that the StrongBinding is out of scope we should detect an error on the |
250 // other end of the pipe. | 250 // other end of the pipe. |
251 loop().RunUntilIdle(); | 251 loop().RunUntilIdle(); |
252 EXPECT_TRUE(encountered_error); | 252 EXPECT_TRUE(encountered_error); |
253 // But destroying the StrongBinding doesn't destroy the object. | 253 // But destroying the StrongBinding doesn't destroy the object. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 was_deleted = false; // It shouldn't be double-deleted! | 314 was_deleted = false; // It shouldn't be double-deleted! |
315 loop().RunUntilIdle(); | 315 loop().RunUntilIdle(); |
316 EXPECT_TRUE(ptr_error_handler_called); | 316 EXPECT_TRUE(ptr_error_handler_called); |
317 EXPECT_FALSE(was_deleted); | 317 EXPECT_FALSE(was_deleted); |
318 | 318 |
319 EXPECT_FALSE(binding_error_handler_called); | 319 EXPECT_FALSE(binding_error_handler_called); |
320 } | 320 } |
321 | 321 |
322 } // namespace | 322 } // namespace |
323 } // mojo | 323 } // mojo |
OLD | NEW |