Commit d95b2346 authored by serya's avatar serya Committed by Commit bot

Refactoring of DevTools bridge tests: taking advantage of Commands for...

Refactoring of DevTools bridge tests: taking advantage of Commands for proxying client-server communication.

Since client and server live on different threads in tests thier communication are proxied. Anounimous classes
are used for that. Since now we have Command's that essentially are call-to-object mapping thay may be used
instead aonymous objects.

BUG=383418

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

Cr-Commit-Position: refs/heads/master@{#302599}
parent f1a7a373
...@@ -7,7 +7,6 @@ package org.chromium.components.devtools_bridge; ...@@ -7,7 +7,6 @@ package org.chromium.components.devtools_bridge;
import android.util.Log; import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
...@@ -287,146 +286,67 @@ public class LocalSessionBridge { ...@@ -287,146 +286,67 @@ public class LocalSessionBridge {
* Exchange java objects instead of serialized messages. * Exchange java objects instead of serialized messages.
*/ */
public static final class ServerSessionProxy implements SessionBase.ServerSessionInterface { public static final class ServerSessionProxy implements SessionBase.ServerSessionInterface {
private final SessionBase.ServerSessionInterface mProxee; private static final String SESSION_ID = "";
private final SessionBase.Executor mServerExecutor; private final SignalingReceiverProxy mProxy;
private final SessionBase.Executor mClientExecutor;
private final int mDelayMs;
public ServerSessionProxy( public ServerSessionProxy(
SessionBase.Executor serverExecutor, SessionBase.Executor clientExecutor, SessionBase.Executor serverExecutor, SessionBase.Executor clientExecutor,
SessionBase.ServerSessionInterface proxee, int delayMs) { SessionBase.ServerSessionInterface proxee, int delayMs) {
mServerExecutor = serverExecutor; mProxy = new SignalingReceiverProxy(
mClientExecutor = clientExecutor; serverExecutor, clientExecutor, new ServerSessionAdaptor(proxee), delayMs);
mProxee = proxee;
mDelayMs = delayMs;
} }
public SessionBase.Executor serverExecutor() { public SessionBase.Executor serverExecutor() {
return mServerExecutor; return mProxy.serverExecutor();
} }
public SessionBase.Executor clientExecutor() { public SessionBase.Executor clientExecutor() {
return mClientExecutor; return mProxy.clientExecutor();
} }
@Override @Override
public void startSession(final RTCConfiguration config, public void startSession(
final String offer, RTCConfiguration config, String offer, SessionBase.NegotiationCallback callback) {
final SessionBase.NegotiationCallback callback) { mProxy.startSession(SESSION_ID, config, offer, callback);
Log.d(TAG, "Starting session: " + offer);
mServerExecutor.postOnSessionThread(mDelayMs, new Runnable() {
@Override
public void run() {
mProxee.startSession(config, offer, wrap(callback));
}
});
} }
@Override @Override
public void renegotiate(final String offer, public void renegotiate(String offer, SessionBase.NegotiationCallback callback) {
final SessionBase.NegotiationCallback callback) { mProxy.renegotiate(SESSION_ID, offer, callback);
Log.d(TAG, "Renegotiation: " + offer);
mServerExecutor.postOnSessionThread(mDelayMs, new Runnable() {
@Override
public void run() {
mProxee.renegotiate(offer, wrap(callback));
}
});
} }
@Override @Override
public void iceExchange(final List<String> clientCandidates, public void iceExchange(
final SessionBase.IceExchangeCallback callback) { List<String> clientCandidates, SessionBase.IceExchangeCallback callback) {
Log.d(TAG, "Client ice candidates " + Integer.toString(clientCandidates.size())); mProxy.iceExchange(SESSION_ID, clientCandidates, callback);
mServerExecutor.postOnSessionThread(mDelayMs, new Runnable() {
@Override
public void run() {
mProxee.iceExchange(clientCandidates, wrap(callback));
}
});
}
private NegotiationCallbackProxy wrap(SessionBase.NegotiationCallback callback) {
return new NegotiationCallbackProxy(callback, mClientExecutor, mDelayMs);
}
private IceExchangeCallbackProxy wrap(SessionBase.IceExchangeCallback callback) {
return new IceExchangeCallbackProxy(callback, mClientExecutor, mDelayMs);
} }
} }
private static final class NegotiationCallbackProxy implements SessionBase.NegotiationCallback { private static final class ServerSessionAdaptor implements SignalingReceiver {
private final SessionBase.NegotiationCallback mProxee; private final SessionBase.ServerSessionInterface mAdaptee;
private final SessionBase.Executor mClientExecutor;
private final int mDelayMs;
public NegotiationCallbackProxy(SessionBase.NegotiationCallback callback,
SessionBase.Executor clientExecutor,
int delayMs) {
mProxee = callback;
mClientExecutor = clientExecutor;
mDelayMs = delayMs;
}
@Override public ServerSessionAdaptor(SessionBase.ServerSessionInterface adaptee) {
public void onSuccess(final String answer) { mAdaptee = adaptee;
Log.d(TAG, "Sending answer: " + answer);
mClientExecutor.postOnSessionThread(mDelayMs, new Runnable() {
@Override
public void run() {
mProxee.onSuccess(answer);
}
});
} }
@Override @Override
public void onFailure(final String message) { public void startSession(
mClientExecutor.postOnSessionThread(mDelayMs, new Runnable() { String sessionId, RTCConfiguration config, String offer,
@Override SessionBase.NegotiationCallback callback) {
public void run() { mAdaptee.startSession(config, offer, callback);
mProxee.onFailure(message);
}
});
}
}
private static final class IceExchangeCallbackProxy implements SessionBase.IceExchangeCallback {
private final SessionBase.IceExchangeCallback mProxee;
private final SessionBase.Executor mClientExecutor;
private final int mDelayMs;
public IceExchangeCallbackProxy(SessionBase.IceExchangeCallback callback,
SessionBase.Executor clientExecutor,
int delayMs) {
mProxee = callback;
mClientExecutor = clientExecutor;
mDelayMs = delayMs;
} }
@Override @Override
public void onSuccess(List<String> serverCandidates) { public void renegotiate(
Log.d(TAG, "Server ice candidates " + Integer.toString(serverCandidates.size())); String sessionId, String offer, SessionBase.NegotiationCallback callback) {
mAdaptee.renegotiate(offer, callback);
final List<String> serverCandidatesCopy = new ArrayList<String>();
serverCandidatesCopy.addAll(serverCandidates);
mClientExecutor.postOnSessionThread(mDelayMs, new Runnable() {
@Override
public void run() {
mProxee.onSuccess(serverCandidatesCopy);
}
});
} }
@Override @Override
public void onFailure(final String message) { public void iceExchange(
Log.d(TAG, "Ice exchange falure: " + message); String sessionId, List<String> clientCandidates,
mClientExecutor.postOnSessionThread(mDelayMs, new Runnable() { SessionBase.IceExchangeCallback callback) {
@Override mAdaptee.iceExchange(clientCandidates, callback);
public void run() {
mProxee.onFailure(message);
}
});
} }
} }
} }
// Copyright 2014 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.components.devtools_bridge;
import org.chromium.components.devtools_bridge.commands.Command;
import org.chromium.components.devtools_bridge.commands.CommandReceiver;
import org.chromium.components.devtools_bridge.commands.CommandSender;
/**
* Helper proxy that binds client and server sessions living on different executors.
*/
final class SignalingReceiverProxy extends CommandSender {
private final CommandReceiver mReceiver;
private final SessionBase.Executor mServerExecutor;
private final SessionBase.Executor mClientExecutor;
private final int mDelayMs;
public SignalingReceiverProxy(
SessionBase.Executor serverExecutor,
SessionBase.Executor clientExecutor,
SignalingReceiver server,
int delayMs) {
mServerExecutor = serverExecutor;
mClientExecutor = clientExecutor;
mReceiver = new CommandReceiver(server);
mDelayMs = delayMs;
}
public SessionBase.Executor serverExecutor() {
return mServerExecutor;
}
public SessionBase.Executor clientExecutor() {
return mClientExecutor;
}
@Override
protected void send(final Command command, final Runnable completionCallback) {
assert mClientExecutor.isCalledOnSessionThread();
mServerExecutor.postOnSessionThread(mDelayMs, new Runnable() {
@Override
public void run() {
mReceiver.receive(command, new Runnable() {
@Override
public void run() {
assert mServerExecutor.isCalledOnSessionThread();
mClientExecutor.postOnSessionThread(mDelayMs, completionCallback);
}
});
}
});
}
}
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