| Index: content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java
|
| index ab17b60daf26bc7e316c7e32b00aa35eee67f081..c4f1d473e30ad9ae3c6452b971b5d1fd08897fe4 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java
|
| @@ -14,8 +14,13 @@ import android.os.Looper;
|
| import android.os.Message;
|
| import android.os.Messenger;
|
| import android.os.RemoteException;
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.MediumTest;
|
| -import android.test.InstrumentationTestCase;
|
| +
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
|
|
| import org.chromium.base.BaseSwitches;
|
| import org.chromium.base.ThreadUtils;
|
| @@ -25,6 +30,7 @@ import org.chromium.base.process_launcher.ChildProcessCreationParams;
|
| import org.chromium.base.process_launcher.FileDescriptorInfo;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.content.browser.test.ChildProcessAllocatorSettings;
|
| +import org.chromium.content.browser.test.ContentJUnit4ClassRunner;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content.common.ContentSwitches;
|
| @@ -35,7 +41,8 @@ import java.util.concurrent.Callable;
|
| /**
|
| * Instrumentation tests for ChildProcessLauncher.
|
| */
|
| -public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| +@RunWith(ContentJUnit4ClassRunner.class)
|
| +public class ChildProcessLauncherTest {
|
| // Pseudo command line arguments to instruct the child process to wait until being killed.
|
| // Allowing the process to continue would lead to a crash when attempting to initialize IPC
|
| // channels that are not being set up in this test.
|
| @@ -45,26 +52,26 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| private static final String DEFAULT_SANDBOXED_PROCESS_SERVICE =
|
| "org.chromium.content.app.SandboxedProcessService";
|
|
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - super.setUp();
|
| + @Before
|
| + public void setUp() throws Exception {
|
| LibraryLoader.get(LibraryProcessType.PROCESS_CHILD).ensureInitialized();
|
| }
|
|
|
| /**
|
| * Tests cleanup for a connection that fails to connect in the first place.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| @ChildProcessAllocatorSettings(sandboxedServiceCount = 4)
|
| public void testServiceFailedToBind() {
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| - assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting());
|
| + Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting());
|
|
|
| // Try to allocate a connection to service class in incorrect package. We can do that by
|
| // using the instrumentation context (getContext()) instead of the app context
|
| // (getTargetContext()).
|
| - Context context = getInstrumentation().getContext();
|
| + Context context = InstrumentationRegistry.getInstrumentation().getContext();
|
| allocateBoundConnectionForTesting(
|
| context, getDefaultChildProcessCreationParams(context.getPackageName()));
|
|
|
| @@ -87,19 +94,20 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| /**
|
| * Tests cleanup for a connection that terminates before setup.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| public void testServiceCrashedBeforeSetup() throws RemoteException {
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| - assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting());
|
| + Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting());
|
|
|
| // Start and connect to a new service.
|
| final ChildProcessConnectionImpl connection = startConnection();
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
|
|
| // Verify that the service is not yet set up.
|
| - assertEquals(0, connection.getPid());
|
| - assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting());
|
| + Assert.assertEquals(0, connection.getPid());
|
| + Assert.assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting());
|
|
|
| // Crash the service.
|
| connection.crashServiceForTesting();
|
| @@ -123,14 +131,15 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| /**
|
| * Tests cleanup for a connection that terminates after setup.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| public void testServiceCrashedAfterSetup() throws RemoteException {
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
|
|
| // Start and connect to a new service.
|
| final ChildProcessConnectionImpl connection = startConnection();
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
|
|
| // Initiate the connection setup.
|
| triggerConnectionSetup(connection);
|
| @@ -170,21 +179,22 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| }));
|
|
|
| // Verify that the connection pid remains set after termination.
|
| - assertTrue(connection.getPid() != 0);
|
| + Assert.assertTrue(connection.getPid() != 0);
|
| }
|
|
|
| /**
|
| * Tests spawning a pending process from queue.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| public void testPendingSpawnQueue() throws RemoteException {
|
| - final Context appContext = getInstrumentation().getTargetContext();
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + final Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
| + Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
|
|
| // Start and connect to a new service.
|
| final ChildProcessConnectionImpl connection = startConnection();
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
|
|
| // Queue up a new spawn request. There is no way to kill the pending connection, leak it
|
| // until the browser restart.
|
| @@ -192,7 +202,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| final boolean inSandbox = true;
|
| enqueuePendingSpawnForTesting(appContext, sProcessWaitArguments,
|
| getDefaultChildProcessCreationParams(packageName), inSandbox);
|
| - assertEquals(1, pendingSpawnsCountForTesting(appContext, packageName, inSandbox));
|
| + Assert.assertEquals(1, pendingSpawnsCountForTesting(appContext, packageName, inSandbox));
|
|
|
| // Initiate the connection setup.
|
| triggerConnectionSetup(connection);
|
| @@ -246,16 +256,17 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| * Tests service number of connections for external APKs and regular tabs are assigned properly,
|
| * i.e. from different ChildConnectionAllocators.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| @ChildProcessAllocatorSettings(
|
| sandboxedServiceCount = 4, sandboxedServiceName = DEFAULT_SANDBOXED_PROCESS_SERVICE)
|
| public void testServiceNumberAllocation() {
|
| - Context appContext = getInstrumentation().getTargetContext();
|
| - assertEquals(0,
|
| + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
| + Assert.assertEquals(0,
|
| allocatedSandboxedConnectionsCountForTesting(
|
| appContext, EXTERNAL_APK_PACKAGE_NAME));
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
|
|
| // Start and connect to a new service of an external APK.
|
| ChildProcessConnectionImpl externalApkConnection =
|
| @@ -265,16 +276,16 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
|
|
| // Verify that one connection is allocated for an external APK and a regular tab
|
| // respectively.
|
| - assertEquals(1,
|
| + Assert.assertEquals(1,
|
| allocatedSandboxedConnectionsCountForTesting(
|
| appContext, EXTERNAL_APK_PACKAGE_NAME));
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
|
|
| // Verify that connections allocated for an external APK and the regular tab are from
|
| // different ChildConnectionAllocators, since both ChildConnectionAllocators start
|
| // allocating connections from number 0.
|
| - assertEquals(0, externalApkConnection.getServiceNumber());
|
| - assertEquals(0, tabConnection.getServiceNumber());
|
| + Assert.assertEquals(0, externalApkConnection.getServiceNumber());
|
| + Assert.assertEquals(0, tabConnection.getServiceNumber());
|
| }
|
|
|
| /**
|
| @@ -282,29 +293,30 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| * allocate a new connection to the APK, but we can still allocate a connection for a regular
|
| * tab.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| @ChildProcessAllocatorSettings(
|
| sandboxedServiceCount = 1, sandboxedServiceName = DEFAULT_SANDBOXED_PROCESS_SERVICE)
|
| public void testExceedMaximumConnectionNumber() {
|
| - Context appContext = getInstrumentation().getTargetContext();
|
| - assertEquals(0,
|
| + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
| + Assert.assertEquals(0,
|
| allocatedSandboxedConnectionsCountForTesting(
|
| appContext, EXTERNAL_APK_PACKAGE_NAME));
|
|
|
| // Setup a connection for an external APK to reach the maximum allowed connection number.
|
| ChildProcessConnectionImpl externalApkConnection =
|
| allocateConnection(EXTERNAL_APK_PACKAGE_NAME);
|
| - assertNotNull(externalApkConnection);
|
| + Assert.assertNotNull(externalApkConnection);
|
|
|
| // Verify that there isn't any connection available for the external APK.
|
| ChildProcessConnectionImpl exceedNumberExternalApkConnection =
|
| allocateConnection(EXTERNAL_APK_PACKAGE_NAME);
|
| - assertNull(exceedNumberExternalApkConnection);
|
| + Assert.assertNull(exceedNumberExternalApkConnection);
|
|
|
| // Verify that we can still allocate connection for a regular tab.
|
| ChildProcessConnectionImpl tabConnection = allocateConnection(appContext.getPackageName());
|
| - assertNotNull(tabConnection);
|
| + Assert.assertNotNull(tabConnection);
|
| }
|
|
|
| /**
|
| @@ -314,10 +326,11 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| * instrumentation test then tries to bind the same slot, which fails, so the
|
| * ChildProcessLauncher retries on a new connection.
|
| */
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| public void testBindServiceFromMultipleProcesses() throws RemoteException {
|
| - final Context context = getInstrumentation().getTargetContext();
|
| + final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
|
|
| // Start the Helper service.
|
| class HelperConnection implements ServiceConnection {
|
| @@ -336,7 +349,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| Intent intent = new Intent();
|
| intent.setComponent(new ComponentName(context.getPackageName(),
|
| context.getPackageName() + ".ChildProcessLauncherTestHelperService"));
|
| - assertTrue(context.bindService(intent, serviceConn, Context.BIND_AUTO_CREATE));
|
| + Assert.assertTrue(context.bindService(intent, serviceConn, Context.BIND_AUTO_CREATE));
|
|
|
| // Wait for the Helper service to connect.
|
| CriteriaHelper.pollInstrumentationThread(
|
| @@ -347,7 +360,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| }
|
| });
|
|
|
| - assertNotNull(serviceConn.mMessenger);
|
| + Assert.assertNotNull(serviceConn.mMessenger);
|
|
|
| class ReplyHandler implements Handler.Callback {
|
| Message mMessage;
|
| @@ -378,13 +391,14 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| });
|
|
|
| // Verify that the Helper was able to launch the sandboxed service.
|
| - assertNotNull(replyHandler.mMessage);
|
| - assertEquals(ChildProcessLauncherTestHelperService.MSG_BIND_SERVICE_REPLY,
|
| + Assert.assertNotNull(replyHandler.mMessage);
|
| + Assert.assertEquals(ChildProcessLauncherTestHelperService.MSG_BIND_SERVICE_REPLY,
|
| replyHandler.mMessage.what);
|
| - assertEquals("Connection slot from helper service is not 0", 0, replyHandler.mMessage.arg2);
|
| + Assert.assertEquals(
|
| + "Connection slot from helper service is not 0", 0, replyHandler.mMessage.arg2);
|
|
|
| final int helperConnPid = replyHandler.mMessage.arg1;
|
| - assertTrue(helperConnPid > 0);
|
| + Assert.assertTrue(helperConnPid > 0);
|
|
|
| // Launch a service from this process. Since slot 0 is already bound by the Helper, it
|
| // will fail to start and the ChildProcessLauncher will retry.
|
| @@ -403,7 +417,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| }
|
| });
|
|
|
| - assertEquals(0, conn.getServiceNumber());
|
| + Assert.assertEquals(0, conn.getServiceNumber());
|
|
|
| final ChildProcessConnection[] sandboxedConnections =
|
| getSandboxedConnectionArrayForTesting(context, context.getPackageName());
|
| @@ -426,23 +440,23 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| for (int i = 0; i < sandboxedConnections.length; ++i) {
|
| ChildProcessConnection sandboxedConn = sandboxedConnections[i];
|
| if (i <= 1) {
|
| - assertNotNull(sandboxedConn);
|
| - assertNotNull(sandboxedConn.getService());
|
| + Assert.assertNotNull(sandboxedConn);
|
| + Assert.assertNotNull(sandboxedConn.getService());
|
| } else {
|
| - assertNull(sandboxedConn);
|
| + Assert.assertNull(sandboxedConn);
|
| }
|
| }
|
|
|
| - assertTrue(conn == sandboxedConnections[0]);
|
| + Assert.assertTrue(conn == sandboxedConnections[0]);
|
| final ChildProcessConnection retryConn = sandboxedConnections[1];
|
|
|
| - assertFalse(conn == retryConn);
|
| + Assert.assertFalse(conn == retryConn);
|
|
|
| - assertEquals(0, conn.getServiceNumber());
|
| - assertEquals(0, conn.getPid());
|
| - assertFalse(conn.getService().bindToCaller());
|
| + Assert.assertEquals(0, conn.getServiceNumber());
|
| + Assert.assertEquals(0, conn.getPid());
|
| + Assert.assertFalse(conn.getService().bindToCaller());
|
|
|
| - assertEquals(1, retryConn.getServiceNumber());
|
| + Assert.assertEquals(1, retryConn.getServiceNumber());
|
| CriteriaHelper.pollInstrumentationThread(
|
| new Criteria("Failed waiting retry connection to get pid") {
|
| @Override
|
| @@ -450,8 +464,8 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| return retryConn.getPid() > 0;
|
| }
|
| });
|
| - assertTrue(retryConn.getPid() != helperConnPid);
|
| - assertTrue(retryConn.getService().bindToCaller());
|
| + Assert.assertTrue(retryConn.getPid() != helperConnPid);
|
| + Assert.assertTrue(retryConn.getService().bindToCaller());
|
| }
|
|
|
| private static void warmUpOnUiThreadBlocking(final Context context) {
|
| @@ -463,20 +477,21 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| });
|
| }
|
|
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| public void testWarmUp() {
|
| - final Context context = getInstrumentation().getTargetContext();
|
| + final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
| warmUpOnUiThreadBlocking(context);
|
| ChildProcessLauncherTestHelperService.runOnLauncherThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
|
|
| final ChildProcessConnection conn =
|
| ChildProcessLauncherTestHelperService.startInternalForTesting(
|
| context, new String[0], new FileDescriptorInfo[0], null);
|
| - assertEquals(
|
| + Assert.assertEquals(
|
| 1, allocatedChromeSandboxedConnectionsCount()); // Used warmup connection.
|
|
|
| ChildProcessLauncher.stop(conn.getPid());
|
| @@ -484,11 +499,12 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| });
|
| }
|
|
|
| + @Test
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| public void testCustomCreationParamDoesNotReuseWarmupConnection() {
|
| // Since warmUp only uses default params.
|
| - final Context context = getInstrumentation().getTargetContext();
|
| + final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
| // Check uses object identity, having the params match exactly is fine.
|
| ChildProcessCreationParams.registerDefault(
|
| getDefaultChildProcessCreationParams(context.getPackageName()));
|
| @@ -499,14 +515,15 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| ChildProcessLauncherTestHelperService.runOnLauncherThreadBlocking(new Runnable() {
|
| @Override
|
| public void run() {
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + Assert.assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
|
|
| startRendererProcess(context, paramId, new FileDescriptorInfo[0]);
|
| - assertEquals(2, allocatedChromeSandboxedConnectionsCount()); // Warmup not used.
|
| + Assert.assertEquals(
|
| + 2, allocatedChromeSandboxedConnectionsCount()); // Warmup not used.
|
|
|
| startRendererProcess(
|
| context, ChildProcessCreationParams.DEFAULT_ID, new FileDescriptorInfo[0]);
|
| - assertEquals(2, allocatedChromeSandboxedConnectionsCount()); // Warmup used.
|
| + Assert.assertEquals(2, allocatedChromeSandboxedConnectionsCount()); // Warmup used.
|
|
|
| ChildProcessCreationParams.unregister(paramId);
|
| }
|
| @@ -515,7 +532,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
|
|
| private ChildProcessConnectionImpl startConnection() {
|
| // Allocate a new connection.
|
| - Context context = getInstrumentation().getTargetContext();
|
| + Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
| final ChildProcessConnectionImpl connection =
|
| (ChildProcessConnectionImpl) allocateBoundConnectionForTesting(
|
| context, getDefaultChildProcessCreationParams(context.getPackageName()));
|
| @@ -568,7 +585,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| @Override
|
| public ChildProcessConnectionImpl call() {
|
| // Allocate a new connection.
|
| - Context context = getInstrumentation().getTargetContext();
|
| + Context context = InstrumentationRegistry.getTargetContext();
|
| ChildProcessCreationParams creationParams =
|
| getDefaultChildProcessCreationParams(packageName);
|
| return (ChildProcessConnectionImpl) ChildProcessLauncher.allocateConnection(
|
| @@ -644,7 +661,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| * Returns the number of Chrome's sandboxed connections.
|
| */
|
| private int allocatedChromeSandboxedConnectionsCount() {
|
| - Context context = getInstrumentation().getTargetContext();
|
| + Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
| return allocatedSandboxedConnectionsCountForTesting(context, context.getPackageName());
|
| }
|
|
|
|
|