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

Unified Diff: ipc/ipc_message_attachment_set_posix_unittest.cc

Issue 2504063002: Revert of Remove IPC::BrokerableAttachment. (Closed)
Patch Set: Created 4 years, 1 month 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 | « ipc/ipc_message_attachment_set.cc ('k') | ipc/ipc_message_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_message_attachment_set_posix_unittest.cc
diff --git a/ipc/ipc_message_attachment_set_posix_unittest.cc b/ipc/ipc_message_attachment_set_posix_unittest.cc
index 0bd143df4dee9eeb497599412d17803dcd05edb9..5ebed84070ce3748485a231c040839ff9a5c7755 100644
--- a/ipc/ipc_message_attachment_set_posix_unittest.cc
+++ b/ipc/ipc_message_attachment_set_posix_unittest.cc
@@ -34,12 +34,6 @@
return true;
}
-int GetFdAt(MessageAttachmentSet* set, int id) {
- return static_cast<internal::PlatformFileAttachment&>(
- *set->GetAttachmentAt(id))
- .TakePlatformFile();
-}
-
// The MessageAttachmentSet will try and close some of the descriptor numbers
// which we given it. This is the base descriptor value. It's great enough such
// that no real descriptor will accidently be closed.
@@ -88,6 +82,44 @@
set->CommitAllDescriptors();
}
+#if defined(OS_ANDROID)
+#define MAYBE_SetDescriptors DISABLED_SetDescriptors
+#else
+#define MAYBE_SetDescriptors SetDescriptors
+#endif
+TEST(MessageAttachmentSet, MAYBE_SetDescriptors) {
+ scoped_refptr<MessageAttachmentSet> set(new MessageAttachmentSet);
+
+ ASSERT_TRUE(set->empty());
+ set->AddDescriptorsToOwn(NULL, 0);
+ ASSERT_TRUE(set->empty());
+
+ const int fd = GetSafeFd();
+ static const int fds[] = {fd};
+ set->AddDescriptorsToOwn(fds, 1);
+ ASSERT_TRUE(!set->empty());
+ ASSERT_EQ(set->size(), 1u);
+
+ set->CommitAllDescriptors();
+
+ ASSERT_TRUE(VerifyClosed(fd));
+}
+
+TEST(MessageAttachmentSet, PeekDescriptors) {
+ scoped_refptr<MessageAttachmentSet> set(new MessageAttachmentSet);
+
+ set->PeekDescriptors(NULL);
+ ASSERT_TRUE(
+ set->AddAttachment(new internal::PlatformFileAttachment(kFDBase)));
+
+ int fds[1];
+ fds[0] = 0;
+ set->PeekDescriptors(fds);
+ ASSERT_EQ(fds[0], kFDBase);
+ set->CommitAllDescriptors();
+ ASSERT_TRUE(set->empty());
+}
+
TEST(MessageAttachmentSet, WalkInOrder) {
scoped_refptr<MessageAttachmentSet> set(new MessageAttachmentSet);
@@ -100,9 +132,11 @@
ASSERT_TRUE(
set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 2)));
- ASSERT_EQ(GetFdAt(set.get(), 0), kFDBase);
- ASSERT_EQ(GetFdAt(set.get(), 1), kFDBase + 1);
- ASSERT_EQ(GetFdAt(set.get(), 2), kFDBase + 2);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(0)->TakePlatformFile(), kFDBase);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(1)->TakePlatformFile(),
+ kFDBase + 1);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(2)->TakePlatformFile(),
+ kFDBase + 2);
set->CommitAllDescriptors();
}
@@ -119,8 +153,8 @@
ASSERT_TRUE(
set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 2)));
- ASSERT_EQ(GetFdAt(set.get(), 0), kFDBase);
- ASSERT_FALSE(set->GetAttachmentAt(2));
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(0)->TakePlatformFile(), kFDBase);
+ ASSERT_FALSE(set->GetNonBrokerableAttachmentAt(2));
set->CommitAllDescriptors();
}
@@ -137,15 +171,21 @@
ASSERT_TRUE(
set->AddAttachment(new internal::PlatformFileAttachment(kFDBase + 2)));
- ASSERT_EQ(GetFdAt(set.get(), 0), kFDBase);
- ASSERT_EQ(GetFdAt(set.get(), 1), kFDBase + 1);
- ASSERT_EQ(GetFdAt(set.get(), 2), kFDBase + 2);
- ASSERT_EQ(GetFdAt(set.get(), 0), kFDBase);
- ASSERT_EQ(GetFdAt(set.get(), 1), kFDBase + 1);
- ASSERT_EQ(GetFdAt(set.get(), 2), kFDBase + 2);
- ASSERT_EQ(GetFdAt(set.get(), 0), kFDBase);
- ASSERT_EQ(GetFdAt(set.get(), 1), kFDBase + 1);
- ASSERT_EQ(GetFdAt(set.get(), 2), kFDBase + 2);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(0)->TakePlatformFile(), kFDBase);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(1)->TakePlatformFile(),
+ kFDBase + 1);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(2)->TakePlatformFile(),
+ kFDBase + 2);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(0)->TakePlatformFile(), kFDBase);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(1)->TakePlatformFile(),
+ kFDBase + 1);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(2)->TakePlatformFile(),
+ kFDBase + 2);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(0)->TakePlatformFile(), kFDBase);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(1)->TakePlatformFile(),
+ kFDBase + 1);
+ ASSERT_EQ(set->GetNonBrokerableAttachmentAt(2)->TakePlatformFile(),
+ kFDBase + 2);
set->CommitAllDescriptors();
}
« no previous file with comments | « ipc/ipc_message_attachment_set.cc ('k') | ipc/ipc_message_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698