Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40968a45 authored by Maksymilian Osowski's avatar Maksymilian Osowski
Browse files

Added recording of JS dialog messages.

Change-Id: I3854f1fea81d47255c9fb398bdcbdff5ed4d8a52
parent 100e1065
Loading
Loading
Loading
Loading
+45 −12
Original line number Diff line number Diff line
@@ -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);

        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');
    }

        mOutputs[index].append("CONSOLE MESSAGE: line " + consoleMessage.lineNumber());
        mOutputs[index].append(": " + consoleMessage.message() + "\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
+13 −13
Original line number Diff line number Diff line
@@ -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;