Index: components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/DevToolsBridgeServerSandbox.java |
diff --git a/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/DevToolsBridgeServerSandbox.java b/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/DevToolsBridgeServerSandbox.java |
index 3c82610c07579d0497a4d537beb17e2093e526a4..7364e0cc4146b46ee7f052984128a3db15cdd6b5 100644 |
--- a/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/DevToolsBridgeServerSandbox.java |
+++ b/components/devtools_bridge/test/android/javatests/src/org/chromium/components/devtools_bridge/DevToolsBridgeServerSandbox.java |
@@ -4,14 +4,11 @@ |
package org.chromium.components.devtools_bridge; |
-import android.content.ComponentName; |
import android.content.Context; |
-import android.content.Intent; |
-import android.content.ServiceConnection; |
-import android.os.IBinder; |
import android.os.Process; |
import android.util.Log; |
-import android.widget.Toast; |
+ |
+import org.chromium.components.devtools_bridge.util.LooperExecutor; |
import java.io.IOException; |
@@ -20,83 +17,50 @@ import java.io.IOException; |
*/ |
public class DevToolsBridgeServerSandbox { |
private static final String TAG = "DevToolsBridgeServerSandbox"; |
- private Context mContext; |
- |
- private final ServiceConnection mServiceConnection = new ServiceConnection() { |
- @Override |
- public void onServiceConnected(ComponentName name, IBinder service) { |
- mBinder = ((LocalBindingTestService.LocalBinder) service); |
- startInternal(); |
- } |
- |
- @Override |
- public void onServiceDisconnected(ComponentName name) { |
- stopInternal(); |
- mBinder = null; |
- } |
- }; |
- |
- private LocalBindingTestService.LocalBinder mBinder; |
+ private static final String SERVER_SOCKET_NAME = "chrome_shell_devtools_remote"; |
- /** |
- * Service for hosting DevToolsBridgeServer in manual tests which exposes |
- * Chrome Shell DevTools socket. |
- */ |
- public static class Service extends LocalBindingTestService { |
- public Service() { |
- super("chrome_shell_devtools_remote"); |
- } |
- } |
+ private Context mContext; |
+ private LooperExecutor mExecutor; |
+ private DevToolsBridgeServer mServer; |
+ private SessionDependencyFactory mFactory; |
+ private ClientSessionTestingHost mClientSession1; |
+ private ClientSessionTestingHost mClientSession2; |
public void start(Context context) { |
assert mContext == null; |
mContext = context; |
- Intent intent = new Intent(mContext, Service.class); |
- mContext.bindService( |
- intent, mServiceConnection, Context.BIND_DEBUG_UNBIND | Context.BIND_AUTO_CREATE); |
- } |
- |
- public void stop() throws SecurityException { |
- mContext.unbindService(mServiceConnection); |
- mContext = null; |
- } |
- |
- private SessionDependencyFactory mFactory; |
- private ClientSessionTestingHost mClientSession1; |
- private ClientSessionTestingHost mClientSession2; |
+ mExecutor = LooperExecutor.newInstanceForMainLooper(mContext); |
+ mServer = new DevToolsBridgeServer(new ServerDelegate(context)); |
- private void startInternal() { |
- Log.d(TAG, "Service connected. Starting client sessions"); |
- Toast.makeText(mContext, "Connected to the service", Toast.LENGTH_SHORT).show(); |
+ mFactory = SessionDependencyFactory.newInstance(); |
+ mClientSession1 = createSession("Session 1", "webview_devtools_remote_" + Process.myPid()); |
+ mClientSession2 = createSession("Session 2", "chrome_devtools_remote_" + Process.myPid()); |
- createConnections(); |
mClientSession1.start(); |
mClientSession2.start(); |
} |
- private void createConnections() { |
- assert mClientSession1 == null; |
- assert mClientSession2 == null; |
- mFactory = SessionDependencyFactory.newInstance(); |
+ public void stop() { |
+ mClientSession1.dispose(); |
+ mClientSession2.dispose(); |
+ mFactory.dispose(); |
+ mClientSession1 = null; |
+ mClientSession2 = null; |
+ mFactory = null; |
+ mServer.dispose(); |
+ mServer = null; |
+ mContext = null; |
+ } |
- String pid = Integer.toString(Process.myPid()); |
+ private ClientSessionTestingHost createSession(String sessionId, String socketName) { |
try { |
- mClientSession1 = createSessionHost( |
- "Session 1", "webview_devtools_remote_" + pid); |
- mClientSession2 = createSessionHost( |
- "Session 2", "chrome_devtools_remote_" + pid); |
+ return new ClientSessionTestingHost( |
+ mFactory, mServer, mExecutor, sessionId, socketName); |
} catch (IOException e) { |
- e.printStackTrace(); |
- Log.d(TAG, "Failed to start client sessions"); |
+ throw new RuntimeException(e); |
} |
} |
- private ClientSessionTestingHost createSessionHost(String sessionId, String socketName) |
- throws IOException { |
- return new ClientSessionTestingHost( |
- mFactory, mBinder.getReceiver(), mBinder.createExecutor(), sessionId, socketName); |
- } |
- |
private void stopInternal() { |
Log.d(TAG, "Service disconnected. Stopping client sessions"); |
mClientSession1.dispose(); |
@@ -106,4 +70,27 @@ public class DevToolsBridgeServerSandbox { |
mClientSession2 = null; |
mFactory = null; |
} |
+ |
+ private static class ServerDelegate implements DevToolsBridgeServer.Delegate { |
+ private Context mContext; |
+ |
+ public ServerDelegate(Context context) { |
+ mContext = context; |
+ } |
+ |
+ @Override |
+ public Context getContext() { |
+ return mContext; |
+ } |
+ |
+ @Override |
+ public void onSessionCountChange(int sessionCount) { |
+ Log.i(TAG, sessionCount + " active session"); |
+ } |
+ |
+ @Override |
+ public void querySocketName(DevToolsBridgeServer.QuerySocketCallback callback) { |
+ callback.onSuccess(SERVER_SOCKET_NAME); |
+ } |
+ } |
} |