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

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

Issue 2069303002: Add new Cronet exception class for QUIC errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switch to using NetError Created 4 years, 5 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.MoreAsserts; 8 import android.test.MoreAsserts;
9 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 import android.util.Log; 10 import android.util.Log;
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 assertEquals("A=B", callback.mResponseInfo.getAllHeaders().get("Set-Cook ie").get(0)); 1772 assertEquals("A=B", callback.mResponseInfo.getAllHeaders().get("Set-Cook ie").get(0));
1773 1773
1774 // Make a request that check that cookie header isn't sent. 1774 // Make a request that check that cookie header isn't sent.
1775 String headerName = "Cookie"; 1775 String headerName = "Cookie";
1776 String url2 = NativeTestServer.getEchoHeaderURL(headerName); 1776 String url2 = NativeTestServer.getEchoHeaderURL(headerName);
1777 TestUrlRequestCallback callback2 = startAndWaitForComplete(url2); 1777 TestUrlRequestCallback callback2 = startAndWaitForComplete(url2);
1778 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); 1778 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode());
1779 assertEquals("Header not found. :(", callback2.mResponseAsString); 1779 assertEquals("Header not found. :(", callback2.mResponseAsString);
1780 } 1780 }
1781 1781
1782 @SmallTest
1783 @Feature({"Cronet"})
1784 @OnlyRunNativeCronet
1785 public void testQuicErrorCode() throws Exception {
1786 TestUrlRequestCallback callback =
1787 startAndWaitForComplete(MockUrlRequestJobFactory.getMockUrlWithF ailure(
1788 FailurePhase.START, NetError.ERR_QUIC_PROTOCOL_ERROR));
1789 assertNull(callback.mResponseInfo);
1790 assertNotNull(callback.mError);
1791 assertEquals(
1792 NetError.ERR_QUIC_PROTOCOL_ERROR, callback.mError.getCronetInter nalErrorCode());
1793 QuicException quicException = (QuicException) callback.mError;
pauljensen 2016/06/30 17:35:12 might want to add before this line assertTrue(call
mgersh 2016/06/30 22:55:53 Done.
1794 // 1 is QUIC_INTERNAL_ERROR
1795 assertEquals(1, quicException.getQuicDetailedErrorCode());
1796 }
1797
1782 private void checkSpecificErrorCode(int netError, int errorCode, String name , 1798 private void checkSpecificErrorCode(int netError, int errorCode, String name ,
1783 boolean immediatelyRetryable) throws Exception { 1799 boolean immediatelyRetryable) throws Exception {
1784 TestUrlRequestCallback callback = startAndWaitForComplete( 1800 TestUrlRequestCallback callback = startAndWaitForComplete(
1785 MockUrlRequestJobFactory.getMockUrlWithFailure(FailurePhase.STAR T, netError)); 1801 MockUrlRequestJobFactory.getMockUrlWithFailure(FailurePhase.STAR T, netError));
1786 assertNull(callback.mResponseInfo); 1802 assertNull(callback.mResponseInfo);
1787 assertNotNull(callback.mError); 1803 assertNotNull(callback.mError);
1788 assertEquals(netError, callback.mError.getCronetInternalErrorCode()); 1804 assertEquals(netError, callback.mError.getCronetInternalErrorCode());
1789 assertEquals(errorCode, callback.mError.getErrorCode()); 1805 assertEquals(errorCode, callback.mError.getErrorCode());
1790 assertEquals( 1806 assertEquals(
1791 "Exception in CronetUrlRequest: net::ERR_" + name, callback.mErr or.getMessage()); 1807 "Exception in CronetUrlRequest: net::ERR_" + name, callback.mErr or.getMessage());
1792 assertEquals(0, callback.mRedirectCount); 1808 assertEquals(0, callback.mRedirectCount);
1793 assertTrue(callback.mOnErrorCalled); 1809 assertTrue(callback.mOnErrorCalled);
1794 assertEquals(callback.mResponseStep, ResponseStep.NOTHING); 1810 assertEquals(callback.mResponseStep, ResponseStep.NOTHING);
1795 } 1811 }
1796 1812
1797 // Returns the contents of byteBuffer, from its position() to its limit(), 1813 // Returns the contents of byteBuffer, from its position() to its limit(),
1798 // as a String. Does not modify byteBuffer's position(). 1814 // as a String. Does not modify byteBuffer's position().
1799 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int end) { 1815 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int end) {
1800 // Use a duplicate to avoid modifying byteBuffer. 1816 // Use a duplicate to avoid modifying byteBuffer.
1801 ByteBuffer duplicate = byteBuffer.duplicate(); 1817 ByteBuffer duplicate = byteBuffer.duplicate();
1802 duplicate.position(start); 1818 duplicate.position(start);
1803 duplicate.limit(end); 1819 duplicate.limit(end);
1804 byte[] contents = new byte[duplicate.remaining()]; 1820 byte[] contents = new byte[duplicate.remaining()];
1805 duplicate.get(contents); 1821 duplicate.get(contents);
1806 return new String(contents); 1822 return new String(contents);
1807 } 1823 }
1808 } 1824 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698