OLD | NEW |
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; | 9 import android.util.Pair; |
10 | 10 |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 FailurePhase.READ_ASYNC, arbitraryNetError)); | 505 FailurePhase.READ_ASYNC, arbitraryNetError)); |
506 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); | 506 assertEquals(200, listener.mResponseInfo.getHttpStatusCode()); |
507 assertNotNull(listener.mError); | 507 assertNotNull(listener.mError); |
508 assertEquals(arbitraryNetError, listener.mError.netError()); | 508 assertEquals(arbitraryNetError, listener.mError.netError()); |
509 assertEquals(0, listener.mRedirectCount); | 509 assertEquals(0, listener.mRedirectCount); |
510 assertTrue(listener.mOnErrorCalled); | 510 assertTrue(listener.mOnErrorCalled); |
511 assertEquals(listener.mResponseStep, ResponseStep.ON_RESPONSE_STARTED); | 511 assertEquals(listener.mResponseStep, ResponseStep.ON_RESPONSE_STARTED); |
512 } | 512 } |
513 | 513 |
514 /** | 514 /** |
| 515 * Tests that an SSL cert error will be reported via {@link UrlRequest#onFai
led}. |
| 516 */ |
| 517 @SmallTest |
| 518 @Feature({"Cronet"}) |
| 519 public void testMockSSLCertificateError() throws Exception { |
| 520 TestUrlRequestListener listener = startAndWaitForComplete( |
| 521 MockUrlRequestJobFactory.getMockUrlForSSLCertificateError()); |
| 522 assertNull(listener.mResponseInfo); |
| 523 assertNotNull(listener.mError); |
| 524 assertTrue(listener.mOnErrorCalled); |
| 525 assertEquals(-201, listener.mError.netError()); |
| 526 assertEquals("Exception in CronetUrlRequest: net::ERR_CERT_DATE_INVALID"
, |
| 527 listener.mError.getMessage()); |
| 528 assertEquals(listener.mResponseStep, ResponseStep.NOTHING); |
| 529 } |
| 530 |
| 531 /** |
515 * Checks that the buffer is updated correctly, when starting at an offset. | 532 * Checks that the buffer is updated correctly, when starting at an offset. |
516 */ | 533 */ |
517 @SmallTest | 534 @SmallTest |
518 @Feature({"Cronet"}) | 535 @Feature({"Cronet"}) |
519 public void testSimpleGetBufferUpdates() throws Exception { | 536 public void testSimpleGetBufferUpdates() throws Exception { |
520 TestUrlRequestListener listener = new TestUrlRequestListener(); | 537 TestUrlRequestListener listener = new TestUrlRequestListener(); |
521 listener.setAutoAdvance(false); | 538 listener.setAutoAdvance(false); |
522 // Since the default method is "GET", the expected response body is also | 539 // Since the default method is "GET", the expected response body is also |
523 // "GET". | 540 // "GET". |
524 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( | 541 UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest( |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1395 int end) { | 1412 int end) { |
1396 // Use a duplicate to avoid modifying byteBuffer. | 1413 // Use a duplicate to avoid modifying byteBuffer. |
1397 ByteBuffer duplicate = byteBuffer.duplicate(); | 1414 ByteBuffer duplicate = byteBuffer.duplicate(); |
1398 duplicate.position(start); | 1415 duplicate.position(start); |
1399 duplicate.limit(end); | 1416 duplicate.limit(end); |
1400 byte[] contents = new byte[duplicate.remaining()]; | 1417 byte[] contents = new byte[duplicate.remaining()]; |
1401 duplicate.get(contents); | 1418 duplicate.get(contents); |
1402 return new String(contents); | 1419 return new String(contents); |
1403 } | 1420 } |
1404 } | 1421 } |
OLD | NEW |