Merge "Add a multiple redirects test for Cronet."

This commit is contained in:
Dan Stahr
2023-03-15 17:49:29 +00:00
committed by Gerrit Code Review

View File

@@ -287,6 +287,24 @@ public class UrlRequestTest {
assertTrue(e.getCause().getMessage().contains("full"));
}
@Test
public void testUrlRequest_redirects() throws Exception {
int expectedNumRedirects = 5;
String url =
mTestServer.getRedirectingAssetUrl("html/hello_world.html", expectedNumRedirects);
UrlRequest request = createUrlRequestBuilder(url).build();
request.start();
mCallback.expectCallback(ResponseStep.ON_SUCCEEDED);
UrlResponseInfo info = mCallback.mResponseInfo;
assertOKStatusCode(info);
assertThat(mCallback.mResponseAsString).contains("hello world");
assertThat(info.getUrlChain()).hasSize(expectedNumRedirects + 1);
assertThat(info.getUrlChain().get(0)).isEqualTo(url);
assertThat(info.getUrlChain().get(expectedNumRedirects)).isEqualTo(info.getUrl());
}
@Test
public void testUrlRequestPost_withRedirect() throws Exception {
String body = Strings.repeat(