Commit 0ea424a8 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Migrate TestWebServer.java to GURL

In migrating the TestWebServer to use GURL, I needed to add a native
library to the weblayer shell, allowing it to use the native GURL code.

Bug: 783819
Change-Id: I14b13f242b6ddf9367c2b0f29c0a1665eae6da78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026112
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarRyan Sleevi <rsleevi@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737815}
parent b225a87f
......@@ -52,9 +52,10 @@ public class AwProxyControllerTest {
mContentUrl = mContentServer.setResponse(
"/", "<html><head><title>" + CONTENT + "</title></head>Page 1</html>", null);
mProxyUrl = mProxyServer
.setResponse("/",
.setResponse(mContentUrl,
"<html><head><title>" + PROXY + "</title></head>Page 1</html>",
null)
.replace(mContentUrl, "")
.replace("http://", "")
.replace("/", "");
}
......@@ -75,7 +76,7 @@ public class AwProxyControllerTest {
mActivityTestRule.createAwTestContainerViewOnMainSync(contentsClient);
final AwContents awContents = testContainerView.getAwContents();
int proxyServerRequestCount = mProxyServer.getRequestCount("/");
int proxyServerRequestCount = mProxyServer.getRequestCount(mContentUrl);
// Set proxy override and load content url
// Localhost should use proxy with loopback rule
......@@ -84,12 +85,13 @@ public class AwProxyControllerTest {
TestAwContentsClient.OnReceivedTitleHelper onReceivedTitleHelper =
contentsClient.getOnReceivedTitleHelper();
int onReceivedTitleCallCount = onReceivedTitleHelper.getCallCount();
mActivityTestRule.loadUrlSync(
awContents, contentsClient.getOnPageFinishedHelper(), mContentUrl);
onReceivedTitleHelper.waitForCallback(onReceivedTitleCallCount);
proxyServerRequestCount++;
Assert.assertEquals(proxyServerRequestCount, mProxyServer.getRequestCount("/"));
Assert.assertEquals(proxyServerRequestCount, mProxyServer.getRequestCount(mContentUrl));
Assert.assertEquals(PROXY, onReceivedTitleHelper.getTitle());
// Clear proxy override and load content url
......@@ -99,7 +101,7 @@ public class AwProxyControllerTest {
awContents, contentsClient.getOnPageFinishedHelper(), mContentUrl);
onReceivedTitleHelper.waitForCallback(onReceivedTitleCallCount);
Assert.assertEquals(proxyServerRequestCount, mProxyServer.getRequestCount("/"));
Assert.assertEquals(proxyServerRequestCount, mProxyServer.getRequestCount(mContentUrl));
Assert.assertEquals(CONTENT, onReceivedTitleHelper.getTitle());
}
......@@ -112,7 +114,7 @@ public class AwProxyControllerTest {
mActivityTestRule.createAwTestContainerViewOnMainSync(contentsClient);
final AwContents awContents = testContainerView.getAwContents();
int proxyServerRequestCount = mProxyServer.getRequestCount("/");
int proxyServerRequestCount = mProxyServer.getRequestCount(mContentUrl);
// Set proxy override and load a local url
// Localhost should not use proxy settings
......@@ -124,7 +126,7 @@ public class AwProxyControllerTest {
awContents, contentsClient.getOnPageFinishedHelper(), mContentUrl);
onReceivedTitleHelper.waitForCallback(onReceivedTitleCallCount);
Assert.assertEquals(proxyServerRequestCount, mProxyServer.getRequestCount("/"));
Assert.assertEquals(proxyServerRequestCount, mProxyServer.getRequestCount(mContentUrl));
Assert.assertEquals(CONTENT, onReceivedTitleHelper.getTitle());
}
......
......@@ -13,7 +13,6 @@ import org.chromium.base.ApiCompatibilityUtils;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
......@@ -353,8 +352,9 @@ public class TestWebServer extends WebServer {
*/
public HTTPRequest getLastRequest(String requestPath) {
synchronized (mLock) {
if (!mLastRequestMap.containsKey(requestPath))
if (!mLastRequestMap.containsKey(requestPath)) {
throw new IllegalArgumentException("Path not set: " + requestPath);
}
return mLastRequestMap.get(requestPath);
}
}
......@@ -393,12 +393,13 @@ public class TestWebServer extends WebServer {
boolean copyBinaryBodyToResponse = false;
boolean contentLengthAlreadyIncluded = false;
boolean contentTypeAlreadyIncluded = false;
String path = URI.create(request.getURI()).getPath();
StringBuilder textBody = new StringBuilder();
String requestURI = request.getURI();
Response response;
synchronized (mLock) {
response = mResponseMap.get(path);
response = mResponseMap.get(requestURI);
}
if (response == null || response.mIsNotFound) {
......@@ -442,9 +443,9 @@ public class TestWebServer extends WebServer {
}
}
synchronized (mLock) {
mResponseCountMap.put(
path, Integer.valueOf(mResponseCountMap.get(path).intValue() + 1));
mLastRequestMap.put(path, request);
mResponseCountMap.put(requestURI,
Integer.valueOf(mResponseCountMap.get(requestURI).intValue() + 1));
mLastRequestMap.put(requestURI, request);
}
}
......@@ -457,17 +458,18 @@ public class TestWebServer extends WebServer {
stream.println();
if (textBody.length() != 0) {
if (!contentTypeAlreadyIncluded && (path.endsWith(".html") || path.endsWith(".htm"))) {
if (!contentTypeAlreadyIncluded
&& (requestURI.endsWith(".html") || requestURI.endsWith(".htm"))) {
stream.println("Content-Type: text/html");
}
stream.println("Content-Length: " + textBody.length());
stream.println();
stream.print(textBody.toString());
} else if (copyBinaryBodyToResponse) {
if (!contentTypeAlreadyIncluded && path.endsWith(".js")) {
if (!contentTypeAlreadyIncluded && requestURI.endsWith(".js")) {
stream.println("Content-Type: application/javascript");
} else if (!contentTypeAlreadyIncluded
&& (path.endsWith(".html") || path.endsWith(".htm"))) {
&& (requestURI.endsWith(".html") || requestURI.endsWith(".htm"))) {
stream.println("Content-Type: text/html");
}
if (!contentLengthAlreadyIncluded) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment