Chromium Code Reviews| 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 2481eaafde431ee9496a296365aeee61e9578399..7a565fdd923a2dda8677dad93a26738fc3ae6236 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 |
| @@ -24,7 +24,7 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
| @MediumTest |
| @Feature({"ProcessManagement"}) |
| public void testServiceFailedToBind() throws InterruptedException, RemoteException { |
| - Context appContext = getInstrumentation().getTargetContext(); |
| + final Context appContext = getInstrumentation().getTargetContext(); |
| assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
| assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting()); |
| @@ -35,8 +35,22 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
| ChildProcessLauncher.allocateBoundConnectionForTesting(context); |
| // Verify that the connection is not considered as allocated. |
| - assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
| - assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting()); |
| + assertTrue("Crashed connection wasn't released from the allocator.", |
| + CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return ChildProcessLauncher.allocatedConnectionsCountForTesting( |
|
ppi
2014/12/19 12:28:52
To reliably ensure that the connection was not all
auygun
2014/12/19 13:18:17
Sure. I'll also change the assert below. It doesn'
|
| + appContext) == 0; |
| + } |
| + })); |
| + |
| + assertTrue("Crashed connection wasn't released from ChildProcessLauncher.", |
| + CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return ChildProcessLauncher.connectedServicesCountForTesting() == 0; |
| + } |
| + })); |
| } |
| /** |
| @@ -138,6 +152,75 @@ public class ChildProcessLauncherTest extends InstrumentationTestCase { |
| assertTrue(connection.getPid() != 0); |
| } |
| + /** |
| + * Tests spawning a pending process from queue. |
| + */ |
| + @MediumTest |
| + @Feature({"ProcessManagement"}) |
| + public void testPendingSpawnQueue() throws InterruptedException, RemoteException { |
| + final Context appContext = getInstrumentation().getTargetContext(); |
| + assertEquals(0, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
| + |
| + // Start and connect to a new service. |
| + final ChildProcessConnectionImpl connection = startConnection(); |
| + assertEquals(1, ChildProcessLauncher.allocatedConnectionsCountForTesting(appContext)); |
| + |
| + // Queue up a a new spawn request. |
| + ChildProcessLauncher.enqueuePendingSpawnForTesting(appContext); |
| + assertEquals(1, ChildProcessLauncher.pendingSpawnsCountForTesting()); |
| + |
| + // Initiate the connection setup. |
| + ChildProcessLauncher.triggerConnectionSetup(connection, new String[0], 1, |
| + new FileDescriptorInfo[0], ChildProcessLauncher.CALLBACK_FOR_RENDERER_PROCESS, 0); |
| + |
| + // Verify that the connection completes the setup. |
| + assertTrue("The connection wasn't registered in ChildProcessLauncher after setup.", |
| + CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return ChildProcessLauncher.connectedServicesCountForTesting() == 1; |
| + } |
| + })); |
| + |
| + assertTrue("The connection failed to get a pid in setup.", |
| + CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return connection.getPid() != 0; |
| + } |
| + })); |
| + |
| + // Crash the service. |
| + assertTrue(connection.crashServiceForTesting()); |
| + |
| + // Verify that a new service is started for the pending spawn. |
| + assertTrue("Failed to spawn from queue.", |
| + CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return ChildProcessLauncher.pendingSpawnsCountForTesting() == 0; |
| + } |
| + })); |
| + |
| + assertTrue("The connection wasn't allocated for the pending spawn.", |
| + CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return ChildProcessLauncher.allocatedConnectionsCountForTesting( |
| + appContext) == 1; |
| + } |
| + })); |
| + |
| + // Verify that the connection completes the setup for the pending spawn. |
| + assertTrue("The connection wasn't registered in ChildProcessLauncher after setup.", |
| + CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return ChildProcessLauncher.connectedServicesCountForTesting() == 1; |
| + } |
| + })); |
| + } |
| + |
| private ChildProcessConnectionImpl startConnection() throws InterruptedException { |
| // Allocate a new connection. |
| Context context = getInstrumentation().getTargetContext(); |