Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Backport some TestWebServer commits from upstream. #198

Merged
merged 2 commits into from
Oct 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ private void autoLoginTestHelper(final String testName, final String xAutoLoginH
List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>();
headers.add(Pair.create("x-auto-login", xAutoLoginHeader));

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String pageUrl = webServer.setResponse(path, html, headers);
final int callCount = loginRequestHelper.getCallCount();
loadUrlAsync(awContents, pageUrl);
Expand All @@ -46,7 +45,7 @@ private void autoLoginTestHelper(final String testName, final String xAutoLoginH
assertEquals(expectedAccount, loginRequestHelper.getAccount());
assertEquals(expectedArgs, loginRequestHelper.getArgs());
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onReceivedTouchIconUrl(String url, boolean precomposed) {
protected void setUp() throws Exception {
super.setUp();
AwContents.setShouldDownloadFavicons();
mWebServer = new TestWebServer(false);
mWebServer = TestWebServer.start();
}

private void init(TestAwContentsClientBase contentsClient) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void onFormResubmission(Message dontResend, Message resend) {
@Override
public void setUp() throws Exception {
super.setUp();
mServer = new TestWebServer(false);
mServer = TestWebServer.start();
mContentsClient = new TestAwContentsClient();
final AwTestContainerView testContainerView =
createAwTestContainerViewOnMainSync(mContentsClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected void setUp() throws Exception {
mAwContents = mTestContainerView.getAwContents();
mShouldInterceptRequestHelper = mContentsClient.getShouldInterceptRequestHelper();

mWebServer = new TestWebServer(false);
mWebServer = TestWebServer.start();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase {
@Override
protected void setUp() throws Exception {
super.setUp();
mWebServer = new TestWebServer(false);
mWebServer = TestWebServer.start();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ public void testUpdateVisitedHistoryCallback() throws Throwable {
final String path = "/testUpdateVisitedHistoryCallback.html";
final String html = "testUpdateVisitedHistoryCallback";

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String pageUrl = webServer.setResponse(path, html, null);
final DoUpdateVisitedHistoryHelper doUpdateVisitedHistoryHelper =
mContentsClient.getDoUpdateVisitedHistoryHelper();
Expand All @@ -88,7 +87,7 @@ public void testUpdateVisitedHistoryCallback() throws Throwable {
assertEquals(pageUrl, doUpdateVisitedHistoryHelper.getUrl());
assertEquals(true, doUpdateVisitedHistoryHelper.getIsReload());
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand All @@ -110,9 +109,8 @@ public void testGetVisitedHistoryExerciseCodePath() throws Throwable {
final String visitedLinks[] = {"http://foo.com", "http://bar.com", null};
final String html = "<a src=\"http://foo.com\">foo</a><a src=\"http://bar.com\">bar</a>";

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String pageUrl = webServer.setResponse(path, html, null);
loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
visitedHistoryHelper.waitForCallback(callCount);
Expand All @@ -123,7 +121,7 @@ public void testGetVisitedHistoryExerciseCodePath() throws Throwable {

loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,8 @@ public void testClearCacheMemoryAndDisk() throws Throwable {
createAwTestContainerViewOnMainSync(mContentsClient);
final AwContents awContents = testContainer.getAwContents();

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String pagePath = "/clear_cache_test.html";
List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>();
// Set Cache-Control headers to cache this request. One century should be long enough.
Expand Down Expand Up @@ -296,7 +295,7 @@ public void testClearCacheMemoryAndDisk() throws Throwable {
pageUrl);
assertEquals(2, webServer.getRequestCount(pagePath));
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down Expand Up @@ -324,10 +323,8 @@ public void testGetFavicon() throws Throwable {
final AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
final AwContents awContents = testView.getAwContents();

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);

final String faviconUrl = webServer.setResponseBase64(
"/" + CommonResources.FAVICON_FILENAME, CommonResources.FAVICON_DATA_BASE64,
CommonResources.getImagePngHeaders(false));
Expand Down Expand Up @@ -357,7 +354,7 @@ public Boolean call() {
assertTrue(awContents.getFavicon().sameAs(originalFavicon));

} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand All @@ -376,9 +373,8 @@ public void testDownload() throws Throwable {
downloadHeaders.add(Pair.create("Content-Type", mimeType));
downloadHeaders.add(Pair.create("Content-Length", Integer.toString(data.length())));

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String pageUrl = webServer.setResponse(
"/download.txt", data, downloadHeaders);
final OnDownloadStartHelper downloadStartHelper =
Expand All @@ -392,7 +388,7 @@ public void testDownload() throws Throwable {
assertEquals(mimeType, downloadStartHelper.getMimeType());
assertEquals(data.length(), downloadStartHelper.getContentLength());
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down Expand Up @@ -479,9 +475,8 @@ public void testCanInjectHeaders() throws Throwable {
createAwTestContainerViewOnMainSync(mContentsClient);
final AwContents awContents = testContainer.getAwContents();

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String pagePath = "/test_can_inject_headers.html";
final String pageUrl = webServer.setResponse(
pagePath, "<html><body>foo</body></html>", null);
Expand All @@ -504,7 +499,7 @@ public void testCanInjectHeaders() throws Throwable {
assertEquals(value.getValue(), matchingHeaders[0].getValue());
}
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void setUp() throws Exception {
mContentsClient = new TestAwContentsClient();
mTestView = createAwTestContainerViewOnMainSync(mContentsClient);
mAwContents = mTestView.getAwContents();
mWebServer = new TestWebServer(false);
mWebServer = TestWebServer.start();
mOrigin = mWebServer.getBaseUrl();

AwSettings settings = getAwSettingsOnUiThread(mAwContents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1728,10 +1728,9 @@ public void testUserAgentWithTestServer() throws Throwable {
final String customUserAgentString =
"testUserAgentWithTestServerUserAgent";

TestWebServer webServer = null;
String fileName = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String httpPath = "/testUserAgentWithTestServer.html";
final String url = webServer.setResponse(httpPath, "foo", null);

Expand All @@ -1748,7 +1747,7 @@ public void testUserAgentWithTestServer() throws Throwable {
Header header = matchingHeaders[0];
assertEquals(customUserAgentString, header.getValue());
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down Expand Up @@ -1935,9 +1934,8 @@ public void testBlockNetworkImagesBlocksNetworkImageAndReloadInPlace() throws Th
settings.setJavaScriptEnabled(true);
ImagePageGenerator generator = new ImagePageGenerator(0, false);

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String httpImageUrl = generator.getPageUrl(webServer);

settings.setImagesEnabled(false);
Expand All @@ -1954,17 +1952,16 @@ public Boolean call() throws Exception {
}
});
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

@SmallTest
@Feature({"AndroidWebView", "Preferences"})
public void testBlockNetworkImagesWithTwoViews() throws Throwable {
ViewPair views = createViews();
TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
runPerViewSettingsTest(
new AwSettingsImagesEnabledHelper(
views.getContainer0(),
Expand All @@ -1977,7 +1974,7 @@ public void testBlockNetworkImagesWithTwoViews() throws Throwable {
webServer,
new ImagePageGenerator(1, true)));
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand All @@ -1992,11 +1989,10 @@ public void testBlockNetworkLoadsWithHttpResources() throws Throwable {
awSettings.setJavaScriptEnabled(true);
ImagePageGenerator generator = new ImagePageGenerator(0, false);

TestWebServer webServer = null;
String fileName = null;
TestWebServer webServer = TestWebServer.start();
try {
// Set up http image.
webServer = new TestWebServer(false);
final String httpPath = "/image.png";
final String imageUrl = webServer.setResponseBase64(
httpPath, generator.getImageSourceNoAdvance(),
Expand Down Expand Up @@ -2029,8 +2025,8 @@ public void testBlockNetworkLoadsWithHttpResources() throws Throwable {
assertEquals(1, webServer.getRequestCount(httpPath));
assertEquals("img_onload_fired", getTitleOnUiThread(awContents));
} finally {
webServer.shutdown();
if (fileName != null) TestFileUtil.deleteFile(fileName);
if (webServer != null) webServer.shutdown();
}
}

Expand Down Expand Up @@ -2062,9 +2058,8 @@ public void testBlockNetworkLoadsWithAudio() throws Throwable {
final CallbackHelper callback = new CallbackHelper();
awSettings.setJavaScriptEnabled(true);

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String httpPath = "/audio.mp3";
// Don't care about the response is correct or not, just want
// to know whether Url is accessed.
Expand Down Expand Up @@ -2100,7 +2095,7 @@ public void run() {
assertTrue(0 != webServer.getRequestCount(httpPath));
*/
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down Expand Up @@ -2223,9 +2218,8 @@ public void testCacheMode() throws Throwable {
clearCacheOnUiThread(awContents, true);

assertEquals(WebSettings.LOAD_DEFAULT, awSettings.getCacheMode());
TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String htmlPath = "/testCacheMode.html";
final String url = webServer.setResponse(htmlPath, "response", null);
awSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
Expand Down Expand Up @@ -2254,7 +2248,7 @@ public void testCacheMode() throws Throwable {
urlNotInCache);
assertEquals(0, webServer.getRequestCount(htmlNotInCachePath));
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand All @@ -2273,9 +2267,8 @@ public void testCacheModeWithBlockedNetworkLoads() throws Throwable {

assertEquals(WebSettings.LOAD_DEFAULT, awSettings.getCacheMode());
awSettings.setBlockNetworkLoads(true);
TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
final String htmlPath = "/testCacheModeWithBlockedNetworkLoads.html";
final String url = webServer.setResponse(htmlPath, "response", null);
loadUrlSyncAndExpectError(awContents,
Expand Down Expand Up @@ -2305,24 +2298,23 @@ public void testCacheModeWithBlockedNetworkLoads() throws Throwable {
url);
assertEquals(0, webServer.getRequestCount(htmlPath));
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

@SmallTest
@Feature({"AndroidWebView", "Preferences"})
public void testCacheModeWithTwoViews() throws Throwable {
ViewPair views = createViews();
TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
runPerViewSettingsTest(
new AwSettingsCacheModeTestHelper(
views.getContainer0(), views.getClient0(), 0, webServer),
new AwSettingsCacheModeTestHelper(
views.getContainer1(), views.getClient1(), 1, webServer));
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down Expand Up @@ -2389,9 +2381,8 @@ public void testAppCache() throws Throwable {
// Note that the cache isn't actually enabled until the call to setAppCachePath.
settings.setAppCacheEnabled(true);

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
ManifestTestHelper helper = new ManifestTestHelper(
webServer, "testAppCache.html", "appcache.manifest");
loadUrlSync(
Expand All @@ -2410,7 +2401,7 @@ public void testAppCache() throws Throwable {
helper.getHtmlUrl());
helper.waitUntilManifestIsRequested(0);
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand All @@ -2431,9 +2422,8 @@ public void testAppCacheWithTwoViews() throws Throwable {
// AppCachePath setting is global, no need to set it for the second view.
settings1.setAppCacheEnabled(true);

TestWebServer webServer = null;
TestWebServer webServer = TestWebServer.start();
try {
webServer = new TestWebServer(false);
ManifestTestHelper helper0 = new ManifestTestHelper(
webServer, "testAppCache_0.html", "appcache.manifest_0");
loadUrlSync(
Expand Down Expand Up @@ -2468,7 +2458,7 @@ public void testAppCacheWithTwoViews() throws Throwable {
assertEquals(
prevManifestRequestCount, webServer.getRequestCount(helper1.getManifestPath()));
} finally {
if (webServer != null) webServer.shutdown();
webServer.shutdown();
}
}

Expand Down Expand Up @@ -2777,8 +2767,8 @@ public void onReceivedSslError(ValueCallback<Boolean> callback, SslError error)
TestWebServer httpsServer = null;
TestWebServer httpServer = null;
try {
httpsServer = new TestWebServer(true);
httpServer = new TestWebServer(false);
httpsServer = TestWebServer.startSsl();
httpServer = TestWebServer.start();

final String jsUrl = "/insecure.js";
final String imageUrl = "/insecure.png";
Expand Down
Loading