| 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 7e5f7319052e7d230009baf07986978d16eecf51..660aa91f95d4c4293a9720df522b76cb357225fc 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
|
| @@ -10,10 +10,9 @@ import android.test.InstrumentationTestCase;
|
| import android.test.suitebuilder.annotation.MediumTest;
|
|
|
| import org.chromium.base.BaseSwitches;
|
| -import org.chromium.base.library_loader.LibraryLoader;
|
| -import org.chromium.base.library_loader.LibraryProcessType;
|
| import org.chromium.base.test.util.CommandLineFlags;
|
| import org.chromium.base.test.util.Feature;
|
| +import org.chromium.content.browser.test.ChildProcessLauncherTestHelper;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
|
|
| @@ -21,8 +20,6 @@ import java.util.concurrent.Callable;
|
|
|
| /**
|
| * Instrumentation tests for ChildProcessLauncher.
|
| - * TODO(hanxi): Add tests for assigning {@ChildConnectionAllocator} for different package names
|
| - * when render processes can be run in WebAPKs.
|
| */
|
| public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| // Pseudo command line arguments to instruct the child process to wait until being killed.
|
| @@ -38,7 +35,9 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| @Feature({"ProcessManagement"})
|
| @CommandLineFlags.Add(ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FOR_TESTING + "=4")
|
| public void testServiceFailedToBind() throws InterruptedException, RemoteException {
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + final Context appContext = getInstrumentation().getContext();
|
| + assertEquals(0, ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext));
|
| assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting());
|
|
|
| // Try to allocate a connection to service class in incorrect package. We can do that by
|
| @@ -46,13 +45,15 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| // (getTargetContext()).
|
| Context context = getInstrumentation().getContext();
|
| ChildProcessLauncher.allocateBoundConnectionForTesting(
|
| - context, getDefaultChildProcessCreationParams(context.getPackageName()));
|
| + context, ChildProcessLauncherTestHelper.getChildProcessCreationParams(
|
| + context.getPackageName(), null));
|
|
|
| // Verify that the connection is not considered as allocated.
|
| CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() {
|
| @Override
|
| public Integer call() {
|
| - return allocatedChromeSandboxedConnectionsCount();
|
| + return ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext);
|
| }
|
| }));
|
|
|
| @@ -70,12 +71,17 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| public void testServiceCrashedBeforeSetup() throws InterruptedException, RemoteException {
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + final Context appContext = getInstrumentation().getTargetContext();
|
| + assertEquals(0, ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext));
|
| assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting());
|
|
|
| // Start and connect to a new service.
|
| - final ChildProcessConnectionImpl connection = startConnection();
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + final ChildProcessConnectionImpl connection =
|
| + ChildProcessLauncherTestHelper.startConnection(appContext,
|
| + appContext.getPackageName(), null);
|
| + assertEquals(1, ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext));
|
|
|
| // Verify that the service is not yet set up.
|
| assertEquals(0, connection.getPid());
|
| @@ -88,7 +94,8 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() {
|
| @Override
|
| public Integer call() {
|
| - return allocatedChromeSandboxedConnectionsCount();
|
| + return ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext);
|
| }
|
| }));
|
|
|
| @@ -106,11 +113,16 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| @MediumTest
|
| @Feature({"ProcessManagement"})
|
| public void testServiceCrashedAfterSetup() throws InterruptedException, RemoteException {
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + final Context appContext = getInstrumentation().getTargetContext();
|
| + assertEquals(0, ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext));
|
|
|
| // Start and connect to a new service.
|
| - final ChildProcessConnectionImpl connection = startConnection();
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + final ChildProcessConnectionImpl connection =
|
| + ChildProcessLauncherTestHelper.startConnection(appContext,
|
| + appContext.getPackageName(), null);
|
| + assertEquals(1, ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext));
|
|
|
| // Initiate the connection setup.
|
| triggerConnectionSetup(connection);
|
| @@ -138,7 +150,8 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() {
|
| @Override
|
| public Integer call() {
|
| - return allocatedChromeSandboxedConnectionsCount();
|
| + return ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext);
|
| }
|
| }));
|
|
|
| @@ -160,18 +173,23 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| @Feature({"ProcessManagement"})
|
| public void testPendingSpawnQueue() throws InterruptedException, RemoteException {
|
| final Context appContext = getInstrumentation().getTargetContext();
|
| - assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| + assertEquals(0, ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext));
|
|
|
| // Start and connect to a new service.
|
| - final ChildProcessConnectionImpl connection = startConnection();
|
| - assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| + final ChildProcessConnectionImpl connection =
|
| + ChildProcessLauncherTestHelper.startConnection(appContext,
|
| + appContext.getPackageName(), null);
|
| + assertEquals(1, ChildProcessLauncherTestHelper.allocatedChromeSandboxedConnectionsCount(
|
| + appContext));
|
|
|
| // Queue up a new spawn request. There is no way to kill the pending connection, leak it
|
| // until the browser restart.
|
| final String packageName = appContext.getPackageName();
|
| final boolean inSandbox = true;
|
| ChildProcessLauncher.enqueuePendingSpawnForTesting(appContext, sProcessWaitArguments,
|
| - getDefaultChildProcessCreationParams(packageName), inSandbox);
|
| + ChildProcessLauncherTestHelper.getChildProcessCreationParams(packageName, null),
|
| + inSandbox);
|
| assertEquals(1, ChildProcessLauncher.pendingSpawnsCountForTesting(appContext, packageName,
|
| inSandbox));
|
|
|
| @@ -211,7 +229,8 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| Criteria.equals(1, new Callable<Integer>() {
|
| @Override
|
| public Integer call() {
|
| - return allocatedChromeSandboxedConnectionsCount();
|
| + return ChildProcessLauncherTestHelper
|
| + .allocatedChromeSandboxedConnectionsCount(appContext);
|
| }
|
| }));
|
|
|
| @@ -224,38 +243,6 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| }));
|
| }
|
|
|
| - private ChildProcessConnectionImpl startConnection() throws InterruptedException {
|
| - // Allocate a new connection.
|
| - Context context = getInstrumentation().getTargetContext();
|
| - final ChildProcessConnectionImpl connection =
|
| - (ChildProcessConnectionImpl) ChildProcessLauncher.allocateBoundConnectionForTesting(
|
| - context, getDefaultChildProcessCreationParams(context.getPackageName()));
|
| -
|
| - // Wait for the service to connect.
|
| - CriteriaHelper.pollInstrumentationThread(
|
| - new Criteria("The connection wasn't established.") {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return connection.isConnected();
|
| - }
|
| - });
|
| - return connection;
|
| - }
|
| -
|
| - /**
|
| - * Returns the number of Chrome's sandboxed connections.
|
| - */
|
| - private int allocatedChromeSandboxedConnectionsCount() {
|
| - Context context = getInstrumentation().getTargetContext();
|
| - return ChildProcessLauncher.allocatedSandboxedConnectionsCountForTesting(
|
| - context, context.getPackageName());
|
| - }
|
| -
|
| - private ChildProcessCreationParams getDefaultChildProcessCreationParams(String packageName) {
|
| - return new ChildProcessCreationParams(packageName, 0,
|
| - LibraryProcessType.PROCESS_CHILD);
|
| - }
|
| -
|
| private void triggerConnectionSetup(ChildProcessConnectionImpl connection) {
|
| ChildProcessLauncher.triggerConnectionSetup(connection, sProcessWaitArguments, 1,
|
| new FileDescriptorInfo[0], ChildProcessLauncher.CALLBACK_FOR_RENDERER_PROCESS, 0);
|
| @@ -264,7 +251,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| @Override
|
| protected void setUp() throws Exception {
|
| super.setUp();
|
| - LibraryLoader.get(LibraryProcessType.PROCESS_CHILD)
|
| - .ensureInitialized(getInstrumentation().getTargetContext());
|
| + ChildProcessLauncherTestHelper.ensureLibraryInitialized(
|
| + getInstrumentation().getTargetContext());
|
| }
|
| }
|
|
|