Merge changes I650518a4,If15fddac

* changes:
  Fix DumpRenderTree2 to not attempt to read expected results over HTTPS
  Fix FsUtils.readDataFromUrl() to do the network request on a background thread
This commit is contained in:
Steve Block
2010-11-09 06:32:13 -08:00
committed by Android (Google) Code Review
6 changed files with 71 additions and 45 deletions

View File

@@ -243,8 +243,7 @@ public class FileFilter {
* Currently we run .html and .xhtml tests.
*
* @param testName
* @return
* if the file is a test
* @return if the file is a test
*/
public static boolean isTestFile(String testName) {
return testName.endsWith(".html") || testName.endsWith(".xhtml");
@@ -254,9 +253,11 @@ public class FileFilter {
* Return a URL of the test on the server.
*
* @param relativePath
* @param allowHttps Whether to allow the use of HTTPS, even if the file is in the SSL
* directory.
* @return a URL of the test on the server
*/
public static URL getUrl(String relativePath) {
public static URL getUrl(String relativePath, boolean allowHttps) {
String urlBase = ForwarderManager.getHostSchemePort(false);
/**
@@ -265,7 +266,7 @@ public class FileFilter {
*/
if (relativePath.startsWith(HTTP_TESTS_PATH)) {
relativePath = relativePath.substring(HTTP_TESTS_PATH.length());
if (relativePath.startsWith(SSL_PATH)) {
if (relativePath.startsWith(SSL_PATH) && allowHttps) {
urlBase = ForwarderManager.getHostSchemePort(true);
}
} else {

View File

@@ -131,45 +131,72 @@ public class FsUtils {
return bytes;
}
static class UrlDataGetter extends Thread {
private URL mUrl;
private byte[] mBytes;
private boolean mGetComplete;
public UrlDataGetter(URL url) {
mUrl = url;
}
public byte[] get() {
start();
synchronized(this) {
while (!mGetComplete) {
try{
wait();
} catch(InterruptedException e) {
}
}
}
return mBytes;
}
public synchronized void run() {
mGetComplete = false;
HttpGet httpRequest = new HttpGet(mUrl.toString());
ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
@Override
public byte[] handleResponse(HttpResponse response) throws IOException {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
return null;
}
HttpEntity entity = response.getEntity();
return (entity == null ? null : EntityUtils.toByteArray(entity));
}
};
mBytes = null;
try {
/**
* TODO: Not exactly sure why some requests hang indefinitely, but adding this
* timeout (in static getter for http client) in loop helps.
*/
boolean timedOut;
do {
timedOut = false;
try {
mBytes = getHttpClient().execute(httpRequest, handler);
} catch (SocketTimeoutException e) {
timedOut = true;
Log.w(LOG_TAG, "Expected SocketTimeoutException: " + mUrl, e);
}
} while (timedOut);
} catch (IOException e) {
Log.e(LOG_TAG, "url=" + mUrl, e);
}
mGetComplete = true;
notify();
}
}
public static byte[] readDataFromUrl(URL url) {
if (url == null) {
Log.w(LOG_TAG, "readDataFromUrl(): url is null!");
return null;
}
HttpGet httpRequest = new HttpGet(url.toString());
ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
@Override
public byte[] handleResponse(HttpResponse response) throws IOException {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
return null;
}
HttpEntity entity = response.getEntity();
return (entity == null ? null : EntityUtils.toByteArray(entity));
}
};
byte[] bytes = null;
try {
/**
* TODO: Not exactly sure why some requests hang indefinitely, but adding this
* timeout (in static getter for http client) in loop helps.
*/
boolean timedOut;
do {
timedOut = false;
try {
bytes = getHttpClient().execute(httpRequest, handler);
} catch (SocketTimeoutException e) {
timedOut = true;
Log.w(LOG_TAG, "Expected SocketTimeoutException: " + url, e);
}
} while (timedOut);
} catch (IOException e) {
Log.e(LOG_TAG, "url=" + url, e);
}
return bytes;
UrlDataGetter getter = new UrlDataGetter(url);
return getter.get();
}
public static List<String> getLayoutTestsDirContents(String dirRelativePath, boolean recurse,

View File

@@ -439,7 +439,7 @@ public class LayoutTestsExecutor extends Activity {
Log.i(LOG_TAG, "runNextTest(): Start: " + mCurrentTestRelativePath +
" (" + mCurrentTestIndex + ")");
mCurrentTestUri = FileFilter.getUrl(mCurrentTestRelativePath).toString();
mCurrentTestUri = FileFilter.getUrl(mCurrentTestRelativePath, true).toString();
reset();

View File

@@ -127,7 +127,6 @@ public class ManagerService extends Service {
}
};
private FileFilter mFileFilter;
private Summarizer mSummarizer;
private String mCurrentlyRunningTest;
@@ -146,8 +145,7 @@ public class ManagerService extends Service {
public void onCreate() {
super.onCreate();
mFileFilter = new FileFilter();
mSummarizer = new Summarizer(mFileFilter, RESULTS_ROOT_DIR_PATH, getApplicationContext());
mSummarizer = new Summarizer(RESULTS_ROOT_DIR_PATH, getApplicationContext());
}
@Override
@@ -264,7 +262,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.readDataFromUrl(FileFilter.getUrl(relativePath));
bytes = FsUtils.readDataFromUrl(FileFilter.getUrl(relativePath, false));
}
mLastExpectedResultPathFetched = bytes == null ? null : relativePath;

View File

@@ -213,8 +213,8 @@ public class Summarizer {
private SummarizerDBHelper mDbHelper;
public Summarizer(FileFilter fileFilter, String resultsRootDirPath, Context context) {
mFileFilter = fileFilter;
public Summarizer(String resultsRootDirPath, Context context) {
mFileFilter = new FileFilter();
mResultsRootDirPath = resultsRootDirPath;
/**

View File

@@ -50,13 +50,13 @@ public class TestsListPreloaderThread extends Thread {
* @param doneMsg
*/
public TestsListPreloaderThread(String path, Message doneMsg) {
mFileFilter = new FileFilter();
mRelativePath = path;
mDoneMsg = doneMsg;
}
@Override
public void run() {
mFileFilter = new FileFilter();
if (FileFilter.isTestFile(mRelativePath)) {
mTestsList.add(mRelativePath);
} else {