| 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 | 9 |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 bool encountered_error = false; | 81 bool encountered_error = false; |
| 82 ServiceImpl impl; | 82 ServiceImpl impl; |
| 83 sample::ServicePtr ptr; | 83 sample::ServicePtr ptr; |
| 84 auto request = GetProxy(&ptr); | 84 auto request = GetProxy(&ptr); |
| 85 ptr.set_connection_error_handler( | 85 ptr.set_connection_error_handler( |
| 86 [&encountered_error]() { encountered_error = true; }); | 86 [&encountered_error]() { encountered_error = true; }); |
| 87 bool called = false; | 87 bool called = false; |
| 88 auto called_cb = [&called](int32_t result) { called = true; }; | 88 auto called_cb = [&called](int32_t result) { called = true; }; |
| 89 { | 89 { |
| 90 Binding<sample::Service> binding(&impl, std::move(request)); | 90 Binding<sample::Service> binding(&impl, std::move(request)); |
| 91 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 91 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 92 called_cb); | 92 called_cb); |
| 93 loop().RunUntilIdle(); | 93 loop().RunUntilIdle(); |
| 94 EXPECT_TRUE(called); | 94 EXPECT_TRUE(called); |
| 95 EXPECT_FALSE(encountered_error); | 95 EXPECT_FALSE(encountered_error); |
| 96 } | 96 } |
| 97 // Now that the Binding is out of scope we should detect an error on the other | 97 // Now that the Binding is out of scope we should detect an error on the other |
| 98 // end of the pipe. | 98 // end of the pipe. |
| 99 loop().RunUntilIdle(); | 99 loop().RunUntilIdle(); |
| 100 EXPECT_TRUE(encountered_error); | 100 EXPECT_TRUE(encountered_error); |
| 101 | 101 |
| 102 // And calls should fail. | 102 // And calls should fail. |
| 103 called = false; | 103 called = false; |
| 104 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 104 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 105 called_cb); | 105 called_cb); |
| 106 loop().RunUntilIdle(); | 106 loop().RunUntilIdle(); |
| 107 EXPECT_FALSE(called); | 107 EXPECT_FALSE(called); |
| 108 } | 108 } |
| 109 | 109 |
| 110 // Tests that the binding's connection error handler gets called when the other | 110 // Tests that the binding's connection error handler gets called when the other |
| 111 // end is closed. | 111 // end is closed. |
| 112 TEST_F(BindingTest, ConnectionError) { | 112 TEST_F(BindingTest, ConnectionError) { |
| 113 bool called = false; | 113 bool called = false; |
| 114 { | 114 { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Tests that explicitly calling Unbind followed by rebinding works. | 174 // Tests that explicitly calling Unbind followed by rebinding works. |
| 175 TEST_F(BindingTest, Unbind) { | 175 TEST_F(BindingTest, Unbind) { |
| 176 ServiceImpl impl; | 176 ServiceImpl impl; |
| 177 sample::ServicePtr ptr; | 177 sample::ServicePtr ptr; |
| 178 Binding<sample::Service> binding(&impl, GetProxy(&ptr)); | 178 Binding<sample::Service> binding(&impl, GetProxy(&ptr)); |
| 179 | 179 |
| 180 bool called = false; | 180 bool called = false; |
| 181 auto called_cb = [&called](int32_t result) { called = true; }; | 181 auto called_cb = [&called](int32_t result) { called = true; }; |
| 182 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 182 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 183 called_cb); | 183 called_cb); |
| 184 loop().RunUntilIdle(); | 184 loop().RunUntilIdle(); |
| 185 EXPECT_TRUE(called); | 185 EXPECT_TRUE(called); |
| 186 | 186 |
| 187 called = false; | 187 called = false; |
| 188 auto request = binding.Unbind(); | 188 auto request = binding.Unbind(); |
| 189 EXPECT_FALSE(binding.is_bound()); | 189 EXPECT_FALSE(binding.is_bound()); |
| 190 // All calls should fail when not bound... | 190 // All calls should fail when not bound... |
| 191 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 191 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 192 called_cb); | 192 called_cb); |
| 193 loop().RunUntilIdle(); | 193 loop().RunUntilIdle(); |
| 194 EXPECT_FALSE(called); | 194 EXPECT_FALSE(called); |
| 195 | 195 |
| 196 called = false; | 196 called = false; |
| 197 binding.Bind(std::move(request)); | 197 binding.Bind(std::move(request)); |
| 198 EXPECT_TRUE(binding.is_bound()); | 198 EXPECT_TRUE(binding.is_bound()); |
| 199 // ...and should succeed again when the rebound. | 199 // ...and should succeed again when the rebound. |
| 200 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 200 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 201 called_cb); | 201 called_cb); |
| 202 loop().RunUntilIdle(); | 202 loop().RunUntilIdle(); |
| 203 EXPECT_TRUE(called); | 203 EXPECT_TRUE(called); |
| 204 } | 204 } |
| 205 | 205 |
| 206 class IntegerAccessorImpl : public sample::IntegerAccessor { | 206 class IntegerAccessorImpl : public sample::IntegerAccessor { |
| 207 public: | 207 public: |
| 208 IntegerAccessorImpl() {} | 208 IntegerAccessorImpl() {} |
| 209 ~IntegerAccessorImpl() override {} | 209 ~IntegerAccessorImpl() override {} |
| 210 | 210 |
| 211 private: | 211 private: |
| 212 // sample::IntegerAccessor implementation. | 212 // sample::IntegerAccessor implementation. |
| 213 void GetInteger(const GetIntegerCallback& callback) override { | 213 void GetInteger(const GetIntegerCallback& callback) override { |
| 214 callback.Run(1, sample::ENUM_VALUE); | 214 callback.Run(1, sample::Enum::VALUE); |
| 215 } | 215 } |
| 216 void SetInteger(int64_t data, sample::Enum type) override {} | 216 void SetInteger(int64_t data, sample::Enum type) override {} |
| 217 | 217 |
| 218 MOJO_DISALLOW_COPY_AND_ASSIGN(IntegerAccessorImpl); | 218 MOJO_DISALLOW_COPY_AND_ASSIGN(IntegerAccessorImpl); |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 TEST_F(BindingTest, SetInterfacePtrVersion) { | 221 TEST_F(BindingTest, SetInterfacePtrVersion) { |
| 222 IntegerAccessorImpl impl; | 222 IntegerAccessorImpl impl; |
| 223 sample::IntegerAccessorPtr ptr; | 223 sample::IntegerAccessorPtr ptr; |
| 224 Binding<sample::IntegerAccessor> binding(&impl, &ptr); | 224 Binding<sample::IntegerAccessor> binding(&impl, &ptr); |
| 225 EXPECT_EQ(3u, ptr.version()); | 225 EXPECT_EQ(3u, ptr.version()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 TEST_F(BindingTest, PauseResume) { | 228 TEST_F(BindingTest, PauseResume) { |
| 229 bool called = false; | 229 bool called = false; |
| 230 auto called_cb = [&called](int32_t result) { called = true; }; | 230 auto called_cb = [&called](int32_t result) { called = true; }; |
| 231 sample::ServicePtr ptr; | 231 sample::ServicePtr ptr; |
| 232 auto request = GetProxy(&ptr); | 232 auto request = GetProxy(&ptr); |
| 233 ServiceImpl impl; | 233 ServiceImpl impl; |
| 234 Binding<sample::Service> binding(&impl, std::move(request)); | 234 Binding<sample::Service> binding(&impl, std::move(request)); |
| 235 binding.PauseIncomingMethodCallProcessing(); | 235 binding.PauseIncomingMethodCallProcessing(); |
| 236 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 236 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 237 called_cb); | 237 called_cb); |
| 238 EXPECT_FALSE(called); | 238 EXPECT_FALSE(called); |
| 239 loop().RunUntilIdle(); | 239 loop().RunUntilIdle(); |
| 240 // Frobinate() should not be called as the binding is paused. | 240 // Frobinate() should not be called as the binding is paused. |
| 241 EXPECT_FALSE(called); | 241 EXPECT_FALSE(called); |
| 242 | 242 |
| 243 // Resume the binding, which should trigger processing. | 243 // Resume the binding, which should trigger processing. |
| 244 binding.ResumeIncomingMethodCallProcessing(); | 244 binding.ResumeIncomingMethodCallProcessing(); |
| 245 loop().RunUntilIdle(); | 245 loop().RunUntilIdle(); |
| 246 EXPECT_TRUE(called); | 246 EXPECT_TRUE(called); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 bool was_deleted = false; | 278 bool was_deleted = false; |
| 279 ServiceImpl impl(&was_deleted); | 279 ServiceImpl impl(&was_deleted); |
| 280 sample::ServicePtr ptr; | 280 sample::ServicePtr ptr; |
| 281 auto request = GetProxy(&ptr); | 281 auto request = GetProxy(&ptr); |
| 282 ptr.set_connection_error_handler( | 282 ptr.set_connection_error_handler( |
| 283 [&encountered_error]() { encountered_error = true; }); | 283 [&encountered_error]() { encountered_error = true; }); |
| 284 bool called = false; | 284 bool called = false; |
| 285 auto called_cb = [&called](int32_t result) { called = true; }; | 285 auto called_cb = [&called](int32_t result) { called = true; }; |
| 286 { | 286 { |
| 287 StrongBinding<sample::Service> binding(&impl, std::move(request)); | 287 StrongBinding<sample::Service> binding(&impl, std::move(request)); |
| 288 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 288 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 289 called_cb); | 289 called_cb); |
| 290 loop().RunUntilIdle(); | 290 loop().RunUntilIdle(); |
| 291 EXPECT_TRUE(called); | 291 EXPECT_TRUE(called); |
| 292 EXPECT_FALSE(encountered_error); | 292 EXPECT_FALSE(encountered_error); |
| 293 } | 293 } |
| 294 // Now that the StrongBinding is out of scope we should detect an error on the | 294 // Now that the StrongBinding is out of scope we should detect an error on the |
| 295 // other end of the pipe. | 295 // other end of the pipe. |
| 296 loop().RunUntilIdle(); | 296 loop().RunUntilIdle(); |
| 297 EXPECT_TRUE(encountered_error); | 297 EXPECT_TRUE(encountered_error); |
| 298 // But destroying the StrongBinding doesn't destroy the object. | 298 // But destroying the StrongBinding doesn't destroy the object. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 was_deleted = false; // It shouldn't be double-deleted! | 359 was_deleted = false; // It shouldn't be double-deleted! |
| 360 loop().RunUntilIdle(); | 360 loop().RunUntilIdle(); |
| 361 EXPECT_TRUE(ptr_error_handler_called); | 361 EXPECT_TRUE(ptr_error_handler_called); |
| 362 EXPECT_FALSE(was_deleted); | 362 EXPECT_FALSE(was_deleted); |
| 363 | 363 |
| 364 EXPECT_FALSE(binding_error_handler_called); | 364 EXPECT_FALSE(binding_error_handler_called); |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace | 367 } // namespace |
| 368 } // mojo | 368 } // mojo |
| OLD | NEW |