| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 run_loop.Quit(); | 94 run_loop.Quit(); |
| 95 }); | 95 }); |
| 96 bool called = false; | 96 bool called = false; |
| 97 base::RunLoop run_loop2; | 97 base::RunLoop run_loop2; |
| 98 auto called_cb = [&called, &run_loop2](int32_t result) { | 98 auto called_cb = [&called, &run_loop2](int32_t result) { |
| 99 called = true; | 99 called = true; |
| 100 run_loop2.Quit(); | 100 run_loop2.Quit(); |
| 101 }; | 101 }; |
| 102 { | 102 { |
| 103 Binding<sample::Service> binding(&impl, std::move(request)); | 103 Binding<sample::Service> binding(&impl, std::move(request)); |
| 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 run_loop2.Run(); | 106 run_loop2.Run(); |
| 107 EXPECT_TRUE(called); | 107 EXPECT_TRUE(called); |
| 108 EXPECT_FALSE(encountered_error); | 108 EXPECT_FALSE(encountered_error); |
| 109 } | 109 } |
| 110 // Now that the Binding is out of scope we should detect an error on the other | 110 // Now that the Binding is out of scope we should detect an error on the other |
| 111 // end of the pipe. | 111 // end of the pipe. |
| 112 run_loop.Run(); | 112 run_loop.Run(); |
| 113 EXPECT_TRUE(encountered_error); | 113 EXPECT_TRUE(encountered_error); |
| 114 | 114 |
| 115 // And calls should fail. | 115 // And calls should fail. |
| 116 called = false; | 116 called = false; |
| 117 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 117 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 118 called_cb); | 118 called_cb); |
| 119 loop().RunUntilIdle(); | 119 loop().RunUntilIdle(); |
| 120 EXPECT_FALSE(called); | 120 EXPECT_FALSE(called); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Tests that the binding's connection error handler gets called when the other | 123 // Tests that the binding's connection error handler gets called when the other |
| 124 // end is closed. | 124 // end is closed. |
| 125 TEST_F(BindingTest, ConnectionError) { | 125 TEST_F(BindingTest, ConnectionError) { |
| 126 bool called = false; | 126 bool called = false; |
| 127 { | 127 { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 ServiceImpl impl; | 203 ServiceImpl impl; |
| 204 sample::ServicePtr ptr; | 204 sample::ServicePtr ptr; |
| 205 Binding<sample::Service> binding(&impl, GetProxy(&ptr)); | 205 Binding<sample::Service> binding(&impl, GetProxy(&ptr)); |
| 206 | 206 |
| 207 bool called = false; | 207 bool called = false; |
| 208 base::RunLoop run_loop; | 208 base::RunLoop run_loop; |
| 209 auto called_cb = [&called, &run_loop](int32_t result) { | 209 auto called_cb = [&called, &run_loop](int32_t result) { |
| 210 called = true; | 210 called = true; |
| 211 run_loop.Quit(); | 211 run_loop.Quit(); |
| 212 }; | 212 }; |
| 213 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 213 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 214 called_cb); | 214 called_cb); |
| 215 run_loop.Run(); | 215 run_loop.Run(); |
| 216 EXPECT_TRUE(called); | 216 EXPECT_TRUE(called); |
| 217 | 217 |
| 218 called = false; | 218 called = false; |
| 219 auto request = binding.Unbind(); | 219 auto request = binding.Unbind(); |
| 220 EXPECT_FALSE(binding.is_bound()); | 220 EXPECT_FALSE(binding.is_bound()); |
| 221 // All calls should fail when not bound... | 221 // All calls should fail when not bound... |
| 222 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 222 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 223 called_cb); | 223 called_cb); |
| 224 loop().RunUntilIdle(); | 224 loop().RunUntilIdle(); |
| 225 EXPECT_FALSE(called); | 225 EXPECT_FALSE(called); |
| 226 | 226 |
| 227 called = false; | 227 called = false; |
| 228 binding.Bind(std::move(request)); | 228 binding.Bind(std::move(request)); |
| 229 EXPECT_TRUE(binding.is_bound()); | 229 EXPECT_TRUE(binding.is_bound()); |
| 230 // ...and should succeed again when the rebound. | 230 // ...and should succeed again when the rebound. |
| 231 base::RunLoop run_loop2; | 231 base::RunLoop run_loop2; |
| 232 auto called_cb2 = [&called, &run_loop2](int32_t result) { | 232 auto called_cb2 = [&called, &run_loop2](int32_t result) { |
| 233 called = true; | 233 called = true; |
| 234 run_loop2.Quit(); | 234 run_loop2.Quit(); |
| 235 }; | 235 }; |
| 236 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 236 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 237 called_cb2); | 237 called_cb2); |
| 238 run_loop2.Run(); | 238 run_loop2.Run(); |
| 239 EXPECT_TRUE(called); | 239 EXPECT_TRUE(called); |
| 240 } | 240 } |
| 241 | 241 |
| 242 class IntegerAccessorImpl : public sample::IntegerAccessor { | 242 class IntegerAccessorImpl : public sample::IntegerAccessor { |
| 243 public: | 243 public: |
| 244 IntegerAccessorImpl() {} | 244 IntegerAccessorImpl() {} |
| 245 ~IntegerAccessorImpl() override {} | 245 ~IntegerAccessorImpl() override {} |
| 246 | 246 |
| 247 private: | 247 private: |
| 248 // sample::IntegerAccessor implementation. | 248 // sample::IntegerAccessor implementation. |
| 249 void GetInteger(const GetIntegerCallback& callback) override { | 249 void GetInteger(const GetIntegerCallback& callback) override { |
| 250 callback.Run(1, sample::ENUM_VALUE); | 250 callback.Run(1, sample::Enum::VALUE); |
| 251 } | 251 } |
| 252 void SetInteger(int64_t data, sample::Enum type) override {} | 252 void SetInteger(int64_t data, sample::Enum type) override {} |
| 253 | 253 |
| 254 MOJO_DISALLOW_COPY_AND_ASSIGN(IntegerAccessorImpl); | 254 MOJO_DISALLOW_COPY_AND_ASSIGN(IntegerAccessorImpl); |
| 255 }; | 255 }; |
| 256 | 256 |
| 257 TEST_F(BindingTest, SetInterfacePtrVersion) { | 257 TEST_F(BindingTest, SetInterfacePtrVersion) { |
| 258 IntegerAccessorImpl impl; | 258 IntegerAccessorImpl impl; |
| 259 sample::IntegerAccessorPtr ptr; | 259 sample::IntegerAccessorPtr ptr; |
| 260 Binding<sample::IntegerAccessor> binding(&impl, &ptr); | 260 Binding<sample::IntegerAccessor> binding(&impl, &ptr); |
| 261 EXPECT_EQ(3u, ptr.version()); | 261 EXPECT_EQ(3u, ptr.version()); |
| 262 } | 262 } |
| 263 | 263 |
| 264 TEST_F(BindingTest, PauseResume) { | 264 TEST_F(BindingTest, PauseResume) { |
| 265 bool called = false; | 265 bool called = false; |
| 266 base::RunLoop run_loop; | 266 base::RunLoop run_loop; |
| 267 auto called_cb = [&called, &run_loop](int32_t result) { | 267 auto called_cb = [&called, &run_loop](int32_t result) { |
| 268 called = true; | 268 called = true; |
| 269 run_loop.Quit(); | 269 run_loop.Quit(); |
| 270 }; | 270 }; |
| 271 sample::ServicePtr ptr; | 271 sample::ServicePtr ptr; |
| 272 auto request = GetProxy(&ptr); | 272 auto request = GetProxy(&ptr); |
| 273 ServiceImpl impl; | 273 ServiceImpl impl; |
| 274 Binding<sample::Service> binding(&impl, std::move(request)); | 274 Binding<sample::Service> binding(&impl, std::move(request)); |
| 275 binding.PauseIncomingMethodCallProcessing(); | 275 binding.PauseIncomingMethodCallProcessing(); |
| 276 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 276 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 277 called_cb); | 277 called_cb); |
| 278 EXPECT_FALSE(called); | 278 EXPECT_FALSE(called); |
| 279 loop().RunUntilIdle(); | 279 loop().RunUntilIdle(); |
| 280 // Frobinate() should not be called as the binding is paused. | 280 // Frobinate() should not be called as the binding is paused. |
| 281 EXPECT_FALSE(called); | 281 EXPECT_FALSE(called); |
| 282 | 282 |
| 283 // Resume the binding, which should trigger processing. | 283 // Resume the binding, which should trigger processing. |
| 284 binding.ResumeIncomingMethodCallProcessing(); | 284 binding.ResumeIncomingMethodCallProcessing(); |
| 285 run_loop.Run(); | 285 run_loop.Run(); |
| 286 EXPECT_TRUE(called); | 286 EXPECT_TRUE(called); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 run_loop.Quit(); | 330 run_loop.Quit(); |
| 331 }); | 331 }); |
| 332 bool called = false; | 332 bool called = false; |
| 333 base::RunLoop run_loop2; | 333 base::RunLoop run_loop2; |
| 334 auto called_cb = [&called, &run_loop2](int32_t result) { | 334 auto called_cb = [&called, &run_loop2](int32_t result) { |
| 335 called = true; | 335 called = true; |
| 336 run_loop2.Quit(); | 336 run_loop2.Quit(); |
| 337 }; | 337 }; |
| 338 { | 338 { |
| 339 StrongBinding<sample::Service> binding(&impl, std::move(request)); | 339 StrongBinding<sample::Service> binding(&impl, std::move(request)); |
| 340 ptr->Frobinate(nullptr, sample::Service::BAZ_OPTIONS_REGULAR, nullptr, | 340 ptr->Frobinate(nullptr, sample::Service::BazOptions::REGULAR, nullptr, |
| 341 called_cb); | 341 called_cb); |
| 342 run_loop2.Run(); | 342 run_loop2.Run(); |
| 343 EXPECT_TRUE(called); | 343 EXPECT_TRUE(called); |
| 344 EXPECT_FALSE(encountered_error); | 344 EXPECT_FALSE(encountered_error); |
| 345 } | 345 } |
| 346 // Now that the StrongBinding is out of scope we should detect an error on the | 346 // Now that the StrongBinding is out of scope we should detect an error on the |
| 347 // other end of the pipe. | 347 // other end of the pipe. |
| 348 run_loop.Run(); | 348 run_loop.Run(); |
| 349 EXPECT_TRUE(encountered_error); | 349 EXPECT_TRUE(encountered_error); |
| 350 // But destroying the StrongBinding doesn't destroy the object. | 350 // But destroying the StrongBinding doesn't destroy the object. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 was_deleted = false; // It shouldn't be double-deleted! | 417 was_deleted = false; // It shouldn't be double-deleted! |
| 418 run_loop.Run(); | 418 run_loop.Run(); |
| 419 EXPECT_TRUE(ptr_error_handler_called); | 419 EXPECT_TRUE(ptr_error_handler_called); |
| 420 EXPECT_FALSE(was_deleted); | 420 EXPECT_FALSE(was_deleted); |
| 421 | 421 |
| 422 EXPECT_FALSE(binding_error_handler_called); | 422 EXPECT_FALSE(binding_error_handler_called); |
| 423 } | 423 } |
| 424 | 424 |
| 425 } // namespace | 425 } // namespace |
| 426 } // mojo | 426 } // mojo |
| OLD | NEW |