diff --git a/tests/DumpRenderTree2/AndroidManifest.xml b/tests/DumpRenderTree2/AndroidManifest.xml
index baa365c976474..3454316495b44 100644
--- a/tests/DumpRenderTree2/AndroidManifest.xml
+++ b/tests/DumpRenderTree2/AndroidManifest.xml
@@ -24,5 +24,12 @@ limitations under the License.
If the path doesn't contain an extension, it adds the ending to the path. + * + * @param relativePath + * @param newEnding + * @return + * a new path, containing the newExtension + */ + public static String setPathEnding(String relativePath, String newEnding) { + int dotPos = relativePath.lastIndexOf('.'); + if (dotPos == -1) { + return relativePath + newEnding; + } + + return relativePath.substring(0, dotPos) + newEnding; + } +} \ No newline at end of file diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java new file mode 100644 index 0000000000000..68daaf0d0a0a6 --- /dev/null +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dumprendertree2; + +import android.util.Log; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +/** + * + */ +public class FsUtils { + public static final String LOG_TAG = "FsUtils"; + + public static void writeDataToStorage(File file, byte[] bytes, boolean append) { + Log.d(LOG_TAG + "::writeDataToStorage", file.getAbsolutePath()); + try { + OutputStream outputStream = null; + try { + file.getParentFile().mkdirs(); + file.createNewFile(); + Log.d(LOG_TAG + "::writeDataToStorage", "File created."); + outputStream = new FileOutputStream(file, append); + outputStream.write(bytes); + } finally { + if (outputStream != null) { + outputStream.close(); + } + } + } catch (IOException e) { + Log.e(LOG_TAG + "::writeDataToStorage", e.getMessage()); + } + } +} diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTest.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTest.java new file mode 100644 index 0000000000000..605afab66a136 --- /dev/null +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dumprendertree2; + +import android.os.Handler; + +/** + * A class that represents a single layout test. It is responsible for running the test, + * checking its result and creating an AbstractResult object. + */ +public class LayoutTest { + + private String mRelativePath; + private Handler mCallbackHandler; + private AbstractResult mResult; + + public LayoutTest(String relativePath, Handler callbackHandler) { + mRelativePath = relativePath; + mCallbackHandler = callbackHandler; + } + + public void run() { + /** TODO: This is just a stub! */ + mCallbackHandler.obtainMessage(LayoutTestsRunnerThread.MSG_TEST_FINISHED).sendToTarget(); + } + + public AbstractResult getResult() { + return mResult; + } + + public String getRelativePath() { + return mRelativePath; + } +} \ No newline at end of file diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunner.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunner.java new file mode 100644 index 0000000000000..c18abcccb5f83 --- /dev/null +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunner.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dumprendertree2; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.view.Window; + +/** + * An Activity that is responsible only for updating the UI features, like titles, progress bars, + * etc. + * + *
Also, the webview form the test must be running in this activity's thread if we want
+ * to be able to display it on the screen.
+ */
+public class LayoutTestsRunner extends Activity {
+
+ public static final int MSG_UPDATE_PROGRESS = 1;
+ public static final int MSG_SHOW_PROGRESS_DIALOG = 2;
+ public static final int MSG_DISMISS_PROGRESS_DIALOG = 3;
+
+ /** Constants for adding extras to an intent */
+ public static final String EXTRA_TEST_PATH = "TestPath";
+
+ private static ProgressDialog sProgressDialog;
+
+ private Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_UPDATE_PROGRESS:
+ int i = msg.arg1;
+ int size = msg.arg2;
+ getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
+ i * Window.PROGRESS_END / size);
+ setTitle(i * 100 / size + "% (" + i + "/" + size + ")");
+ break;
+
+ case MSG_SHOW_PROGRESS_DIALOG:
+ sProgressDialog.show();
+ break;
+
+ case MSG_DISMISS_PROGRESS_DIALOG:
+ sProgressDialog.dismiss();
+ break;
+ }
+ }
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ /** Prepare the progress dialog */
+ sProgressDialog = new ProgressDialog(LayoutTestsRunner.this);
+ sProgressDialog.setCancelable(false);
+ sProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
+ sProgressDialog.setTitle(R.string.dialog_progress_title);
+ sProgressDialog.setMessage(getText(R.string.dialog_progress_msg));
+
+ requestWindowFeature(Window.FEATURE_PROGRESS);
+
+ /** Execute the intent */
+ Intent intent = getIntent();
+ if (!intent.getAction().equals(Intent.ACTION_RUN)) {
+ return;
+ }
+ String path = intent.getStringExtra(EXTRA_TEST_PATH);
+
+ new LayoutTestsRunnerThread(path, mHandler).start();
+ }
+}
\ No newline at end of file
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunnerThread.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunnerThread.java
new file mode 100644
index 0000000000000..d75579e70b1e4
--- /dev/null
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunnerThread.java
@@ -0,0 +1,252 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.dumprendertree2;
+
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Log;
+
+import java.io.File;
+import java.util.LinkedList;
+
+/**
+ * A Thread that is responsible for finding and loading the tests, starting them and
+ * generating summaries. The actual running of the test is delegated to LayoutTestsRunner
+ * activity (a UI thread) because of a WebView object that need to be created in UI thread
+ * so it can be displayed on the screen. However, the logic for doing this remains in
+ * this class (in handler created in constructor).
+ */
+public class LayoutTestsRunnerThread extends Thread {
+
+ private static final String LOG_TAG = "LayoutTestsRunnerThread";
+
+ /** Messages for handler on this thread */
+ public static final int MSG_TEST_FINISHED = 0;
+
+ /** Messages for our handler running on UI thread */
+ public static final int MSG_RUN_TEST = 0;
+
+ /** TODO: make it a setting */
+ private static final String TESTS_ROOT_DIR_PATH =
+ Environment.getExternalStorageDirectory() +
+ File.separator + "android" +
+ File.separator + "LayoutTests";
+
+ /** TODO: make it a setting */
+ private static final String RESULTS_ROOT_DIR_PATH =
+ Environment.getExternalStorageDirectory() +
+ File.separator + "android" +
+ File.separator + "LayoutTests-results";
+
+ /** A list containing relative paths of tests to run */
+ private LinkedListTests that were _not_ ignored
");
+ appendResultsMap(mResults, html);
+ html.append("Tests that _were_ ignored
");
+ appendResultsMap(mResultsIgnored, html);
+ html.append(HTML_DIFF_ENDING);
+ FsUtils.writeDataToStorage(new File(mResultsRootDirPath, HTML_DIFF_INDEX_RELATIVE_PATH),
+ html.toString().getBytes(), false);
+ }
+
+ private void appendResultsMap(Map");
+ html.append(resultCode.toString());
+ html.append("
");
+ html.append(relativePath);
+ html.append("
");
+ }
+ }
+ }
+ }
+}
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java
index d8509c12b37e1..790d1d36429be 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ui/DirListActivity.java
@@ -17,6 +17,7 @@
package com.android.dumprendertree2.ui;
import com.android.dumprendertree2.FileFilter;
+import com.android.dumprendertree2.LayoutTestsRunner;
import com.android.dumprendertree2.R;
import android.app.Activity;
@@ -25,6 +26,7 @@ import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Environment;
@@ -80,6 +82,8 @@ public class DirListActivity extends ListActivity {
*/
private String mRootDirPath = ROOT_DIR_PATH;
+ private FileFilter mFileFilter;
+
/**
* A thread responsible for loading the contents of the directory from sd card
* and sending them via Message to main thread that then loads them into
@@ -186,6 +190,7 @@ public class DirListActivity extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ mFileFilter = new FileFilter(ROOT_DIR_PATH);
mListView = getListView();
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@@ -196,7 +201,12 @@ public class DirListActivity extends ListActivity {
if (item.isDirectory()) {
showDir(item.getRelativePath());
} else {
- /** TODO: run the test */
+ /** Run the test */
+ Intent intent = new Intent();
+ intent.setClass(DirListActivity.this, LayoutTestsRunner.class);
+ intent.setAction(Intent.ACTION_RUN);
+ intent.putExtra(LayoutTestsRunner.EXTRA_TEST_PATH, item.getRelativePath());
+ startActivity(intent);
}
}
});
@@ -249,7 +259,7 @@ public class DirListActivity extends ListActivity {
}
@Override
- protected Dialog onCreateDialog(int id, Bundle args) {
+ protected Dialog onCreateDialog(int id, final Bundle args) {
Dialog dialog = null;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -264,8 +274,14 @@ public class DirListActivity extends ListActivity {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- /** TODO: Run tests from the dir */
removeDialog(DIALOG_RUN_ABORT_DIR);
+ /** Run the tests */
+ Intent intent = new Intent();
+ intent.setClass(DirListActivity.this, LayoutTestsRunner.class);
+ intent.setAction(Intent.ACTION_RUN);
+ intent.putExtra(LayoutTestsRunner.EXTRA_TEST_PATH,
+ args.getString("relativePath"));
+ startActivity(intent);
}
});
@@ -367,9 +383,9 @@ public class DirListActivity extends ListActivity {
for (File item : dir.listFiles()) {
if (item.isDirectory() && FileFilter.isTestDir(item.getName())) {
- subDirs.add(new ListItem(getRelativePath(item), true));
+ subDirs.add(new ListItem(mFileFilter.getRelativePath(item), true));
} else if (FileFilter.isTestFile(item.getName())) {
- subFiles.add(new ListItem(getRelativePath(item), false));
+ subFiles.add(new ListItem(mFileFilter.getRelativePath(item), false));
}
}
@@ -381,9 +397,4 @@ public class DirListActivity extends ListActivity {
return subDirs.toArray(new ListItem[subDirs.size()]);
}
-
- private String getRelativePath(File file) {
- File rootDir = new File(mRootDirPath);
- return file.getAbsolutePath().replaceFirst(rootDir.getPath() + File.separator, "");
- }
}
\ No newline at end of file