| Index: chrome/android/javatests/src/org/chromium/chrome/browser/ChildProcessLauncherTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ChildProcessLauncherTest.java
|
| similarity index 70%
|
| rename from content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java
|
| rename to chrome/android/javatests/src/org/chromium/chrome/browser/ChildProcessLauncherTest.java
|
| index 7e5f7319052e7d230009baf07986978d16eecf51..1670286dc7a851e32fde6f48a5d8411c64fe9165 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ChildProcessLauncherTest.java
|
| @@ -2,8 +2,9 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -package org.chromium.content.browser;
|
| +package org.chromium.chrome.browser;
|
|
|
| +import android.app.Service;
|
| import android.content.Context;
|
| import android.os.RemoteException;
|
| import android.test.InstrumentationTestCase;
|
| @@ -14,15 +15,18 @@ 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.ChildProcessConnectionImpl;
|
| +import org.chromium.content.browser.ChildProcessCreationParams;
|
| +import org.chromium.content.browser.ChildProcessLauncher;
|
| +import org.chromium.content.browser.FileDescriptorInfo;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| import org.chromium.content.browser.test.util.CriteriaHelper;
|
| +import org.chromium.webapk.lib.common.WebApkSandboxedProcessService;
|
|
|
| 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.
|
| @@ -31,6 +35,8 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| private static final String[] sProcessWaitArguments = {
|
| "_", "--" + BaseSwitches.RENDERER_WAIT_FOR_JAVA_DEBUGGER };
|
|
|
| + private static final String TESTING_WEB_APK_PACKAGE_NAME = "org.chromium.webapk.template.test";
|
| +
|
| /**
|
| * Tests cleanup for a connection that fails to connect in the first place.
|
| */
|
| @@ -46,7 +52,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| // (getTargetContext()).
|
| Context context = getInstrumentation().getContext();
|
| ChildProcessLauncher.allocateBoundConnectionForTesting(
|
| - context, getDefaultChildProcessCreationParams(context.getPackageName()));
|
| + context, getChildProcessCreationParams(context.getPackageName(), null));
|
|
|
| // Verify that the connection is not considered as allocated.
|
| CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() {
|
| @@ -171,7 +177,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| final String packageName = appContext.getPackageName();
|
| final boolean inSandbox = true;
|
| ChildProcessLauncher.enqueuePendingSpawnForTesting(appContext, sProcessWaitArguments,
|
| - getDefaultChildProcessCreationParams(packageName), inSandbox);
|
| + getChildProcessCreationParams(packageName, null), inSandbox);
|
| assertEquals(1, ChildProcessLauncher.pendingSpawnsCountForTesting(appContext, packageName,
|
| inSandbox));
|
|
|
| @@ -224,12 +230,80 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| }));
|
| }
|
|
|
| + /**
|
| + * Tests service number of connections for WebAPKs and regular tabs are assigned properly,
|
| + * i.e. from different ChildConnectionAllocators.
|
| + */
|
| + @MediumTest
|
| + @Feature({"ProcessManagement", "webapk"})
|
| + public void testServiceNumberAllocation() throws InterruptedException, RemoteException {
|
| + Context appContext = getInstrumentation().getTargetContext();
|
| + assertEquals(0, ChildProcessLauncher.allocatedSandboxedConnectionsCountForTesting(
|
| + appContext, TESTING_WEB_APK_PACKAGE_NAME));
|
| + assertEquals(0, allocatedChromeSandboxedConnectionsCount());
|
| +
|
| + // Start and connect to a new service of a WebAPK.
|
| + ChildProcessConnectionImpl webapkConnection = startConnection(TESTING_WEB_APK_PACKAGE_NAME,
|
| + WebApkSandboxedProcessService.class);
|
| + // Start and connect to a new service for a regular tab.
|
| + ChildProcessConnectionImpl tabConnection = startConnection();
|
| +
|
| + // Verify that one connection is allocated for a WebAPK and a regular tab respectively.
|
| + assertEquals(1, ChildProcessLauncher.allocatedSandboxedConnectionsCountForTesting(
|
| + appContext, TESTING_WEB_APK_PACKAGE_NAME));
|
| + assertEquals(1, allocatedChromeSandboxedConnectionsCount());
|
| +
|
| + // Verify that connections allocated for a WebAPK and the regular tab are from different
|
| + // ChildConnectionAllocators, since both ChildConnectionAllocators start allocating
|
| + // connections from number 0.
|
| + assertEquals(0, webapkConnection.getServiceNumber());
|
| + assertEquals(0, tabConnection.getServiceNumber());
|
| + }
|
| +
|
| + /**
|
| + * Tests that after reaching the maximum allowed connections for a WebAPK, we can't allocate
|
| + * a new connection to the WebAPK, but we can still allocate a connection for a regular tab.
|
| + */
|
| + @MediumTest
|
| + @Feature({"ProcessManagement", "webapk"})
|
| + @CommandLineFlags.Add(ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FOR_TESTING + "=1")
|
| + public void testExceedMaximumConnectionNumber() throws InterruptedException, RemoteException {
|
| + Context appContext = getInstrumentation().getTargetContext();
|
| + assertEquals(0, ChildProcessLauncher.allocatedSandboxedConnectionsCountForTesting(
|
| + appContext, TESTING_WEB_APK_PACKAGE_NAME));
|
| +
|
| + // Setup a connection for a WebAPK to reach the maximum allowed connection number.
|
| + ChildProcessConnectionImpl webapkConnection = startConnection(TESTING_WEB_APK_PACKAGE_NAME,
|
| + WebApkSandboxedProcessService.class);
|
| + assertNotNull(webapkConnection);
|
| +
|
| + // Verify that there isn't any connection available for the WebAPK.
|
| + ChildProcessConnectionImpl exceedNumberWebapkConnection =
|
| + startConnection(TESTING_WEB_APK_PACKAGE_NAME, WebApkSandboxedProcessService.class);
|
| + assertNull(exceedNumberWebapkConnection);
|
| +
|
| + // Verify that we can still allocate connection for a regular tab.
|
| + ChildProcessConnectionImpl tabConnection = startConnection();
|
| + assertNotNull(tabConnection);
|
| + }
|
| +
|
| private ChildProcessConnectionImpl startConnection() throws InterruptedException {
|
| + Context context = getInstrumentation().getTargetContext();
|
| + return startConnection(context.getPackageName(), null);
|
| + }
|
| +
|
| + private ChildProcessConnectionImpl startConnection(String packageName,
|
| + Class<? extends Service> serviceName)
|
| + throws InterruptedException {
|
| // Allocate a new connection.
|
| Context context = getInstrumentation().getTargetContext();
|
| final ChildProcessConnectionImpl connection =
|
| (ChildProcessConnectionImpl) ChildProcessLauncher.allocateBoundConnectionForTesting(
|
| - context, getDefaultChildProcessCreationParams(context.getPackageName()));
|
| + context, getChildProcessCreationParams(packageName, serviceName));
|
| +
|
| + if (connection == null) {
|
| + return null;
|
| + }
|
|
|
| // Wait for the service to connect.
|
| CriteriaHelper.pollInstrumentationThread(
|
| @@ -251,9 +325,10 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
|
| context, context.getPackageName());
|
| }
|
|
|
| - private ChildProcessCreationParams getDefaultChildProcessCreationParams(String packageName) {
|
| + private ChildProcessCreationParams getChildProcessCreationParams(String packageName,
|
| + Class<? extends Service> serviceName) {
|
| return new ChildProcessCreationParams(packageName, 0,
|
| - LibraryProcessType.PROCESS_CHILD);
|
| + LibraryProcessType.PROCESS_CHILD, serviceName);
|
| }
|
|
|
| private void triggerConnectionSetup(ChildProcessConnectionImpl connection) {
|
|
|