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 <stdio.h> | 5 #include <stdio.h> |
6 | |
7 #include <algorithm> | 6 #include <algorithm> |
8 #include <string> | 7 #include <string> |
| 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "mojo/message_pump/message_pump_mojo.h" | 12 #include "mojo/message_pump/message_pump_mojo.h" |
13 #include "mojo/public/c/system/macros.h" | 13 #include "mojo/public/c/system/macros.h" |
14 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
15 #include "mojo/public/cpp/bindings/interface_ptr.h" | 15 #include "mojo/public/cpp/bindings/interface_ptr.h" |
16 #include "mojo/public/cpp/bindings/lib/connector.h" | 16 #include "mojo/public/cpp/bindings/lib/connector.h" |
17 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | 17 #include "mojo/public/cpp/bindings/lib/filter_chain.h" |
18 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 18 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 : loop_(common::MessagePumpMojo::Create()), | 195 : loop_(common::MessagePumpMojo::Create()), |
196 test_message_receiver_(nullptr) {} | 196 test_message_receiver_(nullptr) {} |
197 | 197 |
198 ~ValidationIntegrationTest() override {} | 198 ~ValidationIntegrationTest() override {} |
199 | 199 |
200 void SetUp() override { | 200 void SetUp() override { |
201 ScopedMessagePipeHandle tester_endpoint; | 201 ScopedMessagePipeHandle tester_endpoint; |
202 ASSERT_EQ(MOJO_RESULT_OK, | 202 ASSERT_EQ(MOJO_RESULT_OK, |
203 CreateMessagePipe(nullptr, &tester_endpoint, &testee_endpoint_)); | 203 CreateMessagePipe(nullptr, &tester_endpoint, &testee_endpoint_)); |
204 test_message_receiver_ = | 204 test_message_receiver_ = |
205 new TestMessageReceiver(this, tester_endpoint.Pass()); | 205 new TestMessageReceiver(this, std::move(tester_endpoint)); |
206 } | 206 } |
207 | 207 |
208 void TearDown() override { | 208 void TearDown() override { |
209 delete test_message_receiver_; | 209 delete test_message_receiver_; |
210 test_message_receiver_ = nullptr; | 210 test_message_receiver_ = nullptr; |
211 | 211 |
212 // Make sure that the other end receives the OnConnectionError() | 212 // Make sure that the other end receives the OnConnectionError() |
213 // notification. | 213 // notification. |
214 PumpMessages(); | 214 PumpMessages(); |
215 } | 215 } |
216 | 216 |
217 MessageReceiver* test_message_receiver() { return test_message_receiver_; } | 217 MessageReceiver* test_message_receiver() { return test_message_receiver_; } |
218 | 218 |
219 ScopedMessagePipeHandle testee_endpoint() { return testee_endpoint_.Pass(); } | 219 ScopedMessagePipeHandle testee_endpoint() { |
| 220 return std::move(testee_endpoint_); |
| 221 } |
220 | 222 |
221 private: | 223 private: |
222 class TestMessageReceiver : public MessageReceiver { | 224 class TestMessageReceiver : public MessageReceiver { |
223 public: | 225 public: |
224 TestMessageReceiver(ValidationIntegrationTest* owner, | 226 TestMessageReceiver(ValidationIntegrationTest* owner, |
225 ScopedMessagePipeHandle handle) | 227 ScopedMessagePipeHandle handle) |
226 : owner_(owner), | 228 : owner_(owner), |
227 connector_(handle.Pass(), | 229 connector_(std::move(handle), |
228 mojo::internal::Connector::SINGLE_THREADED_SEND) { | 230 mojo::internal::Connector::SINGLE_THREADED_SEND) { |
229 connector_.set_enforce_errors_from_incoming_receiver(false); | 231 connector_.set_enforce_errors_from_incoming_receiver(false); |
230 } | 232 } |
231 ~TestMessageReceiver() override {} | 233 ~TestMessageReceiver() override {} |
232 | 234 |
233 bool Accept(Message* message) override { | 235 bool Accept(Message* message) override { |
234 bool rv = connector_.Accept(message); | 236 bool rv = connector_.Accept(message); |
235 owner_->PumpMessages(); | 237 owner_->PumpMessages(); |
236 return rv; | 238 return rv; |
237 } | 239 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 413 |
412 RunValidationTests("resp_boundscheck_", validators.GetHead()); | 414 RunValidationTests("resp_boundscheck_", validators.GetHead()); |
413 } | 415 } |
414 | 416 |
415 // Test that InterfacePtr<X> applies the correct validators and they don't | 417 // Test that InterfacePtr<X> applies the correct validators and they don't |
416 // conflict with each other: | 418 // conflict with each other: |
417 // - MessageHeaderValidator | 419 // - MessageHeaderValidator |
418 // - X::ResponseValidator_ | 420 // - X::ResponseValidator_ |
419 TEST_F(ValidationIntegrationTest, InterfacePtr) { | 421 TEST_F(ValidationIntegrationTest, InterfacePtr) { |
420 IntegrationTestInterfacePtr interface_ptr = MakeProxy( | 422 IntegrationTestInterfacePtr interface_ptr = MakeProxy( |
421 InterfacePtrInfo<IntegrationTestInterface>(testee_endpoint().Pass(), 0u)); | 423 InterfacePtrInfo<IntegrationTestInterface>(testee_endpoint(), 0u)); |
422 interface_ptr.internal_state()->EnableTestingMode(); | 424 interface_ptr.internal_state()->EnableTestingMode(); |
423 | 425 |
424 RunValidationTests("integration_intf_resp", test_message_receiver()); | 426 RunValidationTests("integration_intf_resp", test_message_receiver()); |
425 RunValidationTests("integration_msghdr", test_message_receiver()); | 427 RunValidationTests("integration_msghdr", test_message_receiver()); |
426 } | 428 } |
427 | 429 |
428 // Test that Binding<X> applies the correct validators and they don't | 430 // Test that Binding<X> applies the correct validators and they don't |
429 // conflict with each other: | 431 // conflict with each other: |
430 // - MessageHeaderValidator | 432 // - MessageHeaderValidator |
431 // - X::RequestValidator_ | 433 // - X::RequestValidator_ |
432 TEST_F(ValidationIntegrationTest, Binding) { | 434 TEST_F(ValidationIntegrationTest, Binding) { |
433 IntegrationTestInterfaceImpl interface_impl; | 435 IntegrationTestInterfaceImpl interface_impl; |
434 Binding<IntegrationTestInterface> binding( | 436 Binding<IntegrationTestInterface> binding( |
435 &interface_impl, | 437 &interface_impl, |
436 MakeRequest<IntegrationTestInterface>(testee_endpoint().Pass())); | 438 MakeRequest<IntegrationTestInterface>(testee_endpoint())); |
437 binding.EnableTestingMode(); | 439 binding.EnableTestingMode(); |
438 | 440 |
439 RunValidationTests("integration_intf_rqst", test_message_receiver()); | 441 RunValidationTests("integration_intf_rqst", test_message_receiver()); |
440 RunValidationTests("integration_msghdr", test_message_receiver()); | 442 RunValidationTests("integration_msghdr", test_message_receiver()); |
441 } | 443 } |
442 | 444 |
443 // Test pointer validation (specifically, that the encoded offset is 32-bit) | 445 // Test pointer validation (specifically, that the encoded offset is 32-bit) |
444 TEST_F(ValidationTest, ValidateEncodedPointer) { | 446 TEST_F(ValidationTest, ValidateEncodedPointer) { |
445 uint64_t offset; | 447 uint64_t offset; |
446 | 448 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 static_cast<StructWithEnum::EnumWithin>(2))); | 486 static_cast<StructWithEnum::EnumWithin>(2))); |
485 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue( | 487 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue( |
486 static_cast<StructWithEnum::EnumWithin>(3))); | 488 static_cast<StructWithEnum::EnumWithin>(3))); |
487 EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue( | 489 EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue( |
488 static_cast<StructWithEnum::EnumWithin>(4))); | 490 static_cast<StructWithEnum::EnumWithin>(4))); |
489 } | 491 } |
490 | 492 |
491 } // namespace | 493 } // namespace |
492 } // namespace test | 494 } // namespace test |
493 } // namespace mojo | 495 } // namespace mojo |
OLD | NEW |