Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1772)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/util/TestWebServer.java

Issue 10946008: Componentize IgnoreNavigationResourceThrottle and add chrome and webview specific implementations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed presubmit warning for jni_generator.py Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/javatests/src/org/chromium/android_webview/test/util/TestWebServer.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/util/TestWebServer.java b/android_webview/javatests/src/org/chromium/android_webview/test/util/TestWebServer.java
index a02d3f9adc91b8f7a24bfac860999226899ebb1a..1b37ed3340563cc8db5ea661b7212c909e6df90a 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/util/TestWebServer.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/util/TestWebServer.java
@@ -73,8 +73,11 @@ public class TestWebServer {
private static class Response {
final byte[] mResponseData;
final List<Pair<String, String>> mResponseHeaders;
+ final boolean mIsRedirect;
- Response(byte[] resposneData, List<Pair<String, String>> responseHeaders) {
+ Response(byte[] resposneData, List<Pair<String, String>> responseHeaders,
+ boolean isRedirect) {
+ mIsRedirect = isRedirect;
mResponseData = resposneData;
mResponseHeaders = responseHeaders == null ?
new ArrayList<Pair<String, String>>() : responseHeaders;
@@ -142,12 +145,29 @@ public class TestWebServer {
sInstance = null;
}
+ private final static int RESPONSE_STATUS_NORMAL = 0;
+ private final static int RESPONSE_STATUS_MOVED_TEMPORARILY = 1;
+
private String setResponseInternal(
String requestPath, byte[] responseData,
- List<Pair<String, String>> responseHeaders) {
- mResponseMap.put(requestPath, new Response(responseData, responseHeaders));
+ List<Pair<String, String>> responseHeaders,
+ int status) {
+ final boolean isRedirect = (status == RESPONSE_STATUS_MOVED_TEMPORARILY);
+ mResponseMap.put(requestPath, new Response(responseData, responseHeaders, isRedirect));
mResponseCountMap.put(requestPath, new Integer(0));
mLastRequestMap.put(requestPath, null);
+ return getResponseUrl(requestPath);
+ }
+
+ /**
+ * Gets the URL on the server under which a particular request path will be accessible.
+ *
+ * This only gets the URL, you still need to set the response if you intend to access it.
+ *
+ * @param requestPath The path to respond to.
+ * @return The full URL including the requestPath.
+ */
+ public String getResponseUrl(String requestPath) {
return mServerUri + requestPath;
}
@@ -165,7 +185,25 @@ public class TestWebServer {
public String setResponse(
String requestPath, String responseString,
List<Pair<String, String>> responseHeaders) {
- return setResponseInternal(requestPath, responseString.getBytes(), responseHeaders);
+ return setResponseInternal(requestPath, responseString.getBytes(), responseHeaders,
+ RESPONSE_STATUS_NORMAL);
+ }
+
+ /**
+ * Sets a redirect.
+ *
+ * @param requestPath The path to respond to.
+ * @param targetPath The path to redirect to.
+ * @return The full URL including the path that should be requested to get the expected
+ * response.
+ */
+ public String setRedirect(
+ String requestPath, String targetPath) {
+ List<Pair<String, String>> responseHeaders = new ArrayList<Pair<String, String>>();
+ responseHeaders.add(Pair.create("Location", targetPath));
+
+ return setResponseInternal(requestPath, targetPath.getBytes(), responseHeaders,
+ RESPONSE_STATUS_MOVED_TEMPORARILY);
}
/**
@@ -185,7 +223,8 @@ public class TestWebServer {
List<Pair<String, String>> responseHeaders) {
return setResponseInternal(requestPath,
Base64.decode(base64EncodedResponse, Base64.DEFAULT),
- responseHeaders);
+ responseHeaders,
+ RESPONSE_STATUS_NORMAL);
}
/**
@@ -281,6 +320,11 @@ public class TestWebServer {
Response response = mResponseMap.get(path);
if (path.equals(SHUTDOWN_PREFIX)) {
httpResponse = createResponse(HttpStatus.SC_OK);
+ } else if (response.mIsRedirect) {
+ httpResponse = createResponse(HttpStatus.SC_MOVED_TEMPORARILY);
+ for (Pair<String, String> header : response.mResponseHeaders) {
+ httpResponse.addHeader(header.first, header.second);
+ }
boliu 2012/10/09 18:27:39 Sorry for not comment earlier, and it's not really
} else if (response == null) {
httpResponse = createResponse(HttpStatus.SC_NOT_FOUND);
} else {

Powered by Google App Engine
This is Rietveld 408576698