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

Unified Diff: mojo/edk/system/core_unittest.cc

Issue 2052553002: Add Core::ReplaceHandleWithReducedRights(). (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/core.cc ('k') | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/core_unittest.cc
diff --git a/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc
index 33e90b7a4362a2bb64c958e0b35b03769f786500..3c00802bba101da8b12b537478bff95727a68875 100644
--- a/mojo/edk/system/core_unittest.cc
+++ b/mojo/edk/system/core_unittest.cc
@@ -216,14 +216,33 @@ TEST_F(CoreTest, Basic) {
EXPECT_EQ(0u, hss.satisfied_signals);
EXPECT_EQ(0u, hss.satisfiable_signals);
- // |h| shares |info| with |h_dup|, which was closed above.
- EXPECT_EQ(1u, info.GetDtorCallCount());
- EXPECT_EQ(1u, info.GetCloseCallCount());
- EXPECT_EQ(1u, info.GetCancelAllStateCallCount());
- EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
+ constexpr MojoHandleRights kRightsToRemove = MOJO_HANDLE_RIGHT_MAP_EXECUTABLE;
+ static_assert(kDefaultMockHandleRights & kRightsToRemove,
+ "Oops, reducing rights will be a no-op");
+ MojoHandle h_replacement = MOJO_HANDLE_INVALID;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->ReplaceHandleWithReducedRights(
+ h, kRightsToRemove, MakeUserPointer(&h_replacement)));
+ EXPECT_NE(h_replacement, MOJO_HANDLE_INVALID);
+ // This isn't guaranteed per se, but we count on handle values not being
+ // reused eagerly.
+ EXPECT_NE(h_replacement, h);
+ // |h| should be dead.
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, core()->Close(h));
+ rights = MOJO_HANDLE_RIGHT_NONE;
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->GetRights(h_replacement, MakeUserPointer(&rights)));
+ EXPECT_EQ(kDefaultMockHandleRights & ~kRightsToRemove, rights);
+
+ // |info| is shared between |h| (which was replaced, but not explicitly closed
+ // per se), |h_dup| (which was closed), and |h_replacement|.
EXPECT_EQ(2u, info.GetDtorCallCount());
- EXPECT_EQ(2u, info.GetCloseCallCount());
+ EXPECT_EQ(1u, info.GetCloseCallCount());
EXPECT_EQ(2u, info.GetCancelAllStateCallCount());
+ EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h_replacement));
+ EXPECT_EQ(3u, info.GetDtorCallCount());
+ EXPECT_EQ(2u, info.GetCloseCallCount());
+ EXPECT_EQ(3u, info.GetCancelAllStateCallCount());
// No awakables should ever have ever been added.
EXPECT_EQ(0u, info.GetRemoveAwakableCallCount());
@@ -256,6 +275,20 @@ TEST_F(CoreTest, InvalidArguments) {
EXPECT_EQ(0u, rights);
}
+ // |ReplaceHandleWithReducedRights()|:
+ {
+ MojoHandle h = MOJO_HANDLE_INVALID;
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ core()->ReplaceHandleWithReducedRights(
+ MOJO_HANDLE_INVALID, MOJO_HANDLE_RIGHT_NONE, MakeUserPointer(&h)));
+ EXPECT_EQ(MOJO_HANDLE_INVALID, h);
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ core()->ReplaceHandleWithReducedRights(10, MOJO_HANDLE_RIGHT_NONE,
+ MakeUserPointer(&h)));
+ EXPECT_EQ(MOJO_HANDLE_INVALID, h);
+ }
+
// |DuplicateHandleWithReducedRights()|:
{
MojoHandle h = MOJO_HANDLE_INVALID;
@@ -632,6 +665,17 @@ TEST_F(CoreTest, InvalidArgumentsDeath) {
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
}
+ // |ReplaceHandleWithReducedRights()|:
+ {
+ MockHandleInfo info;
+ MojoHandle h = CreateMockHandle(&info);
+ EXPECT_DEATH_IF_SUPPORTED(core()->ReplaceHandleWithReducedRights(
+ h, MOJO_HANDLE_RIGHT_NONE, NullUserPointer()),
+ kMemoryCheckFailedRegex);
+
+ EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h));
+ }
+
// |DuplicateHandleWithReducedRights()|:
{
MockHandleInfo info;
« no previous file with comments | « mojo/edk/system/core.cc ('k') | mojo/edk/system/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698