| 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.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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 for (int i = 0; i < headers.length; i += 2) { | 142 for (int i = 0; i < headers.length; i += 2) { |
| 143 headersList.add(new AbstractMap.SimpleImmutableEntry<String, String>
( | 143 headersList.add(new AbstractMap.SimpleImmutableEntry<String, String>
( |
| 144 headers[i], headers[i + 1])); | 144 headers[i], headers[i + 1])); |
| 145 } | 145 } |
| 146 UrlResponseInfo unknown = new UrlResponseInfo( | 146 UrlResponseInfo unknown = new UrlResponseInfo( |
| 147 Arrays.asList(urls), statusCode, message, headersList, false, "u
nknown", ":0"); | 147 Arrays.asList(urls), statusCode, message, headersList, false, "u
nknown", ":0"); |
| 148 unknown.setReceivedBytesCount(receivedBytes); | 148 unknown.setReceivedBytesCount(receivedBytes); |
| 149 return unknown; | 149 return unknown; |
| 150 } | 150 } |
| 151 | 151 |
| 152 void assertResponseEquals(UrlResponseInfo expected, UrlResponseInfo actual)
{ | |
| 153 assertEquals(expected.getAllHeaders(), actual.getAllHeaders()); | |
| 154 assertEquals(expected.getAllHeadersAsList(), actual.getAllHeadersAsList(
)); | |
| 155 assertEquals(expected.getHttpStatusCode(), actual.getHttpStatusCode()); | |
| 156 assertEquals(expected.getHttpStatusText(), actual.getHttpStatusText()); | |
| 157 assertEquals(expected.getUrlChain(), actual.getUrlChain()); | |
| 158 assertEquals(expected.getUrl(), actual.getUrl()); | |
| 159 // Transferred bytes and proxy server are not supported in pure java | |
| 160 if (!(mTestFramework.mCronetEngine instanceof JavaCronetEngine)) { | |
| 161 assertEquals(expected.getReceivedBytesCount(), actual.getReceivedByt
esCount()); | |
| 162 assertEquals(expected.getProxyServer(), actual.getProxyServer()); | |
| 163 // This is a place where behavior intentionally differs between nati
ve and java | |
| 164 assertEquals(expected.getNegotiatedProtocol(), actual.getNegotiatedP
rotocol()); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 /** | 152 /** |
| 169 * Tests a redirect by running it step-by-step. Also tests that delaying a | 153 * Tests a redirect by running it step-by-step. Also tests that delaying a |
| 170 * request works as expected. To make sure there are no unexpected pending | 154 * request works as expected. To make sure there are no unexpected pending |
| 171 * messages, does a GET between UrlRequest.Callback callbacks. | 155 * messages, does a GET between UrlRequest.Callback callbacks. |
| 172 */ | 156 */ |
| 173 @SmallTest | 157 @SmallTest |
| 174 @Feature({"Cronet"}) | 158 @Feature({"Cronet"}) |
| 175 public void testRedirectAsync() throws Exception { | 159 public void testRedirectAsync() throws Exception { |
| 176 // Start the request and wait to see the redirect. | 160 // Start the request and wait to see the redirect. |
| 177 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 161 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| (...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { | 1598 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { |
| 1615 // Use a duplicate to avoid modifying byteBuffer. | 1599 // Use a duplicate to avoid modifying byteBuffer. |
| 1616 ByteBuffer duplicate = byteBuffer.duplicate(); | 1600 ByteBuffer duplicate = byteBuffer.duplicate(); |
| 1617 duplicate.position(start); | 1601 duplicate.position(start); |
| 1618 duplicate.limit(end); | 1602 duplicate.limit(end); |
| 1619 byte[] contents = new byte[duplicate.remaining()]; | 1603 byte[] contents = new byte[duplicate.remaining()]; |
| 1620 duplicate.get(contents); | 1604 duplicate.get(contents); |
| 1621 return new String(contents); | 1605 return new String(contents); |
| 1622 } | 1606 } |
| 1623 } | 1607 } |
| OLD | NEW |