按包名分析
com.android.dumprendertree2.scriptsupport
/**
* This method is called from adb to start executing the tests. It doesn't return
* until everything is finished so that the script can wait for the end if it needs
* to.
*/
public void startLayoutTests() {
ScriptTestRunner runner = (ScriptTestRunner)getInstrumentation();
String relativePath = runner.getTestsRelativePath();
ForwarderManager.getForwarderManager().start();
Intent intent = new Intent();
intent.setClassName("com.android.dumprendertree2", "TestsListActivity");
intent.setAction(Intent.ACTION_RUN);
intent.putExtra(TestsListActivity.EXTRA_TEST_PATH, relativePath);
setActivityIntent(intent);
getActivity().registerOnEverythingFinishedCallback(new OnEverythingFinishedCallback() {
/** This method is safe to call on any thread */
@Override
public void onFinished() {
synchronized (Starter.this) {
mEverythingFinished = true;
Starter.this.notifyAll();
}
}
});
synchronized (this) {
while (!mEverythingFinished) {
try {
this.wait();
} catch (InterruptedException e) {
Log.e(LOG_TAG, "startLayoutTests()", e);
}
}
}
ForwarderManager.getForwarderManager().stop();
}
com.android.dumprendertree2.forwarder
/**
* A port forwarding server. Listens on localhost on specified port and forwards thetcp
* communications to external socket via adb networking proxy.
*/
public class Forwarderextends Thread
/**
* Worker class for {@link Forwarder}. A ConnectionHandler will be created once the Forwarder
* accepts an incoming connection, and it will then forward the incoming/outgoing streams to a
* connection already proxied by adb networking (see also {@link AdbUtils}).
*/
public class ConnectionHandler
/**
* A simple class to start and stop Forwarders running on some ports.
*
* It uses a singleton pattern and is thread safe.
*/
public class ForwarderManager
/**
* The utility class that can setup a socket allowing the device to communicate with remote
* machines through the machine that the device is connected to via adb.
*/
public class AdbUtils
com.android.dumprendertre2
需要注意的一点,LayoutTestExecutor 通过下面的接口注册了 JavaScriptInterface,让 JavaScript 可以调用 Java 程序,这一点非常有用。
private static class WebViewWithJavascriptInterfaces extends WebView {
public WebViewWithJavascriptInterfaces(
Context context, Map<String, Object> javascriptInterfaces) {
super(context,
null, // attribute set
0, // default style resource ID
javascriptInterfaces,
false); // is private browsing
}
}