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 77016cd3daf8d1b16c54dcc53a60a84baadc35b4..1f0c700a0bdd0eb11118f96f185f65b08645e0ba 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 |
@@ -12,6 +12,7 @@ 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.util.Criteria; |
import org.chromium.content.browser.test.util.CriteriaHelper; |
@@ -20,6 +21,8 @@ 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. |
@@ -33,23 +36,24 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
*/ |
@MediumTest |
@Feature({"ProcessManagement"}) |
+ @CommandLineFlags.Add(ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FOR_TESTING + "=4") |
public void testServiceFailedToBind() throws InterruptedException, RemoteException { |
- final Context appContext = getInstrumentation().getTargetContext(); |
- assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
+ assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
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(); |
- ChildProcessLauncher.allocateBoundConnectionForTesting(context); |
+ ChildProcessLauncher.allocateBoundConnectionForTesting( |
+ context, new ChildProcessCreationParams(context.getPackageName(), 0, |
+ LibraryProcessType.PROCESS_CHILD)); |
// Verify that the connection is not considered as allocated. |
CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() { |
@Override |
public Integer call() { |
- return ChildProcessLauncher.allocatedConnectionsCountForTesting( |
- appContext); |
+ return allocatedChromeSandboxedConnectionsCount(); |
} |
})); |
@@ -67,13 +71,12 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
@MediumTest |
@Feature({"ProcessManagement"}) |
public void testServiceCrashedBeforeSetup() throws InterruptedException, RemoteException { |
- final Context appContext = getInstrumentation().getTargetContext(); |
- assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
+ assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting()); |
// Start and connect to a new service. |
final ChildProcessConnectionImpl connection = startConnection(); |
- assertEquals(1, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
+ assertEquals(1, allocatedChromeSandboxedConnectionsCount()); |
// Verify that the service is not yet set up. |
assertEquals(0, connection.getPid()); |
@@ -86,8 +89,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() { |
@Override |
public Integer call() { |
- return ChildProcessLauncher.allocatedConnectionsCountForTesting( |
- appContext); |
+ return allocatedChromeSandboxedConnectionsCount(); |
} |
})); |
@@ -105,12 +107,11 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
@MediumTest |
@Feature({"ProcessManagement"}) |
public void testServiceCrashedAfterSetup() throws InterruptedException, RemoteException { |
- final Context appContext = getInstrumentation().getTargetContext(); |
- assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
+ assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
// Start and connect to a new service. |
final ChildProcessConnectionImpl connection = startConnection(); |
- assertEquals(1, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
+ assertEquals(1, allocatedChromeSandboxedConnectionsCount()); |
// Initiate the connection setup. |
triggerConnectionSetup(connection); |
@@ -138,8 +139,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
CriteriaHelper.pollInstrumentationThread(Criteria.equals(0, new Callable<Integer>() { |
@Override |
public Integer call() { |
- return ChildProcessLauncher.allocatedConnectionsCountForTesting( |
- appContext); |
+ return allocatedChromeSandboxedConnectionsCount(); |
} |
})); |
@@ -161,11 +161,11 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
@Feature({"ProcessManagement"}) |
public void testPendingSpawnQueue() throws InterruptedException, RemoteException { |
final Context appContext = getInstrumentation().getTargetContext(); |
- assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
+ assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
// Start and connect to a new service. |
final ChildProcessConnectionImpl connection = startConnection(); |
- assertEquals(1, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
+ assertEquals(1, allocatedChromeSandboxedConnectionsCount()); |
// Queue up a new spawn request. There is no way to kill the pending connection, leak it |
// until the browser restart. |
@@ -207,8 +207,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
Criteria.equals(1, new Callable<Integer>() { |
@Override |
public Integer call() { |
- return ChildProcessLauncher.allocatedConnectionsCountForTesting( |
- appContext); |
+ return allocatedChromeSandboxedConnectionsCount(); |
} |
})); |
@@ -224,8 +223,10 @@ 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); |
+ final ChildProcessConnectionImpl connection = |
+ (ChildProcessConnectionImpl) ChildProcessLauncher.allocateBoundConnectionForTesting( |
+ context, new ChildProcessCreationParams(context.getPackageName(), 0, |
+ LibraryProcessType.PROCESS_CHILD)); |
// Wait for the service to connect. |
CriteriaHelper.pollInstrumentationThread( |
@@ -238,6 +239,15 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
return connection; |
} |
+ /** |
+ * Returns the number of Chrome's sandboxed connections. |
+ */ |
+ private int allocatedChromeSandboxedConnectionsCount() { |
+ Context context = getInstrumentation().getTargetContext(); |
+ return ChildProcessLauncher.allocatedSandboxedConnectionsCountForTesting( |
+ context, context.getPackageName()); |
+ } |
+ |
private void triggerConnectionSetup(ChildProcessConnectionImpl connection) { |
ChildProcessLauncher.triggerConnectionSetup(connection, sProcessWaitArguments, 1, |
new FileDescriptorInfo[0], ChildProcessLauncher.CALLBACK_FOR_RENDERER_PROCESS, 0); |