Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java

Issue 1359343005: Update ResponseInfo to UrlResponseInfo with API review comments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update README.md Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.os.ConditionVariable; 7 import android.os.ConditionVariable;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 import android.util.Pair;
10 9
11 import org.chromium.base.test.util.Feature; 10 import org.chromium.base.test.util.Feature;
12 import org.chromium.net.TestUrlRequestListener.FailureType; 11 import org.chromium.net.TestUrlRequestListener.FailureType;
13 import org.chromium.net.TestUrlRequestListener.ResponseStep; 12 import org.chromium.net.TestUrlRequestListener.ResponseStep;
14 import org.chromium.net.test.FailurePhase; 13 import org.chromium.net.test.FailurePhase;
15 14
16 import java.nio.ByteBuffer; 15 import java.nio.ByteBuffer;
17 import java.util.ArrayList; 16 import java.util.ArrayList;
18 import java.util.List; 17 import java.util.List;
19 import java.util.Map; 18 import java.util.Map;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 // Create request. 53 // Create request.
55 UrlRequest.Builder builder = new UrlRequest.Builder( 54 UrlRequest.Builder builder = new UrlRequest.Builder(
56 url, listener, listener.getExecutor(), mActivity.mCronetEngine); 55 url, listener, listener.getExecutor(), mActivity.mCronetEngine);
57 UrlRequest urlRequest = builder.build(); 56 UrlRequest urlRequest = builder.build();
58 urlRequest.start(); 57 urlRequest.start();
59 listener.blockForDone(); 58 listener.blockForDone();
60 assertTrue(urlRequest.isDone()); 59 assertTrue(urlRequest.isDone());
61 return listener; 60 return listener;
62 } 61 }
63 62
64 private void checkResponseInfo(ResponseInfo responseInfo, 63 private void checkResponseInfo(UrlResponseInfo responseInfo, String expected Url,
65 String expectedUrl, int expectedHttpStatusCode, 64 int expectedHttpStatusCode, String expectedHttpStatusText) {
66 String expectedHttpStatusText) {
67 assertEquals(expectedUrl, responseInfo.getUrl()); 65 assertEquals(expectedUrl, responseInfo.getUrl());
68 assertEquals(expectedUrl, responseInfo.getUrlChain()[ 66 assertEquals(
69 responseInfo.getUrlChain().length - 1]); 67 expectedUrl, responseInfo.getUrlChain().get(responseInfo.getUrlC hain().size() - 1));
70 assertEquals(expectedHttpStatusCode, responseInfo.getHttpStatusCode()); 68 assertEquals(expectedHttpStatusCode, responseInfo.getHttpStatusCode());
71 assertEquals(expectedHttpStatusText, responseInfo.getHttpStatusText()); 69 assertEquals(expectedHttpStatusText, responseInfo.getHttpStatusText());
72 assertFalse(responseInfo.wasCached()); 70 assertFalse(responseInfo.wasCached());
71 assertTrue(responseInfo.toString().length() > 0);
73 } 72 }
74 73
75 private void checkResponseInfoHeader(ResponseInfo responseInfo, 74 private void checkResponseInfoHeader(
76 String headerName, String headerValue) { 75 UrlResponseInfo responseInfo, String headerName, String headerValue) {
77 Map<String, List<String>> responseHeaders = 76 Map<String, List<String>> responseHeaders =
78 responseInfo.getAllHeaders(); 77 responseInfo.getAllHeaders();
79 List<String> header = responseHeaders.get(headerName); 78 List<String> header = responseHeaders.get(headerName);
80 assertNotNull(header); 79 assertNotNull(header);
81 assertTrue(header.contains(headerValue)); 80 assertTrue(header.contains(headerValue));
82 } 81 }
83 82
84 @SmallTest 83 @SmallTest
85 @Feature({"Cronet"}) 84 @Feature({"Cronet"})
86 public void testBuilderChecks() throws Exception { 85 public void testBuilderChecks() throws Exception {
(...skipping 26 matching lines...) Expand all
113 assertEquals("CronetEngine is required.", e.getMessage()); 112 assertEquals("CronetEngine is required.", e.getMessage());
114 } 113 }
115 // Verify successful creation doesn't throw. 114 // Verify successful creation doesn't throw.
116 new UrlRequest.Builder(NativeTestServer.getRedirectURL(), listener, list ener.getExecutor(), 115 new UrlRequest.Builder(NativeTestServer.getRedirectURL(), listener, list ener.getExecutor(),
117 mActivity.mCronetEngine); 116 mActivity.mCronetEngine);
118 } 117 }
119 118
120 @SmallTest 119 @SmallTest
121 @Feature({"Cronet"}) 120 @Feature({"Cronet"})
122 public void testSimpleGet() throws Exception { 121 public void testSimpleGet() throws Exception {
123 TestUrlRequestListener listener = startAndWaitForComplete( 122 String url = NativeTestServer.getEchoMethodURL();
124 NativeTestServer.getEchoMethodURL()); 123 TestUrlRequestListener listener = startAndWaitForComplete(url);
125 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); 124 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
126 // Default method is 'GET'. 125 // Default method is 'GET'.
127 assertEquals("GET", listener.mResponseAsString); 126 assertEquals("GET", listener.mResponseAsString);
128 assertEquals(0, listener.mRedirectCount); 127 assertEquals(0, listener.mRedirectCount);
129 assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED); 128 assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED);
129 assertEquals(String.format("UrlResponseInfo[%s]: urlChain = [%s], httpSt atus = 200 OK, "
130 + "headers = [Connection=close, Content-Len gth=3, "
131 + "Content-Type=text/plain], wasCached = fa lse, "
132 + "negotiatedProtocol = unknown, proxyServe r= :0, "
133 + "receivedBytesCount = 86",
134 url, url),
135 listener.mResponseInfo.toString());
130 checkResponseInfo(listener.mResponseInfo, 136 checkResponseInfo(listener.mResponseInfo,
131 NativeTestServer.getEchoMethodURL(), 200, "OK"); 137 NativeTestServer.getEchoMethodURL(), 200, "OK");
132 checkResponseInfo(listener.mExtendedResponseInfo.getResponseInfo(),
133 NativeTestServer.getEchoMethodURL(), 200, "OK");
134 } 138 }
135 139
136 /** 140 /**
137 * Tests a redirect by running it step-by-step. Also tests that delaying a 141 * Tests a redirect by running it step-by-step. Also tests that delaying a
138 * request works as expected. To make sure there are no unexpected pending 142 * request works as expected. To make sure there are no unexpected pending
139 * messages, does a GET between UrlRequestListener callbacks. 143 * messages, does a GET between UrlRequestListener callbacks.
140 */ 144 */
141 @SmallTest 145 @SmallTest
142 @Feature({"Cronet"}) 146 @Feature({"Cronet"})
143 public void testRedirectAsync() throws Exception { 147 public void testRedirectAsync() throws Exception {
144 // Start the request and wait to see the redirect. 148 // Start the request and wait to see the redirect.
145 TestUrlRequestListener listener = new TestUrlRequestListener(); 149 TestUrlRequestListener listener = new TestUrlRequestListener();
146 listener.setAutoAdvance(false); 150 listener.setAutoAdvance(false);
147 UrlRequest.Builder builder = new UrlRequest.Builder(NativeTestServer.get RedirectURL(), 151 UrlRequest.Builder builder = new UrlRequest.Builder(NativeTestServer.get RedirectURL(),
148 listener, listener.getExecutor(), mActivity.mCronetEngine); 152 listener, listener.getExecutor(), mActivity.mCronetEngine);
149 UrlRequest urlRequest = builder.build(); 153 UrlRequest urlRequest = builder.build();
150 urlRequest.start(); 154 urlRequest.start();
151 listener.waitForNextStep(); 155 listener.waitForNextStep();
152 156
153 // Check the redirect. 157 // Check the redirect.
154 assertEquals(ResponseStep.ON_RECEIVED_REDIRECT, listener.mResponseStep); 158 assertEquals(ResponseStep.ON_RECEIVED_REDIRECT, listener.mResponseStep);
155 assertEquals(1, listener.mRedirectResponseInfoList.size()); 159 assertEquals(1, listener.mRedirectResponseInfoList.size());
156 checkResponseInfo(listener.mRedirectResponseInfoList.get(0), 160 checkResponseInfo(listener.mRedirectResponseInfoList.get(0),
157 NativeTestServer.getRedirectURL(), 302, "Found"); 161 NativeTestServer.getRedirectURL(), 302, "Found");
158 assertEquals(1, 162 assertEquals(1, listener.mRedirectResponseInfoList.get(0).getUrlChain(). size());
159 listener.mRedirectResponseInfoList.get(0).getUrlChain().length);
160 assertEquals(NativeTestServer.getSuccessURL(), listener.mRedirectUrlList .get(0)); 163 assertEquals(NativeTestServer.getSuccessURL(), listener.mRedirectUrlList .get(0));
161 checkResponseInfoHeader(listener.mRedirectResponseInfoList.get(0), 164 checkResponseInfoHeader(listener.mRedirectResponseInfoList.get(0),
162 "redirect-header", "header-value"); 165 "redirect-header", "header-value");
163 166
167 assertEquals(String.format("UrlResponseInfo[%s]: urlChain = [%s], httpSt atus = 302 Found, "
168 + "headers = [Location=/success.txt, "
169 + "redirect-header=header-value], wasCached = false, "
170 + "negotiatedProtocol = unknown, proxyServe r= :0, "
171 + "receivedBytesCount = 74",
172 NativeTestServer.getRedirectURL(), NativeTestServer .getRedirectURL()),
173 listener.mRedirectResponseInfoList.get(0).toString());
174
164 // Wait for an unrelated request to finish. The request should not 175 // Wait for an unrelated request to finish. The request should not
165 // advance until followRedirect is invoked. 176 // advance until followRedirect is invoked.
166 testSimpleGet(); 177 testSimpleGet();
167 assertEquals(ResponseStep.ON_RECEIVED_REDIRECT, listener.mResponseStep); 178 assertEquals(ResponseStep.ON_RECEIVED_REDIRECT, listener.mResponseStep);
168 assertEquals(1, listener.mRedirectResponseInfoList.size()); 179 assertEquals(1, listener.mRedirectResponseInfoList.size());
169 180
170 // Follow the redirect and wait for the next set of headers. 181 // Follow the redirect and wait for the next set of headers.
171 urlRequest.followRedirect(); 182 urlRequest.followRedirect();
172 listener.waitForNextStep(); 183 listener.waitForNextStep();
173 184
174 assertEquals(ResponseStep.ON_RESPONSE_STARTED, listener.mResponseStep); 185 assertEquals(ResponseStep.ON_RESPONSE_STARTED, listener.mResponseStep);
175 assertEquals(1, listener.mRedirectResponseInfoList.size()); 186 assertEquals(1, listener.mRedirectResponseInfoList.size());
176 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); 187 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
177 checkResponseInfo(listener.mResponseInfo, NativeTestServer.getSuccessURL (), 200, "OK"); 188 checkResponseInfo(listener.mResponseInfo, NativeTestServer.getSuccessURL (), 200, "OK");
178 assertEquals(2, listener.mResponseInfo.getUrlChain().length); 189 assertEquals(2, listener.mResponseInfo.getUrlChain().size());
179 assertEquals(NativeTestServer.getRedirectURL(), listener.mResponseInfo.g etUrlChain()[0]); 190 assertEquals(
180 assertEquals(NativeTestServer.getSuccessURL(), listener.mResponseInfo.ge tUrlChain()[1]); 191 NativeTestServer.getRedirectURL(), listener.mResponseInfo.getUrl Chain().get(0));
192 assertEquals(NativeTestServer.getSuccessURL(), listener.mResponseInfo.ge tUrlChain().get(1));
181 193
182 // Wait for an unrelated request to finish. The request should not 194 // Wait for an unrelated request to finish. The request should not
183 // advance until read is invoked. 195 // advance until read is invoked.
184 testSimpleGet(); 196 testSimpleGet();
185 assertEquals(ResponseStep.ON_RESPONSE_STARTED, listener.mResponseStep); 197 assertEquals(ResponseStep.ON_RESPONSE_STARTED, listener.mResponseStep);
186 198
187 // One read should get all the characters, but best not to depend on 199 // One read should get all the characters, but best not to depend on
188 // how much is actually read from the socket at once. 200 // how much is actually read from the socket at once.
189 while (!listener.isDone()) { 201 while (!listener.isDone()) {
190 listener.startNextRead(urlRequest); 202 listener.startNextRead(urlRequest);
191 listener.waitForNextStep(); 203 listener.waitForNextStep();
192 String response = listener.mResponseAsString; 204 String response = listener.mResponseAsString;
193 ResponseStep step = listener.mResponseStep; 205 ResponseStep step = listener.mResponseStep;
194 if (!listener.isDone()) { 206 if (!listener.isDone()) {
195 assertEquals(ResponseStep.ON_READ_COMPLETED, step); 207 assertEquals(ResponseStep.ON_READ_COMPLETED, step);
196 } 208 }
197 // Should not receive any messages while waiting for another get, 209 // Should not receive any messages while waiting for another get,
198 // as the next read has not been started. 210 // as the next read has not been started.
199 testSimpleGet(); 211 testSimpleGet();
200 assertEquals(response, listener.mResponseAsString); 212 assertEquals(response, listener.mResponseAsString);
201 assertEquals(step, listener.mResponseStep); 213 assertEquals(step, listener.mResponseStep);
202 } 214 }
203 assertEquals(ResponseStep.ON_SUCCEEDED, listener.mResponseStep); 215 assertEquals(ResponseStep.ON_SUCCEEDED, listener.mResponseStep);
204 assertEquals(NativeTestServer.SUCCESS_BODY, listener.mResponseAsString); 216 assertEquals(NativeTestServer.SUCCESS_BODY, listener.mResponseAsString);
205 217
218 assertEquals(String.format("UrlResponseInfo[%s]: urlChain = [%s, %s], ht tpStatus = 200 OK, "
219 + "headers = [Content-Type=text/plain, "
220 + "Access-Control-Allow-Origin=*, header-na me=header-value, "
221 + "multi-header-name=header-value1, "
222 + "multi-header-name=header-value2], wasCac hed = false, "
223 + "negotiatedProtocol = unknown, proxyServe r= :0, "
224 + "receivedBytesCount = 260",
225 NativeTestServer.getSuccessURL(), NativeTestServer. getRedirectURL(),
226 NativeTestServer.getSuccessURL()),
227 listener.mResponseInfo.toString());
228
206 // Make sure there are no other pending messages, which would trigger 229 // Make sure there are no other pending messages, which would trigger
207 // asserts in TestURLRequestListener. 230 // asserts in TestURLRequestListener.
208 testSimpleGet(); 231 testSimpleGet();
209 } 232 }
210 233
211 @SmallTest 234 @SmallTest
212 @Feature({"Cronet"}) 235 @Feature({"Cronet"})
213 public void testNotFound() throws Exception { 236 public void testNotFound() throws Exception {
214 String url = NativeTestServer.getFileURL("/notfound.html"); 237 String url = NativeTestServer.getFileURL("/notfound.html");
215 TestUrlRequestListener listener = startAndWaitForComplete(url); 238 TestUrlRequestListener listener = startAndWaitForComplete(url);
216 checkResponseInfo(listener.mResponseInfo, url, 404, "Not Found"); 239 checkResponseInfo(listener.mResponseInfo, url, 404, "Not Found");
217 checkResponseInfo(listener.mExtendedResponseInfo.getResponseInfo(),
218 url, 404, "Not Found");
219 assertEquals( 240 assertEquals(
220 "<!DOCTYPE html>\n<html>\n<head>\n<title>Not found</title>\n" 241 "<!DOCTYPE html>\n<html>\n<head>\n<title>Not found</title>\n"
221 + "<p>Test page loaded.</p>\n</head>\n</html>\n", 242 + "<p>Test page loaded.</p>\n</head>\n</html>\n",
222 listener.mResponseAsString); 243 listener.mResponseAsString);
223 assertEquals(0, listener.mRedirectCount); 244 assertEquals(0, listener.mRedirectCount);
224 assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED); 245 assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED);
225 } 246 }
226 247
227 // Checks that UrlRequestListener.onFailed is only called once in the case 248 // Checks that UrlRequestListener.onFailed is only called once in the case
228 // of ERR_CONTENT_LENGTH_MISMATCH, which has an unusual failure path. 249 // of ERR_CONTENT_LENGTH_MISMATCH, which has an unusual failure path.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 assertEquals(2, multiHeader.size()); 431 assertEquals(2, multiHeader.size());
411 assertEquals("header-value1", multiHeader.get(0)); 432 assertEquals("header-value1", multiHeader.get(0));
412 assertEquals("header-value2", multiHeader.get(1)); 433 assertEquals("header-value2", multiHeader.get(1));
413 } 434 }
414 435
415 @SmallTest 436 @SmallTest
416 @Feature({"Cronet"}) 437 @Feature({"Cronet"})
417 public void testResponseHeadersList() throws Exception { 438 public void testResponseHeadersList() throws Exception {
418 TestUrlRequestListener listener = startAndWaitForComplete(NativeTestServ er.getSuccessURL()); 439 TestUrlRequestListener listener = startAndWaitForComplete(NativeTestServ er.getSuccessURL());
419 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); 440 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
420 List<Pair<String, String>> responseHeaders = 441 List<Map.Entry<String, String>> responseHeaders =
421 listener.mResponseInfo.getAllHeadersAsList(); 442 listener.mResponseInfo.getAllHeadersAsList();
422 assertEquals(5, responseHeaders.size()); 443 assertEquals(5, responseHeaders.size());
423 assertEquals("Content-Type", responseHeaders.get(0).first); 444 assertEquals("Content-Type", responseHeaders.get(0).getKey());
424 assertEquals("text/plain", responseHeaders.get(0).second); 445 assertEquals("text/plain", responseHeaders.get(0).getValue());
425 assertEquals("Access-Control-Allow-Origin", 446 assertEquals("Access-Control-Allow-Origin", responseHeaders.get(1).getKe y());
426 responseHeaders.get(1).first); 447 assertEquals("*", responseHeaders.get(1).getValue());
427 assertEquals("*", responseHeaders.get(1).second); 448 assertEquals("header-name", responseHeaders.get(2).getKey());
428 assertEquals("header-name", responseHeaders.get(2).first); 449 assertEquals("header-value", responseHeaders.get(2).getValue());
429 assertEquals("header-value", responseHeaders.get(2).second); 450 assertEquals("multi-header-name", responseHeaders.get(3).getKey());
430 assertEquals("multi-header-name", responseHeaders.get(3).first); 451 assertEquals("header-value1", responseHeaders.get(3).getValue());
431 assertEquals("header-value1", responseHeaders.get(3).second); 452 assertEquals("multi-header-name", responseHeaders.get(4).getKey());
432 assertEquals("multi-header-name", responseHeaders.get(4).first); 453 assertEquals("header-value2", responseHeaders.get(4).getValue());
433 assertEquals("header-value2", responseHeaders.get(4).second);
434 } 454 }
435 455
436 @SmallTest 456 @SmallTest
437 @Feature({"Cronet"}) 457 @Feature({"Cronet"})
438 public void testMockMultiRedirect() throws Exception { 458 public void testMockMultiRedirect() throws Exception {
439 TestUrlRequestListener listener = 459 TestUrlRequestListener listener =
440 startAndWaitForComplete(NativeTestServer.getMultiRedirectURL()); 460 startAndWaitForComplete(NativeTestServer.getMultiRedirectURL());
441 ResponseInfo mResponseInfo = listener.mResponseInfo; 461 UrlResponseInfo mResponseInfo = listener.mResponseInfo;
442 assertEquals(2, listener.mRedirectCount); 462 assertEquals(2, listener.mRedirectCount);
443 assertEquals(200, mResponseInfo.getHttpStatusCode()); 463 assertEquals(200, mResponseInfo.getHttpStatusCode());
444 assertEquals(2, listener.mRedirectResponseInfoList.size()); 464 assertEquals(2, listener.mRedirectResponseInfoList.size());
445 465
446 // Check first redirect (multiredirect.html -> redirect.html) 466 // Check first redirect (multiredirect.html -> redirect.html)
447 ResponseInfo firstRedirectResponseInfo = 467 UrlResponseInfo firstRedirectResponseInfo = listener.mRedirectResponseIn foList.get(0);
448 listener.mRedirectResponseInfoList.get(0); 468 assertEquals(1, firstRedirectResponseInfo.getUrlChain().size());
449 assertEquals(1, firstRedirectResponseInfo.getUrlChain().length); 469 assertEquals(NativeTestServer.getMultiRedirectURL(),
450 assertEquals( 470 firstRedirectResponseInfo.getUrlChain().get(0));
451 NativeTestServer.getMultiRedirectURL(), firstRedirectResponseInf o.getUrlChain()[0]);
452 checkResponseInfo( 471 checkResponseInfo(
453 firstRedirectResponseInfo, NativeTestServer.getMultiRedirectURL( ), 302, "Found"); 472 firstRedirectResponseInfo, NativeTestServer.getMultiRedirectURL( ), 302, "Found");
454 checkResponseInfoHeader(firstRedirectResponseInfo, 473 checkResponseInfoHeader(firstRedirectResponseInfo,
455 "redirect-header0", "header-value"); 474 "redirect-header0", "header-value");
475 assertEquals(77, firstRedirectResponseInfo.getReceivedBytesCount());
456 476
457 // Check second redirect (redirect.html -> success.txt) 477 // Check second redirect (redirect.html -> success.txt)
458 ResponseInfo secondRedirectResponseInfo = 478 UrlResponseInfo secondRedirectResponseInfo = listener.mRedirectResponseI nfoList.get(1);
459 listener.mRedirectResponseInfoList.get(1); 479 assertEquals(2, secondRedirectResponseInfo.getUrlChain().size());
460 assertEquals(2, secondRedirectResponseInfo.getUrlChain().length);
461 assertEquals(NativeTestServer.getMultiRedirectURL(), 480 assertEquals(NativeTestServer.getMultiRedirectURL(),
462 secondRedirectResponseInfo.getUrlChain()[0]); 481 secondRedirectResponseInfo.getUrlChain().get(0));
463 assertEquals( 482 assertEquals(
464 NativeTestServer.getRedirectURL(), secondRedirectResponseInfo.ge tUrlChain()[1]); 483 NativeTestServer.getRedirectURL(), secondRedirectResponseInfo.ge tUrlChain().get(1));
465 checkResponseInfo( 484 checkResponseInfo(
466 secondRedirectResponseInfo, NativeTestServer.getRedirectURL(), 3 02, "Found"); 485 secondRedirectResponseInfo, NativeTestServer.getRedirectURL(), 3 02, "Found");
467 checkResponseInfoHeader(secondRedirectResponseInfo, 486 checkResponseInfoHeader(secondRedirectResponseInfo,
468 "redirect-header", "header-value"); 487 "redirect-header", "header-value");
488 assertEquals(151, secondRedirectResponseInfo.getReceivedBytesCount());
469 489
470 // Check final response (success.txt). 490 // Check final response (success.txt).
471 assertEquals(NativeTestServer.getSuccessURL(), mResponseInfo.getUrl()); 491 assertEquals(NativeTestServer.getSuccessURL(), mResponseInfo.getUrl());
472 assertEquals(3, mResponseInfo.getUrlChain().length); 492 assertEquals(3, mResponseInfo.getUrlChain().size());
473 assertEquals(NativeTestServer.getMultiRedirectURL(), mResponseInfo.getUr lChain()[0]); 493 assertEquals(NativeTestServer.getMultiRedirectURL(), mResponseInfo.getUr lChain().get(0));
474 assertEquals(NativeTestServer.getRedirectURL(), mResponseInfo.getUrlChai n()[1]); 494 assertEquals(NativeTestServer.getRedirectURL(), mResponseInfo.getUrlChai n().get(1));
475 assertEquals(NativeTestServer.getSuccessURL(), mResponseInfo.getUrlChain ()[2]); 495 assertEquals(NativeTestServer.getSuccessURL(), mResponseInfo.getUrlChain ().get(2));
476 assertTrue(listener.mHttpResponseDataLength != 0); 496 assertTrue(listener.mHttpResponseDataLength != 0);
477 assertEquals(2, listener.mRedirectCount); 497 assertEquals(2, listener.mRedirectCount);
478 assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED); 498 assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED);
499 assertEquals(337, mResponseInfo.getReceivedBytesCount());
479 } 500 }
480 501
481 @SmallTest 502 @SmallTest
482 @Feature({"Cronet"}) 503 @Feature({"Cronet"})
483 public void testMockNotFound() throws Exception { 504 public void testMockNotFound() throws Exception {
484 TestUrlRequestListener listener = 505 TestUrlRequestListener listener =
485 startAndWaitForComplete(NativeTestServer.getNotFoundURL()); 506 startAndWaitForComplete(NativeTestServer.getNotFoundURL());
486 assertEquals(404, listener.mResponseInfo.getHttpStatusCode()); 507 assertEquals(404, listener.mResponseInfo.getHttpStatusCode());
508 assertEquals(121, listener.mResponseInfo.getReceivedBytesCount());
487 assertTrue(listener.mHttpResponseDataLength != 0); 509 assertTrue(listener.mHttpResponseDataLength != 0);
488 assertEquals(0, listener.mRedirectCount); 510 assertEquals(0, listener.mRedirectCount);
489 assertFalse(listener.mOnErrorCalled); 511 assertFalse(listener.mOnErrorCalled);
490 assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED); 512 assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED);
491 } 513 }
492 514
493 @SmallTest 515 @SmallTest
494 @Feature({"Cronet"}) 516 @Feature({"Cronet"})
495 public void testMockStartAsyncError() throws Exception { 517 public void testMockStartAsyncError() throws Exception {
496 final int arbitraryNetError = -3; 518 final int arbitraryNetError = -3;
497 TestUrlRequestListener listener = 519 TestUrlRequestListener listener =
498 startAndWaitForComplete(MockUrlRequestJobFactory.getMockUrlWithF ailure( 520 startAndWaitForComplete(MockUrlRequestJobFactory.getMockUrlWithF ailure(
499 FailurePhase.START, arbitraryNetError)); 521 FailurePhase.START, arbitraryNetError));
500 assertNull(listener.mResponseInfo); 522 assertNull(listener.mResponseInfo);
501 assertNotNull(listener.mError); 523 assertNotNull(listener.mError);
502 assertEquals(arbitraryNetError, listener.mError.netError()); 524 assertEquals(arbitraryNetError, listener.mError.netError());
503 assertEquals(0, listener.mRedirectCount); 525 assertEquals(0, listener.mRedirectCount);
504 assertTrue(listener.mOnErrorCalled); 526 assertTrue(listener.mOnErrorCalled);
505 assertEquals(listener.mResponseStep, ResponseStep.NOTHING); 527 assertEquals(listener.mResponseStep, ResponseStep.NOTHING);
506 } 528 }
507 529
508 @SmallTest 530 @SmallTest
509 @Feature({"Cronet"}) 531 @Feature({"Cronet"})
510 public void testMockReadDataSyncError() throws Exception { 532 public void testMockReadDataSyncError() throws Exception {
511 final int arbitraryNetError = -4; 533 final int arbitraryNetError = -4;
512 TestUrlRequestListener listener = 534 TestUrlRequestListener listener =
513 startAndWaitForComplete(MockUrlRequestJobFactory.getMockUrlWithF ailure( 535 startAndWaitForComplete(MockUrlRequestJobFactory.getMockUrlWithF ailure(
514 FailurePhase.READ_SYNC, arbitraryNetError)); 536 FailurePhase.READ_SYNC, arbitraryNetError));
515 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); 537 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
538 assertEquals(0, listener.mResponseInfo.getReceivedBytesCount());
516 assertNotNull(listener.mError); 539 assertNotNull(listener.mError);
517 assertEquals(arbitraryNetError, listener.mError.netError()); 540 assertEquals(arbitraryNetError, listener.mError.netError());
518 assertEquals(0, listener.mRedirectCount); 541 assertEquals(0, listener.mRedirectCount);
519 assertTrue(listener.mOnErrorCalled); 542 assertTrue(listener.mOnErrorCalled);
520 assertEquals(listener.mResponseStep, ResponseStep.ON_RESPONSE_STARTED); 543 assertEquals(listener.mResponseStep, ResponseStep.ON_RESPONSE_STARTED);
521 } 544 }
522 545
523 @SmallTest 546 @SmallTest
524 @Feature({"Cronet"}) 547 @Feature({"Cronet"})
525 public void testMockReadDataAsyncError() throws Exception { 548 public void testMockReadDataAsyncError() throws Exception {
526 final int arbitraryNetError = -5; 549 final int arbitraryNetError = -5;
527 TestUrlRequestListener listener = 550 TestUrlRequestListener listener =
528 startAndWaitForComplete(MockUrlRequestJobFactory.getMockUrlWithF ailure( 551 startAndWaitForComplete(MockUrlRequestJobFactory.getMockUrlWithF ailure(
529 FailurePhase.READ_ASYNC, arbitraryNetError)); 552 FailurePhase.READ_ASYNC, arbitraryNetError));
530 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); 553 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
554 assertEquals(0, listener.mResponseInfo.getReceivedBytesCount());
531 assertNotNull(listener.mError); 555 assertNotNull(listener.mError);
532 assertEquals(arbitraryNetError, listener.mError.netError()); 556 assertEquals(arbitraryNetError, listener.mError.netError());
533 assertEquals(0, listener.mRedirectCount); 557 assertEquals(0, listener.mRedirectCount);
534 assertTrue(listener.mOnErrorCalled); 558 assertTrue(listener.mOnErrorCalled);
535 assertEquals(listener.mResponseStep, ResponseStep.ON_RESPONSE_STARTED); 559 assertEquals(listener.mResponseStep, ResponseStep.ON_RESPONSE_STARTED);
536 } 560 }
537 561
538 /** 562 /**
539 * Tests that an SSL cert error will be reported via {@link UrlRequest#onFai led}. 563 * Tests that an SSL cert error will be reported via {@link UrlRequest#onFai led}.
540 */ 564 */
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 int end) { 1561 int end) {
1538 // Use a duplicate to avoid modifying byteBuffer. 1562 // Use a duplicate to avoid modifying byteBuffer.
1539 ByteBuffer duplicate = byteBuffer.duplicate(); 1563 ByteBuffer duplicate = byteBuffer.duplicate();
1540 duplicate.position(start); 1564 duplicate.position(start);
1541 duplicate.limit(end); 1565 duplicate.limit(end);
1542 byte[] contents = new byte[duplicate.remaining()]; 1566 byte[] contents = new byte[duplicate.remaining()];
1543 duplicate.get(contents); 1567 duplicate.get(contents);
1544 return new String(contents); 1568 return new String(contents);
1545 } 1569 }
1546 } 1570 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698