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

Side by Side 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: Fix test failures. Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.RemoteException; 8 import android.os.RemoteException;
9 import android.test.InstrumentationTestCase; 9 import android.test.InstrumentationTestCase;
10 import android.test.suitebuilder.annotation.MediumTest; 10 import android.test.suitebuilder.annotation.MediumTest;
11 11
12 import org.chromium.base.BaseSwitches; 12 import org.chromium.base.BaseSwitches;
13 import org.chromium.base.library_loader.LibraryLoader; 13 import org.chromium.base.library_loader.LibraryLoader;
14 import org.chromium.base.library_loader.LibraryProcessType; 14 import org.chromium.base.library_loader.LibraryProcessType;
15 import org.chromium.base.test.util.CommandLineFlags; 15 import org.chromium.base.test.util.CommandLineFlags;
16 import org.chromium.base.test.util.Feature; 16 import org.chromium.base.test.util.Feature;
17 import org.chromium.content.browser.test.util.Criteria; 17 import org.chromium.content.browser.test.util.Criteria;
18 import org.chromium.content.browser.test.util.CriteriaHelper; 18 import org.chromium.content.browser.test.util.CriteriaHelper;
19 19
20 import java.util.concurrent.Callable; 20 import java.util.concurrent.Callable;
21 21
22 /** 22 /**
23 * Instrumentation tests for ChildProcessLauncher. 23 * Instrumentation tests for ChildProcessLauncher.
24 * TODO(hanxi): Add tests for assigning {@ChildConnectionAllocator} for differen t package names
25 * when render processes can be run in WebAPKs.
26 */ 24 */
27 public class ChildProcessLauncherTest extends InstrumentationTestCase { 25 public class ChildProcessLauncherTest extends InstrumentationTestCase {
28 // Pseudo command line arguments to instruct the child process to wait until being killed. 26 // Pseudo command line arguments to instruct the child process to wait until being killed.
29 // Allowing the process to continue would lead to a crash when attempting to initialize IPC 27 // Allowing the process to continue would lead to a crash when attempting to initialize IPC
30 // channels that are not being set up in this test. 28 // channels that are not being set up in this test.
31 private static final String[] sProcessWaitArguments = { 29 private static final String[] sProcessWaitArguments = {
32 "_", "--" + BaseSwitches.RENDERER_WAIT_FOR_JAVA_DEBUGGER }; 30 "_", "--" + BaseSwitches.RENDERER_WAIT_FOR_JAVA_DEBUGGER };
31 private static final String EXTERNAL_APK_PACKAGE_NAME = "org.chromium.extern al.apk";
32 private static final String DEFAULT_SANDBOXED_PROCESS_SERVICE =
33 "org.chromium.content.app.SandboxedProcessService";
33 34
34 /** 35 /**
35 * Tests cleanup for a connection that fails to connect in the first place. 36 * Tests cleanup for a connection that fails to connect in the first place.
36 */ 37 */
37 @MediumTest 38 @MediumTest
38 @Feature({"ProcessManagement"}) 39 @Feature({"ProcessManagement"})
39 @CommandLineFlags.Add(ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FOR _TESTING + "=4") 40 @CommandLineFlags.Add(ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FOR _TESTING + "=4")
40 public void testServiceFailedToBind() throws InterruptedException, RemoteExc eption { 41 public void testServiceFailedToBind() throws InterruptedException, RemoteExc eption {
41 assertEquals(0, allocatedChromeSandboxedConnectionsCount()); 42 assertEquals(0, allocatedChromeSandboxedConnectionsCount());
42 assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting()) ; 43 assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting()) ;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 218
218 // Verify that the connection completes the setup for the pending spawn. 219 // Verify that the connection completes the setup for the pending spawn.
219 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable <Integer>() { 220 CriteriaHelper.pollInstrumentationThread(Criteria.equals(1, new Callable <Integer>() {
220 @Override 221 @Override
221 public Integer call() { 222 public Integer call() {
222 return ChildProcessLauncher.connectedServicesCountForTesting(); 223 return ChildProcessLauncher.connectedServicesCountForTesting();
223 } 224 }
224 })); 225 }));
225 } 226 }
226 227
228 /**
229 * Tests service number of connections for external APKs and regular tabs ar e assigned properly,
230 * i.e. from different ChildConnectionAllocators.
231 */
232 @MediumTest
233 @Feature({"ProcessManagement"})
234 @CommandLineFlags.Add({ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FO R_TESTING + "=4",
235 ChildProcessLauncher.SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING + "= "
236 + DEFAULT_SANDBOXED_PROCESS_SERVICE})
237 public void testServiceNumberAllocation() throws InterruptedException {
238 Context appContext = getInstrumentation().getTargetContext();
239 assertEquals(0, ChildProcessLauncher.allocatedSandboxedConnectionsCountF orTesting(
240 appContext, EXTERNAL_APK_PACKAGE_NAME));
241 assertEquals(0, allocatedChromeSandboxedConnectionsCount());
242
243 // Start and connect to a new service of an external APK.
244 ChildProcessConnectionImpl externalApkConnection =
245 allocateConnection(EXTERNAL_APK_PACKAGE_NAME);
246 // Start and connect to a new service for a regular tab.
247 ChildProcessConnectionImpl tabConnection = allocateConnection(appContext .getPackageName());
248
249 // Verify that one connection is allocated for an external APK and a reg ular tab
250 // respectively.
251 assertEquals(1, ChildProcessLauncher.allocatedSandboxedConnectionsCountF orTesting(
252 appContext, EXTERNAL_APK_PACKAGE_NAME));
253 assertEquals(1, allocatedChromeSandboxedConnectionsCount());
254
255 // Verify that connections allocated for an external APK and the regular tab are from
256 // different ChildConnectionAllocators, since both ChildConnectionAlloca tors start
257 // allocating connections from number 0.
258 assertEquals(0, externalApkConnection.getServiceNumber());
259 assertEquals(0, tabConnection.getServiceNumber());
260 }
261
262 /**
263 * Tests that after reaching the maximum allowed connections for an external APK, we can't
264 * allocate a new connection to the APK, but we can still allocate a connect ion for a regular
265 * tab.
266 */
267 @MediumTest
268 @Feature({"ProcessManagement"})
269 @CommandLineFlags.Add({ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FO R_TESTING + "=1",
270 ChildProcessLauncher.SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING + "= "
271 + DEFAULT_SANDBOXED_PROCESS_SERVICE})
272 public void testExceedMaximumConnectionNumber() throws InterruptedException, RemoteException {
273 Context appContext = getInstrumentation().getTargetContext();
274 assertEquals(0, ChildProcessLauncher.allocatedSandboxedConnectionsCountF orTesting(
275 appContext, EXTERNAL_APK_PACKAGE_NAME));
276
277 // Setup a connection for an external APK to reach the maximum allowed c onnection number.
278 ChildProcessConnectionImpl externalApkConnection =
279 allocateConnection(EXTERNAL_APK_PACKAGE_NAME);
280 assertNotNull(externalApkConnection);
281
282 // Verify that there isn't any connection available for the external APK .
283 ChildProcessConnectionImpl exceedNumberExternalApkConnection =
284 allocateConnection(EXTERNAL_APK_PACKAGE_NAME);
285 assertNull(exceedNumberExternalApkConnection);
286
287 // Verify that we can still allocate connection for a regular tab.
288 ChildProcessConnectionImpl tabConnection = allocateConnection(appContext .getPackageName());
289 assertNotNull(tabConnection);
290 }
291
227 private ChildProcessConnectionImpl startConnection() throws InterruptedExcep tion { 292 private ChildProcessConnectionImpl startConnection() throws InterruptedExcep tion {
228 // Allocate a new connection. 293 // Allocate a new connection.
229 Context context = getInstrumentation().getTargetContext(); 294 Context context = getInstrumentation().getTargetContext();
230 final ChildProcessConnectionImpl connection = 295 final ChildProcessConnectionImpl connection =
231 (ChildProcessConnectionImpl) ChildProcessLauncher.allocateBoundC onnectionForTesting( 296 (ChildProcessConnectionImpl) ChildProcessLauncher.allocateBoundC onnectionForTesting(
232 context, getDefaultChildProcessCreationParams(context.ge tPackageName())); 297 context, getDefaultChildProcessCreationParams(context.ge tPackageName()));
233 298
234 // Wait for the service to connect. 299 // Wait for the service to connect.
235 CriteriaHelper.pollInstrumentationThread( 300 CriteriaHelper.pollInstrumentationThread(
236 new Criteria("The connection wasn't established.") { 301 new Criteria("The connection wasn't established.") {
237 @Override 302 @Override
238 public boolean isSatisfied() { 303 public boolean isSatisfied() {
239 return connection.isConnected(); 304 return connection.isConnected();
240 } 305 }
241 }); 306 });
242 return connection; 307 return connection;
243 } 308 }
244 309
245 /** 310 /**
311 * Returns a new connection if it is allocated. Note this function only allo cates a connection
312 * but doesn't really start the connection to bind a service. It is for test ing whether the
313 * connection is allocated properly for different application packages.
314 */
315 private ChildProcessConnectionImpl allocateConnection(String packageName) {
316 // Allocate a new connection.
317 Context context = getInstrumentation().getTargetContext();
318 return (ChildProcessConnectionImpl) ChildProcessLauncher.allocateConnect ionForTesting(
319 context, getDefaultChildProcessCreationParams(packageNam e));
320 }
321
322 /**
246 * Returns the number of Chrome's sandboxed connections. 323 * Returns the number of Chrome's sandboxed connections.
247 */ 324 */
248 private int allocatedChromeSandboxedConnectionsCount() { 325 private int allocatedChromeSandboxedConnectionsCount() {
249 Context context = getInstrumentation().getTargetContext(); 326 Context context = getInstrumentation().getTargetContext();
250 return ChildProcessLauncher.allocatedSandboxedConnectionsCountForTesting ( 327 return ChildProcessLauncher.allocatedSandboxedConnectionsCountForTesting (
251 context, context.getPackageName()); 328 context, context.getPackageName());
252 } 329 }
253 330
254 private ChildProcessCreationParams getDefaultChildProcessCreationParams(Stri ng packageName) { 331 private ChildProcessCreationParams getDefaultChildProcessCreationParams(Stri ng packageName) {
255 return new ChildProcessCreationParams(packageName, 0, 332 return new ChildProcessCreationParams(packageName, 0,
256 LibraryProcessType.PROCESS_CHILD); 333 LibraryProcessType.PROCESS_CHILD);
257 } 334 }
258 335
259 private void triggerConnectionSetup(ChildProcessConnectionImpl connection) { 336 private void triggerConnectionSetup(ChildProcessConnectionImpl connection) {
260 ChildProcessLauncher.triggerConnectionSetup(connection, sProcessWaitArgu ments, 1, 337 ChildProcessLauncher.triggerConnectionSetup(connection, sProcessWaitArgu ments, 1,
261 new FileDescriptorInfo[0], ChildProcessLauncher.CALLBACK_FOR_REN DERER_PROCESS, 0); 338 new FileDescriptorInfo[0], ChildProcessLauncher.CALLBACK_FOR_REN DERER_PROCESS, 0);
262 } 339 }
263 340
264 @Override 341 @Override
265 protected void setUp() throws Exception { 342 protected void setUp() throws Exception {
266 super.setUp(); 343 super.setUp();
267 LibraryLoader.get(LibraryProcessType.PROCESS_CHILD) 344 LibraryLoader.get(LibraryProcessType.PROCESS_CHILD)
268 .ensureInitialized(getInstrumentation().getTargetContext()); 345 .ensureInitialized(getInstrumentation().getTargetContext());
269 } 346 }
270 } 347 }
OLDNEW
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ChildProcessLauncher.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698