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/FileList.java73
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java80
-rwxr-xr-xtests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java23
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java64
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java104
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java42
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java166
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java290
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestsAutoTest.java209
-rw-r--r--tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java153
10 files changed, 833 insertions, 371 deletions
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/FileList.java b/tests/DumpRenderTree/src/com/android/dumprendertree/FileList.java
index 0218317..e741177 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/FileList.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/FileList.java
@@ -23,7 +23,9 @@ import java.util.List;
import java.util.Map;
import java.io.File;
+import android.app.AlertDialog;
import android.app.ListActivity;
+import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ListView;
@@ -31,7 +33,7 @@ import android.widget.SimpleAdapter;
import android.os.Bundle;
-public abstract class FileList extends ListActivity
+public abstract class FileList extends ListActivity
{
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode)
@@ -39,7 +41,7 @@ public abstract class FileList extends ListActivity
case KeyEvent.KEYCODE_DPAD_LEFT:
if (mPath.length() > mBaseLength) {
File f = new File(mPath);
- mFocusFile = f.getName();
+ mFocusFile = f.getName();
mFocusIndex = 0;
f = f.getParentFile();
mPath = f.getPath();
@@ -47,7 +49,7 @@ public abstract class FileList extends ListActivity
return true;
}
break;
-
+
case KeyEvent.KEYCODE_DPAD_RIGHT:
{
Map map = (Map) getListView().getItemAtPosition(getListView().getSelectedItemPosition());
@@ -61,24 +63,24 @@ public abstract class FileList extends ListActivity
}
return true;
}
-
+
default:
break;
}
return super.onKeyDown(keyCode, event);
}
- public void onCreate(Bundle icicle)
+ public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setupPath();
updateList();
}
-
+
protected List getData()
{
List myData = new ArrayList<HashMap>();
-
+
File f = new File(mPath);
if (!f.exists()) {
addItem(myData, "!LayoutTests path missing!", "");
@@ -103,10 +105,10 @@ public abstract class FileList extends ListActivity
addItem(myData, files[i], path);
}
}
-
+
return myData;
}
-
+
protected void addItem(List<Map> data, String name, String path)
{
HashMap temp = new HashMap();
@@ -114,34 +116,58 @@ public abstract class FileList extends ListActivity
temp.put("path", path);
data.add(temp);
}
-
+
protected void onListItemClick(ListView l, View v, int position, long id)
{
- Map map = (Map) l.getItemAtPosition(position);
- String path = (String)map.get("path");
+ Map map = (Map) l.getItemAtPosition(position);
+ final String path = (String)map.get("path");
if ((new File(path)).isDirectory()) {
- mPath = path;
- mFocusFile = null;
- updateList();
+ final CharSequence[] items = {"Open", "Run"};
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Select an Action");
+ builder.setSingleChoiceItems(items, -1,
+ new DialogInterface.OnClickListener(){
+ public void onClick(DialogInterface dialog, int which) {
+ switch (which) {
+ case OPEN_DIRECTORY:
+ dialog.dismiss();
+ mPath = path;
+ mFocusFile = null;
+ updateList();
+ break;
+ case RUN_TESTS:
+ dialog.dismiss();
+ processDirectory(path, false);
+ break;
+ }
+ }
+ });
+ builder.create().show();
} else {
processFile(path, false);
}
}
-
+
+ /*
+ * This function is called when the user has selected a directory in the
+ * list and wants to perform an action on it instead of navigating into
+ * the directory.
+ */
+ abstract void processDirectory(String path, boolean selection);
/*
* This function is called when the user has selected a file in the
* file list. The selected file could be a file or a directory.
* The flag indicates if this was from a selection or not.
*/
abstract void processFile(String filename, boolean selection);
-
+
/*
* This function is called when the file list is being built. Return
* true if the file is to be added to the file list.
*/
abstract boolean fileFilter(File f);
-
+
protected void updateList() {
setListAdapter(new SimpleAdapter(this,
getData(),
@@ -152,16 +178,19 @@ public abstract class FileList extends ListActivity
setTitle(title);
getListView().setSelection(mFocusIndex);
}
-
- protected void setupPath()
+
+ protected void setupPath()
{
mPath = "/sdcard/android/layout_tests";
mBaseLength = mPath.length();
}
-
+
protected String mPath;
protected int mBaseLength;
protected String mFocusFile;
protected int mFocusIndex;
-
+
+ private final static int OPEN_DIRECTORY = 0;
+ private final static int RUN_TESTS = 1;
+
}
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java b/tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java
new file mode 100644
index 0000000..cc2f1f5
--- /dev/null
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/FsUtils.java
@@ -0,0 +1,80 @@
+package com.android.dumprendertree;
+
+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;
+
+public class FsUtils {
+
+ private static final String LOGTAG = "FsUtils";
+ private FsUtils() {
+ //no creation of instances
+ }
+
+ public static void findLayoutTestsRecursively(BufferedOutputStream bos,
+ String dir) throws IOException {
+ Log.v(LOGTAG, "Searching tests under " + dir);
+
+ File d = new File(dir);
+ if (!d.isDirectory()) {
+ throw new AssertionError("A directory expected, but got " + dir);
+ }
+
+ String[] files = d.list();
+ for (int i = 0; i < files.length; i++) {
+ String s = dir + "/" + files[i];
+ if (FileFilter.ignoreTest(s)) {
+ Log.v(LOGTAG, " Ignoring: " + s);
+ continue;
+ }
+ if (s.toLowerCase().endsWith(".html")
+ || s.toLowerCase().endsWith(".xml")) {
+ bos.write(s.getBytes());
+ bos.write('\n');
+ continue;
+ }
+
+ File f = new File(s);
+ if (f.isDirectory()) {
+ findLayoutTestsRecursively(bos, s);
+ continue;
+ }
+
+ Log.v(LOGTAG, "Skipping " + s);
+ }
+ }
+
+ public static void updateTestStatus(String statusFile, String s) {
+ try {
+ BufferedOutputStream bos = new BufferedOutputStream(
+ new FileOutputStream(statusFile));
+ bos.write(s.getBytes());
+ bos.close();
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Cannot update file " + statusFile);
+ }
+ }
+
+ public static String readTestStatus(String statusFile) {
+ // read out the test name it stopped last time.
+ String status = null;
+ File testStatusFile = new File(statusFile);
+ if(testStatusFile.exists()) {
+ try {
+ BufferedReader inReader = new BufferedReader(
+ new FileReader(testStatusFile));
+ status = inReader.readLine();
+ inReader.close();
+ } catch (IOException e) {
+ Log.e(LOGTAG, "Error reading test status.", e);
+ }
+ }
+ return status;
+ }
+
+}
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java
index ebdc9c7..e00d3ad 100755
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoRunner.java
@@ -16,14 +16,11 @@
package com.android.dumprendertree;
-import junit.framework.TestSuite;
-import com.android.dumprendertree.LayoutTestsAutoTest;
-
+import android.os.Bundle;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
-import android.util.Log;
-import android.content.Intent;
-import android.os.Bundle;
+
+import junit.framework.TestSuite;
/**
@@ -61,13 +58,27 @@ public class LayoutTestsAutoRunner extends InstrumentationTestRunner {
}
}
+ String delay_str = (String) icicle.get("delay");
+ if(delay_str != null) {
+ try {
+ this.mDelay = Integer.parseInt(delay_str);
+ } catch (Exception e) {
+ }
+ }
+
String r = (String)icicle.get("rebaseline");
this.mRebaseline = (r != null && r.toLowerCase().equals("true"));
super.onCreate(icicle);
+
+ String logtime = (String) icicle.get("logtime");
+ this.mLogtime = (logtime != null
+ && logtime.toLowerCase().equals("true"));
}
public String mTestPath = null;
public int mTimeoutInMillis = 0;
+ public int mDelay = 0;
public boolean mRebaseline = false;
+ public boolean mLogtime = false;
}
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
index caef861..a03490d 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LayoutTestsAutoTest.java
@@ -178,15 +178,13 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
private void resumeTestList() {
// read out the test name it stoped last time.
try {
- BufferedReader inReader = new BufferedReader(new FileReader(TEST_STATUS_FILE));
- String line = inReader.readLine();
+ String line = FsUtils.readTestStatus(TEST_STATUS_FILE);
for (int i = 0; i < mTestList.size(); i++) {
if (mTestList.elementAt(i).equals(line)) {
mTestList = new Vector<String>(mTestList.subList(i+1, mTestList.size()));
break;
}
}
- inReader.close();
} catch (Exception e) {
Log.e(LOGTAG, "Error reading " + TEST_STATUS_FILE);
}
@@ -204,18 +202,7 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
Log.e(LOGTAG, "Fail to delete " + TEST_STATUS_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 String getResultFile(String test) {
String shortName = test.substring(0, test.lastIndexOf('.'));
// Write actual results to result directory.
@@ -223,7 +210,10 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
}
private String getExpectedResultFile(String test) {
- String shortName = test.substring(0, test.lastIndexOf('.'));
+ int pos = test.lastIndexOf('.');
+ if(pos == -1)
+ return null;
+ String shortName = test.substring(0, pos);
return shortName + "-expected.txt";
}
@@ -303,6 +293,10 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
});
String resultFile = getResultFile(test);
+ if(resultFile == null) {
+ //simply ignore this test
+ return;
+ }
if (mRebaselineResults) {
String expectedResultFile = getExpectedResultFile(test);
File f = new File(expectedResultFile);
@@ -385,12 +379,12 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
// Run tests.
for (int i = 0; i < mTestList.size(); i++) {
String s = mTestList.elementAt(i);
- updateTestStatus(s);
+ FsUtils.updateTestStatus(TEST_STATUS_FILE, s);
// Run tests
runTestAndWaitUntilDone(activity, s, runner.mTimeoutInMillis);
}
- updateTestStatus("#DONE");
+ FsUtils.updateTestStatus(TEST_STATUS_FILE, "#DONE");
activity.finish();
}
@@ -417,7 +411,7 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
try {
File tests_list = new File(LAYOUT_TESTS_LIST_FILE);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tests_list, false));
- findTestsRecursively(bos, getTestPath());
+ FsUtils.findLayoutTestsRecursively(bos, getTestPath());
bos.flush();
bos.close();
} catch (Exception e) {
@@ -425,38 +419,6 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
}
}
- private void findTestsRecursively(BufferedOutputStream bos, String dir) throws IOException {
- Log.v(LOGTAG, "Searching tests under " + dir);
-
- File d = new File(dir);
- if (!d.isDirectory()) {
- throw new AssertionError("A directory expected, but got " + dir);
- }
-
- String[] files = d.list();
- for (int i = 0; i < files.length; i++) {
- String s = dir + "/" + files[i];
- if (FileFilter.ignoreTest(s)) {
- Log.v(LOGTAG, " Ignoring: " + s);
- continue;
- }
- if (s.toLowerCase().endsWith(".html")
- || s.toLowerCase().endsWith(".xml")) {
- bos.write(s.getBytes());
- bos.write('\n');
- continue;
- }
-
- File f = new File(s);
- if (f.isDirectory()) {
- findTestsRecursively(bos, s);
- continue;
- }
-
- Log.v(LOGTAG, "Skipping " + s);
- }
- }
-
// Running all the layout tests at once sometimes
// causes the dumprendertree to run out of memory.
// So, additional tests are added to run the tests
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
index 81cf3a8..cbcac6c 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/LoadTestsAutoTest.java
@@ -16,18 +16,15 @@
package com.android.dumprendertree;
+import dalvik.system.VMRuntime;
+
import android.app.Instrumentation;
import android.content.Intent;
-
-import android.util.Log;
-
import android.os.Bundle;
import android.os.Debug;
-import android.os.Debug.MemoryInfo;
+import android.os.Process;
import android.test.ActivityInstrumentationTestCase2;
-
-import com.android.dumprendertree.TestShellActivity;
-import com.android.dumprendertree.TestShellCallback;
+import android.util.Log;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -69,52 +66,85 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel
TestShellActivity activity = (TestShellActivity) getActivity();
+ Log.v(LOGTAG, "About to run tests, calling gc first...");
+ freeMem();
+
// Run tests
runTestAndWaitUntilDone(activity, runner.mTestPath, runner.mTimeoutInMillis);
- // TODO(fqian): let am instrumentation pass in the command line, currently
- // am instrument does not allow spaces in the command.
dumpMemoryInfo();
// Kill activity
activity.finish();
}
+ private void freeMem() {
+ Log.v(LOGTAG, "freeMem: calling gc/finalization...");
+ final VMRuntime runtime = VMRuntime.getRuntime();
+
+ runtime.gcSoftReferences();
+ runtime.runFinalizationSync();
+ runtime.gcSoftReferences();
+ runtime.runFinalizationSync();
+ runtime.gcSoftReferences();
+ runtime.runFinalizationSync();
+ Runtime.getRuntime().runFinalization();
+ Runtime.getRuntime().gc();
+ Runtime.getRuntime().gc();
+
+ }
+
+ private void printRow(PrintStream ps, String format, Object...objs) {
+ ps.println(String.format(format, objs));
+ }
+
private void dumpMemoryInfo() {
try {
+ freeMem();
Log.v(LOGTAG, "Dumping memory information.");
FileOutputStream out = new FileOutputStream(LOAD_TEST_RESULT, true);
PrintStream ps = new PrintStream(out);
- MemoryInfo mi = new MemoryInfo();
- Debug.getMemoryInfo(mi);
-
- //try to fake the dumpsys format
- //this will eventually be changed to XML
- String format = "%15s:%9d%9d%9d%9d";
- String pss =
- String.format(format, "(Pss)",
- mi.nativePss, mi.dalvikPss, mi.otherPss,
- mi.nativePss + mi.dalvikPss + mi.otherPss);
- String sd =
- String.format(format, "(shared dirty)",
- mi.nativeSharedDirty, mi.dalvikSharedDirty, mi.otherSharedDirty,
- mi.nativeSharedDirty + mi.dalvikSharedDirty + mi.otherSharedDirty);
- String pd =
- String.format(format, "(priv dirty)",
- mi.nativePrivateDirty, mi.dalvikPrivateDirty, mi.otherPrivateDirty,
- mi.nativePrivateDirty + mi.dalvikPrivateDirty + mi.otherPrivateDirty);
-
ps.print("\n\n\n");
- ps.println("** MEMINFO in pid 0 [com.android.dumprendertree] **");
- ps.println(" native dalvik other total");
- ps.println(" size: 12060 5255 N/A 17315");
- ps.println(" allocated: 12060 5255 N/A 17315");
- ps.println(" free: 12060 5255 N/A 17315");
- ps.println(pss);
- ps.println(sd);
- ps.println(pd);
+ ps.println("** MEMINFO in pid " + Process.myPid()
+ + " [com.android.dumprendertree] **");
+ String formatString = "%17s %8s %8s %8s %8s";
+
+ long nativeMax = Debug.getNativeHeapSize() / 1024;
+ long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024;
+ long nativeFree = Debug.getNativeHeapFreeSize() / 1024;
+ Runtime runtime = Runtime.getRuntime();
+ long dalvikMax = runtime.totalMemory() / 1024;
+ long dalvikFree = runtime.freeMemory() / 1024;
+ long dalvikAllocated = dalvikMax - dalvikFree;
+
+
+ Debug.MemoryInfo memInfo = new Debug.MemoryInfo();
+ Debug.getMemoryInfo(memInfo);
+
+ final int nativeShared = memInfo.nativeSharedDirty;
+ final int dalvikShared = memInfo.dalvikSharedDirty;
+ final int otherShared = memInfo.otherSharedDirty;
+
+ final int nativePrivate = memInfo.nativePrivateDirty;
+ final int dalvikPrivate = memInfo.dalvikPrivateDirty;
+ final int otherPrivate = memInfo.otherPrivateDirty;
+
+ printRow(ps, formatString, "", "native", "dalvik", "other", "total");
+ printRow(ps, formatString, "size:", nativeMax, dalvikMax, "N/A", nativeMax + dalvikMax);
+ printRow(ps, formatString, "allocated:", nativeAllocated, dalvikAllocated, "N/A",
+ nativeAllocated + dalvikAllocated);
+ printRow(ps, formatString, "free:", nativeFree, dalvikFree, "N/A",
+ nativeFree + dalvikFree);
+
+ printRow(ps, formatString, "(Pss):", memInfo.nativePss, memInfo.dalvikPss,
+ memInfo.otherPss, memInfo.nativePss + memInfo.dalvikPss + memInfo.otherPss);
+
+ printRow(ps, formatString, "(shared dirty):", nativeShared, dalvikShared, otherShared,
+ nativeShared + dalvikShared + otherShared);
+ printRow(ps, formatString, "(priv dirty):", nativePrivate, dalvikPrivate, otherPrivate,
+ nativePrivate + dalvikPrivate + otherPrivate);
ps.print("\n\n\n");
ps.flush();
ps.close();
@@ -134,7 +164,7 @@ public class LoadTestsAutoTest extends ActivityInstrumentationTestCase2<TestShel
LoadTestsAutoTest.this.notifyAll();
}
}
-
+
public void timedOut(String url) {
}
});
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java b/tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java
index 00e0f89..e15ab65 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/Menu.java
@@ -17,19 +17,23 @@
package com.android.dumprendertree;
import android.content.Intent;
-import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
public class Menu extends FileList {
-
- public void onCreate(Bundle icicle)
- {
+
+ private static final int MENU_START = 0x01;
+ private static String LOGTAG = "MenuActivity";
+ static final String LAYOUT_TESTS_LIST_FILE = "/sdcard/android/layout_tests_list.txt";
+
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
}
-
+
boolean fileFilter(File f) {
if (f.getName().startsWith("."))
return false;
@@ -41,14 +45,36 @@ public class Menu extends FileList {
return true;
return false;
}
-
- void processFile(String filename, boolean selection)
- {
+
+ void processFile(String filename, boolean selection) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, TestShellActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(TestShellActivity.TEST_URL, "file://" + filename);
startActivity(intent);
}
+
+ @Override
+ void processDirectory(String path, boolean selection) {
+ generateTestList(path);
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setClass(this, TestShellActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ intent.putExtra(TestShellActivity.UI_AUTO_TEST, LAYOUT_TESTS_LIST_FILE);
+ startActivity(intent);
+ }
+
+ private void generateTestList(String path) {
+ try {
+ File tests_list = new File(LAYOUT_TESTS_LIST_FILE);
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tests_list, false));
+ FsUtils.findLayoutTestsRecursively(bos, path);
+ bos.flush();
+ bos.close();
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Error when creating test list: " + e.getMessage());
+ }
+ }
+
}
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java
new file mode 100644
index 0000000..de39800
--- /dev/null
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTest.java
@@ -0,0 +1,166 @@
+package com.android.dumprendertree;
+
+import android.os.Handler;
+import android.os.Message;
+import android.test.ActivityInstrumentationTestCase2;
+import android.util.Log;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class ReliabilityTest extends ActivityInstrumentationTestCase2<ReliabilityTestActivity> {
+
+ private static final String LOGTAG = "ReliabilityTest";
+ private static final String PKG_NAME = "com.android.dumprendertree";
+ 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";
+ private static final String TEST_LOAD_TIME_FILE = "/sdcard/android/reliability_load_time.txt";
+ private static final String TEST_DONE = "#DONE";
+ static final String RELIABILITY_TEST_RUNNER_FILES[] = {
+ "run_reliability_tests.py"
+ };
+
+ public ReliabilityTest() {
+ super(PKG_NAME, ReliabilityTestActivity.class);
+ }
+
+ public void runReliabilityTest() throws Throwable {
+ ReliabilityTestActivity activity = getActivity();
+ LayoutTestsAutoRunner runner = (LayoutTestsAutoRunner)getInstrumentation();
+
+ File testListFile = new File(TEST_LIST_FILE);
+ if(!testListFile.exists())
+ throw new FileNotFoundException("test list file not found.");
+
+ BufferedReader listReader = new BufferedReader(
+ new FileReader(testListFile));
+
+ //always try to resume first, hence cleaning up status will be the
+ //responsibility of driver scripts
+ String lastUrl = FsUtils.readTestStatus(TEST_STATUS_FILE);
+ if(lastUrl != null && !TEST_DONE.equals(lastUrl))
+ fastForward(listReader, lastUrl);
+
+ String url = null;
+ Handler handler = null;
+ boolean timeoutFlag = false;
+ long start, elapsed;
+
+ //read from BufferedReader instead of populating a list in advance,
+ //this will avoid excessive memory usage in case of a large list
+ while((url = listReader.readLine()) != null) {
+ url = url.trim();
+ if(url.length() == 0)
+ continue;
+ start = System.currentTimeMillis();
+ Log.v(LOGTAG, "Testing URL: " + url);
+ FsUtils.updateTestStatus(TEST_STATUS_FILE, url);
+ activity.reset();
+ //use message to send new URL to avoid interacting with
+ //WebView in non-UI thread
+ handler = activity.getHandler();
+ Message msg = handler.obtainMessage(
+ ReliabilityTestActivity.MSG_NAVIGATE,
+ runner.mTimeoutInMillis, runner.mDelay);
+ msg.getData().putString(ReliabilityTestActivity.MSG_NAV_URL, url);
+ msg.getData().putBoolean(ReliabilityTestActivity.MSG_NAV_LOGTIME,
+ runner.mLogtime);
+ handler.sendMessage(msg);
+ timeoutFlag = activity.waitUntilDone();
+ elapsed = System.currentTimeMillis() - start;
+ if(elapsed < 1000) {
+ Log.w(LOGTAG, "Page load finished in " + elapsed
+ + "ms, too soon?");
+ } else {
+ Log.v(LOGTAG, "Page load finished in " + elapsed + "ms");
+ }
+ if(timeoutFlag) {
+ writeTimeoutFile(url);
+ }
+ if(runner.mLogtime) {
+ writeLoadTime(url, activity.getPageLoadTime());
+ }
+ System.runFinalization();
+ System.gc();
+ System.gc();
+ }
+ FsUtils.updateTestStatus(TEST_STATUS_FILE, TEST_DONE);
+ activity.finish();
+ listReader.close();
+ }
+
+ 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) {
+ Log.e(LOGTAG, "Cannot extract scripts for testing.", e);
+ }
+ }
+
+ private void fastForward(BufferedReader testListReader, String lastUrl) {
+ //fastforward the BufferedReader to the position right after last url
+ if(lastUrl == null)
+ return;
+
+ String line = null;
+ try {
+ while((line = testListReader.readLine()) != null) {
+ if(lastUrl.equals(line))
+ return;
+ }
+ } catch (IOException ioe) {
+ Log.e(LOGTAG, "Error while reading test list.", ioe);
+ return;
+ }
+ }
+
+ private void writeTimeoutFile(String s) {
+ //append to the file containing the list of timeout urls
+ 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, e);
+ }
+ }
+
+ private void writeLoadTime(String s, long time) {
+ //append to the file containing the list of timeout urls
+ try {
+ BufferedOutputStream bos = new BufferedOutputStream(
+ new FileOutputStream(TEST_LOAD_TIME_FILE, true));
+ bos.write((s + '|' + time + '\n').getBytes());
+ bos.close();
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Cannot update file " + TEST_LOAD_TIME_FILE, e);
+ }
+ }
+}
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
new file mode 100644
index 0000000..5ddd0b3
--- /dev/null
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestActivity.java
@@ -0,0 +1,290 @@
+package com.android.dumprendertree;
+
+import android.app.Activity;
+import android.app.ActivityThread;
+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.webkit.SslErrorHandler;
+import android.webkit.WebChromeClient;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.webkit.WebSettings.LayoutAlgorithm;
+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) {
+ switch (msg.what) {
+ case MSG_TIMEOUT:
+ handleTimeout();
+ return;
+ case MSG_NAVIGATE:
+ manualDelay = msg.arg2;
+ 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;
+ }
+ timeoutFlag = false;
+ 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();
+ Log.v(LOGTAG, "Page timeout triggered, progress = " + progress);
+ timeoutFlag = true;
+ handler.postDelayed(pageDoneRunner, manualDelay);
+ }
+
+ public boolean waitUntilDone() {
+ validateNotAppThread();
+ synchronized (pageDoneLock) {
+ while(!isPageDone()) {
+ try {
+ pageDoneLock.wait();
+ } catch (InterruptedException ie) {
+ //no-op
+ }
+ }
+ }
+ return timeoutFlag;
+ }
+
+ public Handler getHandler() {
+ return handler;
+ }
+
+ private final void validateNotAppThread() {
+ if (ActivityThread.currentActivityThread() != null) {
+ throw new RuntimeException(
+ "This method can not be called from the main application thread");
+ }
+ }
+
+ public long getPageLoadTime() {
+ return pageLoadTime;
+ }
+
+ class SimpleWebViewClient extends WebViewClient {
+
+ @Override
+ public void onReceivedError(WebView view, int errorCode, String description,
+ String failingUrl) {
+ Log.v(LOGTAG, "Received WebCore error: code=" + errorCode
+ + ", 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);
+ // let handleTimeout take care of finishing the page
+ if(!timeoutFlag)
+ 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();
+ return true;
+ }
+
+ @Override
+ public boolean onJsPrompt(WebView view, String url, String message, String defaultValue,
+ JsPromptResult result) {
+ 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
+ handler.removeMessages(MSG_TIMEOUT);
+ webView.stopLoading();
+ handler.postDelayed(pageDoneRunner, manualDelay);
+ }
+ }
+ }
+
+ class PageDoneRunner implements Runnable {
+
+ public void run() {
+ Log.v(LOGTAG, "Finishing URL: " + webView.getUrl());
+ pageLoadTime = System.currentTimeMillis() - startTime;
+ setPageDone(true);
+ }
+ }
+}
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestsAutoTest.java b/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestsAutoTest.java
deleted file mode 100644
index 347efde..0000000
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/ReliabilityTestsAutoTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-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 1ba291c..0d22eca 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
@@ -17,7 +17,10 @@
package com.android.dumprendertree;
import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import android.content.Intent;
+import android.content.DialogInterface.OnClickListener;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Bundle;
@@ -35,21 +38,24 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileReader;
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());
+ if(mCallback != null)
+ mCallback.timedOut(mWebView.getUrl());
requestWebKitData();
return;
} else if (msg.what == MSG_WEBKIT_DATA) {
@@ -63,10 +69,10 @@ public class TestShellActivity extends Activity implements LayoutTestController
public void requestWebKitData() {
Message callback = mHandler.obtainMessage(MSG_WEBKIT_DATA);
-
+
if (mRequestedWebKitData)
throw new AssertionError("Requested webkit data twice: " + mWebView.getUrl());
-
+
mRequestedWebKitData = true;
switch (mDumpDataType) {
case DUMP_AS_TEXT:
@@ -79,12 +85,12 @@ public class TestShellActivity extends Activity implements LayoutTestController
finished();
break;
}
- }
+ }
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
-
+
LinearLayout contentView = new LinearLayout(this);
contentView.setOrientation(LinearLayout.VERTICAL);
setContentView(contentView);
@@ -133,59 +139,122 @@ public class TestShellActivity extends Activity implements LayoutTestController
mWebView.addJavascriptInterface(mCallbackProxy, "layoutTestController");
mWebView.addJavascriptInterface(mCallbackProxy, "eventSender");
contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0f));
-
+
mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
-
+
mHandler = new AsyncHandler();
-
+
Intent intent = getIntent();
if (intent != null) {
executeIntent(intent);
}
}
-
+
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
executeIntent(intent);
}
-
+
private void executeIntent(Intent intent) {
resetTestStatus();
if (!Intent.ACTION_VIEW.equals(intent.getAction())) {
return;
}
-
+
mTestUrl = intent.getStringExtra(TEST_URL);
- if (mTestUrl == null)
+ if (mTestUrl == null) {
+ mUiAutoTestPath = intent.getStringExtra(UI_AUTO_TEST);
+ if(mUiAutoTestPath != null) {
+ beginUiAutoTest();
+ }
return;
-
+ }
+
mResultFile = intent.getStringExtra(RESULT_FILE);
mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0);
Log.v(LOGTAG, " Loading " + mTestUrl);
mWebView.loadUrl(mTestUrl);
-
+
if (mTimeoutInMillis > 0) {
// Create a timeout timer
Message m = mHandler.obtainMessage(MSG_TIMEOUT);
mHandler.sendMessageDelayed(m, mTimeoutInMillis);
}
}
-
+
+ private void beginUiAutoTest() {
+ try {
+ mTestListReader = new BufferedReader(
+ new FileReader(mUiAutoTestPath));
+ } catch (IOException ioe) {
+ Log.e(LOGTAG, "Failed to open test list for read.", ioe);
+ finishUiAutoTest();
+ return;
+ }
+ moveToNextTest();
+ }
+
+ private void finishUiAutoTest() {
+ try {
+ if(mTestListReader != null)
+ mTestListReader.close();
+ } catch (IOException ioe) {
+ Log.w(LOGTAG, "Failed to close test list file.", ioe);
+ }
+ finished();
+ }
+
+ private void moveToNextTest() {
+ String url = null;
+ try {
+ url = mTestListReader.readLine();
+ } catch (IOException ioe) {
+ Log.e(LOGTAG, "Failed to read next test.", ioe);
+ finishUiAutoTest();
+ return;
+ }
+ if (url == null) {
+ mUiAutoTestPath = null;
+ finishUiAutoTest();
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage("All tests finished. Exit?")
+ .setCancelable(false)
+ .setPositiveButton("Yes", new OnClickListener(){
+ public void onClick(DialogInterface dialog, int which) {
+ TestShellActivity.this.finish();
+ }
+ })
+ .setNegativeButton("No", new OnClickListener(){
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ });
+ builder.create().show();
+ return;
+ }
+ url = "file://" + url;
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ intent.putExtra(TestShellActivity.TEST_URL, url);
+ intent.putExtra(TIMEOUT_IN_MILLIS, 10000);
+ executeIntent(intent);
+ }
+
@Override
protected void onStop() {
super.onStop();
mWebView.stopLoading();
}
-
+
@Override
protected void onDestroy() {
super.onDestroy();
mWebView.destroy();
mWebView = null;
}
-
+
@Override
public void onLowMemory() {
super.onLowMemory();
@@ -199,13 +268,13 @@ public class TestShellActivity extends Activity implements LayoutTestController
finished();
return;
}
-
+
try {
File parentDir = new File(mResultFile).getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}
-
+
FileOutputStream os = new FileOutputStream(mResultFile);
if (timeout) {
Log.w("Layout test: Timeout", mResultFile);
@@ -222,22 +291,27 @@ public class TestShellActivity extends Activity implements LayoutTestController
os.flush();
os.close();
} catch (IOException ex) {
- Log.e(LOGTAG, "Cannot write to " + mResultFile + ", " + ex.getMessage());
+ Log.e(LOGTAG, "Cannot write to " + mResultFile + ", " + ex.getMessage());
}
finished();
}
-
+
public void setCallback(TestShellCallback callback) {
mCallback = callback;
}
-
+
public void finished() {
- if (mCallback != null) {
- mCallback.finished();
+ if (mUiAutoTestPath != null) {
+ //don't really finish here
+ moveToNextTest();
+ } else {
+ if (mCallback != null) {
+ mCallback.finished();
+ }
}
}
-
+
public void setDefaultDumpDataType(DumpDataType defaultDumpDataType) {
mDefaultDumpDataType = defaultDumpDataType;
}
@@ -257,7 +331,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
String url = mWebView.getUrl();
Log.v(LOGTAG, "waitUntilDone called: " + url);
}
-
+
public void notifyDone() {
String url = mWebView.getUrl();
Log.v(LOGTAG, "notifyDone called: " + url);
@@ -266,7 +340,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
mChromeClient.onProgressChanged(mWebView, 100);
}
}
-
+
public void display() {
mWebView.invalidate();
}
@@ -332,7 +406,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
}
public void queueScript(String scriptToRunInCurrentContext) {
- mWebView.loadUrl("javascript:"+scriptToRunInCurrentContext);
+ mWebView.loadUrl("javascript:"+scriptToRunInCurrentContext);
}
public void repaintSweepHorizontally() {
@@ -359,7 +433,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
public void testRepaint() {
mWebView.invalidate();
}
-
+
private final WebChromeClient mChromeClient = new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
@@ -406,7 +480,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
result.confirm();
return true;
}
-
+
@Override
public boolean onJsConfirm(WebView view, String url, String message,
JsResult result) {
@@ -419,7 +493,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
result.confirm();
return true;
}
-
+
@Override
public boolean onJsPrompt(WebView view, String url, String message,
String defaultValue, JsPromptResult result) {
@@ -435,7 +509,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
return true;
}
};
-
+
private void resetTestStatus() {
mWaitUntilDone = false;
mDumpDataType = mDefaultDumpDataType;
@@ -444,17 +518,19 @@ public class TestShellActivity extends Activity implements LayoutTestController
mRequestedWebKitData = false;
mEventSender.resetMouse();
}
-
+
private WebView mWebView;
private WebViewEventSender mEventSender;
private AsyncHandler mHandler;
private TestShellCallback mCallback;
private CallbackProxy mCallbackProxy;
-
+
private String mTestUrl;
private String mResultFile;
private int mTimeoutInMillis;
+ private String mUiAutoTestPath;
+ private BufferedReader mTestListReader;
// States
private boolean mTimedOut;
@@ -472,13 +548,14 @@ public class TestShellActivity extends Activity implements LayoutTestController
private Vector mWebHistory;
static final String TIMEOUT_STR = "**Test timeout";
-
+
static final int MSG_TIMEOUT = 0;
static final int MSG_WEBKIT_DATA = 1;
static final String LOGTAG="TestShell";
-
+
static final String TEST_URL = "TestUrl";
static final String RESULT_FILE = "ResultFile";
static final String TIMEOUT_IN_MILLIS = "TimeoutInMillis";
+ static final String UI_AUTO_TEST = "UiAutoTest";
}