summaryrefslogtreecommitdiffstats
path: root/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java')
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java95
1 files changed, 55 insertions, 40 deletions
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
index 8e7ac08..5ddd0b3 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
@@ -21,52 +21,57 @@ import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
public class ReliabilityTestActivity extends Activity {
-
+
public static final String TEST_URL_ACTION = "com.andrdoid.dumprendertree.TestUrlAction";
public static final String PARAM_URL = "URL";
public static final String PARAM_TIMEOUT = "Timeout";
public static final int RESULT_TIMEOUT = 0xDEAD;
public static final int MSG_TIMEOUT = 0xC001;
public static final int MSG_NAVIGATE = 0xC002;
-
+ public static final String MSG_NAV_URL = "url";
+ public static final String MSG_NAV_LOGTIME = "logtime";
+
private static final String LOGTAG = "ReliabilityTestActivity";
-
+
private WebView webView;
private SimpleWebViewClient webViewClient;
private SimpleChromeClient chromeClient;
private Handler handler;
private boolean timeoutFlag;
+ private boolean logTime;
private boolean pageDone;
private Object pageDoneLock;
private int pageStartCount;
private int manualDelay;
+ private long startTime;
+ private long pageLoadTime;
private PageDoneRunner pageDoneRunner = new PageDoneRunner();
-
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v(LOGTAG, "onCreate, inst=" + Integer.toHexString(hashCode()));
-
+
LinearLayout contentView = new LinearLayout(this);
contentView.setOrientation(LinearLayout.VERTICAL);
setContentView(contentView);
setTitle("Idle");
-
+
webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
-
+
webViewClient = new SimpleWebViewClient();
chromeClient = new SimpleChromeClient();
webView.setWebViewClient(webViewClient);
webView.setWebChromeClient(chromeClient);
-
+
contentView.addView(webView, new LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT, 0.0f));
-
+
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -76,15 +81,16 @@ public class ReliabilityTestActivity extends Activity {
return;
case MSG_NAVIGATE:
manualDelay = msg.arg2;
- navigate((String)msg.obj, msg.arg1);
+ navigate(msg.getData().getString(MSG_NAV_URL), msg.arg1);
+ logTime = msg.getData().getBoolean(MSG_NAV_LOGTIME);
return;
}
}
};
-
+
pageDoneLock = new Object();
}
-
+
public void reset() {
synchronized (pageDoneLock) {
pageDone = false;
@@ -93,42 +99,46 @@ public class ReliabilityTestActivity extends Activity {
pageStartCount = 0;
chromeClient.resetJsTimeout();
}
-
+
private void navigate(String url, int timeout) {
if(url == null) {
Log.v(LOGTAG, "URL is null, cancelling...");
finish();
}
webView.stopLoading();
+ if(logTime) {
+ webView.clearCache(true);
+ }
+ startTime = System.currentTimeMillis();
Log.v(LOGTAG, "Navigating to URL: " + url);
webView.loadUrl(url);
-
+
if(timeout != 0) {
//set a timer with specified timeout (in ms)
handler.sendMessageDelayed(handler.obtainMessage(MSG_TIMEOUT),
timeout);
}
}
-
+
@Override
protected void onDestroy() {
Log.v(LOGTAG, "onDestroy, inst=" + Integer.toHexString(hashCode()));
super.onDestroy();
}
-
+
private boolean isPageDone() {
synchronized (pageDoneLock) {
return pageDone;
}
}
-
+
private void setPageDone(boolean pageDone) {
synchronized (pageDoneLock) {
this.pageDone = pageDone;
pageDoneLock.notifyAll();
}
}
-
+
private void handleTimeout() {
int progress = webView.getProgress();
webView.stopLoading();
@@ -136,7 +146,7 @@ public class ReliabilityTestActivity extends Activity {
timeoutFlag = true;
handler.postDelayed(pageDoneRunner, manualDelay);
}
-
+
public boolean waitUntilDone() {
validateNotAppThread();
synchronized (pageDoneLock) {
@@ -150,11 +160,11 @@ public class ReliabilityTestActivity extends Activity {
}
return timeoutFlag;
}
-
+
public Handler getHandler() {
return handler;
}
-
+
private final void validateNotAppThread() {
if (ActivityThread.currentActivityThread() != null) {
throw new RuntimeException(
@@ -162,8 +172,12 @@ public class ReliabilityTestActivity extends Activity {
}
}
+ public long getPageLoadTime() {
+ return pageLoadTime;
+ }
+
class SimpleWebViewClient extends WebViewClient {
-
+
@Override
public void onReceivedError(WebView view, int errorCode, String description,
String failingUrl) {
@@ -171,27 +185,27 @@ public class ReliabilityTestActivity extends Activity {
+ ", description=" + description
+ ", url=" + failingUrl);
}
-
+
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
//ignore certificate error
Log.v(LOGTAG, "Received SSL error: " + error.toString());
handler.proceed();
}
-
+
@Override
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host,
String realm) {
// cancel http auth request
handler.cancel();
}
-
+
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
pageStartCount++;
Log.v(LOGTAG, "onPageStarted: " + url);
}
-
+
@Override
public void onPageFinished(WebView view, String url) {
Log.v(LOGTAG, "onPageFinished: " + url);
@@ -200,23 +214,23 @@ public class ReliabilityTestActivity extends Activity {
handler.postDelayed(new WebViewStatusChecker(), 500);
}
}
-
+
class SimpleChromeClient extends WebChromeClient {
-
+
private int timeoutCounter = 0;
-
+
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
result.confirm();
return true;
}
-
+
@Override
public boolean onJsBeforeUnload(WebView view, String url, String message, JsResult result) {
result.confirm();
return true;
}
-
+
@Override
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
result.confirm();
@@ -229,32 +243,32 @@ public class ReliabilityTestActivity extends Activity {
result.confirm();
return true;
}
-
+
@Override
public boolean onJsTimeout() {
timeoutCounter++;
Log.v(LOGTAG, "JavaScript timeout, count=" + timeoutCounter);
return timeoutCounter > 2;
}
-
+
public void resetJsTimeout() {
timeoutCounter = 0;
}
-
+
@Override
public void onReceivedTitle(WebView view, String title) {
ReliabilityTestActivity.this.setTitle(title);
}
}
-
+
class WebViewStatusChecker implements Runnable {
-
+
private int initialStartCount;
-
+
public WebViewStatusChecker() {
initialStartCount = pageStartCount;
}
-
+
public void run() {
if (initialStartCount == pageStartCount) {
//perform cleanup
@@ -264,11 +278,12 @@ public class ReliabilityTestActivity extends Activity {
}
}
}
-
+
class PageDoneRunner implements Runnable {
-
+
public void run() {
Log.v(LOGTAG, "Finishing URL: " + webView.getUrl());
+ pageLoadTime = System.currentTimeMillis() - startTime;
setPageDone(true);
}
}