OLD | NEW |
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.ComponentName; | 7 import android.content.ComponentName; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.ServiceConnection; | 10 import android.content.ServiceConnection; |
11 import android.os.Handler; | 11 import android.os.Handler; |
12 import android.os.IBinder; | 12 import android.os.IBinder; |
13 import android.os.Looper; | 13 import android.os.Looper; |
14 import android.os.Message; | 14 import android.os.Message; |
15 import android.os.Messenger; | 15 import android.os.Messenger; |
16 import android.os.RemoteException; | 16 import android.os.RemoteException; |
17 import android.support.test.filters.MediumTest; | 17 import android.support.test.filters.MediumTest; |
18 import android.test.InstrumentationTestCase; | 18 import android.test.InstrumentationTestCase; |
19 | 19 |
20 import org.chromium.base.BaseSwitches; | 20 import org.chromium.base.BaseSwitches; |
21 import org.chromium.base.ThreadUtils; | 21 import org.chromium.base.ThreadUtils; |
22 import org.chromium.base.library_loader.LibraryLoader; | 22 import org.chromium.base.library_loader.LibraryLoader; |
23 import org.chromium.base.library_loader.LibraryProcessType; | 23 import org.chromium.base.library_loader.LibraryProcessType; |
24 import org.chromium.base.process_launcher.ChildProcessCreationParams; | 24 import org.chromium.base.process_launcher.ChildProcessCreationParams; |
25 import org.chromium.base.process_launcher.FileDescriptorInfo; | 25 import org.chromium.base.process_launcher.FileDescriptorInfo; |
26 import org.chromium.base.test.util.CommandLineFlags; | |
27 import org.chromium.base.test.util.Feature; | 26 import org.chromium.base.test.util.Feature; |
| 27 import org.chromium.content.browser.test.ChildProcessAllocatorSettings; |
28 import org.chromium.content.browser.test.util.Criteria; | 28 import org.chromium.content.browser.test.util.Criteria; |
29 import org.chromium.content.browser.test.util.CriteriaHelper; | 29 import org.chromium.content.browser.test.util.CriteriaHelper; |
30 import org.chromium.content.common.ContentSwitches; | 30 import org.chromium.content.common.ContentSwitches; |
31 import org.chromium.content_shell_apk.ChildProcessLauncherTestHelperService; | 31 import org.chromium.content_shell_apk.ChildProcessLauncherTestHelperService; |
32 | 32 |
33 import java.util.concurrent.Callable; | 33 import java.util.concurrent.Callable; |
34 import java.util.concurrent.Semaphore; | 34 import java.util.concurrent.Semaphore; |
35 | 35 |
36 /** | 36 /** |
37 * Instrumentation tests for ChildProcessLauncher. | 37 * Instrumentation tests for ChildProcessLauncher. |
(...skipping 12 matching lines...) Expand all Loading... |
50 protected void setUp() throws Exception { | 50 protected void setUp() throws Exception { |
51 super.setUp(); | 51 super.setUp(); |
52 LibraryLoader.get(LibraryProcessType.PROCESS_CHILD).ensureInitialized(); | 52 LibraryLoader.get(LibraryProcessType.PROCESS_CHILD).ensureInitialized(); |
53 } | 53 } |
54 | 54 |
55 /** | 55 /** |
56 * Tests cleanup for a connection that fails to connect in the first place. | 56 * Tests cleanup for a connection that fails to connect in the first place. |
57 */ | 57 */ |
58 @MediumTest | 58 @MediumTest |
59 @Feature({"ProcessManagement"}) | 59 @Feature({"ProcessManagement"}) |
60 @CommandLineFlags.Add(ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FOR
_TESTING + "=4") | 60 @ChildProcessAllocatorSettings(sandboxedServiceCount = 4) |
61 public void testServiceFailedToBind() { | 61 public void testServiceFailedToBind() { |
62 assertEquals(0, allocatedChromeSandboxedConnectionsCount()); | 62 assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
63 assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting())
; | 63 assertEquals(0, ChildProcessLauncher.connectedServicesCountForTesting())
; |
64 | 64 |
65 // Try to allocate a connection to service class in incorrect package. W
e can do that by | 65 // Try to allocate a connection to service class in incorrect package. W
e can do that by |
66 // using the instrumentation context (getContext()) instead of the app c
ontext | 66 // using the instrumentation context (getContext()) instead of the app c
ontext |
67 // (getTargetContext()). | 67 // (getTargetContext()). |
68 Context context = getInstrumentation().getContext(); | 68 Context context = getInstrumentation().getContext(); |
69 ChildProcessLauncher.allocateBoundConnectionForTesting( | 69 ChildProcessLauncher.allocateBoundConnectionForTesting( |
70 context, getDefaultChildProcessCreationParams(context.getPackage
Name())); | 70 context, getDefaultChildProcessCreationParams(context.getPackage
Name())); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 244 } |
245 })); | 245 })); |
246 } | 246 } |
247 | 247 |
248 /** | 248 /** |
249 * Tests service number of connections for external APKs and regular tabs ar
e assigned properly, | 249 * Tests service number of connections for external APKs and regular tabs ar
e assigned properly, |
250 * i.e. from different ChildConnectionAllocators. | 250 * i.e. from different ChildConnectionAllocators. |
251 */ | 251 */ |
252 @MediumTest | 252 @MediumTest |
253 @Feature({"ProcessManagement"}) | 253 @Feature({"ProcessManagement"}) |
254 @CommandLineFlags.Add({ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FO
R_TESTING + "=4", | 254 @ChildProcessAllocatorSettings( |
255 ChildProcessLauncher.SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING + "=
" | 255 sandboxedServiceCount = 4, sandboxedServiceName = DEFAULT_SANDBOXED_
PROCESS_SERVICE) |
256 + DEFAULT_SANDBOXED_PROCESS_SERVICE}) | |
257 public void testServiceNumberAllocation() { | 256 public void testServiceNumberAllocation() { |
258 Context appContext = getInstrumentation().getTargetContext(); | 257 Context appContext = getInstrumentation().getTargetContext(); |
259 assertEquals(0, ChildProcessLauncher.allocatedSandboxedConnectionsCountF
orTesting( | 258 assertEquals(0, ChildProcessLauncher.allocatedSandboxedConnectionsCountF
orTesting( |
260 appContext, EXTERNAL_APK_PACKAGE_NAME)); | 259 appContext, EXTERNAL_APK_PACKAGE_NAME)); |
261 assertEquals(0, allocatedChromeSandboxedConnectionsCount()); | 260 assertEquals(0, allocatedChromeSandboxedConnectionsCount()); |
262 | 261 |
263 // Start and connect to a new service of an external APK. | 262 // Start and connect to a new service of an external APK. |
264 ChildProcessConnectionImpl externalApkConnection = | 263 ChildProcessConnectionImpl externalApkConnection = |
265 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); | 264 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); |
266 // Start and connect to a new service for a regular tab. | 265 // Start and connect to a new service for a regular tab. |
(...skipping 12 matching lines...) Expand all Loading... |
279 assertEquals(0, tabConnection.getServiceNumber()); | 278 assertEquals(0, tabConnection.getServiceNumber()); |
280 } | 279 } |
281 | 280 |
282 /** | 281 /** |
283 * Tests that after reaching the maximum allowed connections for an external
APK, we can't | 282 * Tests that after reaching the maximum allowed connections for an external
APK, we can't |
284 * allocate a new connection to the APK, but we can still allocate a connect
ion for a regular | 283 * allocate a new connection to the APK, but we can still allocate a connect
ion for a regular |
285 * tab. | 284 * tab. |
286 */ | 285 */ |
287 @MediumTest | 286 @MediumTest |
288 @Feature({"ProcessManagement"}) | 287 @Feature({"ProcessManagement"}) |
289 @CommandLineFlags.Add({ChildProcessLauncher.SWITCH_NUM_SANDBOXED_SERVICES_FO
R_TESTING + "=1", | 288 @ChildProcessAllocatorSettings( |
290 ChildProcessLauncher.SWITCH_SANDBOXED_SERVICES_NAME_FOR_TESTING + "=
" | 289 sandboxedServiceCount = 1, sandboxedServiceName = DEFAULT_SANDBOXED_
PROCESS_SERVICE) |
291 + DEFAULT_SANDBOXED_PROCESS_SERVICE}) | |
292 public void testExceedMaximumConnectionNumber() { | 290 public void testExceedMaximumConnectionNumber() { |
293 Context appContext = getInstrumentation().getTargetContext(); | 291 Context appContext = getInstrumentation().getTargetContext(); |
294 assertEquals(0, ChildProcessLauncher.allocatedSandboxedConnectionsCountF
orTesting( | 292 assertEquals(0, ChildProcessLauncher.allocatedSandboxedConnectionsCountF
orTesting( |
295 appContext, EXTERNAL_APK_PACKAGE_NAME)); | 293 appContext, EXTERNAL_APK_PACKAGE_NAME)); |
296 | 294 |
297 // Setup a connection for an external APK to reach the maximum allowed c
onnection number. | 295 // Setup a connection for an external APK to reach the maximum allowed c
onnection number. |
298 ChildProcessConnectionImpl externalApkConnection = | 296 ChildProcessConnectionImpl externalApkConnection = |
299 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); | 297 allocateConnection(EXTERNAL_APK_PACKAGE_NAME); |
300 assertNotNull(externalApkConnection); | 298 assertNotNull(externalApkConnection); |
301 | 299 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 return new ChildProcessCreationParams(packageName, false /* isExternalSe
rvice */, | 569 return new ChildProcessCreationParams(packageName, false /* isExternalSe
rvice */, |
572 LibraryProcessType.PROCESS_CHILD, false /* bindToCallerCheck */)
; | 570 LibraryProcessType.PROCESS_CHILD, false /* bindToCallerCheck */)
; |
573 } | 571 } |
574 | 572 |
575 private void triggerConnectionSetup(ChildProcessConnectionImpl connection) { | 573 private void triggerConnectionSetup(ChildProcessConnectionImpl connection) { |
576 ChildProcessLauncher.triggerConnectionSetup(connection, sProcessWaitArgu
ments, | 574 ChildProcessLauncher.triggerConnectionSetup(connection, sProcessWaitArgu
ments, |
577 1 /* childProcessId */, new FileDescriptorInfo[0], null /* launc
hCallback */, | 575 1 /* childProcessId */, new FileDescriptorInfo[0], null /* launc
hCallback */, |
578 null /* childProcessCallback */); | 576 null /* childProcessCallback */); |
579 } | 577 } |
580 } | 578 } |
OLD | NEW |