Index: content/public/test/android/javatests/src/org/chromium/content/browser/test/ChildProcessLauncherTestHelper.java |
diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/ChildProcessLauncherTestHelper.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/ChildProcessLauncherTestHelper.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ee84a37b092acdb705a92bedf41172c68cc6eb68 |
--- /dev/null |
+++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/ChildProcessLauncherTestHelper.java |
@@ -0,0 +1,74 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.content.browser.test; |
+ |
+import android.app.Service; |
+import android.content.Context; |
+ |
+import org.chromium.base.library_loader.LibraryLoader; |
+import org.chromium.base.library_loader.LibraryProcessType; |
+import org.chromium.content.browser.ChildProcessConnectionImpl; |
+import org.chromium.content.browser.ChildProcessCreationParams; |
+import org.chromium.content.browser.ChildProcessLauncher; |
+import org.chromium.content.browser.test.util.Criteria; |
+import org.chromium.content.browser.test.util.CriteriaHelper; |
+ |
+/** |
+ * A helper class for {@link ChildProcessLauncherTest} and its subclass |
+ * {@link ChromeChildProcessLauncherTest}. |
+ */ |
+public class ChildProcessLauncherTestHelper { |
+ |
+ /** |
+ * Returns the number of Chrome's sandboxed connections. |
+ */ |
+ public static int allocatedChromeSandboxedConnectionsCount(Context context) { |
+ return ChildProcessLauncher.allocatedSandboxedConnectionsCountForTesting( |
+ context, context.getPackageName()); |
+ } |
+ |
+ /** |
+ * Returns whether the connection is established and connected. |
+ */ |
+ public static ChildProcessConnectionImpl startConnection(Context context, String packageName, |
+ Class<? extends Service> servicecClass) |
+ throws InterruptedException { |
+ // Allocate a new connection. |
+ final ChildProcessConnectionImpl connection = |
+ (ChildProcessConnectionImpl) ChildProcessLauncher.allocateBoundConnectionForTesting( |
+ context, |
+ ChildProcessLauncherTestHelper.getChildProcessCreationParams( |
+ packageName, servicecClass)); |
+ |
+ if (connection == null) { |
+ return null; |
+ } |
+ // Wait for the service to connect. |
+ CriteriaHelper.pollInstrumentationThread( |
+ new Criteria("The connection wasn't established.") { |
+ @Override |
+ public boolean isSatisfied() { |
+ return connection.isConnected(); |
+ } |
+ }); |
+ return connection; |
+ } |
+ |
+ /** |
+ * Returns a {@link ChildProcessCreationParams} for the given package name and service name. |
+ */ |
+ public static ChildProcessCreationParams getChildProcessCreationParams(String packageName, |
+ Class<? extends Service> serviceClass) { |
+ return new ChildProcessCreationParams(packageName, 0, |
+ LibraryProcessType.PROCESS_CHILD, serviceClass); |
+ } |
+ |
+ /** |
+ * Loads and initialize the library if necessary. |
+ */ |
+ public static void ensureLibraryInitialized(Context context) throws Exception { |
+ LibraryLoader.get(LibraryProcessType.PROCESS_CHILD).ensureInitialized(context); |
+ } |
+} |