summaryrefslogtreecommitdiffstats
path: root/tests/DumpRenderTree2/src
diff options
context:
space:
mode:
authorMaksymilian Osowski <maxosowski@google.com>2010-07-16 16:45:12 +0100
committerMaksymilian Osowski <maxosowski@google.com>2010-07-21 15:20:47 +0100
commit4ee7f4b19489f4dc9b87e90d1e5c7742cfa7ebe0 (patch)
treec7483671d2f9081c129fd6998be1c8156a4f123e /tests/DumpRenderTree2/src
parent3c8ccb384513dd9bae0f98ac516ea36fbaa3173b (diff)
downloadframeworks_base-4ee7f4b19489f4dc9b87e90d1e5c7742cfa7ebe0.zip
frameworks_base-4ee7f4b19489f4dc9b87e90d1e5c7742cfa7ebe0.tar.gz
frameworks_base-4ee7f4b19489f4dc9b87e90d1e5c7742cfa7ebe0.tar.bz2
LayoutTest class with supporting classes (AbstractResult, TextResult).
These classes are responsible for actually running the tests, checking the results, generating visual diffs, etc. Change-Id: I9b7f554409db1c97ac086c456db3aea3b993b5c6
Diffstat (limited to 'tests/DumpRenderTree2/src')
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/AbstractResult.java38
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java29
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTest.java138
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunner.java6
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsRunnerThread.java81
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java87
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/TextResult.java153
7 files changed, 482 insertions, 50 deletions
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/AbstractResult.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/AbstractResult.java
index f545840..880a5cb 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/AbstractResult.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/AbstractResult.java
@@ -16,6 +16,9 @@
package com.android.dumprendertree2;
+import android.os.Message;
+import android.webkit.WebView;
+
/**
* A class that represent a result of the test. It is responsible for returning the result's
* raw data and generating its own diff in HTML format.
@@ -47,12 +50,39 @@ public abstract class AbstractResult {
}
/**
- * Returns result's raw data that can be written to the disk.
+ * Makes the result object obtain the result of the test from the webview
+ * and store it in the format that suits itself bests. This method is asynchronous.
+ * The message passed as a parameter is a message that should be sent to its target
+ * when the result finishes obtaining the result.
+ *
+ * @param webview
+ * @param resultObtainedMsg
+ */
+ public abstract void obtainActualResult(WebView webview, Message resultObtainedMsg);
+
+ public abstract void setExpectedImageResult(byte[] expectedResult);
+
+ public abstract void setExpectedTextResult(String expectedResult);
+
+ /**
+ * Returns result's image data that can be written to the disk. It can be null
+ * if there is an error of some sort or for example the test times out.
+ *
+ * <p> Some tests will not provide data (like text tests)
+ *
+ * @return
+ * results image data
+ */
+ 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 raw data
+ * results text data
*/
- public abstract byte[] getData();
+ 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 68daaf0..212c187 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 605afab..aa505b7 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 c18abcc..4421aba 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 d75579e..791ee0e 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<String> mTestsList = new LinkedList<String>();
@@ -72,8 +81,7 @@ public class LayoutTestsRunnerThread extends Thread {
*/
private String mRelativePath;
- /** A handler obtained from UI thread to handle messages concerning updating the display */
- private Handler mUiDisplayHandler;
+ private LayoutTestsRunner mActivity;
private LayoutTest mCurrentTest;
private String mCurrentTestPath;
@@ -87,10 +95,11 @@ public class LayoutTestsRunnerThread extends Thread {
* @param path
* @param uiDisplayHandler
*/
- public LayoutTestsRunnerThread(String path, Handler uiDisplayHandler) {
+ public LayoutTestsRunnerThread(String path, LayoutTestsRunner activity) {
mFileFilter = new FileFilter(TESTS_ROOT_DIR_PATH);
mRelativePath = path;
- mUiDisplayHandler = uiDisplayHandler;
+ mUiDisplayHandler = activity.getHandler();
+ mActivity = activity;
/** This creates a handler that runs on the thread that _created_ this thread */
mHandlerOnUiThread = new Handler() {
@@ -111,6 +120,9 @@ public class LayoutTestsRunnerThread extends Thread {
mSummarizer = new Summarizer(mFileFilter, RESULTS_ROOT_DIR_PATH);
+ /** A handler obtained from UI thread to handle messages concerning updating the display */
+ final Handler uiDisplayHandler = mActivity.getHandler();
+
/** Creates a new handler in _this_ thread */
mHandler = new Handler() {
@Override
@@ -118,7 +130,7 @@ public class LayoutTestsRunnerThread extends Thread {
switch (msg.what) {
case MSG_TEST_FINISHED:
onTestFinished(mCurrentTest);
- mUiDisplayHandler.obtainMessage(LayoutTestsRunner.MSG_UPDATE_PROGRESS,
+ uiDisplayHandler.obtainMessage(LayoutTestsRunner.MSG_UPDATE_PROGRESS,
mCurrentTestCount, mTotalTestCount).sendToTarget();
runNextTest();
break;
@@ -135,9 +147,9 @@ public class LayoutTestsRunnerThread extends Thread {
/** Populate the tests' list accordingly */
if (file.isDirectory()) {
- mUiDisplayHandler.sendEmptyMessage(LayoutTestsRunner.MSG_SHOW_PROGRESS_DIALOG);
+ uiDisplayHandler.sendEmptyMessage(LayoutTestsRunner.MSG_SHOW_PROGRESS_DIALOG);
preloadTests(mRelativePath);
- mUiDisplayHandler.sendEmptyMessage(LayoutTestsRunner.MSG_DISMISS_PROGRESS_DIALOG);
+ uiDisplayHandler.sendEmptyMessage(LayoutTestsRunner.MSG_DISMISS_PROGRESS_DIALOG);
} else {
mTestsList.addLast(mRelativePath);
mTotalTestCount = 1;
@@ -194,7 +206,8 @@ public class LayoutTestsRunnerThread extends Thread {
mCurrentTestCount++;
mCurrentTestPath = mTestsList.removeFirst();
- mCurrentTest = new LayoutTest(mCurrentTestPath, mHandler);
+ mCurrentTest = new LayoutTest(mCurrentTestPath, TESTS_ROOT_DIR_PATH,
+ mHandler.obtainMessage(MSG_TEST_FINISHED), mActivity);
/**
* This will run the test on UI thread. The reason why we need to run the test
@@ -221,22 +234,30 @@ public class LayoutTestsRunnerThread extends Thread {
}
private void dumpResultData(AbstractResult result, String testPath) {
- String resultPath = null;
+ dumpActualTextResult(result, testPath);
+ dumpActualImageResult(result, testPath);
+ }
+
+ private void dumpActualTextResult(AbstractResult result, String testPath) {
+ String actualTextResult = result.getActualTextResult();
+ if (actualTextResult == null) {
+ return;
+ }
- switch (result.getType()) {
- case TEXT:
- resultPath = FileFilter.setPathEnding(testPath, "-actual.txt");
- break;
+ String resultPath = FileFilter.setPathEnding(testPath, "-actual." + TEXT_RESULT_EXTENSION);
+ FsUtils.writeDataToStorage(new File(RESULTS_ROOT_DIR_PATH, resultPath),
+ actualTextResult.getBytes(), false);
+ }
- case PIXEL:
- /** TODO: Check if it is for sure *.bmp */
- resultPath = FileFilter.setPathEnding(testPath, "-actual.bmp");
- break;
+ private void dumpActualImageResult(AbstractResult result, String testPath) {
+ byte[] actualImageResult = result.getActualImageResult();
+ if (actualImageResult == null) {
+ return;
}
- /** Dump the result */
+ String resultPath = FileFilter.setPathEnding(testPath, "-actual." + IMAGE_RESULT_EXTENSION);
FsUtils.writeDataToStorage(new File(RESULTS_ROOT_DIR_PATH, resultPath),
- result.getData(), false);
+ actualImageResult, false);
}
private void onFinishedTests() {
@@ -249,4 +270,24 @@ public class LayoutTestsRunnerThread extends Thread {
* - zip results
* - run more tests before zipping */
}
-}
+
+ public static String getExpectedTextResult(String relativePath) {
+ return new String(getExpectedResult(relativePath, TEXT_RESULT_EXTENSION));
+ }
+
+ public static byte[] getExpectedImageResult(String relativePath) {
+ return getExpectedResult(relativePath, IMAGE_RESULT_EXTENSION);
+ }
+
+ private static byte[] getExpectedResult(String relativePath, String extension) {
+ relativePath = FileFilter.setPathEnding(relativePath, "-expected." + extension);
+
+ byte[] bytes = FsUtils.readDataFromStorage(new File(TESTS_ROOT_DIR_PATH, relativePath));
+ if (bytes == null) {
+ relativePath = EXPECTED_RESULT_SECONDARY_LOCATION_RELATIVE_DIR_PREFIX + relativePath;
+ bytes = FsUtils.readDataFromStorage(new File(TESTS_ROOT_DIR_PATH, relativePath));
+ }
+
+ return bytes;
+ }
+} \ No newline at end of file
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java
index 9b28fcd..4d15bb5 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java
@@ -34,21 +34,70 @@ public class Summarizer {
private static final String LOG_TAG = "Summarizer";
private static final String CSS =
- "body {font-family: Verdana;} a {font-size: 12px; color: black; } h3" +
- "{ font-size: 20px; padding: 0; margin: 0; margin-bottom: 10px; } " +
- ".space { margin-top:30px; } table.diff_both, table.diff_both tr, " +
- "table.diff_both td { border: 0; padding: 0; margin: 0; } " +
- "table.diff_both { width: 600px; } table.diff_both td.dleft, " +
- "table.diff_both td.dright { border: 0; width: 50%; } " +
- "table.diff " + "table.diff_both caption { text-align: left; margin-bottom: 3px;}" +
- "{ border:1px solid black; border-collapse: collapse; width: 100%; } " +
- "table.diff tr { vertical-align: top; border-bottom: 1px dashed black; " +
- "border-top: 1px dashed black; font-size: 15px; } table.diff td.linecount " +
- "{ border-right: 1px solid; background-color: #aaa; width: 20px; text-align: " +
- "right; padding-right: 1px; padding-top: 2px; padding-bottom: 2px; } " +
- "table.diff td.line { padding-left: 3px; padding-top: 2px; " +
- "padding-bottom: 2px; } span.eql { background-color: #f3f3f3;} " +
- "span.del { background-color: #ff8888; } span.ins { background-color: #88ff88; }";
+ "* {" +
+ " font-family: Verdana;" +
+ " border: 0;" +
+ " margin: 0;" +
+ " padding: 0;}" +
+ "body {" +
+ " margin: 10px;}" +
+ "a {" +
+ " font-size: 12px;" +
+ " color: black;}" +
+ "h1 {" +
+ " font-size: 33px;" +
+ " margin: 4px 0 4px 0;}" +
+ "h2 {" +
+ " font-size:22px;" +
+ " margin: 20px 0 3px 0;}" +
+ "h3 {" +
+ " font-size: 20px;" +
+ " margin-bottom: 6px;}" +
+ "table.visual_diff {" +
+ " border-bottom: 0px solid;" +
+ " border-collapse: collapse;" +
+ " width: 100%;" +
+ " margin-bottom: 3px;}" +
+ "table.visual_diff tr.headers td {" +
+ " border-bottom: 1px solid;" +
+ " border-top: 0;" +
+ " padding-bottom: 3px;}" +
+ "table.visual_diff tr.results td {" +
+ " border-top: 1px dashed;" +
+ " border-right: 1px solid;" +
+ " font-size: 15px;" +
+ " vertical-align: top;}" +
+ "table.visual_diff tr.results td.line_count {" +
+ " background-color:#aaa;" +
+ " min-width:20px;" +
+ " text-align: right;" +
+ " border-right: 1px solid;" +
+ " border-left: 1px solid;" +
+ " padding: 2px 1px 2px 0px;}" +
+ "table.visual_diff tr.results td.line {" +
+ " padding: 2px 0px 2px 4px;" +
+ " border-right: 1px solid;" +
+ " width: 49.8%;}" +
+ "table.visual_diff tr.footers td {" +
+ " border-top: 1px solid;" +
+ " border-bottom: 0;}" +
+ "table.visual_diff tr td.space {" +
+ " border: 0;" +
+ " width: 0.4%}" +
+ "div.space {" +
+ " margin-top:30px;}" +
+ "span.eql {" +
+ " background-color: #f3f3f3;}" +
+ "span.del {" +
+ " background-color: #ff8888; }" +
+ "span.ins {" +
+ " background-color: #88ff88; }" +
+ "span.fail {" +
+ " color: red;}" +
+ "span.pass {" +
+ " color: green;}" +
+ "span.time_out {" +
+ " color: orange;}";
private static final String HTML_DIFF_BEGINNING = "<html><head><style type=\"text/css\">" +
CSS + "</style></head><body>";
private static final String HTML_DIFF_ENDING = "</body></html>";
@@ -116,7 +165,7 @@ public class Summarizer {
return;
}
- AbstractResult.ResultCode resultCode = result.getCode();
+ AbstractResult.ResultCode resultCode = result.getResultCode();
/** Add the test to correct collection according to its result code */
if (mFileFilter.isIgnoreRes(testPath)) {
@@ -149,9 +198,9 @@ public class Summarizer {
StringBuilder html = new StringBuilder();
html.append(HTML_DIFF_BEGINNING);
Set<String> results;
- html.append("<h1>Tests that were _not_ ignored</h1>");
+ html.append("<h1>NOT ignored</h1>");
appendResultsMap(mResults, html);
- html.append("<h1>Tests that _were_ ignored</h1>");
+ html.append("<h1>Ignored</h1>");
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 0000000..e3dcef0
--- /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.
+ *
+ * <p>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("<h3>");
+ html.append(mRelativePath);
+ html.append("</h3>");
+ html.append("<table class=\"visual_diff\">");
+
+ html.append("<tr class=\"headers\">");
+ html.append("<td colspan=\"2\">Expected result:</td>");
+ html.append("<td class=\"space\"></td>");
+ html.append("<td colspan=\"2\">Actual result:</td>");
+ html.append("</tr>");
+
+ html.append("<tr class=\"results\">");
+ html.append("<td class=\"line_count\">1:</td>");
+ html.append("<td class=\"line\">");
+ if (mExpectedResult == null) {
+ html.append("NULL");
+ } else {
+ html.append(mExpectedResult.replace("\n", "<br />"));
+ }
+ html.append("</td>");
+ html.append("<td class=\"space\"></td>");
+ html.append("<td class=\"line_count\">1:</td>");
+ html.append("<td class=\"line\">");
+ if (mActualResult == null) {
+ html.append("NULL");
+ } else {
+ html.append(mActualResult.replace("\n", "<br />"));
+ }
+ html.append("</td>");
+ html.append("</tr>");
+
+ html.append("<tr class=\"footers\">");
+ html.append("<td colspan=\"2\"></td>");
+ html.append("<td class=\"space\"></td>");
+ html.append("<td colspan=\"2\"></td>");
+ html.append("</tr>");
+
+ html.append("</table>");
+
+ 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