summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjbudorick <jbudorick@chromium.org>2016-03-25 16:37:48 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-25 23:42:09 +0000
commit08bddd4b5abb2cfe1610d0e101707074965ddbba (patch)
treeaa63e9ee16b42c1cf5207da4f8b75862d575f0ac
parentde49c2d22f6c873aac94696ef004ecf8d8dd6b52 (diff)
downloadchromium_src-08bddd4b5abb2cfe1610d0e101707074965ddbba.zip
chromium_src-08bddd4b5abb2cfe1610d0e101707074965ddbba.tar.gz
chromium_src-08bddd4b5abb2cfe1610d0e101707074965ddbba.tar.bz2
[cronet] Switch CronetTestInstrumentation from lighttpd to EmbeddedTestServer.
BUG=589637 Review URL: https://codereview.chromium.org/1834583005 Cr-Commit-Position: refs/heads/master@{#383407}
-rw-r--r--components/cronet.gypi1
-rw-r--r--components/cronet/android/test/javatests/src/org/chromium/net/ContextInitTest.java36
-rw-r--r--components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java72
-rw-r--r--components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlTest.java44
-rw-r--r--components/cronet/android/test/javatests/src/org/chromium/net/HttpUrlRequestFactoryTest.java24
-rw-r--r--net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java2
6 files changed, 118 insertions, 61 deletions
diff --git a/components/cronet.gypi b/components/cronet.gypi
index 7f433a2..ce5a031 100644
--- a/components/cronet.gypi
+++ b/components/cronet.gypi
@@ -500,6 +500,7 @@
'dependencies': [
'cronet_test_apk_java',
'../base/base.gyp:base_java_test_support',
+ '../net/net.gyp:net_java_test_support',
'../net/net.gyp:require_net_test_support_apk',
],
'variables': {
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/ContextInitTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/ContextInitTest.java
index 8efae2c..fb47ff7 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/ContextInitTest.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/ContextInitTest.java
@@ -8,6 +8,7 @@ import android.content.ContextWrapper;
import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.test.util.Feature;
+import org.chromium.net.test.EmbeddedTestServer;
import java.util.HashMap;
@@ -17,10 +18,23 @@ import java.util.HashMap;
*/
@SuppressWarnings("deprecation")
public class ContextInitTest extends CronetTestBase {
- // URL used for base tests.
- private static final String URL = "http://127.0.0.1:8000";
- // URL used for tests that return HTTP not found (404).
- private static final String URL_404 = "http://127.0.0.1:8000/notfound404";
+ private EmbeddedTestServer mTestServer;
+ private String mUrl;
+ private String mUrl404;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mTestServer = EmbeddedTestServer.createAndStartDefaultServer(getContext());
+ mUrl = mTestServer.getURL("/echo?status=200");
+ mUrl404 = mTestServer.getURL("/echo?status=404");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mTestServer.stopAndDestroyServer();
+ super.tearDown();
+ }
@SmallTest
@Feature({"Cronet"})
@@ -29,7 +43,7 @@ public class ContextInitTest extends CronetTestBase {
// Immediately make a request after initializing the factory.
HttpUrlRequestFactory factory = testFramework.initRequestFactory();
- TestHttpUrlRequestListener listener = makeRequest(factory, URL);
+ TestHttpUrlRequestListener listener = makeRequest(factory, mUrl);
listener.blockForComplete();
assertEquals(200, listener.mHttpStatusCode);
}
@@ -44,7 +58,7 @@ public class ContextInitTest extends CronetTestBase {
HashMap<String, String> headers = new HashMap<String, String>();
TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
HttpUrlRequest request = factory.createRequest(
- URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
+ mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
request.start();
request.cancel();
listener.blockForComplete();
@@ -58,7 +72,7 @@ public class ContextInitTest extends CronetTestBase {
// Make two request right after initializing the factory.
int[] statusCodes = {0, 0};
- String[] urls = {URL, URL_404};
+ String[] urls = {mUrl, mUrl404};
HttpUrlRequestFactory factory = testFramework.initRequestFactory();
for (int i = 0; i < 2; i++) {
TestHttpUrlRequestListener listener = makeRequest(factory, urls[i]);
@@ -93,8 +107,8 @@ public class ContextInitTest extends CronetTestBase {
public void testInitTwoFactoriesSimultaneously() throws Exception {
final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();
- RequestThread thread1 = new RequestThread(testFramework, URL);
- RequestThread thread2 = new RequestThread(testFramework, URL_404);
+ RequestThread thread1 = new RequestThread(testFramework, mUrl);
+ RequestThread thread2 = new RequestThread(testFramework, mUrl404);
thread1.start();
thread2.start();
@@ -109,8 +123,8 @@ public class ContextInitTest extends CronetTestBase {
public void testInitTwoFactoriesInSequence() throws Exception {
final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();
- RequestThread thread1 = new RequestThread(testFramework, URL);
- RequestThread thread2 = new RequestThread(testFramework, URL_404);
+ RequestThread thread1 = new RequestThread(testFramework, mUrl);
+ RequestThread thread2 = new RequestThread(testFramework, mUrl404);
thread1.start();
thread1.join();
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java
index ba3ffa3..c55b974 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java
@@ -20,6 +20,7 @@ import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.net.CronetEngine.UrlRequestInfo;
import org.chromium.net.TestUrlRequestCallback.ResponseStep;
+import org.chromium.net.test.EmbeddedTestServer;
import java.io.BufferedReader;
import java.io.File;
@@ -36,15 +37,30 @@ import java.util.concurrent.Executor;
@JNINamespace("cronet")
public class CronetUrlRequestContextTest extends CronetTestBase {
// URLs used for tests.
- private static final String TEST_URL = "http://127.0.0.1:8000";
- private static final String URL_404 = "http://127.0.0.1:8000/notfound404";
private static final String MOCK_CRONET_TEST_FAILED_URL =
"http://mock.failed.request/-2";
private static final String MOCK_CRONET_TEST_SUCCESS_URL =
"http://mock.http/success.txt";
+ private EmbeddedTestServer mTestServer;
+ private String mUrl;
+ private String mUrl404;
CronetTestFramework mTestFramework;
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mTestServer = EmbeddedTestServer.createAndStartDefaultServer(getContext());
+ mUrl = mTestServer.getURL("/echo?status=200");
+ mUrl404 = mTestServer.getURL("/echo?status=404");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mTestServer.stopAndDestroyServer();
+ super.tearDown();
+ }
+
static class RequestThread extends Thread {
public TestUrlRequestCallback mCallback;
@@ -142,8 +158,8 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
}
cronetEngineBuilder.setUserAgent(userAgentValue);
cronetEngineBuilder.setLibraryName("cronet_tests");
- mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(
- TEST_URL, cronetEngineBuilder);
+ mTestFramework =
+ startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cronetEngineBuilder);
NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer returns false if it's
// already running
assertTrue(NativeTestServer.startNativeTestServer(getContext()));
@@ -219,8 +235,8 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
} catch (IllegalStateException e) {
}
TestUrlRequestCallback callback = new TestUrlRequestCallback();
- UrlRequest urlRequest = mTestFramework.mCronetEngine.createRequest(
- TEST_URL, callback, callback.getExecutor());
+ UrlRequest urlRequest =
+ mTestFramework.mCronetEngine.createRequest(mUrl, callback, callback.getExecutor());
urlRequest.start();
callback.blockForDone();
assertEquals(0, networkQualityListener.rttObservationCount());
@@ -243,8 +259,8 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
mTestFramework.mCronetEngine.removeRttListener(networkQualityListener);
mTestFramework.mCronetEngine.removeThroughputListener(networkQualityListener);
TestUrlRequestCallback callback = new TestUrlRequestCallback();
- UrlRequest urlRequest = mTestFramework.mCronetEngine.createRequest(
- TEST_URL, callback, callback.getExecutor());
+ UrlRequest urlRequest =
+ mTestFramework.mCronetEngine.createRequest(mUrl, callback, callback.getExecutor());
urlRequest.start();
callback.blockForDone();
testExecutor.runAllTasks();
@@ -266,8 +282,8 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
mTestFramework.mCronetEngine.addThroughputListener(networkQualityListener);
TestUrlRequestCallback callback = new TestUrlRequestCallback();
- UrlRequest urlRequest = mTestFramework.mCronetEngine.createRequest(
- TEST_URL, callback, callback.getExecutor());
+ UrlRequest urlRequest =
+ mTestFramework.mCronetEngine.createRequest(mUrl, callback, callback.getExecutor());
urlRequest.start();
callback.blockForDone();
testExecutor.runAllTasks();
@@ -299,7 +315,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedListener);
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
urlRequestBuilder.addRequestAnnotation("request annotation")
.addRequestAnnotation(this)
.build()
@@ -309,7 +325,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
CronetEngine.UrlRequestInfo requestInfo = requestFinishedListener.mRequestInfo;
assertNotNull("RequestFinishedListener must be called", requestInfo);
- assertEquals(TEST_URL, requestInfo.getUrl());
+ assertEquals(mUrl, requestInfo.getUrl());
assertNotNull(requestInfo.getResponseInfo());
assertEquals(newHashSet("request annotation", this), // Use sets for unordered comparison.
new HashSet<Object>(requestInfo.getAnnotations()));
@@ -367,7 +383,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
mTestFramework.mCronetEngine.removeRequestFinishedListener(requestFinishedListener);
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
urlRequestBuilder.build().start();
callback.blockForDone();
testExecutor.runAllTasks();
@@ -393,7 +409,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
}
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
urlRequestBuilder.build().start();
callback.blockForDone();
testExecutor.runAllTasks();
@@ -412,7 +428,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// if there are active requests.
callback.setAutoAdvance(false);
UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
UrlRequest urlRequest = urlRequestBuilder.build();
urlRequest.start();
try {
@@ -558,7 +574,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// if there are active requests.
callback.setAutoAdvance(false);
UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
UrlRequest urlRequest = urlRequestBuilder.build();
urlRequest.start();
try {
@@ -591,7 +607,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// Start a request.
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder =
- new UrlRequest.Builder(TEST_URL, callback, callback.getExecutor(), cronetEngine);
+ new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), cronetEngine);
urlRequestBuilder.build().start();
callback.blockForDone();
cronetEngine.stopNetLog();
@@ -608,7 +624,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
mTestFramework = startCronetTestFramework();
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
urlRequestBuilder.build().start();
callback.blockForDone();
mTestFramework.mCronetEngine.shutdown();
@@ -640,7 +656,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// Start a request.
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
urlRequestBuilder.build().start();
callback.blockForDone();
mTestFramework.mCronetEngine.stopNetLog();
@@ -661,7 +677,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// Start a request.
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
urlRequestBuilder.build().start();
callback.blockForDone();
// Stop NetLog multiple times.
@@ -691,7 +707,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// Start a request.
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder =
- new UrlRequest.Builder(TEST_URL, callback, callback.getExecutor(), cronetEngine);
+ new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), cronetEngine);
urlRequestBuilder.build().start();
callback.blockForDone();
cronetEngine.stopNetLog();
@@ -851,7 +867,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
CronetEngine cronetEngine = testFramework.initCronetEngine();
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder =
- new UrlRequest.Builder(TEST_URL, callback, callback.getExecutor(), cronetEngine);
+ new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), cronetEngine);
urlRequestBuilder.build().start();
callback.blockForDone();
assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
@@ -865,7 +881,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// Make two requests after initializing the context.
CronetEngine cronetEngine = testFramework.initCronetEngine();
int[] statusCodes = {0, 0};
- String[] urls = {TEST_URL, URL_404};
+ String[] urls = {mUrl, mUrl404};
for (int i = 0; i < 2; i++) {
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder urlRequestBuilder =
@@ -885,8 +901,8 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// Threads will block on runBlocker to ensure simultaneous execution.
ConditionVariable runBlocker = new ConditionVariable(false);
- RequestThread thread1 = new RequestThread(testFramework, TEST_URL, runBlocker);
- RequestThread thread2 = new RequestThread(testFramework, URL_404, runBlocker);
+ RequestThread thread1 = new RequestThread(testFramework, mUrl, runBlocker);
+ RequestThread thread2 = new RequestThread(testFramework, mUrl404, runBlocker);
thread1.start();
thread2.start();
@@ -903,8 +919,8 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();
ConditionVariable runBlocker = new ConditionVariable(true);
- RequestThread thread1 = new RequestThread(testFramework, TEST_URL, runBlocker);
- RequestThread thread2 = new RequestThread(testFramework, URL_404, runBlocker);
+ RequestThread thread1 = new RequestThread(testFramework, mUrl, runBlocker);
+ RequestThread thread2 = new RequestThread(testFramework, mUrl404, runBlocker);
thread1.start();
thread1.join();
@@ -941,7 +957,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
TestUrlRequestCallback callback = new TestUrlRequestCallback();
UrlRequest.Builder builder = new UrlRequest.Builder(
- TEST_URL, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
+ mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEngine);
builder.build().start();
callback.blockForDone();
byte delta2[] = mTestFramework.mCronetEngine.getGlobalMetricsDeltas();
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlTest.java
index f807c38..e9b2876 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlTest.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlTest.java
@@ -9,6 +9,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.PathUtils;
import org.chromium.base.test.util.Feature;
+import org.chromium.net.test.EmbeddedTestServer;
import java.io.File;
import java.util.HashMap;
@@ -18,16 +19,29 @@ import java.util.HashMap;
*/
@SuppressWarnings("deprecation")
public class CronetUrlTest extends CronetTestBase {
- // URL used for base tests.
- private static final String URL = "http://127.0.0.1:8000";
+ private EmbeddedTestServer mTestServer;
+ private String mUrl;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mTestServer = EmbeddedTestServer.createAndStartDefaultServer(getContext());
+ mUrl = mTestServer.getURL("/echo?status=200");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mTestServer.stopAndDestroyServer();
+ super.tearDown();
+ }
@SmallTest
@Feature({"Cronet"})
public void testLoadUrl() throws Exception {
- CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(URL);
+ CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(mUrl);
// Make sure that the URL is set as expected.
- assertEquals(URL, testFramework.getUrl());
+ assertEquals(mUrl, testFramework.getUrl());
assertEquals(200, testFramework.getHttpStatusCode());
}
@@ -46,10 +60,10 @@ public class CronetUrlTest extends CronetTestBase {
String[] commandLineArgs = {CronetTestFramework.POST_DATA_KEY, "test",
CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.LibraryInitType.LEGACY};
CronetTestFramework testFramework =
- startCronetTestFrameworkWithUrlAndCommandLineArgs(URL, commandLineArgs);
+ startCronetTestFrameworkWithUrlAndCommandLineArgs(mUrl, commandLineArgs);
// Make sure that the URL is set as expected.
- assertEquals(URL, testFramework.getUrl());
+ assertEquals(mUrl, testFramework.getUrl());
assertEquals(200, testFramework.getHttpStatusCode());
}
@@ -71,7 +85,7 @@ public class CronetUrlTest extends CronetTestBase {
HashMap<String, String> headers = new HashMap<String, String>();
TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
HttpUrlRequest request = factory.createRequest(
- URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
+ mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
request.start();
listener.blockForComplete();
factory.stopNetLog();
@@ -96,14 +110,14 @@ public class CronetUrlTest extends CronetTestBase {
@SmallTest
@Feature({"Cronet"})
public void testCalledByNativeException() throws Exception {
- CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(URL);
+ CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(mUrl);
HashMap<String, String> headers = new HashMap<String, String>();
BadHttpUrlRequestListener listener = new BadHttpUrlRequestListener();
// Create request with bad listener to trigger an exception.
HttpUrlRequest request = testFramework.mRequestFactory.createRequest(
- URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
+ mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
request.start();
listener.blockForComplete();
assertTrue(request.isCanceled());
@@ -115,14 +129,14 @@ public class CronetUrlTest extends CronetTestBase {
@SmallTest
@Feature({"Cronet"})
public void testSetUploadDataWithNullContentType() throws Exception {
- CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(URL);
+ CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(mUrl);
HashMap<String, String> headers = new HashMap<String, String>();
BadHttpUrlRequestListener listener = new BadHttpUrlRequestListener();
// Create request.
HttpUrlRequest request = testFramework.mRequestFactory.createRequest(
- URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
+ mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
byte[] uploadData = new byte[] {1, 2, 3};
try {
request.setUploadData(null, uploadData);
@@ -138,24 +152,24 @@ public class CronetUrlTest extends CronetTestBase {
CronetEngine.Builder builder = new CronetEngine.Builder(getContext());
builder.enableLegacyMode(true);
- CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(URL);
+ CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(mUrl);
// Make sure that the URL is set as expected.
- assertEquals(URL, testFramework.getUrl());
+ assertEquals(mUrl, testFramework.getUrl());
assertEquals(200, testFramework.getHttpStatusCode());
}
@SmallTest
@Feature({"Cronet"})
public void testRequestHead() throws Exception {
- CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(URL);
+ CronetTestFramework testFramework = startCronetTestFrameworkForLegacyApi(mUrl);
HashMap<String, String> headers = new HashMap<String, String>();
TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
// Create request.
HttpUrlRequest request = testFramework.mRequestFactory.createRequest(
- URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
+ mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
request.setHttpMethod("HEAD");
request.start();
listener.blockForComplete();
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/HttpUrlRequestFactoryTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/HttpUrlRequestFactoryTest.java
index ffc725f..742efcf 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/HttpUrlRequestFactoryTest.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/HttpUrlRequestFactoryTest.java
@@ -9,6 +9,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.test.util.Feature;
import org.chromium.net.CronetTestBase.OnlyRunNativeCronet;
+import org.chromium.net.test.EmbeddedTestServer;
import java.io.File;
import java.util.HashMap;
@@ -19,8 +20,21 @@ import java.util.regex.Pattern;
*/
@SuppressWarnings("deprecation")
public class HttpUrlRequestFactoryTest extends CronetTestBase {
- // URL used for base tests.
- private static final String URL = "http://127.0.0.1:8000";
+ private EmbeddedTestServer mTestServer;
+ private String mUrl;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mTestServer = EmbeddedTestServer.createAndStartDefaultServer(getContext());
+ mUrl = mTestServer.getURL("/echo?status=200");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mTestServer.stopAndDestroyServer();
+ super.tearDown();
+ }
@SmallTest
@Feature({"Cronet"})
@@ -54,8 +68,7 @@ public class HttpUrlRequestFactoryTest extends CronetTestBase {
factory.getName()));
HashMap<String, String> headers = new HashMap<String, String>();
TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
- HttpUrlRequest request = factory.createRequest(
- URL, 0, headers, listener);
+ HttpUrlRequest request = factory.createRequest(mUrl, 0, headers, listener);
request.start();
listener.blockForComplete();
assertEquals(200, listener.mHttpStatusCode);
@@ -78,8 +91,7 @@ public class HttpUrlRequestFactoryTest extends CronetTestBase {
factory.getName()));
HashMap<String, String> headers = new HashMap<String, String>();
TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
- HttpUrlRequest request = factory.createRequest(
- URL, 0, headers, listener);
+ HttpUrlRequest request = factory.createRequest(mUrl, 0, headers, listener);
request.start();
listener.blockForComplete();
assertEquals(200, listener.mHttpStatusCode);
diff --git a/net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java b/net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java
index 202a8db..e0e67d5 100644
--- a/net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java
+++ b/net/test/android/javatests/src/org/chromium/net/test/EmbeddedTestServer.java
@@ -221,7 +221,7 @@ public class EmbeddedTestServer {
throws InterruptedException {
EmbeddedTestServer server = new EmbeddedTestServer();
server.initializeNative(context);
- server.addDefaultHandlers("/");
+ server.addDefaultHandlers("");
if (!server.start()) {
throw new EmbeddedTestServerFailure("Failed to start serving using default handlers.");
}