summaryrefslogtreecommitdiffstats
path: root/tests/DumpRenderTree/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/DumpRenderTree/src')
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java20
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java5
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestsAutoTest.java209
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java85
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java1
5 files changed, 304 insertions, 16 deletions
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
index 562b1f3..caef861 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
@@ -41,6 +41,7 @@ class MyTestRecorder {
private BufferedOutputStream mBufferedOutputPassedStream;
private BufferedOutputStream mBufferedOutputFailedStream;
private BufferedOutputStream mBufferedOutputNoresultStream;
+ private BufferedOutputStream mBufferedOutputTimedoutStream;
public void passed(String layout_file) {
try {
@@ -72,11 +73,22 @@ class MyTestRecorder {
}
}
+ public void timedout(String url) {
+ try {
+ mBufferedOutputTimedoutStream.write(url.getBytes());
+ mBufferedOutputTimedoutStream.write('\n');
+ mBufferedOutputTimedoutStream.flush();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public MyTestRecorder(boolean resume) {
try {
File resultsPassedFile = new File("/sdcard/layout_tests_passed.txt");
File resultsFailedFile = new File("/sdcard/layout_tests_failed.txt");
File noExpectedResultFile = new File("/sdcard/layout_tests_nontext.txt");
+ File resultTimedoutFile = new File("/sdcard/layout_tests_timedout.txt");
mBufferedOutputPassedStream =
new BufferedOutputStream(new FileOutputStream(resultsPassedFile, resume));
@@ -84,6 +96,8 @@ class MyTestRecorder {
new BufferedOutputStream(new FileOutputStream(resultsFailedFile, resume));
mBufferedOutputNoresultStream =
new BufferedOutputStream(new FileOutputStream(noExpectedResultFile, resume));
+ mBufferedOutputTimedoutStream =
+ new BufferedOutputStream(new FileOutputStream(resultTimedoutFile, resume));
} catch (Exception e) {
e.printStackTrace();
}
@@ -94,6 +108,7 @@ class MyTestRecorder {
mBufferedOutputPassedStream.close();
mBufferedOutputFailedStream.close();
mBufferedOutputNoresultStream.close();
+ mBufferedOutputTimedoutStream.close();
} catch (Exception e) {
e.printStackTrace();
}
@@ -281,7 +296,10 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
mFinished = true;
LayoutTestsAutoTest.this.notifyAll();
}
- }
+ }
+
+ public void timedOut(String url) {
+ }
});
String resultFile = getResultFile(test);
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
index 5cb5155..81cf3a8 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
@@ -42,7 +42,7 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel
private boolean mFinished;
static final String LOAD_TEST_RUNNER_FILES[] = {
"run_page_cycler.py"
- };
+ };
public LoadTestsAutoTest() {
super("com.android.dumprendertree", TestShellActivity.class);
@@ -134,6 +134,9 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel
LoadTestsAutoTest.this.notifyAll();
}
}
+
+ public void timedOut(String url) {
+ }
});
mFinished = false;
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestsAutoTest.java
new file mode 100644
index 0000000..347efde
--- /dev/null
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestsAutoTest.java
@@ -0,0 +1,209 @@
+package com.android.dumprendertree;
+
+import com.android.dumprendertree.TestShellActivity.DumpDataType;
+
+import android.content.Intent;
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.Log;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Vector;
+
+public class ReliabilityTestsAutoTest extends ActivityInstrumentationTestCase2<TestShellActivity> {
+
+ private static final String LOGTAG = "ReliabilityTests";
+ private static final String TEST_LIST_FILE = "/sdcard/android/reliability_tests_list.txt";
+ private static final String TEST_STATUS_FILE = "/sdcard/android/reliability_running_test.txt";
+ private static final String TEST_TIMEOUT_FILE = "/sdcard/android/reliability_timeout_test.txt";
+ static final String RELIABILITY_TEST_RUNNER_FILES[] = {
+ "run_reliability_tests.py"
+ };
+
+ private boolean finished;
+ private List<String> testList;
+
+ public ReliabilityTestsAutoTest() {
+ super("com.android.dumprendertree", TestShellActivity.class);
+ }
+
+ private void getTestList() {
+ // Read test list.
+ testList = new Vector<String>();
+ try {
+ BufferedReader inReader = new BufferedReader(new FileReader(TEST_LIST_FILE));
+ String line;
+ while ((line = inReader.readLine()) != null) {
+ testList.add(line);
+ }
+ inReader.close();
+ Log.v(LOGTAG, "Test list has " + testList.size() + " test(s).");
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Error while reading test list : " + e.getMessage());
+ }
+ }
+
+ private void resumeTestList() {
+ // read out the test name it stopped last time.
+ try {
+ BufferedReader inReader = new BufferedReader(new FileReader(TEST_STATUS_FILE));
+ String line = inReader.readLine();
+ for (int i = 0; i < testList.size(); i++) {
+ if (testList.get(i).equals(line)) {
+ testList = new Vector<String>(testList.subList(i+1, testList.size()));
+ break;
+ }
+ }
+ inReader.close();
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Error reading " + TEST_STATUS_FILE);
+ }
+ }
+
+ private void clearTestStatus() {
+ // Delete TEST_STATUS_FILE
+ try {
+ File f = new File(TEST_STATUS_FILE);
+ if (f.delete())
+ Log.v(LOGTAG, "Deleted " + TEST_STATUS_FILE);
+ else
+ Log.e(LOGTAG, "Fail to delete " + TEST_STATUS_FILE);
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Fail to delete " + TEST_STATUS_FILE + " : " + e.getMessage());
+ }
+ }
+
+ private void clearTestTimeout() {
+ // Delete TEST_TIMEOUT_FILE
+ try {
+ File f = new File(TEST_TIMEOUT_FILE);
+ if (f.delete())
+ Log.v(LOGTAG, "Deleted " + TEST_TIMEOUT_FILE);
+ else
+ Log.e(LOGTAG, "Fail to delete " + TEST_TIMEOUT_FILE);
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Fail to delete " + TEST_TIMEOUT_FILE + " : " + e.getMessage());
+ }
+ }
+
+ private void updateTestStatus(String s) {
+ // Write TEST_STATUS_FILE
+ try {
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(TEST_STATUS_FILE));
+ bos.write(s.getBytes());
+ bos.close();
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Cannot update file " + TEST_STATUS_FILE);
+ }
+ }
+
+ private void writeTimeoutFile(String s) {
+ // Write TEST_TIMEOUT_FILE
+ try {
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(TEST_TIMEOUT_FILE, true));
+ bos.write(s.getBytes());
+ bos.write('\n');
+ bos.close();
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Cannot update file " + TEST_TIMEOUT_FILE);
+ }
+ }
+
+ private void runReliabilityTest(boolean resume) {
+ LayoutTestsAutoRunner runner = (LayoutTestsAutoRunner) getInstrumentation();
+
+ getTestList();
+ if(!resume)
+ clearTestStatus();
+ else
+ resumeTestList();
+
+ TestShellActivity activity = getActivity();
+ activity.setDefaultDumpDataType(DumpDataType.NO_OP);
+ // Run tests.
+ for (int i = 0; i < testList.size(); i++) {
+ String s = testList.get(i);
+ updateTestStatus(s);
+ // Run tests
+ runTestAndWaitUntilDone(activity, s, runner.mTimeoutInMillis);
+ }
+
+ updateTestStatus("#DONE");
+
+ activity.finish();
+ }
+
+ private void runTestAndWaitUntilDone(TestShellActivity activity, String url, int timeout) {
+ activity.setCallback(new TestShellCallback() {
+ public void finished() {
+ synchronized (ReliabilityTestsAutoTest.this) {
+ finished = true;
+ ReliabilityTestsAutoTest.this.notifyAll();
+ }
+ }
+
+ public void timedOut(String url) {
+ writeTimeoutFile(url);
+ }
+ });
+
+ finished = false;
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setClass(activity, TestShellActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ intent.putExtra(TestShellActivity.TEST_URL, url);
+ intent.putExtra(TestShellActivity.TIMEOUT_IN_MILLIS, timeout);
+ activity.startActivity(intent);
+
+ // Wait until done.
+ synchronized (this) {
+ while(!finished){
+ try {
+ this.wait();
+ } catch (InterruptedException e) { }
+ }
+ }
+ }
+
+ public void startReliabilityTests() {
+ clearTestTimeout();
+ runReliabilityTest(false);
+ }
+
+ public void resumeReliabilityTests() {
+ runReliabilityTest(true);
+ }
+
+ public void copyRunnerAssetsToCache() {
+ try {
+ String out_dir = getActivity().getApplicationContext()
+ .getCacheDir().getPath() + "/";
+
+ for( int i=0; i< RELIABILITY_TEST_RUNNER_FILES.length; i++) {
+ InputStream in = getActivity().getAssets().open(
+ RELIABILITY_TEST_RUNNER_FILES[i]);
+ OutputStream out = new FileOutputStream(
+ out_dir + RELIABILITY_TEST_RUNNER_FILES[i]);
+
+ byte[] buf = new byte[2048];
+ int len;
+
+ while ((len = in.read(buf)) >= 0 ) {
+ out.write(buf, 0, len);
+ }
+ out.close();
+ in.close();
+ }
+ }catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+}
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
index 404d101..1ba291c 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
@@ -16,29 +16,40 @@
package com.android.dumprendertree;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Vector;
-
import android.app.Activity;
import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.http.SslError;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
import android.util.Log;
+import android.view.ViewGroup;
+import android.webkit.HttpAuthHandler;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
-import android.view.ViewGroup;
+import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
+import android.webkit.WebViewClient;
import android.widget.LinearLayout;
-import android.os.*;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Vector;
public class TestShellActivity extends Activity implements LayoutTestController {
+
+ static enum DumpDataType {DUMP_AS_TEXT, EXT_REPR, NO_OP}
+
public class AsyncHandler extends Handler {
@Override
public void handleMessage(Message msg) {
if (msg.what == MSG_TIMEOUT) {
mTimedOut = true;
+ mCallback.timedOut(mWebView.getUrl());
requestWebKitData();
return;
} else if (msg.what == MSG_WEBKIT_DATA) {
@@ -57,10 +68,16 @@ public class TestShellActivity extends Activity implements LayoutTestController
throw new AssertionError("Requested webkit data twice: " + mWebView.getUrl());
mRequestedWebKitData = true;
- if (mDumpAsText) {
- mWebView.documentAsText(callback);
- } else {
- mWebView.externalRepresentation(callback);
+ switch (mDumpDataType) {
+ case DUMP_AS_TEXT:
+ mWebView.documentAsText(callback);
+ break;
+ case EXT_REPR:
+ mWebView.externalRepresentation(callback);
+ break;
+ default:
+ finished();
+ break;
}
}
@@ -75,6 +92,41 @@ public class TestShellActivity extends Activity implements LayoutTestController
mWebView = new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(mChromeClient);
+ mWebView.setWebViewClient(new WebViewClient(){
+
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ Log.v(LOGTAG, "onPageFinished, url=" + url);
+ super.onPageFinished(view, url);
+ }
+
+ @Override
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
+ Log.v(LOGTAG, "onPageStarted, url=" + url);
+ super.onPageStarted(view, url, favicon);
+ }
+
+ @Override
+ public void onReceivedError(WebView view, int errorCode, String description,
+ String failingUrl) {
+ Log.v(LOGTAG, "onReceivedError, errorCode=" + errorCode
+ + ", desc=" + description + ", url=" + failingUrl);
+ super.onReceivedError(view, errorCode, description, failingUrl);
+ }
+
+ @Override
+ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler,
+ String host, String realm) {
+ handler.cancel();
+ }
+
+ @Override
+ public void onReceivedSslError(WebView view, SslErrorHandler handler,
+ SslError error) {
+ handler.proceed();
+ }
+
+ });
mEventSender = new WebViewEventSender(mWebView);
mCallbackProxy = new CallbackProxy(mEventSender, this);
@@ -186,10 +238,14 @@ public class TestShellActivity extends Activity implements LayoutTestController
}
}
+ public void setDefaultDumpDataType(DumpDataType defaultDumpDataType) {
+ mDefaultDumpDataType = defaultDumpDataType;
+ }
+
// .......................................
// LayoutTestController Functions
public void dumpAsText() {
- mDumpAsText = true;
+ mDumpDataType = DumpDataType.DUMP_AS_TEXT;
if (mWebView != null) {
String url = mWebView.getUrl();
Log.v(LOGTAG, "dumpAsText called: "+url);
@@ -382,7 +438,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
private void resetTestStatus() {
mWaitUntilDone = false;
- mDumpAsText = false;
+ mDumpDataType = mDefaultDumpDataType;
mTimedOut = false;
mDumpTitleChanges = false;
mRequestedWebKitData = false;
@@ -406,7 +462,8 @@ public class TestShellActivity extends Activity implements LayoutTestController
private boolean mFinishedRunning;
// Layout test controller variables.
- private boolean mDumpAsText;
+ private DumpDataType mDumpDataType;
+ private DumpDataType mDefaultDumpDataType = DumpDataType.EXT_REPR;
private boolean mWaitUntilDone;
private boolean mDumpTitleChanges;
private StringBuffer mTitleChanges;
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java
index 759c443..55bf947 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellCallback.java
@@ -18,4 +18,5 @@ package com.android.dumprendertree;
public interface TestShellCallback {
public void finished();
+ public void timedOut(String url);
}