diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/AdditionalTextOutput.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/AdditionalTextOutput.java index 4e4d8248367c9..8fca629eaac9c 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/AdditionalTextOutput.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/AdditionalTextOutput.java @@ -28,18 +28,28 @@ import java.net.URL; public class AdditionalTextOutput { private static final String LOG_TAG = "AdditionalTextOutput"; + /** + * Ordering of enums is important as it determines ordering of the toString method! + * StringBuilders will be printed in the order the corresponding types appear here. + */ private enum OutputType { + JS_DIALOG, EXCEEDED_DB_QUOTA_MESSAGE, CONSOLE_MESSAGE; } StringBuilder[] mOutputs = new StringBuilder[OutputType.values().length]; - public void appendExceededDbQuotaMessage(String urlString, String databaseIdentifier) { - int index = OutputType.EXCEEDED_DB_QUOTA_MESSAGE.ordinal(); + private StringBuilder getStringBuilderForType(OutputType outputType) { + int index = outputType.ordinal(); if (mOutputs[index] == null) { mOutputs[index] = new StringBuilder(); } + return mOutputs[index]; + } + + public void appendExceededDbQuotaMessage(String urlString, String databaseIdentifier) { + StringBuilder output = getStringBuilderForType(OutputType.EXCEEDED_DB_QUOTA_MESSAGE); String protocol = ""; String host = ""; @@ -56,20 +66,43 @@ public class AdditionalTextOutput { Log.e(LOG_TAG + "::appendDatabaseCallback", e.getMessage()); } - mOutputs[index].append("UI DELEGATE DATABASE CALLBACK: "); - mOutputs[index].append("exceededDatabaseQuotaForSecurityOrigin:{"); - mOutputs[index].append(protocol + ", " + host + ", " + port + "} "); - mOutputs[index].append("database:" + databaseIdentifier + "\n"); + output.append("UI DELEGATE DATABASE CALLBACK: "); + output.append("exceededDatabaseQuotaForSecurityOrigin:{"); + output.append(protocol + ", " + host + ", " + port + "} "); + output.append("database:" + databaseIdentifier + "\n"); } public void appendConsoleMessage(ConsoleMessage consoleMessage) { - int index = OutputType.CONSOLE_MESSAGE.ordinal(); - if (mOutputs[index] == null) { - mOutputs[index] = new StringBuilder(); - } + StringBuilder output = getStringBuilderForType(OutputType.CONSOLE_MESSAGE); - mOutputs[index].append("CONSOLE MESSAGE: line " + consoleMessage.lineNumber()); - mOutputs[index].append(": " + consoleMessage.message() + "\n"); + output.append("CONSOLE MESSAGE: line " + consoleMessage.lineNumber()); + output.append(": " + consoleMessage.message() + "\n"); + } + + public void appendJsAlert(String message) { + StringBuilder output = getStringBuilderForType(OutputType.JS_DIALOG); + + output.append("ALERT: "); + output.append(message); + output.append('\n'); + } + + public void appendJsConfirm(String message) { + StringBuilder output = getStringBuilderForType(OutputType.JS_DIALOG); + + output.append("CONFIRM: "); + output.append(message); + output.append('\n'); + } + + public void appendJsPrompt(String message, String defaultValue) { + StringBuilder output = getStringBuilderForType(OutputType.JS_DIALOG); + + output.append("PROMPT: "); + output.append(message); + output.append(", default text: "); + output.append(defaultValue); + output.append('\n'); } @Override diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java index fe00a926009dc..a78e1fe4e881c 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java @@ -167,25 +167,22 @@ public class LayoutTestsExecutor extends Activity { /** TODO: This should be recorded as part of the text result */ /** TODO: The quota should also probably be reset somehow for every test? */ if (mDumpDatabaseCallbacks) { - if (mCurrentAdditionalTextOutput == null) { - mCurrentAdditionalTextOutput = new AdditionalTextOutput(); - } - - mCurrentAdditionalTextOutput.appendExceededDbQuotaMessage(url, databaseIdentifier); + getCurrentAdditionalTextOutput().appendExceededDbQuotaMessage(url, + databaseIdentifier); } 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 */ + getCurrentAdditionalTextOutput().appendJsAlert(message); 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 */ + getCurrentAdditionalTextOutput().appendJsConfirm(message); result.confirm(); return true; } @@ -193,18 +190,14 @@ public class LayoutTestsExecutor extends Activity { @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { - /** TODO: Alerts should be recorded as part of text result */ + getCurrentAdditionalTextOutput().appendJsPrompt(message, defaultValue); result.confirm(); return true; } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { - if (mCurrentAdditionalTextOutput == null) { - mCurrentAdditionalTextOutput = new AdditionalTextOutput(); - } - - mCurrentAdditionalTextOutput.appendConsoleMessage(consoleMessage); + getCurrentAdditionalTextOutput().appendConsoleMessage(consoleMessage); return true; } @@ -412,6 +405,13 @@ public class LayoutTestsExecutor extends Activity { unbindService(mServiceConnection); } + private AdditionalTextOutput getCurrentAdditionalTextOutput() { + if (mCurrentAdditionalTextOutput == null) { + mCurrentAdditionalTextOutput = new AdditionalTextOutput(); + } + return mCurrentAdditionalTextOutput; + } + /** LAYOUT TEST CONTROLLER */ private static final int MSG_WAIT_UNTIL_DONE = 0;