Re-land: Re-enable multi-process IPC tests on Android.

This is possible by using the alternate test child implementation.

This re-land is identical to the original CL.

TBR=tsepez@chromium.org

Review-Url: https://codereview.chromium.org/1950143003
Cr-Commit-Position: refs/heads/master@{#391762}


CrOS-Libchrome-Original-Commit: 6de2ee4f09f623c82726ac9ee0b052dd7eaffd07
diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc
index c76af5a..0ed6679 100644
--- a/ipc/ipc_channel_posix_unittest.cc
+++ b/ipc/ipc_channel_posix_unittest.cc
@@ -114,6 +114,15 @@
   static const std::string GetConnectionSocketName();
   static const std::string GetChannelDirName();
 
+  bool WaitForExit(base::Process& process, int* exit_code) {
+#if defined(OS_ANDROID)
+    return AndroidWaitForChildExitWithTimeout(
+        process, base::TimeDelta::Max(), exit_code);
+#else
+    return process.WaitForExit(exit_code);
+#endif  // defined(OS_ANDROID)
+  }
+
  protected:
   void SetUp() override;
   void TearDown() override;
@@ -258,12 +267,7 @@
   ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, out_listener.status());
 }
 
-#if defined(OS_ANDROID)
-#define MAYBE_AdvancedConnected DISABLED_AdvancedConnected
-#else
-#define MAYBE_AdvancedConnected AdvancedConnected
-#endif
-TEST_F(IPCChannelPosixTest, MAYBE_AdvancedConnected) {
+TEST_F(IPCChannelPosixTest, AdvancedConnected) {
   // Test creating a connection to an external process.
   IPCChannelPosixTestListener listener(false);
   IPC::ChannelHandle chan_handle(GetConnectionSocketName());
@@ -285,19 +289,14 @@
   channel->Send(message);
   SpinRunLoop(TestTimeouts::action_timeout());
   int exit_code = 0;
-  EXPECT_TRUE(process.WaitForExit(&exit_code));
+  EXPECT_TRUE(WaitForExit(process, &exit_code));
   EXPECT_EQ(0, exit_code);
   ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
   ASSERT_FALSE(channel->HasAcceptedConnection());
   unlink(chan_handle.name.c_str());
 }
 
-#if defined(OS_ANDROID)
-#define MAYBE_ResetState DISABLED_ResetState
-#else
-#define MAYBE_ResetState ResetState
-#endif
-TEST_F(IPCChannelPosixTest, MAYBE_ResetState) {
+TEST_F(IPCChannelPosixTest, ResetState) {
   // Test creating a connection to an external process. Close the connection,
   // but continue to listen and make sure another external process can connect
   // to us.
@@ -330,7 +329,7 @@
   SpinRunLoop(TestTimeouts::action_timeout());
   EXPECT_TRUE(process.Terminate(0, false));
   int exit_code = 0;
-  EXPECT_TRUE(process2.WaitForExit(&exit_code));
+  EXPECT_TRUE(WaitForExit(process2, &exit_code));
   EXPECT_EQ(0, exit_code);
   ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
   ASSERT_FALSE(channel->HasAcceptedConnection());
@@ -359,12 +358,7 @@
   EXPECT_FALSE(channel2->Connect());
 }
 
-#if defined(OS_ANDROID)
-#define MAYBE_MultiConnection DISABLED_MultiConnection
-#else
-#define MAYBE_MultiConnection MultiConnection
-#endif
-TEST_F(IPCChannelPosixTest, MAYBE_MultiConnection) {
+TEST_F(IPCChannelPosixTest, MultiConnection) {
   // Test setting up a connection to an external process, and then have
   // another external process attempt to connect to us.
   IPCChannelPosixTestListener listener(false);
@@ -385,7 +379,7 @@
   ASSERT_TRUE(process2.IsValid());
   SpinRunLoop(TestTimeouts::action_max_timeout());
   int exit_code = 0;
-  EXPECT_TRUE(process2.WaitForExit(&exit_code));
+  EXPECT_TRUE(WaitForExit(process2, &exit_code));
   EXPECT_EQ(exit_code, 0);
   ASSERT_EQ(IPCChannelPosixTestListener::DENIED, listener.status());
   ASSERT_TRUE(channel->HasAcceptedConnection());
@@ -394,7 +388,7 @@
                                            IPC::Message::PRIORITY_NORMAL);
   channel->Send(message);
   SpinRunLoop(TestTimeouts::action_timeout());
-  EXPECT_TRUE(process.WaitForExit(&exit_code));
+  EXPECT_TRUE(WaitForExit(process, &exit_code));
   EXPECT_EQ(exit_code, 0);
   ASSERT_EQ(IPCChannelPosixTestListener::CHANNEL_ERROR, listener.status());
   ASSERT_FALSE(channel->HasAcceptedConnection());
diff --git a/ipc/ipc_channel_proxy_unittest.cc b/ipc/ipc_channel_proxy_unittest.cc
index 5997668..5367157 100644
--- a/ipc/ipc_channel_proxy_unittest.cc
+++ b/ipc/ipc_channel_proxy_unittest.cc
@@ -273,12 +273,7 @@
   std::unique_ptr<QuitListener> listener_;
 };
 
-#if defined(OS_ANDROID)
-#define MAYBE_MessageClassFilters DISABLED_MessageClassFilters
-#else
-#define MAYBE_MessageClassFilters MessageClassFilters
-#endif
-TEST_F(IPCChannelProxyTest, MAYBE_MessageClassFilters) {
+TEST_F(IPCChannelProxyTest, MessageClassFilters) {
   // Construct a filter per message class.
   std::vector<scoped_refptr<MessageCountFilter> > class_filters;
   class_filters.push_back(make_scoped_refptr(
@@ -302,12 +297,7 @@
     EXPECT_EQ(1U, class_filters[i]->messages_received());
 }
 
-#if defined(OS_ANDROID)
-#define MAYBE_GlobalAndMessageClassFilters DISABLED_GlobalAndMessageClassFilters
-#else
-#define MAYBE_GlobalAndMessageClassFilters GlobalAndMessageClassFilters
-#endif
-TEST_F(IPCChannelProxyTest, MAYBE_GlobalAndMessageClassFilters) {
+TEST_F(IPCChannelProxyTest, GlobalAndMessageClassFilters) {
   // Add a class and global filter.
   scoped_refptr<MessageCountFilter> class_filter(
       new MessageCountFilter(TestMsgStart));
@@ -336,12 +326,7 @@
   EXPECT_EQ(3U, global_filter->messages_received());
 }
 
-#if defined(OS_ANDROID)
-#define MAYBE_FilterRemoval DISABLED_FilterRemoval
-#else
-#define MAYBE_FilterRemoval FilterRemoval
-#endif
-TEST_F(IPCChannelProxyTest, MAYBE_FilterRemoval) {
+TEST_F(IPCChannelProxyTest, FilterRemoval) {
   // Add a class and global filter.
   scoped_refptr<MessageCountFilter> class_filter(
       new MessageCountFilter(TestMsgStart));
diff --git a/ipc/ipc_fuzzing_tests.cc b/ipc/ipc_fuzzing_tests.cc
index 00e91f3..f197a6b 100644
--- a/ipc/ipc_fuzzing_tests.cc
+++ b/ipc/ipc_fuzzing_tests.cc
@@ -271,14 +271,9 @@
 class IPCFuzzingTest : public IPCTestBase {
 };
 
-#if defined(OS_ANDROID)
-#define MAYBE_SanityTest DISABLED_SanityTest
-#else
-#define MAYBE_SanityTest SanityTest
-#endif
 // This test makes sure that the FuzzerClientListener and FuzzerServerListener
 // are working properly by generating two well formed IPC calls.
-TEST_F(IPCFuzzingTest, MAYBE_SanityTest) {
+TEST_F(IPCFuzzingTest, SanityTest) {
   Init("FuzzServerClient");
 
   FuzzerClientListener listener;
@@ -301,17 +296,12 @@
   DestroyChannel();
 }
 
-#if defined(OS_ANDROID)
-#define MAYBE_MsgBadPayloadShort DISABLED_MsgBadPayloadShort
-#else
-#define MAYBE_MsgBadPayloadShort MsgBadPayloadShort
-#endif
 // This test uses a payload that is smaller than expected. This generates an
 // error while unpacking the IPC buffer which in debug trigger an assertion and
 // in release is ignored (!). Right after we generate another valid IPC to make
 // sure framing is working properly.
 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
-TEST_F(IPCFuzzingTest, MAYBE_MsgBadPayloadShort) {
+TEST_F(IPCFuzzingTest, MsgBadPayloadShort) {
   Init("FuzzServerClient");
 
   FuzzerClientListener listener;
@@ -335,16 +325,11 @@
 }
 #endif
 
-#if defined(OS_ANDROID)
-#define MAYBE_MsgBadPayloadArgs DISABLED_MsgBadPayloadArgs
-#else
-#define MAYBE_MsgBadPayloadArgs MsgBadPayloadArgs
-#endif
 // This test uses a payload that has too many arguments, but so the payload size
 // is big enough so the unpacking routine does not generate an error as in the
 // case of MsgBadPayloadShort test. This test does not pinpoint a flaw (per se)
 // as by design we don't carry type information on the IPC message.
-TEST_F(IPCFuzzingTest, MAYBE_MsgBadPayloadArgs) {
+TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) {
   Init("FuzzServerClient");
 
   FuzzerClientListener listener;
diff --git a/ipc/ipc_send_fds_test.cc b/ipc/ipc_send_fds_test.cc
index 81a995d..9480d0e 100644
--- a/ipc/ipc_send_fds_test.cc
+++ b/ipc/ipc_send_fds_test.cc
@@ -143,12 +143,7 @@
   }
 };
 
-#if defined(OS_ANDROID)
-#define MAYBE_DescriptorTest DISABLED_DescriptorTest
-#else
-#define MAYBE_DescriptorTest DescriptorTest
-#endif
-TEST_F(IPCSendFdsTest, MAYBE_DescriptorTest) {
+TEST_F(IPCSendFdsTest, DescriptorTest) {
   Init("SendFdsClient");
   RunServer();
 }
diff --git a/ipc/ipc_test_base.cc b/ipc/ipc_test_base.cc
index 831a59a..757d9f5 100644
--- a/ipc/ipc_test_base.cc
+++ b/ipc/ipc_test_base.cc
@@ -144,8 +144,13 @@
   DCHECK(client_process_.IsValid());
 
   int exit_code;
+#if defined(OS_ANDROID)
+  bool rv = AndroidWaitForChildExitWithTimeout(
+      client_process_, base::TimeDelta::FromSeconds(5), &exit_code);
+#else
   bool rv = client_process_.WaitForExitWithTimeout(
       base::TimeDelta::FromSeconds(5), &exit_code);
+#endif  // defined(OS_ANDROID)
   client_process_.Close();
   return rv;
 }
diff --git a/ipc/mojo/ipc_mojo_bootstrap_unittest.cc b/ipc/mojo/ipc_mojo_bootstrap_unittest.cc
index dcf68bd..4fa52e2 100644
--- a/ipc/mojo/ipc_mojo_bootstrap_unittest.cc
+++ b/ipc/mojo/ipc_mojo_bootstrap_unittest.cc
@@ -59,13 +59,7 @@
   quit_callback_.Run();
 }
 
-// Times out on Android; see http://crbug.com/502290
-#if defined(OS_ANDROID)
-#define MAYBE_Connect DISABLED_Connect
-#else
-#define MAYBE_Connect Connect
-#endif
-TEST_F(IPCMojoBootstrapTest, MAYBE_Connect) {
+TEST_F(IPCMojoBootstrapTest, Connect) {
   base::MessageLoop message_loop;
   base::RunLoop run_loop;
   TestingDelegate delegate(run_loop.QuitClosure());
diff --git a/ipc/run_all_unittests.cc b/ipc/run_all_unittests.cc
index 26a7395..5f9cc16 100644
--- a/ipc/run_all_unittests.cc
+++ b/ipc/run_all_unittests.cc
@@ -4,6 +4,7 @@
 
 #include "base/bind.h"
 #include "base/test/launcher/unit_test_launcher.h"
+#include "base/test/multiprocess_test.h"
 #include "base/test/test_suite.h"
 #include "build/build_config.h"
 
@@ -14,6 +15,8 @@
 
 int main(int argc, char** argv) {
 #if defined(OS_ANDROID)
+  base::InitAndroidMultiProcessTestHelper(main);
+
   JNIEnv* env = base::android::AttachCurrentThread();
   base::RegisterContentUriTestUtils(env);
 #endif
diff --git a/ipc/sync_socket_unittest.cc b/ipc/sync_socket_unittest.cc
index 7c83b24..3385646 100644
--- a/ipc/sync_socket_unittest.cc
+++ b/ipc/sync_socket_unittest.cc
@@ -167,12 +167,7 @@
 class SyncSocketTest : public IPCTestBase {
 };
 
-#if defined(OS_ANDROID)
-#define MAYBE_SanityTest DISABLED_SanityTest
-#else
-#define MAYBE_SanityTest SanityTest
-#endif
-TEST_F(SyncSocketTest, MAYBE_SanityTest) {
+TEST_F(SyncSocketTest, SanityTest) {
   Init("SyncSocketServerClient");
 
   SyncSocketClientListener listener;
@@ -254,13 +249,8 @@
   EXPECT_EQ(0U, received);
 }
 
-#if defined(OS_ANDROID)
-#define MAYBE_BlockingReceiveTest DISABLED_BlockingReceiveTest
-#else
-#define MAYBE_BlockingReceiveTest BlockingReceiveTest
-#endif
 // Tests that read is a blocking operation.
-TEST_F(SyncSocketTest, MAYBE_BlockingReceiveTest) {
+TEST_F(SyncSocketTest, BlockingReceiveTest) {
   base::CancelableSyncSocket pair[2];
   ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&pair[0], &pair[1]));