| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 static org.chromium.base.CollectionUtil.newHashSet; | 7 import static org.chromium.base.CollectionUtil.newHashSet; |
| 8 | 8 |
| 9 import android.os.ConditionVariable; | 9 import android.os.ConditionVariable; |
| 10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 UrlResponseInfo urlResponseInfo = new UrlResponseInfo( | 87 UrlResponseInfo urlResponseInfo = new UrlResponseInfo( |
| 88 Arrays.asList(urls), statusCode, message, headersList, false, "h
2", null); | 88 Arrays.asList(urls), statusCode, message, headersList, false, "h
2", null); |
| 89 urlResponseInfo.setReceivedBytesCount(receivedBytes); | 89 urlResponseInfo.setReceivedBytesCount(receivedBytes); |
| 90 return urlResponseInfo; | 90 return urlResponseInfo; |
| 91 } | 91 } |
| 92 | 92 |
| 93 private void runSimpleGetWithExpectedReceivedBytesCount(int expectedReceived
Bytes) | 93 private void runSimpleGetWithExpectedReceivedBytesCount(int expectedReceived
Bytes) |
| 94 throws Exception { | 94 throws Exception { |
| 95 String url = Http2TestServer.getEchoMethodUrl(); | 95 String url = Http2TestServer.getEchoMethodUrl(); |
| 96 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); | 96 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
| 97 TestRequestFinishedListener requestFinishedListener = new TestRequestFin
ishedListener(); |
| 98 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL
istener); |
| 97 // Create stream. | 99 // Create stream. |
| 98 BidirectionalStream stream = | 100 BidirectionalStream stream = |
| 99 mTestFramework.mCronetEngine | 101 mTestFramework.mCronetEngine |
| 100 .newBidirectionalStreamBuilder(url, callback, callback.g
etExecutor()) | 102 .newBidirectionalStreamBuilder(url, callback, callback.g
etExecutor()) |
| 101 .setHttpMethod("GET") | 103 .setHttpMethod("GET") |
| 102 .build(); | 104 .build(); |
| 103 stream.start(); | 105 stream.start(); |
| 104 callback.blockForDone(); | 106 callback.blockForDone(); |
| 105 assertTrue(stream.isDone()); | 107 assertTrue(stream.isDone()); |
| 108 requestFinishedListener.blockUntilDone(); |
| 106 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 109 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 107 // Default method is 'GET'. | 110 // Default method is 'GET'. |
| 108 assertEquals("GET", callback.mResponseAsString); | 111 assertEquals("GET", callback.mResponseAsString); |
| 109 UrlResponseInfo urlResponseInfo = createUrlResponseInfo( | 112 UrlResponseInfo urlResponseInfo = createUrlResponseInfo( |
| 110 new String[] {url}, "", 200, expectedReceivedBytes, ":status", "
200"); | 113 new String[] {url}, "", 200, expectedReceivedBytes, ":status", "
200"); |
| 111 assertResponseEquals(urlResponseInfo, callback.mResponseInfo); | 114 assertResponseEquals(urlResponseInfo, callback.mResponseInfo); |
| 112 checkResponseInfo(callback.mResponseInfo, Http2TestServer.getEchoMethodU
rl(), 200, ""); | 115 checkResponseInfo(callback.mResponseInfo, Http2TestServer.getEchoMethodU
rl(), 200, ""); |
| 116 RequestFinishedInfo finishedInfo = requestFinishedListener.getRequestInf
o(); |
| 117 assertTrue(finishedInfo.getAnnotations().isEmpty()); |
| 113 } | 118 } |
| 114 | 119 |
| 115 @SmallTest | 120 @SmallTest |
| 116 @Feature({"Cronet"}) | 121 @Feature({"Cronet"}) |
| 117 public void testBuilderCheck() throws Exception { | 122 public void testBuilderCheck() throws Exception { |
| 118 if (testingJavaImpl()) { | 123 if (testingJavaImpl()) { |
| 119 testBuilderCheckJavaImpl(); | 124 testBuilderCheckJavaImpl(); |
| 120 } else { | 125 } else { |
| 121 testBuilderCheckNativeImpl(); | 126 testBuilderCheckNativeImpl(); |
| 122 } | 127 } |
| (...skipping 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 private static String bufferContentsToString(ByteBuffer byteBuffer, int star
t, int end) { | 1449 private static String bufferContentsToString(ByteBuffer byteBuffer, int star
t, int end) { |
| 1445 // Use a duplicate to avoid modifying byteBuffer. | 1450 // Use a duplicate to avoid modifying byteBuffer. |
| 1446 ByteBuffer duplicate = byteBuffer.duplicate(); | 1451 ByteBuffer duplicate = byteBuffer.duplicate(); |
| 1447 duplicate.position(start); | 1452 duplicate.position(start); |
| 1448 duplicate.limit(end); | 1453 duplicate.limit(end); |
| 1449 byte[] contents = new byte[duplicate.remaining()]; | 1454 byte[] contents = new byte[duplicate.remaining()]; |
| 1450 duplicate.get(contents); | 1455 duplicate.get(contents); |
| 1451 return new String(contents); | 1456 return new String(contents); |
| 1452 } | 1457 } |
| 1453 } | 1458 } |
| OLD | NEW |