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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ChildProcessLauncherTest.java

Issue 2076583002: Add WebAPK's tests in ChildProcessLauncherTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move all tests to //content. Created 4 years, 6 months 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
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..d34dffe0cecdd362bd5a3ad7a79c13577b8dd05d 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
@@ -21,8 +21,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.
@@ -30,6 +28,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
// channels that are not being set up in this test.
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.
@@ -224,6 +223,66 @@ 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"})
+ @CommandLineFlags.Add(ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FOR_TESTING + "=4")
+ public void testServiceNumberAllocation() throws InterruptedException {
+ 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 =
+ allocateConnection(TESTING_WEB_APK_PACKAGE_NAME);
+ // Start and connect to a new service for a regular tab.
+ ChildProcessConnectionImpl tabConnection =
+ allocateConnection(appContext.getPackageName());
+
+ // 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 =
+ allocateConnection(TESTING_WEB_APK_PACKAGE_NAME);
+ assertNotNull(webapkConnection);
+
+ // Verify that there isn't any connection available for the WebAPK.
+ ChildProcessConnectionImpl exceedNumberWebapkConnection =
+ allocateConnection(TESTING_WEB_APK_PACKAGE_NAME);
+ assertNull(exceedNumberWebapkConnection);
+
+ // Verify that we can still allocate connection for a regular tab.
+ ChildProcessConnectionImpl tabConnection =
+ allocateConnection(appContext.getPackageName());
+ assertNotNull(tabConnection);
+ }
+
private ChildProcessConnectionImpl startConnection() throws InterruptedException {
// Allocate a new connection.
Context context = getInstrumentation().getTargetContext();
@@ -243,6 +302,18 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase {
}
/**
+ * Returns a new connection if it is allocated. Note this function only allocates a connection
+ * but doesn't really start the connection to bind a service. It is for testing whether the
+ * connection is allocated properly for different application packages.
+ */
+ private ChildProcessConnectionImpl allocateConnection(String packageName) {
+ // Allocate a new connection.
+ Context context = getInstrumentation().getTargetContext();
+ return (ChildProcessConnectionImpl) ChildProcessLauncher.allocateConnectionForTesting(
+ context, getDefaultChildProcessCreationParams(packageName));
+ }
+
+ /**
* Returns the number of Chrome's sandboxed connections.
*/
private int allocatedChromeSandboxedConnectionsCount() {

Powered by Google App Engine
This is Rietveld 408576698