This source file includes following definitions.
- getUrl
- getUrl
- checkServerIsUp
- checkServerIsUp
package org.chromium.chrome.test.util;
import junit.framework.Assert;
import org.chromium.chrome.browser.util.StreamUtil;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
public final class TestHttpServerClient {
private static final int SERVER_PORT = 8000;
private TestHttpServerClient() {
}
public static String getUrl(String path) {
return "http://localhost:" + SERVER_PORT + "/" + path;
}
public static String getUrl(String path, String username, String password) {
return "http://" + username + ":" + password + "@localhost:" + SERVER_PORT + "/" + path;
}
public static void checkServerIsUp() {
checkServerIsUp(getUrl("chrome/test/data/android/ok.txt"), "OK Computer");
}
public static void checkServerIsUp(String serverUrl, String expectedResponse) {
InputStream is = null;
try {
URL testUrl = new URL(serverUrl);
is = testUrl.openStream();
byte[] buffer = new byte[128];
int length = is.read(buffer);
Assert.assertNotSame("Failed to access test HTTP Server at URL: " + serverUrl,
-1, expectedResponse.length());
Assert.assertEquals("Failed to access test HTTP Server at URL: " + serverUrl,
expectedResponse, new String(buffer, 0, length).trim());
} catch (MalformedURLException e) {
Assert.fail(
"Failed to check test HTTP server at URL: " + serverUrl + ". Status: " + e);
} catch (IOException e) {
Assert.fail(
"Failed to check test HTTP server at URL: " + serverUrl + ". Status: " + e);
} finally {
StreamUtil.closeQuietly(is);
}
}
}