Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: mojo/edk/system/core_unittest.cc

Issue 2012613002: Enforce/require MOJO_HANDLE_RIGHT_TRANSFER in sending handles via MojoWriteMessage(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/edk/system/handle_table.h » ('j') | mojo/public/c/system/message_pipe.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/edk/system/core.h" 5 #include "mojo/edk/system/core.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 EXPECT_EQ(MOJO_RESULT_OK, 1785 EXPECT_EQ(MOJO_RESULT_OK,
1786 core()->WriteMessage(h0, NullUserPointer(), 0, 1786 core()->WriteMessage(h0, NullUserPointer(), 0,
1787 MakeUserPointer(h_passed), 2, 1787 MakeUserPointer(h_passed), 2,
1788 MOJO_WRITE_MESSAGE_FLAG_NONE)); 1788 MOJO_WRITE_MESSAGE_FLAG_NONE));
1789 1789
1790 // Again, nothing bad happens, but again you can only close |h0|. 1790 // Again, nothing bad happens, but again you can only close |h0|.
1791 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h0)); 1791 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h0));
1792 } 1792 }
1793 } 1793 }
1794 1794
1795 // Tests not having versus not having the transfer right.
1796 TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing4) {
1797 MojoHandle h0 = MOJO_HANDLE_INVALID;
1798 MojoHandle h1 = MOJO_HANDLE_INVALID;
1799 EXPECT_EQ(MOJO_RESULT_OK,
1800 core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h0),
1801 MakeUserPointer(&h1)));
1802
1803 MojoHandle h_transferrable = MOJO_HANDLE_INVALID;
1804 EXPECT_EQ(MOJO_RESULT_OK,
1805 core()->CreateSharedBuffer(NullUserPointer(), 100,
1806 MakeUserPointer(&h_transferrable)));
1807 MojoHandle h_not_transferrable = MOJO_HANDLE_INVALID;
1808 EXPECT_EQ(MOJO_RESULT_OK, core()->DuplicateHandleWithReducedRights(
1809 h_transferrable, MOJO_HANDLE_RIGHT_TRANSFER,
1810 MakeUserPointer(&h_not_transferrable)));
1811
1812 // We can send |h_transferrable|.
1813 EXPECT_EQ(MOJO_RESULT_OK,
1814 core()->WriteMessage(h0, NullUserPointer(), 0,
1815 MakeUserPointer(&h_transferrable), 1,
1816 MOJO_WRITE_MESSAGE_FLAG_NONE));
1817
1818 // But not |h_not_transferrable|.
1819 EXPECT_EQ(MOJO_RESULT_PERMISSION_DENIED,
1820 core()->WriteMessage(h0, NullUserPointer(), 0,
1821 MakeUserPointer(&h_not_transferrable), 1,
1822 MOJO_WRITE_MESSAGE_FLAG_NONE));
1823
1824 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h0));
1825 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h1));
1826 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_not_transferrable));
1827 }
1828
1795 struct TestAsyncWaiter { 1829 struct TestAsyncWaiter {
1796 TestAsyncWaiter() : result(MOJO_RESULT_UNKNOWN) {} 1830 TestAsyncWaiter() : result(MOJO_RESULT_UNKNOWN) {}
1797 1831
1798 void Awake(MojoResult r) { result = r; } 1832 void Awake(MojoResult r) { result = r; }
1799 1833
1800 MojoResult result; 1834 MojoResult result;
1801 }; 1835 };
1802 1836
1803 TEST_F(CoreTest, AsyncWait) { 1837 TEST_F(CoreTest, AsyncWait) {
1804 TestAsyncWaiter waiter; 1838 TestAsyncWaiter waiter;
(...skipping 18 matching lines...) Expand all
1823 1857
1824 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h)); 1858 EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
1825 } 1859 }
1826 1860
1827 // TODO(vtl): Test |CreateSharedBuffer()|, |DuplicateBufferHandle()|, and 1861 // TODO(vtl): Test |CreateSharedBuffer()|, |DuplicateBufferHandle()|, and
1828 // |MapBuffer()|. 1862 // |MapBuffer()|.
1829 1863
1830 } // namespace 1864 } // namespace
1831 } // namespace system 1865 } // namespace system
1832 } // namespace mojo 1866 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/handle_table.h » ('j') | mojo/public/c/system/message_pipe.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698