diff --git a/tests/DumpRenderTree2/AndroidManifest.xml b/tests/DumpRenderTree2/AndroidManifest.xml
index 3454316495b44..a5199e708df8c 100644
--- a/tests/DumpRenderTree2/AndroidManifest.xml
+++ b/tests/DumpRenderTree2/AndroidManifest.xml
@@ -30,6 +30,7 @@ limitations under the License.
+
Some tests will not provide data (like text tests)
*
* @return
- * results raw data
+ * results image data
*/
- public abstract byte[] getData();
+ public abstract byte[] getActualImageResult();
+
+ /**
+ * Returns result's text data. It can be null
+ * if there is an error of some sort or for example the test times out.
+ *
+ * @return
+ * results text data
+ */
+ public abstract String getActualTextResult();
/**
* Returns the code of this result.
@@ -60,7 +90,7 @@ public abstract class AbstractResult {
* @return
* the code of this result
*/
- public abstract ResultCode getCode();
+ public abstract ResultCode getResultCode();
/**
* Return the type of the result data.
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java
index 68daaf0d0a0a6..212c18773d7d7 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java
@@ -19,6 +19,7 @@ package com.android.dumprendertree2;
import android.util.Log;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -48,4 +49,30 @@ public class FsUtils {
Log.e(LOG_TAG + "::writeDataToStorage", e.getMessage());
}
}
-}
+
+ public static byte[] readDataFromStorage(File file) {
+ if (!file.exists()) {
+ Log.d(LOG_TAG + "::readDataFromStorage", "File does not exist: "
+ + file.getAbsolutePath());
+ return null;
+ }
+
+ byte[] bytes = null;
+ try {
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(file);
+ bytes = new byte[(int) file.length()];
+ fis.read(bytes);
+ } finally {
+ if (fis != null) {
+ fis.close();
+ }
+ }
+ } catch (IOException e) {
+ Log.e(LOG_TAG + "::readDataFromStorage", e.getMessage());
+ }
+
+ return bytes;
+ }
+}
\ No newline at end of file
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTest.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTest.java
index 605afab66a136..aa505b70ed640 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTest.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTest.java
@@ -16,7 +16,19 @@
package com.android.dumprendertree2;
+import android.app.Activity;
+import android.net.Uri;
import android.os.Handler;
+import android.os.Message;
+import android.webkit.JsPromptResult;
+import android.webkit.JsResult;
+import android.webkit.WebChromeClient;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.webkit.WebStorage.QuotaUpdater;
+
+import java.io.File;
/**
* A class that represents a single layout test. It is responsible for running the test,
@@ -24,18 +36,134 @@ import android.os.Handler;
*/
public class LayoutTest {
+ private static final String LOG_TAG = "LayoutTest";
+
+ public static final int MSG_ACTUAL_RESULT_OBTAINED = 0;
+
private String mRelativePath;
- private Handler mCallbackHandler;
+ private String mTestsRootDirPath;
+ private String mUrl;
+ private boolean mOnTestFinishedCalled;
+ private Message mTestFinishedMsg;
private AbstractResult mResult;
- public LayoutTest(String relativePath, Handler callbackHandler) {
+ private WebView mWebView;
+ private Activity mActivity;
+
+ private final Handler mResultHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.what == MSG_ACTUAL_RESULT_OBTAINED) {
+ mResult.setExpectedTextResult(LayoutTestsRunnerThread.getExpectedTextResult(mRelativePath));
+ mResult.setExpectedImageResult(LayoutTestsRunnerThread.getExpectedImageResult(mRelativePath));
+ mTestFinishedMsg.sendToTarget();
+ }
+ }
+ };
+
+ private WebViewClient mWebViewClient = new WebViewClient() {
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ /** Some tests fire up many page loads, we don't want to detect them */
+ if (!url.equals(mUrl)) {
+ return;
+ }
+
+ onTestFinished();
+ }
+ };
+
+ private WebChromeClient mWebChromeClient = new WebChromeClient() {
+ @Override
+ public void onExceededDatabaseQuota(String url, String databaseIdentifier,
+ long currentQuota, long estimatedSize, long totalUsedQuota,
+ QuotaUpdater quotaUpdater) {
+ /** TODO: This should be recorded as part of the text result */
+ quotaUpdater.updateQuota(currentQuota + 5 * 1024 * 1024);
+ }
+
+ @Override
+ public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
+ /** TODO: Alerts should be recorded as part of text result */
+ result.confirm();
+ return true;
+ }
+
+ @Override
+ public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
+ /** TODO: Alerts should be recorded as part of text result */
+ result.confirm();
+ return true;
+ }
+
+ @Override
+ public boolean onJsPrompt(WebView view, String url, String message, String defaultValue,
+ JsPromptResult result) {
+ /** TODO: Alerts should be recorded as part of text result */
+ result.confirm();
+ return true;
+ }
+
+ };
+
+ public LayoutTest(String relativePath, String testsRootDirPath, Message testFinishedMsg,
+ LayoutTestsRunner activity) {
mRelativePath = relativePath;
- mCallbackHandler = callbackHandler;
+ mTestsRootDirPath = testsRootDirPath;
+ mTestFinishedMsg = testFinishedMsg;
+ mActivity = activity;
}
public void run() {
- /** TODO: This is just a stub! */
- mCallbackHandler.obtainMessage(LayoutTestsRunnerThread.MSG_TEST_FINISHED).sendToTarget();
+ mWebView = new WebView(mActivity);
+ mActivity.setContentView(mWebView);
+
+ setupWebView();
+
+ /** TODO: Add timeout msg */
+ mUrl = Uri.fromFile(new File(mTestsRootDirPath, mRelativePath)).toString();
+ mWebView.loadUrl(mUrl);
+ }
+
+ private void onTestFinished() {
+ if (mOnTestFinishedCalled) {
+ return;
+ }
+
+ mOnTestFinishedCalled = true;
+
+ /**
+ * If the result has not been set by the time the test finishes we create
+ * a default type of result.
+ */
+ if (mResult == null) {
+ /** TODO: Default type should be RenderTreeResult. We don't support it now. */
+ mResult = new TextResult(mRelativePath);
+ }
+
+ /** TODO: Implement waitUntilDone */
+
+ mResult.obtainActualResult(mWebView,
+ mResultHandler.obtainMessage(MSG_ACTUAL_RESULT_OBTAINED));
+ }
+
+ private void setupWebView() {
+ WebSettings webViewSettings = mWebView.getSettings();
+ webViewSettings.setAppCacheEnabled(true);
+ webViewSettings.setAppCachePath(mActivity.getApplicationContext().getCacheDir().getPath());
+ webViewSettings.setAppCacheMaxSize(Long.MAX_VALUE);
+ webViewSettings.setJavaScriptEnabled(true);
+ webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
+ webViewSettings.setSupportMultipleWindows(true);
+ webViewSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
+ webViewSettings.setDatabaseEnabled(true);
+ webViewSettings.setDatabasePath(mActivity.getDir("databases", 0).getAbsolutePath());
+ webViewSettings.setDomStorageEnabled(true);
+ webViewSettings.setWorkersEnabled(false);
+ webViewSettings.setXSSAuditorEnabled(false);
+
+ mWebView.setWebViewClient(mWebViewClient);
+ mWebView.setWebChromeClient(mWebChromeClient);
}
public AbstractResult getResult() {
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunner.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunner.java
index c18abcccb5f83..4421aba44191e 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunner.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunner.java
@@ -85,6 +85,10 @@ public class LayoutTestsRunner extends Activity {
}
String path = intent.getStringExtra(EXTRA_TEST_PATH);
- new LayoutTestsRunnerThread(path, mHandler).start();
+ new LayoutTestsRunnerThread(path, this).start();
+ }
+
+ public Handler getHandler() {
+ return mHandler;
}
}
\ 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
index d75579e70b1e4..791ee0e3a4906 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunnerThread.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunnerThread.java
@@ -54,6 +54,15 @@ public class LayoutTestsRunnerThread extends Thread {
File.separator + "android" +
File.separator + "LayoutTests-results";
+ /** TODO: Make it a setting */
+ private static final String EXPECTED_RESULT_SECONDARY_LOCATION_RELATIVE_DIR_PREFIX =
+ "platform" + File.separator +
+ "android-v8" + File.separator;
+
+ /** TODO: Make these settings */
+ private static final String TEXT_RESULT_EXTENSION = "txt";
+ private static final String IMAGE_RESULT_EXTENSION = "png";
+
/** A list containing relative paths of tests to run */
private LinkedList Created if layoutTestController.dumpAsText() was called.
+ */
+public class TextResult extends AbstractResult {
+
+ private static final int MSG_DOCUMENT_AS_TEXT = 0;
+
+ private String mExpectedResult;
+ private String mActualResult;
+ private String mRelativePath;
+ private ResultCode mResultCode;
+ private Message mResultObtainedMsg;
+
+ private Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ if (msg.what == MSG_DOCUMENT_AS_TEXT) {
+ mActualResult = (String) msg.obj;
+ mResultObtainedMsg.sendToTarget();
+ }
+ }
+ };
+
+ public TextResult(String relativePath) {
+ mRelativePath = relativePath;
+ }
+
+ @Override
+ public ResultCode getResultCode() {
+ if (mResultCode != null) {
+ return mResultCode;
+ }
+
+ if (mExpectedResult == null) {
+ mResultCode = AbstractResult.ResultCode.FAIL_NO_EXPECTED_RESULT;
+ } else if (!mExpectedResult.equals(mActualResult)) {
+ mResultCode = AbstractResult.ResultCode.FAIL_RESULT_DIFFERS;
+ } else {
+ mResultCode = AbstractResult.ResultCode.PASS;
+ }
+
+ return mResultCode;
+ }
+
+ @Override
+ public byte[] getActualImageResult() {
+ return null;
+ }
+
+ @Override
+ public String getActualTextResult() {
+ return mActualResult;
+ }
+
+ @Override
+ public void setExpectedImageResult(byte[] expectedResult) {
+ /** This method is not applicable to this type of result */
+ }
+
+ @Override
+ public void setExpectedTextResult(String expectedResult) {
+ mExpectedResult = expectedResult;
+ }
+
+ @Override
+ public String getDiffAsHtml() {
+ /** TODO: just a stub
+ * Probably needs rethinking anyway - just one table would be much better
+ * This will require some changes in Summarizer in CSS as well */
+ StringBuilder html = new StringBuilder();
+ html.append("Tests that were _not_ ignored
");
+ html.append("NOT ignored
");
appendResultsMap(mResults, html);
- html.append("Tests that _were_ ignored
");
+ html.append("Ignored
");
appendResultsMap(mResultsIgnored, html);
html.append(HTML_DIFF_ENDING);
FsUtils.writeDataToStorage(new File(mResultsRootDirPath, HTML_DIFF_INDEX_RELATIVE_PATH),
@@ -179,4 +228,4 @@ public class Summarizer {
}
}
}
-}
+}
\ No newline at end of file
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java
new file mode 100644
index 0000000000000..e3dcef03deb87
--- /dev/null
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java
@@ -0,0 +1,153 @@
+/*
+ * 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;
+import android.os.Message;
+import android.webkit.WebView;
+
+/**
+ * A result object for which the expected output is text. It does not have an image
+ * expected result.
+ *
+ * ");
+ html.append(mRelativePath);
+ html.append("
");
+ html.append("");
+
+ html.append("
");
+
+ return html.toString();
+ }
+
+ @Override
+ public TestType getType() {
+ return TestType.TEXT;
+ }
+
+ @Override
+ public void obtainActualResult(WebView webview, Message resultObtainedMsg) {
+ mResultObtainedMsg = resultObtainedMsg;
+ Message msg = mHandler.obtainMessage(MSG_DOCUMENT_AS_TEXT);
+
+ /** TODO: mDumpTopFrameAsText and mDumpChildFramesAsText */
+ msg.arg1 = 1;
+ msg.arg2 = 0;
+ webview.documentAsText(msg);
+ }
+}
\ No newline at end of file
");
+ html.append(" ");
+
+ html.append("Expected result: ");
+ html.append("");
+ html.append(" Actual result: ");
+ html.append("");
+ html.append(" ");
+
+ html.append("1: ");
+ html.append("");
+ if (mExpectedResult == null) {
+ html.append("NULL");
+ } else {
+ html.append(mExpectedResult.replace("\n", " ");
+ html.append("
"));
+ }
+ html.append("");
+ html.append(" 1: ");
+ html.append("");
+ if (mActualResult == null) {
+ html.append("NULL");
+ } else {
+ html.append(mActualResult.replace("\n", " ");
+ html.append("
"));
+ }
+ html.append("");
+ html.append(" ");
+
+ html.append("");
+ html.append(" ");
+ html.append(" ");
+ html.append("