Merge change 5645 into donut

* changes:
  Added a new operation mode where user can launch all tests under a folder from test app ui.
This commit is contained in:
Android (Google) Code Review
2009-06-29 15:44:19 -07:00
6 changed files with 288 additions and 150 deletions

View File

@@ -23,7 +23,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.io.File; import java.io.File;
import android.app.AlertDialog;
import android.app.ListActivity; import android.app.ListActivity;
import android.content.DialogInterface;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
@@ -31,7 +33,7 @@ import android.widget.SimpleAdapter;
import android.os.Bundle; import android.os.Bundle;
public abstract class FileList extends ListActivity public abstract class FileList extends ListActivity
{ {
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) switch (keyCode)
@@ -39,7 +41,7 @@ public abstract class FileList extends ListActivity
case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_LEFT:
if (mPath.length() > mBaseLength) { if (mPath.length() > mBaseLength) {
File f = new File(mPath); File f = new File(mPath);
mFocusFile = f.getName(); mFocusFile = f.getName();
mFocusIndex = 0; mFocusIndex = 0;
f = f.getParentFile(); f = f.getParentFile();
mPath = f.getPath(); mPath = f.getPath();
@@ -47,7 +49,7 @@ public abstract class FileList extends ListActivity
return true; return true;
} }
break; break;
case KeyEvent.KEYCODE_DPAD_RIGHT: case KeyEvent.KEYCODE_DPAD_RIGHT:
{ {
Map map = (Map) getListView().getItemAtPosition(getListView().getSelectedItemPosition()); Map map = (Map) getListView().getItemAtPosition(getListView().getSelectedItemPosition());
@@ -61,24 +63,24 @@ public abstract class FileList extends ListActivity
} }
return true; return true;
} }
default: default:
break; break;
} }
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
public void onCreate(Bundle icicle) public void onCreate(Bundle icicle)
{ {
super.onCreate(icicle); super.onCreate(icicle);
setupPath(); setupPath();
updateList(); updateList();
} }
protected List getData() protected List getData()
{ {
List myData = new ArrayList<HashMap>(); List myData = new ArrayList<HashMap>();
File f = new File(mPath); File f = new File(mPath);
if (!f.exists()) { if (!f.exists()) {
addItem(myData, "!LayoutTests path missing!", ""); addItem(myData, "!LayoutTests path missing!", "");
@@ -103,10 +105,10 @@ public abstract class FileList extends ListActivity
addItem(myData, files[i], path); addItem(myData, files[i], path);
} }
} }
return myData; return myData;
} }
protected void addItem(List<Map> data, String name, String path) protected void addItem(List<Map> data, String name, String path)
{ {
HashMap temp = new HashMap(); HashMap temp = new HashMap();
@@ -114,34 +116,58 @@ public abstract class FileList extends ListActivity
temp.put("path", path); temp.put("path", path);
data.add(temp); data.add(temp);
} }
protected void onListItemClick(ListView l, View v, int position, long id) protected void onListItemClick(ListView l, View v, int position, long id)
{ {
Map map = (Map) l.getItemAtPosition(position); Map map = (Map) l.getItemAtPosition(position);
String path = (String)map.get("path"); final String path = (String)map.get("path");
if ((new File(path)).isDirectory()) { if ((new File(path)).isDirectory()) {
mPath = path; final CharSequence[] items = {"Open", "Run"};
mFocusFile = null; AlertDialog.Builder builder = new AlertDialog.Builder(this);
updateList(); 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 { } else {
processFile(path, false); 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 * 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. * file list. The selected file could be a file or a directory.
* The flag indicates if this was from a selection or not. * The flag indicates if this was from a selection or not.
*/ */
abstract void processFile(String filename, boolean selection); abstract void processFile(String filename, boolean selection);
/* /*
* This function is called when the file list is being built. Return * This function is called when the file list is being built. Return
* true if the file is to be added to the file list. * true if the file is to be added to the file list.
*/ */
abstract boolean fileFilter(File f); abstract boolean fileFilter(File f);
protected void updateList() { protected void updateList() {
setListAdapter(new SimpleAdapter(this, setListAdapter(new SimpleAdapter(this,
getData(), getData(),
@@ -152,16 +178,19 @@ public abstract class FileList extends ListActivity
setTitle(title); setTitle(title);
getListView().setSelection(mFocusIndex); getListView().setSelection(mFocusIndex);
} }
protected void setupPath() protected void setupPath()
{ {
mPath = "/sdcard/android/layout_tests"; mPath = "/sdcard/android/layout_tests";
mBaseLength = mPath.length(); mBaseLength = mPath.length();
} }
protected String mPath; protected String mPath;
protected int mBaseLength; protected int mBaseLength;
protected String mFocusFile; protected String mFocusFile;
protected int mFocusIndex; protected int mFocusIndex;
private final static int OPEN_DIRECTORY = 0;
private final static int RUN_TESTS = 1;
} }

View File

@@ -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;
}
}

View File

@@ -178,15 +178,13 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
private void resumeTestList() { private void resumeTestList() {
// read out the test name it stoped last time. // read out the test name it stoped last time.
try { try {
BufferedReader inReader = new BufferedReader(new FileReader(TEST_STATUS_FILE)); String line = FsUtils.readTestStatus(TEST_STATUS_FILE);
String line = inReader.readLine();
for (int i = 0; i < mTestList.size(); i++) { for (int i = 0; i < mTestList.size(); i++) {
if (mTestList.elementAt(i).equals(line)) { if (mTestList.elementAt(i).equals(line)) {
mTestList = new Vector<String>(mTestList.subList(i+1, mTestList.size())); mTestList = new Vector<String>(mTestList.subList(i+1, mTestList.size()));
break; break;
} }
} }
inReader.close();
} catch (Exception e) { } catch (Exception e) {
Log.e(LOGTAG, "Error reading " + TEST_STATUS_FILE); 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()); 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) { private String getResultFile(String test) {
String shortName = test.substring(0, test.lastIndexOf('.')); String shortName = test.substring(0, test.lastIndexOf('.'));
// Write actual results to result directory. // Write actual results to result directory.
@@ -392,12 +379,12 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
// Run tests. // Run tests.
for (int i = 0; i < mTestList.size(); i++) { for (int i = 0; i < mTestList.size(); i++) {
String s = mTestList.elementAt(i); String s = mTestList.elementAt(i);
updateTestStatus(s); FsUtils.updateTestStatus(TEST_STATUS_FILE, s);
// Run tests // Run tests
runTestAndWaitUntilDone(activity, s, runner.mTimeoutInMillis); runTestAndWaitUntilDone(activity, s, runner.mTimeoutInMillis);
} }
updateTestStatus("#DONE"); FsUtils.updateTestStatus(TEST_STATUS_FILE, "#DONE");
activity.finish(); activity.finish();
} }
@@ -424,7 +411,7 @@ public class LayoutTestsAutoTest extends ActivityInstrumentationTestCase2<TestSh
try { try {
File tests_list = new File(LAYOUT_TESTS_LIST_FILE); File tests_list = new File(LAYOUT_TESTS_LIST_FILE);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tests_list, false)); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tests_list, false));
findTestsRecursively(bos, getTestPath()); FsUtils.findLayoutTestsRecursively(bos, getTestPath());
bos.flush(); bos.flush();
bos.close(); bos.close();
} catch (Exception e) { } catch (Exception e) {
@@ -432,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 // Running all the layout tests at once sometimes
// causes the dumprendertree to run out of memory. // causes the dumprendertree to run out of memory.
// So, additional tests are added to run the tests // So, additional tests are added to run the tests

View File

@@ -17,19 +17,23 @@
package com.android.dumprendertree; package com.android.dumprendertree;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
public class Menu extends FileList { 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); super.onCreate(icicle);
} }
boolean fileFilter(File f) { boolean fileFilter(File f) {
if (f.getName().startsWith(".")) if (f.getName().startsWith("."))
return false; return false;
@@ -41,14 +45,36 @@ public class Menu extends FileList {
return true; return true;
return false; return false;
} }
void processFile(String filename, boolean selection) void processFile(String filename, boolean selection) {
{
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClass(this, TestShellActivity.class); intent.setClass(this, TestShellActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(TestShellActivity.TEST_URL, "file://" + filename); intent.putExtra(TestShellActivity.TEST_URL, "file://" + filename);
startActivity(intent); 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());
}
}
} }

View File

@@ -45,7 +45,7 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit
//always try to resume first, hence cleaning up status will be the //always try to resume first, hence cleaning up status will be the
//responsibility of driver scripts //responsibility of driver scripts
String lastUrl = readTestStatus(); String lastUrl = FsUtils.readTestStatus(TEST_STATUS_FILE);
if(lastUrl != null && !TEST_DONE.equals(lastUrl)) if(lastUrl != null && !TEST_DONE.equals(lastUrl))
fastForward(listReader, lastUrl); fastForward(listReader, lastUrl);
@@ -62,7 +62,7 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit
continue; continue;
start = System.currentTimeMillis(); start = System.currentTimeMillis();
Log.v(LOGTAG, "Testing URL: " + url); Log.v(LOGTAG, "Testing URL: " + url);
updateTestStatus(url); FsUtils.updateTestStatus(TEST_STATUS_FILE, url);
activity.reset(); activity.reset();
//use message to send new URL to avoid interacting with //use message to send new URL to avoid interacting with
//WebView in non-UI thread //WebView in non-UI thread
@@ -92,7 +92,7 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit
System.gc(); System.gc();
System.gc(); System.gc();
} }
updateTestStatus(TEST_DONE); FsUtils.updateTestStatus(TEST_STATUS_FILE, TEST_DONE);
activity.finish(); activity.finish();
listReader.close(); listReader.close();
} }
@@ -122,35 +122,6 @@ public class ReliabilityTest extends ActivityInstrumentationTestCase2<Reliabilit
} }
} }
private void updateTestStatus(String s) {
// write last tested url into status file
try {
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(TEST_STATUS_FILE));
bos.write(s.getBytes());
bos.close();
} catch (IOException e) {
Log.e(LOGTAG, "Cannot update file " + TEST_STATUS_FILE, e);
}
}
private String readTestStatus() {
// read out the test name it stopped last time.
String status = null;
File testStatusFile = new File(TEST_STATUS_FILE);
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;
}
private void fastForward(BufferedReader testListReader, String lastUrl) { private void fastForward(BufferedReader testListReader, String lastUrl) {
//fastforward the BufferedReader to the position right after last url //fastforward the BufferedReader to the position right after last url
if(lastUrl == null) if(lastUrl == null)

View File

@@ -17,7 +17,10 @@
package com.android.dumprendertree; package com.android.dumprendertree;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.net.http.SslError; import android.net.http.SslError;
import android.os.Bundle; import android.os.Bundle;
@@ -35,21 +38,24 @@ import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.Vector; import java.util.Vector;
public class TestShellActivity extends Activity implements LayoutTestController { public class TestShellActivity extends Activity implements LayoutTestController {
static enum DumpDataType {DUMP_AS_TEXT, EXT_REPR, NO_OP} static enum DumpDataType {DUMP_AS_TEXT, EXT_REPR, NO_OP}
public class AsyncHandler extends Handler { public class AsyncHandler extends Handler {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
if (msg.what == MSG_TIMEOUT) { if (msg.what == MSG_TIMEOUT) {
mTimedOut = true; mTimedOut = true;
mCallback.timedOut(mWebView.getUrl()); if(mCallback != null)
mCallback.timedOut(mWebView.getUrl());
requestWebKitData(); requestWebKitData();
return; return;
} else if (msg.what == MSG_WEBKIT_DATA) { } else if (msg.what == MSG_WEBKIT_DATA) {
@@ -63,10 +69,10 @@ public class TestShellActivity extends Activity implements LayoutTestController
public void requestWebKitData() { public void requestWebKitData() {
Message callback = mHandler.obtainMessage(MSG_WEBKIT_DATA); Message callback = mHandler.obtainMessage(MSG_WEBKIT_DATA);
if (mRequestedWebKitData) if (mRequestedWebKitData)
throw new AssertionError("Requested webkit data twice: " + mWebView.getUrl()); throw new AssertionError("Requested webkit data twice: " + mWebView.getUrl());
mRequestedWebKitData = true; mRequestedWebKitData = true;
switch (mDumpDataType) { switch (mDumpDataType) {
case DUMP_AS_TEXT: case DUMP_AS_TEXT:
@@ -79,12 +85,12 @@ public class TestShellActivity extends Activity implements LayoutTestController
finished(); finished();
break; break;
} }
} }
@Override @Override
protected void onCreate(Bundle icicle) { protected void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
LinearLayout contentView = new LinearLayout(this); LinearLayout contentView = new LinearLayout(this);
contentView.setOrientation(LinearLayout.VERTICAL); contentView.setOrientation(LinearLayout.VERTICAL);
setContentView(contentView); setContentView(contentView);
@@ -133,59 +139,122 @@ public class TestShellActivity extends Activity implements LayoutTestController
mWebView.addJavascriptInterface(mCallbackProxy, "layoutTestController"); mWebView.addJavascriptInterface(mCallbackProxy, "layoutTestController");
mWebView.addJavascriptInterface(mCallbackProxy, "eventSender"); mWebView.addJavascriptInterface(mCallbackProxy, "eventSender");
contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0f)); contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0f));
mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
mHandler = new AsyncHandler(); mHandler = new AsyncHandler();
Intent intent = getIntent(); Intent intent = getIntent();
if (intent != null) { if (intent != null) {
executeIntent(intent); executeIntent(intent);
} }
} }
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
executeIntent(intent); executeIntent(intent);
} }
private void executeIntent(Intent intent) { private void executeIntent(Intent intent) {
resetTestStatus(); resetTestStatus();
if (!Intent.ACTION_VIEW.equals(intent.getAction())) { if (!Intent.ACTION_VIEW.equals(intent.getAction())) {
return; return;
} }
mTestUrl = intent.getStringExtra(TEST_URL); mTestUrl = intent.getStringExtra(TEST_URL);
if (mTestUrl == null) if (mTestUrl == null) {
mUiAutoTestPath = intent.getStringExtra(UI_AUTO_TEST);
if(mUiAutoTestPath != null) {
beginUiAutoTest();
}
return; return;
}
mResultFile = intent.getStringExtra(RESULT_FILE); mResultFile = intent.getStringExtra(RESULT_FILE);
mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0); mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0);
Log.v(LOGTAG, " Loading " + mTestUrl); Log.v(LOGTAG, " Loading " + mTestUrl);
mWebView.loadUrl(mTestUrl); mWebView.loadUrl(mTestUrl);
if (mTimeoutInMillis > 0) { if (mTimeoutInMillis > 0) {
// Create a timeout timer // Create a timeout timer
Message m = mHandler.obtainMessage(MSG_TIMEOUT); Message m = mHandler.obtainMessage(MSG_TIMEOUT);
mHandler.sendMessageDelayed(m, mTimeoutInMillis); 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 @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
mWebView.stopLoading(); mWebView.stopLoading();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
mWebView.destroy(); mWebView.destroy();
mWebView = null; mWebView = null;
} }
@Override @Override
public void onLowMemory() { public void onLowMemory() {
super.onLowMemory(); super.onLowMemory();
@@ -199,13 +268,13 @@ public class TestShellActivity extends Activity implements LayoutTestController
finished(); finished();
return; return;
} }
try { try {
File parentDir = new File(mResultFile).getParentFile(); File parentDir = new File(mResultFile).getParentFile();
if (!parentDir.exists()) { if (!parentDir.exists()) {
parentDir.mkdirs(); parentDir.mkdirs();
} }
FileOutputStream os = new FileOutputStream(mResultFile); FileOutputStream os = new FileOutputStream(mResultFile);
if (timeout) { if (timeout) {
Log.w("Layout test: Timeout", mResultFile); Log.w("Layout test: Timeout", mResultFile);
@@ -222,22 +291,27 @@ public class TestShellActivity extends Activity implements LayoutTestController
os.flush(); os.flush();
os.close(); os.close();
} catch (IOException ex) { } catch (IOException ex) {
Log.e(LOGTAG, "Cannot write to " + mResultFile + ", " + ex.getMessage()); Log.e(LOGTAG, "Cannot write to " + mResultFile + ", " + ex.getMessage());
} }
finished(); finished();
} }
public void setCallback(TestShellCallback callback) { public void setCallback(TestShellCallback callback) {
mCallback = callback; mCallback = callback;
} }
public void finished() { public void finished() {
if (mCallback != null) { if (mUiAutoTestPath != null) {
mCallback.finished(); //don't really finish here
moveToNextTest();
} else {
if (mCallback != null) {
mCallback.finished();
}
} }
} }
public void setDefaultDumpDataType(DumpDataType defaultDumpDataType) { public void setDefaultDumpDataType(DumpDataType defaultDumpDataType) {
mDefaultDumpDataType = defaultDumpDataType; mDefaultDumpDataType = defaultDumpDataType;
} }
@@ -257,7 +331,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
String url = mWebView.getUrl(); String url = mWebView.getUrl();
Log.v(LOGTAG, "waitUntilDone called: " + url); Log.v(LOGTAG, "waitUntilDone called: " + url);
} }
public void notifyDone() { public void notifyDone() {
String url = mWebView.getUrl(); String url = mWebView.getUrl();
Log.v(LOGTAG, "notifyDone called: " + url); Log.v(LOGTAG, "notifyDone called: " + url);
@@ -266,7 +340,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
mChromeClient.onProgressChanged(mWebView, 100); mChromeClient.onProgressChanged(mWebView, 100);
} }
} }
public void display() { public void display() {
mWebView.invalidate(); mWebView.invalidate();
} }
@@ -332,7 +406,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
} }
public void queueScript(String scriptToRunInCurrentContext) { public void queueScript(String scriptToRunInCurrentContext) {
mWebView.loadUrl("javascript:"+scriptToRunInCurrentContext); mWebView.loadUrl("javascript:"+scriptToRunInCurrentContext);
} }
public void repaintSweepHorizontally() { public void repaintSweepHorizontally() {
@@ -359,7 +433,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
public void testRepaint() { public void testRepaint() {
mWebView.invalidate(); mWebView.invalidate();
} }
private final WebChromeClient mChromeClient = new WebChromeClient() { private final WebChromeClient mChromeClient = new WebChromeClient() {
@Override @Override
public void onProgressChanged(WebView view, int newProgress) { public void onProgressChanged(WebView view, int newProgress) {
@@ -406,7 +480,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
result.confirm(); result.confirm();
return true; return true;
} }
@Override @Override
public boolean onJsConfirm(WebView view, String url, String message, public boolean onJsConfirm(WebView view, String url, String message,
JsResult result) { JsResult result) {
@@ -419,7 +493,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
result.confirm(); result.confirm();
return true; return true;
} }
@Override @Override
public boolean onJsPrompt(WebView view, String url, String message, public boolean onJsPrompt(WebView view, String url, String message,
String defaultValue, JsPromptResult result) { String defaultValue, JsPromptResult result) {
@@ -435,7 +509,7 @@ public class TestShellActivity extends Activity implements LayoutTestController
return true; return true;
} }
}; };
private void resetTestStatus() { private void resetTestStatus() {
mWaitUntilDone = false; mWaitUntilDone = false;
mDumpDataType = mDefaultDumpDataType; mDumpDataType = mDefaultDumpDataType;
@@ -444,17 +518,19 @@ public class TestShellActivity extends Activity implements LayoutTestController
mRequestedWebKitData = false; mRequestedWebKitData = false;
mEventSender.resetMouse(); mEventSender.resetMouse();
} }
private WebView mWebView; private WebView mWebView;
private WebViewEventSender mEventSender; private WebViewEventSender mEventSender;
private AsyncHandler mHandler; private AsyncHandler mHandler;
private TestShellCallback mCallback; private TestShellCallback mCallback;
private CallbackProxy mCallbackProxy; private CallbackProxy mCallbackProxy;
private String mTestUrl; private String mTestUrl;
private String mResultFile; private String mResultFile;
private int mTimeoutInMillis; private int mTimeoutInMillis;
private String mUiAutoTestPath;
private BufferedReader mTestListReader;
// States // States
private boolean mTimedOut; private boolean mTimedOut;
@@ -472,13 +548,14 @@ public class TestShellActivity extends Activity implements LayoutTestController
private Vector mWebHistory; private Vector mWebHistory;
static final String TIMEOUT_STR = "**Test timeout"; static final String TIMEOUT_STR = "**Test timeout";
static final int MSG_TIMEOUT = 0; static final int MSG_TIMEOUT = 0;
static final int MSG_WEBKIT_DATA = 1; static final int MSG_WEBKIT_DATA = 1;
static final String LOGTAG="TestShell"; static final String LOGTAG="TestShell";
static final String TEST_URL = "TestUrl"; static final String TEST_URL = "TestUrl";
static final String RESULT_FILE = "ResultFile"; static final String RESULT_FILE = "ResultFile";
static final String TIMEOUT_IN_MILLIS = "TimeoutInMillis"; static final String TIMEOUT_IN_MILLIS = "TimeoutInMillis";
static final String UI_AUTO_TEST = "UiAutoTest";
} }