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 // This file tests the C API, but using the explicit MojoSystemImpl parameter. | 5 // This file tests the C API, but using the explicit MojoSystemImpl parameter. |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "mojo/public/platform/native/system_impl_private.h" | 9 #include "mojo/public/platform/native/system_impl_private.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED, | 716 EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED, |
717 MojoSystemImplDuplicateHandle(sys1, h2, &h3)); | 717 MojoSystemImplDuplicateHandle(sys1, h2, &h3)); |
718 EXPECT_EQ(MOJO_HANDLE_INVALID, h3); | 718 EXPECT_EQ(MOJO_HANDLE_INVALID, h3); |
719 | 719 |
720 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h1)); | 720 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h1)); |
721 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h2)); | 721 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h2)); |
722 | 722 |
723 // 2 SystemImpls are leaked... | 723 // 2 SystemImpls are leaked... |
724 } | 724 } |
725 | 725 |
| 726 TEST(CoreTest, MessagePipeChecksTransferRight) { |
| 727 MojoSystemImpl sys = MojoSystemImplCreateImpl(); |
| 728 |
| 729 MojoHandle h0 = MOJO_HANDLE_INVALID; |
| 730 MojoHandle h1 = MOJO_HANDLE_INVALID; |
| 731 EXPECT_EQ(MOJO_RESULT_OK, |
| 732 MojoSystemImplCreateMessagePipe(sys, nullptr, &h0, &h1)); |
| 733 |
| 734 // Create a shared buffer (which is transferrable and duplicatable). |
| 735 MojoHandle h_transferrable = MOJO_HANDLE_INVALID; |
| 736 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplCreateSharedBuffer(sys, nullptr, 100, |
| 737 &h_transferrable)); |
| 738 |
| 739 // Make a non-transferrable duplicate handle. |
| 740 MojoHandle h_not_transferrable = MOJO_HANDLE_INVALID; |
| 741 EXPECT_EQ(MOJO_RESULT_OK, |
| 742 MojoSystemImplDuplicateHandleWithReducedRights( |
| 743 sys, h_transferrable, MOJO_HANDLE_RIGHT_TRANSFER, |
| 744 &h_not_transferrable)); |
| 745 |
| 746 // |h_transferrable| can be transferred. |
| 747 EXPECT_EQ(MOJO_RESULT_OK, |
| 748 MojoSystemImplWriteMessage(sys, h0, nullptr, 0u, &h_transferrable, |
| 749 1u, MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 750 |
| 751 // |h_not_transferrable| can be transferred. |
| 752 EXPECT_EQ( |
| 753 MOJO_RESULT_PERMISSION_DENIED, |
| 754 MojoSystemImplWriteMessage(sys, h0, nullptr, 0u, &h_not_transferrable, 1u, |
| 755 MOJO_WRITE_MESSAGE_FLAG_NONE)); |
| 756 |
| 757 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys, h0)); |
| 758 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys, h1)); |
| 759 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys, h_not_transferrable)); |
| 760 |
| 761 // 1 SystemImpl is leaked... |
| 762 } |
| 763 |
726 } // namespace | 764 } // namespace |
727 } // namespace mojo | 765 } // namespace mojo |
OLD | NEW |