Commit 3508300b authored by serya's avatar serya Committed by Commit bot

Refactoring DevTools bridge tests: moving interface adapters to SignalingReceiverProxy.

Benefits of this refactoring are:
1. Removed a redundant adapter.
2. Removed an unnecessary interface conversion (A->B->A).
3. Removed from ClientSessionTestingHost references to unrelated class LocalSessionBridge.
4. Reduced number of public classes.

BUG=383418

Review URL: https://codereview.chromium.org/700833002

Cr-Commit-Position: refs/heads/master@{#302615}
parent e72c9f4c
......@@ -5,7 +5,6 @@
package org.chromium.components.devtools_bridge;
import java.io.IOException;
import java.util.List;
/**
* Helper class which handles a client session in tests. Having direct reference to
......@@ -13,11 +12,12 @@ import java.util.List;
* between them to satisfy theading requirements.
*/
public class ClientSessionTestingHost {
private static final String SESSION_ID = "ID";
private final SignalingReceiver mTarget;
private final SessionBase.Executor mTargetExecutor;
private final LocalSessionBridge.ThreadedExecutor mClientExecutor;
private final String mSessionId;
private int mDelayMs = 10;
private final ClientSession mClientSession;
public ClientSessionTestingHost(
......@@ -30,10 +30,14 @@ public class ClientSessionTestingHost {
mClientExecutor = new LocalSessionBridge.ThreadedExecutor();
mSessionId = sessionId;
SignalingReceiverProxy proxy = new SignalingReceiverProxy(
mTargetExecutor, mClientExecutor, target, 0);
mClientSession = new ClientSession(
factory,
mClientExecutor,
new TargetAdaptor().createProxy(),
proxy.asServerSession(SESSION_ID),
clientSocketName);
}
......@@ -54,39 +58,4 @@ public class ClientSessionTestingHost {
}
});
}
/**
* Adapts ServerSessionInterface to DevToolsBridgeServer. Lives on mServerExecutor.
*/
private class TargetAdaptor implements SessionBase.ServerSessionInterface {
/**
* Creates proxy that to safely use on mClientExecutor.
*/
public LocalSessionBridge.ServerSessionProxy createProxy() {
LocalSessionBridge.ServerSessionProxy proxy =
new LocalSessionBridge.ServerSessionProxy(
mTargetExecutor, mClientExecutor, this, mDelayMs);
assert proxy.clientExecutor() == mClientExecutor;
assert proxy.serverExecutor() == mTargetExecutor;
return proxy;
}
@Override
public void startSession(RTCConfiguration config,
String offer,
SessionBase.NegotiationCallback callback) {
mTarget.startSession(mSessionId, config, offer, callback);
}
@Override
public void renegotiate(String offer, SessionBase.NegotiationCallback callback) {
mTarget.renegotiate(mSessionId, offer, callback);
}
@Override
public void iceExchange(List<String> clientCandidates,
SessionBase.IceExchangeCallback callback) {
mTarget.iceExchange(mSessionId, clientCandidates, callback);
}
}
}
......@@ -7,7 +7,6 @@ package org.chromium.components.devtools_bridge;
import android.util.Log;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
......@@ -277,76 +276,12 @@ public class LocalSessionBridge {
}
}
private ServerSessionProxy createServerSessionProxy(SessionBase.ServerSessionInterface proxee) {
return new ServerSessionProxy(mServerExecutor, mClientExecutor, proxee, mDelayMs);
}
/**
* Helper proxy that binds client and server sessions living on different executors.
* Exchange java objects instead of serialized messages.
*/
public static final class ServerSessionProxy implements SessionBase.ServerSessionInterface {
private static final String SESSION_ID = "";
private final SignalingReceiverProxy mProxy;
public ServerSessionProxy(
SessionBase.Executor serverExecutor, SessionBase.Executor clientExecutor,
SessionBase.ServerSessionInterface proxee, int delayMs) {
mProxy = new SignalingReceiverProxy(
serverExecutor, clientExecutor, new ServerSessionAdaptor(proxee), delayMs);
}
public SessionBase.Executor serverExecutor() {
return mProxy.serverExecutor();
}
public SessionBase.Executor clientExecutor() {
return mProxy.clientExecutor();
}
@Override
public void startSession(
RTCConfiguration config, String offer, SessionBase.NegotiationCallback callback) {
mProxy.startSession(SESSION_ID, config, offer, callback);
}
@Override
public void renegotiate(String offer, SessionBase.NegotiationCallback callback) {
mProxy.renegotiate(SESSION_ID, offer, callback);
}
private SessionBase.ServerSessionInterface createServerSessionProxy(
SessionBase.ServerSessionInterface serverSession) {
String sessionId = "";
@Override
public void iceExchange(
List<String> clientCandidates, SessionBase.IceExchangeCallback callback) {
mProxy.iceExchange(SESSION_ID, clientCandidates, callback);
}
}
private static final class ServerSessionAdaptor implements SignalingReceiver {
private final SessionBase.ServerSessionInterface mAdaptee;
public ServerSessionAdaptor(SessionBase.ServerSessionInterface adaptee) {
mAdaptee = adaptee;
}
@Override
public void startSession(
String sessionId, RTCConfiguration config, String offer,
SessionBase.NegotiationCallback callback) {
mAdaptee.startSession(config, offer, callback);
}
@Override
public void renegotiate(
String sessionId, String offer, SessionBase.NegotiationCallback callback) {
mAdaptee.renegotiate(offer, callback);
}
@Override
public void iceExchange(
String sessionId, List<String> clientCandidates,
SessionBase.IceExchangeCallback callback) {
mAdaptee.iceExchange(clientCandidates, callback);
}
return new SignalingReceiverProxy(
mServerExecutor, mClientExecutor, serverSession, sessionId, mDelayMs)
.asServerSession(sessionId);
}
}
......@@ -8,6 +8,8 @@ import org.chromium.components.devtools_bridge.commands.Command;
import org.chromium.components.devtools_bridge.commands.CommandReceiver;
import org.chromium.components.devtools_bridge.commands.CommandSender;
import java.util.List;
/**
* Helper proxy that binds client and server sessions living on different executors.
*/
......@@ -28,6 +30,17 @@ final class SignalingReceiverProxy extends CommandSender {
mDelayMs = delayMs;
}
public SignalingReceiverProxy(
SessionBase.Executor serverExecutor,
SessionBase.Executor clientExecutor,
SessionBase.ServerSessionInterface serverSession,
String sessionId,
int delayMs) {
this(serverExecutor, clientExecutor,
new SignalingReceiverAdaptor(serverSession, sessionId),
delayMs);
}
public SessionBase.Executor serverExecutor() {
return mServerExecutor;
}
......@@ -53,4 +66,72 @@ final class SignalingReceiverProxy extends CommandSender {
}
});
}
public SessionBase.ServerSessionInterface asServerSession(String sessionId) {
return new ServerSessionAdapter(this, sessionId);
}
private static final class ServerSessionAdapter implements SessionBase.ServerSessionInterface {
private final SignalingReceiver mAdaptee;
private final String mSessionId;
public ServerSessionAdapter(SignalingReceiver adaptee, String sessionId) {
mAdaptee = adaptee;
mSessionId = sessionId;
}
@Override
public void startSession(
RTCConfiguration config, String offer, SessionBase.NegotiationCallback callback) {
mAdaptee.startSession(mSessionId, config, offer, callback);
}
@Override
public void renegotiate(String offer, SessionBase.NegotiationCallback callback) {
mAdaptee.renegotiate(mSessionId, offer, callback);
}
@Override
public void iceExchange(
List<String> clientCandidates, SessionBase.IceExchangeCallback callback) {
mAdaptee.iceExchange(mSessionId, clientCandidates, callback);
}
}
private static final class SignalingReceiverAdaptor implements SignalingReceiver {
private final SessionBase.ServerSessionInterface mAdaptee;
private final String mSessionId;
public SignalingReceiverAdaptor(
SessionBase.ServerSessionInterface adaptee, String sessionId) {
mAdaptee = adaptee;
mSessionId = sessionId;
}
@Override
public void startSession(
String sessionId, RTCConfiguration config, String offer,
SessionBase.NegotiationCallback callback) {
if (mSessionId.equals(sessionId)) {
mAdaptee.startSession(config, offer, callback);
}
}
@Override
public void renegotiate(
String sessionId, String offer, SessionBase.NegotiationCallback callback) {
if (mSessionId.equals(sessionId)) {
mAdaptee.renegotiate(offer, callback);
}
}
@Override
public void iceExchange(
String sessionId, List<String> clientCandidates,
SessionBase.IceExchangeCallback callback) {
if (mSessionId.equals(sessionId)) {
mAdaptee.iceExchange(clientCandidates, callback);
}
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment