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

Commit c6f74139 authored by Maksymilian Osowski's avatar Maksymilian Osowski Committed by Android (Google) Code Review
Browse files

Merge "Changed the code to use forwarding service."

parents 69697265 c6a341d3
Loading
Loading
Loading
Loading
+118 −62
Original line number Diff line number Diff line
@@ -18,11 +18,18 @@ package com.android.dumprendertree2;

import android.util.Log;

import com.android.dumprendertree2.forwarder.ForwarderManager;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -38,6 +45,9 @@ public class FileFilter {
    private static final String TEST_EXPECTATIONS_TXT_PATH =
            "platform/android/test_expectations.txt";

    private static final String HTTP_TESTS_PATH = "http/tests/";
    private static final String SSL_PATH = "ssl/";

    private static final String TOKEN_SKIP = "SKIP";
    private static final String TOKEN_IGNORE_RESULT = "IGNORE_RESULT";
    private static final String TOKEN_SLOW = "SLOW";
@@ -52,7 +62,7 @@ public class FileFilter {
        /** It may or may not contain a trailing slash */
        this.mRootDirPath = rootDirPath;

        reloadConfiguration();
        loadTestExpectations();
    }

    private static final String trimTrailingSlashIfPresent(String path) {
@@ -60,13 +70,21 @@ public class FileFilter {
        return file.getPath();
    }

    public void reloadConfiguration() {
        File txt_exp = new File(mRootDirPath, TEST_EXPECTATIONS_TXT_PATH);
    public void loadTestExpectations() {
        URL url = null;
        try {
            url = new URL(ForwarderManager.getHostSchemePort(false) + "LayoutTests/" +
                    TEST_EXPECTATIONS_TXT_PATH);
        } catch (MalformedURLException e) {
            assert false;
        }

        BufferedReader bufferedReader;
        try {
            bufferedReader =
                    new BufferedReader(new FileReader(txt_exp));
            InputStream inputStream = null;
            BufferedReader bufferedReader = null;
            try {
                bufferedReader = new BufferedReader(new StringReader(new String(
                        FsUtils.readDataFromUrl(url))));

                String line;
                String entry;
@@ -123,11 +141,18 @@ public class FileFilter {
                        mSlowList.add(path);
                    }
                }
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            }
        } catch (FileNotFoundException e) {
            Log.w(LOG_TAG, "mRootDirPath=" + mRootDirPath + ": File not found: " +
                    txt_exp.getPath(), e);
            Log.w(LOG_TAG, "reloadConfiguration(): File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.e(LOG_TAG, "mRootDirPath=" + mRootDirPath, e);
            Log.e(LOG_TAG, "url=" + url, e);
        }
    }

@@ -236,6 +261,37 @@ public class FileFilter {
        return testName.endsWith(".html") || testName.endsWith(".xhtml");
    }

    /**
     * Return a URL of the test on the server.
     *
     * @param relativePath
     * @return a URL of the test on the server
     */
    public static URL getUrl(String relativePath) {
        String urlBase = ForwarderManager.getHostSchemePort(false);

        /**
         * URL is formed differently for HTTP vs non-HTTP tests, because HTTP tests
         * expect different document root. See run_apache2.py and .conf file for details
         */
        if (relativePath.startsWith(HTTP_TESTS_PATH)) {
            relativePath = relativePath.substring(HTTP_TESTS_PATH.length());
            if (relativePath.startsWith(SSL_PATH)) {
                urlBase = ForwarderManager.getHostSchemePort(true);
            }
        } else {
            relativePath = "LayoutTests/" + relativePath;
        }

        try {
            return new URL(urlBase + relativePath);
        } catch (MalformedURLException e) {
            Log.e(LOG_TAG, "Malformed URL!", e);
        }

        return null;
    }

    /**
     * Return the path to the file relative to the tests root dir
     *
+104 −3
Original line number Diff line number Diff line
@@ -18,11 +18,23 @@ package com.android.dumprendertree2;

import android.util.Log;

import com.android.dumprendertree2.forwarder.ForwarderManager;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.LinkedList;
import java.util.List;

/**
 *
@@ -30,6 +42,9 @@ import java.io.OutputStream;
public class FsUtils {
    public static final String LOG_TAG = "FsUtils";

    private static final String SCRIPT_URL = ForwarderManager.getHostSchemePort(false) +
            "WebKitTools/DumpRenderTree/android/get_layout_tests_dir_contents.php";

    public static void writeDataToStorage(File file, byte[] bytes, boolean append) {
        Log.d(LOG_TAG, "writeDataToStorage(): " + file.getAbsolutePath());
        try {
@@ -37,7 +52,7 @@ public class FsUtils {
            try {
                file.getParentFile().mkdirs();
                file.createNewFile();
                Log.d(LOG_TAG, "writeDataToStorage(): File created.");
                Log.d(LOG_TAG, "writeDataToStorage(): File created: " + file.getAbsolutePath());
                outputStream = new FileOutputStream(file, append);
                outputStream.write(bytes);
            } finally {
@@ -46,7 +61,8 @@ public class FsUtils {
                }
            }
        } catch (IOException e) {
            Log.e(LOG_TAG, "file.getAbsolutePath=" + file.getAbsolutePath(), e);
            Log.e(LOG_TAG, "file.getAbsolutePath=" + file.getAbsolutePath() + " append=" + append,
                    e);
        }
    }

@@ -75,4 +91,89 @@ public class FsUtils {

        return bytes;
    }

    public static byte[] readDataFromUrl(URL url) {
        if (url == null) {
            Log.w(LOG_TAG, "readDataFromUrl(): url is null!");
            return null;
        }

        byte[] bytes = null;
        try {
            InputStream inputStream = null;
            ByteArrayOutputStream outputStream = null;
            try {
                URLConnection urlConnection = url.openConnection();
                inputStream = urlConnection.getInputStream();
                outputStream = new ByteArrayOutputStream();

                byte[] buffer = new byte[4096];
                int length;
                while ((length = inputStream.read(buffer)) > 0) {
                    outputStream.write(buffer, 0, length);
                }

                bytes = outputStream.toByteArray();
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (outputStream != null) {
                    outputStream.close();
                }
            }
        } catch (FileNotFoundException e) {
            Log.w(LOG_TAG, "readDataFromUrl(): File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.e(LOG_TAG, "url=" + url, e);
        }

        return bytes;
    }

    public static List<String> getLayoutTestsDirContents(String dirRelativePath, boolean recurse,
            boolean mode) {
        String modeString = (mode ? "folders" : "files");

        List<String> results = new LinkedList<String>();

        URL url = null;
        try {
            url = new URL(SCRIPT_URL +
                    "?path=" + dirRelativePath +
                    "&recurse=" + recurse +
                    "&mode=" + modeString);
        } catch (MalformedURLException e) {
            Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" +
                    modeString, e);
            return results;
        }

        try {
            InputStream inputStream = null;
            BufferedReader bufferedReader = null;
            try {
                URLConnection urlConnection = url.openConnection();
                inputStream = urlConnection.getInputStream();
                bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

                String relativePath;
                while ((relativePath = bufferedReader.readLine()) != null) {
                    results.add(relativePath);
                }
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            }
        } catch (IOException e) {
            Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" +
                    modeString, e);
        }

        return results;
    }
}
 No newline at end of file
+10 −5
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ import android.webkit.GeolocationPermissions;
import android.webkit.WebStorage.QuotaUpdater;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -306,6 +308,8 @@ public class LayoutTestsExecutor extends Activity {
         */
        webView.setTouchInterval(-1);

        webView.clearCache(true);

        WebSettings webViewSettings = webView.getSettings();
        webViewSettings.setAppCacheEnabled(true);
        webViewSettings.setAppCachePath(getApplicationContext().getCacheDir().getPath());
@@ -353,10 +357,11 @@ public class LayoutTestsExecutor extends Activity {
        }

        mCurrentTestRelativePath = mTestsList.remove(0);
        Log.d(LOG_TAG + "::runNextTest", "Start: " + mCurrentTestRelativePath +

        Log.i(LOG_TAG, "runNextTest(): Start: " + mCurrentTestRelativePath +
                " (" + mCurrentTestIndex + ")");
        mCurrentTestUri =
                Uri.fromFile(new File(TESTS_ROOT_DIR_PATH, mCurrentTestRelativePath)).toString();

        mCurrentTestUri = FileFilter.getUrl(mCurrentTestRelativePath).toString();

        reset();

+1 −1
Original line number Diff line number Diff line
@@ -243,7 +243,7 @@ public class ManagerService extends Service {
        int size = EXPECTED_RESULT_LOCATION_RELATIVE_DIR_PREFIXES.size();
        for (int i = 0; bytes == null && i < size; i++) {
            relativePath = locations.get(i) + originalRelativePath;
            bytes = FsUtils.readDataFromStorage(new File(TESTS_ROOT_DIR_PATH, relativePath));
            bytes = FsUtils.readDataFromUrl(FileFilter.getUrl(relativePath));
        }

        return bytes;
+17 −26
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.dumprendertree2;

import android.os.Environment;
import android.os.Message;
import android.util.Log;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -64,17 +62,10 @@ public class TestsListPreloaderThread extends Thread {

    @Override
    public void run() {
        /** Check if the path is correct */
        File file = new File(TESTS_ROOT_DIR_PATH, mRelativePath);
        if (!file.exists()) {
            Log.e(LOG_TAG + "::run", "Path does not exist: " + mRelativePath);
        } else {
            /** Populate the tests' list accordingly */
            if (file.isDirectory()) {
                preloadTests(mRelativePath);
            } else {
        if (FileFilter.isTestFile(mRelativePath)) {
            mTestsList.add(mRelativePath);
            }
        } else {
            loadTestsFromUrl(mRelativePath);
        }

        mDoneMsg.obj = mTestsList;
@@ -87,29 +78,29 @@ public class TestsListPreloaderThread extends Thread {
     *
     * @param dirRelativePath
     */
    private void preloadTests(String dirRelativePath) {
    private void loadTestsFromUrl(String dirRelativePath) {
        LinkedList<String> foldersList = new LinkedList<String>();
        foldersList.add(dirRelativePath);

        String relativePath;
        String currentDirRelativePath;
        String itemName;
        File[] items;
        while (!foldersList.isEmpty()) {
            currentDirRelativePath = foldersList.removeFirst();
            items = new File(TESTS_ROOT_DIR_PATH, currentDirRelativePath).listFiles();
            for (File item : items) {
                itemName = item.getName();
                relativePath = currentDirRelativePath + File.separator + itemName;

                if (item.isDirectory() && FileFilter.isTestDir(itemName)) {
                    foldersList.add(relativePath);
                    continue;
            relativePath = foldersList.removeFirst();

            for (String folderRelativePath : FsUtils.getLayoutTestsDirContents(relativePath,
                    false, true)) {
                itemName = new File(folderRelativePath).getName();
                if (FileFilter.isTestDir(itemName)) {
                    foldersList.add(folderRelativePath);
                }
            }

            for (String testRelativePath : FsUtils.getLayoutTestsDirContents(relativePath,
                    false, false)) {
                itemName = new File(testRelativePath).getName();
                if (FileFilter.isTestFile(itemName)) {
                    if (!mFileFilter.isSkip(relativePath)) {
                        mTestsList.add(relativePath);
                    if (!mFileFilter.isSkip(testRelativePath)) {
                        mTestsList.add(testRelativePath);
                    } else {
                        //mSummarizer.addSkippedTest(relativePath);
                        /** TODO: Summarizer is now in service - figure out how to send the info */
Loading