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

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

Issue 2863063002: Making ChildConnectionAllocator simpler. (Closed)
Patch Set: Fixed tests. Created 3 years, 7 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
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.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;
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 } 608 }
609 609
610 private static void enqueuePendingSpawnForTesting(final Context context, 610 private static void enqueuePendingSpawnForTesting(final Context context,
611 final String[] commandLine, final ChildProcessCreationParams creatio nParams, 611 final String[] commandLine, final ChildProcessCreationParams creatio nParams,
612 final boolean inSandbox) { 612 final boolean inSandbox) {
613 ChildProcessLauncherTestUtils.runOnLauncherThreadBlocking(new Runnable() { 613 ChildProcessLauncherTestUtils.runOnLauncherThreadBlocking(new Runnable() {
614 @Override 614 @Override
615 public void run() { 615 public void run() {
616 String packageName = creationParams != null ? creationParams.get PackageName() 616 String packageName = creationParams != null ? creationParams.get PackageName()
617 : context.getPackage Name(); 617 : context.getPackage Name();
618 ChildConnectionAllocator allocator = 618 ChildConnectionAllocator allocator = ChildProcessLauncher.getCon nectionAllocator(
619 ChildConnectionAllocator.getAllocator(context, packageNa me, inSandbox); 619 context, packageName, inSandbox);
620 allocator.enqueuePendingQueueForTesting(new ChildSpawnData(conte xt, commandLine, 620 allocator.enqueuePendingQueueForTesting(new ChildSpawnData(conte xt, commandLine,
621 1 /* childProcessId */, new FileDescriptorInfo[0], 621 1 /* childProcessId */, new FileDescriptorInfo[0],
622 null /* launchCallback */, null /* childProcessCallback */, 622 null /* launchCallback */, null /* childProcessCallback */,
623 true /* inSandbox */, false /* alwaysInForeground */, cr eationParams)); 623 true /* inSandbox */, false /* alwaysInForeground */, cr eationParams));
624 } 624 }
625 }); 625 });
626 } 626 }
627 627
628 private static int allocatedSandboxedConnectionsCountForTesting( 628 private static int allocatedSandboxedConnectionsCountForTesting(
629 final Context context, final String packageName) { 629 final Context context, final String packageName) {
630 return ChildProcessLauncherTestUtils.runOnLauncherAndGetResult( 630 return ChildProcessLauncherTestUtils.runOnLauncherAndGetResult(
631 new Callable<Integer>() { 631 new Callable<Integer>() {
632 @Override 632 @Override
633 public Integer call() { 633 public Integer call() {
634 return ChildConnectionAllocator 634 return ChildProcessLauncher
635 .getAllocator(context, packageName, true /*isSan dboxed */) 635 .getConnectionAllocator(context, packageName, tr ue /*isSandboxed */)
636 .allocatedConnectionsCountForTesting(); 636 .allocatedConnectionsCountForTesting();
637 } 637 }
638 }); 638 });
639 } 639 }
640 640
641 private static BaseChildProcessConnection[] getSandboxedConnectionArrayForTe sting( 641 private static BaseChildProcessConnection[] getSandboxedConnectionArrayForTe sting(
642 final Context context, final String packageName) { 642 final Context context, final String packageName) {
643 return ChildProcessLauncherTestUtils.runOnLauncherAndGetResult( 643 return ChildProcessLauncherTestUtils.runOnLauncherAndGetResult(
644 new Callable<BaseChildProcessConnection[]>() { 644 new Callable<BaseChildProcessConnection[]>() {
645 @Override 645 @Override
646 public BaseChildProcessConnection[] call() { 646 public BaseChildProcessConnection[] call() {
647 return ChildConnectionAllocator 647 return ChildProcessLauncher
648 .getAllocator(context, packageName, true /*isSan dboxed */) 648 .getConnectionAllocator(context, packageName, tr ue /*isSandboxed */)
649 .connectionArrayForTesting(); 649 .connectionArrayForTesting();
650 } 650 }
651 }); 651 });
652 } 652 }
653 653
654 private static int pendingSpawnsCountForTesting( 654 private static int pendingSpawnsCountForTesting(
655 final Context context, final String packageName, final boolean inSan dbox) { 655 final Context context, final String packageName, final boolean inSan dbox) {
656 return ChildProcessLauncherTestUtils.runOnLauncherAndGetResult( 656 return ChildProcessLauncherTestUtils.runOnLauncherAndGetResult(
657 new Callable<Integer>() { 657 new Callable<Integer>() {
658 @Override 658 @Override
659 public Integer call() { 659 public Integer call() {
660 return ChildConnectionAllocator 660 return ChildProcessLauncher
661 .getAllocator(context, packageName, inSandbox) 661 .getConnectionAllocator(context, packageName, in Sandbox)
662 .pendingSpawnsCountForTesting(); 662 .pendingSpawnsCountForTesting();
663 } 663 }
664 }); 664 });
665 } 665 }
666 666
667 /** 667 /**
668 * Returns the number of Chrome's sandboxed connections. 668 * Returns the number of Chrome's sandboxed connections.
669 */ 669 */
670 private int allocatedChromeSandboxedConnectionsCount() { 670 private int allocatedChromeSandboxedConnectionsCount() {
671 Context context = InstrumentationRegistry.getInstrumentation().getTarget Context(); 671 Context context = InstrumentationRegistry.getInstrumentation().getTarget Context();
672 return allocatedSandboxedConnectionsCountForTesting(context, context.get PackageName()); 672 return allocatedSandboxedConnectionsCountForTesting(context, context.get PackageName());
673 } 673 }
674 674
675 private ChildProcessCreationParams getDefaultChildProcessCreationParams(Stri ng packageName) { 675 private ChildProcessCreationParams getDefaultChildProcessCreationParams(Stri ng packageName) {
676 return new ChildProcessCreationParams(packageName, false /* isExternalSe rvice */, 676 return new ChildProcessCreationParams(packageName, false /* isExternalSe rvice */,
677 LibraryProcessType.PROCESS_CHILD, false /* bindToCallerCheck */) ; 677 LibraryProcessType.PROCESS_CHILD, false /* bindToCallerCheck */) ;
678 } 678 }
679 679
680 private void triggerConnectionSetup(final BaseChildProcessConnection connect ion) { 680 private void triggerConnectionSetup(final BaseChildProcessConnection connect ion) {
681 ChildProcessLauncherTestUtils.runOnLauncherThreadBlocking(new Runnable() { 681 ChildProcessLauncherTestUtils.runOnLauncherThreadBlocking(new Runnable() {
682 @Override 682 @Override
683 public void run() { 683 public void run() {
684 ChildProcessLauncher.triggerConnectionSetup(connection, sProcess WaitArguments, 684 ChildProcessLauncher.triggerConnectionSetup(connection, sProcess WaitArguments,
685 1 /* childProcessId */, new FileDescriptorInfo[0], 685 1 /* childProcessId */, new FileDescriptorInfo[0],
686 null /* launchCallback */, null /* childProcessCallback */); 686 null /* launchCallback */, null /* childProcessCallback */);
687 } 687 }
688 }); 688 });
689 } 689 }
690 } 690 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698