Index: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java |
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java |
index 8c33d769de6fe6d93dd73e96ed7744d482804f0c..520f0020a659b5feaf89b05fa990e6285c55d873 100644 |
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java |
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java |
@@ -6,7 +6,6 @@ package org.chromium.net; |
import android.os.ConditionVariable; |
import android.test.suitebuilder.annotation.SmallTest; |
-import android.util.Pair; |
import org.chromium.base.test.util.Feature; |
import org.chromium.net.TestUrlRequestListener.FailureType; |
@@ -61,19 +60,19 @@ public class CronetUrlRequestTest extends CronetTestBase { |
return listener; |
} |
- private void checkResponseInfo(ResponseInfo responseInfo, |
- String expectedUrl, int expectedHttpStatusCode, |
- String expectedHttpStatusText) { |
+ private void checkResponseInfo(UrlResponseInfo responseInfo, String expectedUrl, |
+ int expectedHttpStatusCode, String expectedHttpStatusText) { |
assertEquals(expectedUrl, responseInfo.getUrl()); |
- assertEquals(expectedUrl, responseInfo.getUrlChain()[ |
- responseInfo.getUrlChain().length - 1]); |
+ assertEquals( |
+ expectedUrl, responseInfo.getUrlChain().get(responseInfo.getUrlChain().size() - 1)); |
assertEquals(expectedHttpStatusCode, responseInfo.getHttpStatusCode()); |
assertEquals(expectedHttpStatusText, responseInfo.getHttpStatusText()); |
assertFalse(responseInfo.wasCached()); |
+ assertTrue(responseInfo.toString().length() > 0); |
xunjieli
2015/10/05 20:39:02
Instead of doing this, maybe add a check for testS
mef
2015/10/05 22:09:19
Done.
|
} |
- private void checkResponseInfoHeader(ResponseInfo responseInfo, |
- String headerName, String headerValue) { |
+ private void checkResponseInfoHeader( |
+ UrlResponseInfo responseInfo, String headerName, String headerValue) { |
Map<String, List<String>> responseHeaders = |
responseInfo.getAllHeaders(); |
List<String> header = responseHeaders.get(headerName); |
@@ -129,8 +128,6 @@ public class CronetUrlRequestTest extends CronetTestBase { |
assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED); |
checkResponseInfo(listener.mResponseInfo, |
NativeTestServer.getEchoMethodURL(), 200, "OK"); |
- checkResponseInfo(listener.mExtendedResponseInfo.getResponseInfo(), |
- NativeTestServer.getEchoMethodURL(), 200, "OK"); |
} |
/** |
@@ -155,8 +152,7 @@ public class CronetUrlRequestTest extends CronetTestBase { |
assertEquals(1, listener.mRedirectResponseInfoList.size()); |
checkResponseInfo(listener.mRedirectResponseInfoList.get(0), |
NativeTestServer.getRedirectURL(), 302, "Found"); |
- assertEquals(1, |
- listener.mRedirectResponseInfoList.get(0).getUrlChain().length); |
+ assertEquals(1, listener.mRedirectResponseInfoList.get(0).getUrlChain().size()); |
assertEquals(NativeTestServer.getSuccessURL(), listener.mRedirectUrlList.get(0)); |
checkResponseInfoHeader(listener.mRedirectResponseInfoList.get(0), |
"redirect-header", "header-value"); |
@@ -175,9 +171,10 @@ public class CronetUrlRequestTest extends CronetTestBase { |
assertEquals(1, listener.mRedirectResponseInfoList.size()); |
assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); |
checkResponseInfo(listener.mResponseInfo, NativeTestServer.getSuccessURL(), 200, "OK"); |
- assertEquals(2, listener.mResponseInfo.getUrlChain().length); |
- assertEquals(NativeTestServer.getRedirectURL(), listener.mResponseInfo.getUrlChain()[0]); |
- assertEquals(NativeTestServer.getSuccessURL(), listener.mResponseInfo.getUrlChain()[1]); |
+ assertEquals(2, listener.mResponseInfo.getUrlChain().size()); |
+ assertEquals( |
+ NativeTestServer.getRedirectURL(), listener.mResponseInfo.getUrlChain().get(0)); |
+ assertEquals(NativeTestServer.getSuccessURL(), listener.mResponseInfo.getUrlChain().get(1)); |
// Wait for an unrelated request to finish. The request should not |
// advance until read is invoked. |
@@ -214,8 +211,6 @@ public class CronetUrlRequestTest extends CronetTestBase { |
String url = NativeTestServer.getFileURL("/notfound.html"); |
TestUrlRequestListener listener = startAndWaitForComplete(url); |
checkResponseInfo(listener.mResponseInfo, url, 404, "Not Found"); |
- checkResponseInfo(listener.mExtendedResponseInfo.getResponseInfo(), |
- url, 404, "Not Found"); |
assertEquals( |
"<!DOCTYPE html>\n<html>\n<head>\n<title>Not found</title>\n" |
+ "<p>Test page loaded.</p>\n</head>\n</html>\n", |
@@ -417,20 +412,19 @@ public class CronetUrlRequestTest extends CronetTestBase { |
public void testResponseHeadersList() throws Exception { |
TestUrlRequestListener listener = startAndWaitForComplete(NativeTestServer.getSuccessURL()); |
assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); |
- List<Pair<String, String>> responseHeaders = |
+ List<Map.Entry<String, String>> responseHeaders = |
listener.mResponseInfo.getAllHeadersAsList(); |
assertEquals(5, responseHeaders.size()); |
- assertEquals("Content-Type", responseHeaders.get(0).first); |
- assertEquals("text/plain", responseHeaders.get(0).second); |
- assertEquals("Access-Control-Allow-Origin", |
- responseHeaders.get(1).first); |
- assertEquals("*", responseHeaders.get(1).second); |
- assertEquals("header-name", responseHeaders.get(2).first); |
- assertEquals("header-value", responseHeaders.get(2).second); |
- assertEquals("multi-header-name", responseHeaders.get(3).first); |
- assertEquals("header-value1", responseHeaders.get(3).second); |
- assertEquals("multi-header-name", responseHeaders.get(4).first); |
- assertEquals("header-value2", responseHeaders.get(4).second); |
+ assertEquals("Content-Type", responseHeaders.get(0).getKey()); |
+ assertEquals("text/plain", responseHeaders.get(0).getValue()); |
+ assertEquals("Access-Control-Allow-Origin", responseHeaders.get(1).getKey()); |
+ assertEquals("*", responseHeaders.get(1).getValue()); |
+ assertEquals("header-name", responseHeaders.get(2).getKey()); |
+ assertEquals("header-value", responseHeaders.get(2).getValue()); |
+ assertEquals("multi-header-name", responseHeaders.get(3).getKey()); |
+ assertEquals("header-value1", responseHeaders.get(3).getValue()); |
+ assertEquals("multi-header-name", responseHeaders.get(4).getKey()); |
+ assertEquals("header-value2", responseHeaders.get(4).getValue()); |
} |
@SmallTest |
@@ -438,30 +432,28 @@ public class CronetUrlRequestTest extends CronetTestBase { |
public void testMockMultiRedirect() throws Exception { |
TestUrlRequestListener listener = |
startAndWaitForComplete(NativeTestServer.getMultiRedirectURL()); |
- ResponseInfo mResponseInfo = listener.mResponseInfo; |
+ UrlResponseInfo mResponseInfo = listener.mResponseInfo; |
assertEquals(2, listener.mRedirectCount); |
assertEquals(200, mResponseInfo.getHttpStatusCode()); |
assertEquals(2, listener.mRedirectResponseInfoList.size()); |
// Check first redirect (multiredirect.html -> redirect.html) |
- ResponseInfo firstRedirectResponseInfo = |
- listener.mRedirectResponseInfoList.get(0); |
- assertEquals(1, firstRedirectResponseInfo.getUrlChain().length); |
- assertEquals( |
- NativeTestServer.getMultiRedirectURL(), firstRedirectResponseInfo.getUrlChain()[0]); |
+ UrlResponseInfo firstRedirectResponseInfo = listener.mRedirectResponseInfoList.get(0); |
+ assertEquals(1, firstRedirectResponseInfo.getUrlChain().size()); |
+ assertEquals(NativeTestServer.getMultiRedirectURL(), |
+ firstRedirectResponseInfo.getUrlChain().get(0)); |
checkResponseInfo( |
firstRedirectResponseInfo, NativeTestServer.getMultiRedirectURL(), 302, "Found"); |
checkResponseInfoHeader(firstRedirectResponseInfo, |
"redirect-header0", "header-value"); |
// Check second redirect (redirect.html -> success.txt) |
- ResponseInfo secondRedirectResponseInfo = |
- listener.mRedirectResponseInfoList.get(1); |
- assertEquals(2, secondRedirectResponseInfo.getUrlChain().length); |
+ UrlResponseInfo secondRedirectResponseInfo = listener.mRedirectResponseInfoList.get(1); |
+ assertEquals(2, secondRedirectResponseInfo.getUrlChain().size()); |
assertEquals(NativeTestServer.getMultiRedirectURL(), |
- secondRedirectResponseInfo.getUrlChain()[0]); |
+ secondRedirectResponseInfo.getUrlChain().get(0)); |
assertEquals( |
- NativeTestServer.getRedirectURL(), secondRedirectResponseInfo.getUrlChain()[1]); |
+ NativeTestServer.getRedirectURL(), secondRedirectResponseInfo.getUrlChain().get(1)); |
checkResponseInfo( |
secondRedirectResponseInfo, NativeTestServer.getRedirectURL(), 302, "Found"); |
checkResponseInfoHeader(secondRedirectResponseInfo, |
@@ -469,10 +461,10 @@ public class CronetUrlRequestTest extends CronetTestBase { |
// Check final response (success.txt). |
assertEquals(NativeTestServer.getSuccessURL(), mResponseInfo.getUrl()); |
- assertEquals(3, mResponseInfo.getUrlChain().length); |
- assertEquals(NativeTestServer.getMultiRedirectURL(), mResponseInfo.getUrlChain()[0]); |
- assertEquals(NativeTestServer.getRedirectURL(), mResponseInfo.getUrlChain()[1]); |
- assertEquals(NativeTestServer.getSuccessURL(), mResponseInfo.getUrlChain()[2]); |
+ assertEquals(3, mResponseInfo.getUrlChain().size()); |
+ assertEquals(NativeTestServer.getMultiRedirectURL(), mResponseInfo.getUrlChain().get(0)); |
+ assertEquals(NativeTestServer.getRedirectURL(), mResponseInfo.getUrlChain().get(1)); |
+ assertEquals(NativeTestServer.getSuccessURL(), mResponseInfo.getUrlChain().get(2)); |
assertTrue(listener.mHttpResponseDataLength != 0); |
assertEquals(2, listener.mRedirectCount); |
assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED); |