OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
8 | 8 |
9 import org.chromium.base.test.util.Feature; | 9 import org.chromium.base.test.util.Feature; |
10 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; | |
11 import org.json.JSONObject; | 10 import org.json.JSONObject; |
12 | 11 |
13 import java.nio.ByteBuffer; | 12 import java.nio.ByteBuffer; |
14 | 13 |
15 /** | 14 /** |
16 * Tests functionality of BidirectionalStream's QUIC implementation. | 15 * Tests functionality of BidirectionalStream's QUIC implementation. |
17 */ | 16 */ |
18 public class BidirectionalStreamQuicTest extends CronetTestBase { | 17 public class BidirectionalStreamQuicTest extends CronetTestBase { |
19 private CronetTestFramework mTestFramework; | 18 private CronetTestFramework mTestFramework; |
20 private enum QuicBidirectionalStreams { | 19 private enum QuicBidirectionalStreams { |
21 ENABLED, | 20 ENABLED, |
22 DISABLED, | 21 DISABLED, |
23 } | 22 } |
24 | 23 |
25 private void setUp(QuicBidirectionalStreams enabled) throws Exception { | 24 private void setUp(QuicBidirectionalStreams enabled) throws Exception { |
26 // Load library first to create MockCertVerifier. | 25 // Load library first to create MockCertVerifier. |
27 System.loadLibrary("cronet_tests"); | 26 System.loadLibrary("cronet_tests"); |
28 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); | 27 ExperimentalCronetEngine.Builder builder = |
| 28 new ExperimentalCronetEngine.Builder(getContext()); |
29 | 29 |
30 QuicTestServer.startQuicTestServer(getContext()); | 30 QuicTestServer.startQuicTestServer(getContext()); |
31 | 31 |
32 builder.enableQuic(true); | 32 builder.enableQuic(true); |
33 JSONObject quicParams = new JSONObject().put("host_whitelist", "test.exa
mple.com"); | 33 JSONObject quicParams = new JSONObject().put("host_whitelist", "test.exa
mple.com"); |
34 if (enabled == QuicBidirectionalStreams.DISABLED) { | 34 if (enabled == QuicBidirectionalStreams.DISABLED) { |
35 quicParams.put("quic_disable_bidirectional_streams", true); | 35 quicParams.put("quic_disable_bidirectional_streams", true); |
36 } | 36 } |
37 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules
(); | 37 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules
(); |
38 JSONObject experimentalOptions = new JSONObject() | 38 JSONObject experimentalOptions = new JSONObject() |
39 .put("QUIC", quicParams) | 39 .put("QUIC", quicParams) |
40 .put("HostResolverRules", hostR
esolverParams); | 40 .put("HostResolverRules", hostR
esolverParams); |
41 builder.setExperimentalOptions(experimentalOptions.toString()); | 41 builder.setExperimentalOptions(experimentalOptions.toString()); |
42 | 42 |
43 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe
rverPort(), | 43 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe
rverPort(), |
44 QuicTestServer.getServerPort()); | 44 QuicTestServer.getServerPort()); |
45 | 45 |
46 builder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVerif
ier()); | 46 CronetTestUtil.setMockCertVerifierForTesting( |
| 47 builder, QuicTestServer.createMockCertVerifier()); |
47 | 48 |
48 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, builder); | 49 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, builder); |
49 } | 50 } |
50 | 51 |
51 @Override | 52 @Override |
52 protected void tearDown() throws Exception { | 53 protected void tearDown() throws Exception { |
53 QuicTestServer.shutdownQuicTestServer(); | 54 QuicTestServer.shutdownQuicTestServer(); |
54 super.tearDown(); | 55 super.tearDown(); |
55 } | 56 } |
56 | 57 |
57 @SmallTest | 58 @SmallTest |
58 @Feature({"Cronet"}) | 59 @Feature({"Cronet"}) |
59 @OnlyRunNativeCronet | 60 @OnlyRunNativeCronet |
60 // Test that QUIC is negotiated. | 61 // Test that QUIC is negotiated. |
61 public void testSimpleGet() throws Exception { | 62 public void testSimpleGet() throws Exception { |
62 setUp(QuicBidirectionalStreams.ENABLED); | 63 setUp(QuicBidirectionalStreams.ENABLED); |
63 String path = "/simple.txt"; | 64 String path = "/simple.txt"; |
64 String quicURL = QuicTestServer.getServerURL() + path; | 65 String quicURL = QuicTestServer.getServerURL() + path; |
65 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); | 66 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
66 BidirectionalStream stream = new BidirectionalStream | 67 BidirectionalStream stream = |
67 .Builder(quicURL, callback, callbac
k.getExecutor(), | 68 mTestFramework.mCronetEngine |
68 mTestFramework.mCronetEngin
e) | 69 .newBidirectionalStreamBuilder(quicURL, callback, callba
ck.getExecutor()) |
69 .setHttpMethod("GET") | 70 .setHttpMethod("GET") |
70 .build(); | 71 .build(); |
71 stream.start(); | 72 stream.start(); |
72 callback.blockForDone(); | 73 callback.blockForDone(); |
73 assertTrue(stream.isDone()); | 74 assertTrue(stream.isDone()); |
74 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 75 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
75 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); | 76 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); |
76 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); | 77 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
77 } | 78 } |
78 | 79 |
79 @SmallTest | 80 @SmallTest |
80 @Feature({"Cronet"}) | 81 @Feature({"Cronet"}) |
81 @OnlyRunNativeCronet | 82 @OnlyRunNativeCronet |
82 public void testSimplePost() throws Exception { | 83 public void testSimplePost() throws Exception { |
83 setUp(QuicBidirectionalStreams.ENABLED); | 84 setUp(QuicBidirectionalStreams.ENABLED); |
84 String path = "/simple.txt"; | 85 String path = "/simple.txt"; |
85 String quicURL = QuicTestServer.getServerURL() + path; | 86 String quicURL = QuicTestServer.getServerURL() + path; |
86 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); | 87 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
87 // Although we have no way to verify data sent at this point, this test | 88 // Although we have no way to verify data sent at this point, this test |
88 // can make sure that onWriteCompleted is invoked appropriately. | 89 // can make sure that onWriteCompleted is invoked appropriately. |
89 callback.addWriteData("Test String".getBytes()); | 90 callback.addWriteData("Test String".getBytes()); |
90 callback.addWriteData("1234567890".getBytes()); | 91 callback.addWriteData("1234567890".getBytes()); |
91 callback.addWriteData("woot!".getBytes()); | 92 callback.addWriteData("woot!".getBytes()); |
92 BidirectionalStream stream = new BidirectionalStream | 93 BidirectionalStream stream = |
93 .Builder(quicURL, callback, callbac
k.getExecutor(), | 94 mTestFramework.mCronetEngine |
94 mTestFramework.mCronetEngin
e) | 95 .newBidirectionalStreamBuilder(quicURL, callback, callba
ck.getExecutor()) |
95 .addHeader("foo", "bar") | 96 .addHeader("foo", "bar") |
96 .addHeader("empty", "") | 97 .addHeader("empty", "") |
97 .addHeader("Content-Type", "zebra") | 98 .addHeader("Content-Type", "zebra") |
98 .build(); | 99 .build(); |
99 stream.start(); | 100 stream.start(); |
100 callback.blockForDone(); | 101 callback.blockForDone(); |
101 assertTrue(stream.isDone()); | 102 assertTrue(stream.isDone()); |
102 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 103 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
103 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); | 104 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); |
104 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); | 105 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
105 } | 106 } |
106 | 107 |
107 @SmallTest | 108 @SmallTest |
108 @Feature({"Cronet"}) | 109 @Feature({"Cronet"}) |
109 @OnlyRunNativeCronet | 110 @OnlyRunNativeCronet |
110 public void testSimplePostWithFlush() throws Exception { | 111 public void testSimplePostWithFlush() throws Exception { |
111 setUp(QuicBidirectionalStreams.ENABLED); | 112 setUp(QuicBidirectionalStreams.ENABLED); |
112 // TODO(xunjieli): Use ParameterizedTest instead of the loop. | 113 // TODO(xunjieli): Use ParameterizedTest instead of the loop. |
113 for (int i = 0; i < 2; i++) { | 114 for (int i = 0; i < 2; i++) { |
114 String path = "/simple.txt"; | 115 String path = "/simple.txt"; |
115 String quicURL = QuicTestServer.getServerURL() + path; | 116 String quicURL = QuicTestServer.getServerURL() + path; |
116 TestBidirectionalStreamCallback callback = new TestBidirectionalStre
amCallback(); | 117 TestBidirectionalStreamCallback callback = new TestBidirectionalStre
amCallback(); |
117 // Although we have no way to verify data sent at this point, this t
est | 118 // Although we have no way to verify data sent at this point, this t
est |
118 // can make sure that onWriteCompleted is invoked appropriately. | 119 // can make sure that onWriteCompleted is invoked appropriately. |
119 callback.addWriteData("Test String".getBytes(), false); | 120 callback.addWriteData("Test String".getBytes(), false); |
120 callback.addWriteData("1234567890".getBytes(), false); | 121 callback.addWriteData("1234567890".getBytes(), false); |
121 callback.addWriteData("woot!".getBytes(), true); | 122 callback.addWriteData("woot!".getBytes(), true); |
122 BidirectionalStream stream = new BidirectionalStream | 123 BidirectionalStream stream = mTestFramework.mCronetEngine |
123 .Builder(quicURL, callback, cal
lback.getExecutor(), | 124 .newBidirectionalStreamBuilder( |
124 mTestFramework.mCronetE
ngine) | 125 quicURL, callback, call
back.getExecutor()) |
125 .delayRequestHeadersUntilFirstF
lush(i == 0) | 126 .delayRequestHeadersUntilFirstF
lush(i == 0) |
126 .addHeader("foo", "bar") | 127 .addHeader("foo", "bar") |
127 .addHeader("empty", "") | 128 .addHeader("empty", "") |
128 .addHeader("Content-Type", "zeb
ra") | 129 .addHeader("Content-Type", "zeb
ra") |
129 .build(); | 130 .build(); |
130 stream.start(); | 131 stream.start(); |
131 callback.blockForDone(); | 132 callback.blockForDone(); |
132 assertTrue(stream.isDone()); | 133 assertTrue(stream.isDone()); |
133 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 134 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
134 assertEquals( | 135 assertEquals( |
(...skipping 13 matching lines...) Expand all Loading... |
148 String quicURL = QuicTestServer.getServerURL() + path; | 149 String quicURL = QuicTestServer.getServerURL() + path; |
149 TestBidirectionalStreamCallback callback = new TestBidirectionalStre
amCallback(); | 150 TestBidirectionalStreamCallback callback = new TestBidirectionalStre
amCallback(); |
150 // Although we have no way to verify data sent at this point, this t
est | 151 // Although we have no way to verify data sent at this point, this t
est |
151 // can make sure that onWriteCompleted is invoked appropriately. | 152 // can make sure that onWriteCompleted is invoked appropriately. |
152 callback.addWriteData("Test String".getBytes(), false); | 153 callback.addWriteData("Test String".getBytes(), false); |
153 callback.addWriteData("1234567890".getBytes(), false); | 154 callback.addWriteData("1234567890".getBytes(), false); |
154 callback.addWriteData("woot!".getBytes(), true); | 155 callback.addWriteData("woot!".getBytes(), true); |
155 callback.addWriteData("Test String".getBytes(), false); | 156 callback.addWriteData("Test String".getBytes(), false); |
156 callback.addWriteData("1234567890".getBytes(), false); | 157 callback.addWriteData("1234567890".getBytes(), false); |
157 callback.addWriteData("woot!".getBytes(), true); | 158 callback.addWriteData("woot!".getBytes(), true); |
158 BidirectionalStream stream = new BidirectionalStream | 159 BidirectionalStream stream = mTestFramework.mCronetEngine |
159 .Builder(quicURL, callback, cal
lback.getExecutor(), | 160 .newBidirectionalStreamBuilder( |
160 mTestFramework.mCronetE
ngine) | 161 quicURL, callback, call
back.getExecutor()) |
161 .delayRequestHeadersUntilFirstF
lush(i == 0) | 162 .delayRequestHeadersUntilFirstF
lush(i == 0) |
162 .addHeader("foo", "bar") | 163 .addHeader("foo", "bar") |
163 .addHeader("empty", "") | 164 .addHeader("empty", "") |
164 .addHeader("Content-Type", "zeb
ra") | 165 .addHeader("Content-Type", "zeb
ra") |
165 .build(); | 166 .build(); |
166 stream.start(); | 167 stream.start(); |
167 callback.blockForDone(); | 168 callback.blockForDone(); |
168 assertTrue(stream.isDone()); | 169 assertTrue(stream.isDone()); |
169 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 170 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
170 assertEquals( | 171 assertEquals( |
(...skipping 13 matching lines...) Expand all Loading... |
184 String url = QuicTestServer.getServerURL() + path; | 185 String url = QuicTestServer.getServerURL() + path; |
185 | 186 |
186 TestBidirectionalStreamCallback callback = new TestBidirectionalStre
amCallback() { | 187 TestBidirectionalStreamCallback callback = new TestBidirectionalStre
amCallback() { |
187 @Override | 188 @Override |
188 public void onStreamReady(BidirectionalStream stream) { | 189 public void onStreamReady(BidirectionalStream stream) { |
189 // This flush should send the delayed headers. | 190 // This flush should send the delayed headers. |
190 stream.flush(); | 191 stream.flush(); |
191 super.onStreamReady(stream); | 192 super.onStreamReady(stream); |
192 } | 193 } |
193 }; | 194 }; |
194 BidirectionalStream stream = new BidirectionalStream | 195 BidirectionalStream stream = |
195 .Builder(url, callback, callbac
k.getExecutor(), | 196 mTestFramework.mCronetEngine |
196 mTestFramework.mCronetE
ngine) | 197 .newBidirectionalStreamBuilder(url, callback, callba
ck.getExecutor()) |
197 .setHttpMethod("GET") | 198 .setHttpMethod("GET") |
198 .delayRequestHeadersUntilFirstF
lush(i == 0) | 199 .delayRequestHeadersUntilFirstFlush(i == 0) |
199 .addHeader("foo", "bar") | 200 .addHeader("foo", "bar") |
200 .addHeader("empty", "") | 201 .addHeader("empty", "") |
201 .build(); | 202 .build(); |
202 // Flush before stream is started should not crash. | 203 // Flush before stream is started should not crash. |
203 stream.flush(); | 204 stream.flush(); |
204 | 205 |
205 stream.start(); | 206 stream.start(); |
206 callback.blockForDone(); | 207 callback.blockForDone(); |
207 assertTrue(stream.isDone()); | 208 assertTrue(stream.isDone()); |
208 | 209 |
209 // Flush after stream is completed is no-op. It shouldn't call into
the destroyed | 210 // Flush after stream is completed is no-op. It shouldn't call into
the destroyed |
210 // adapter. | 211 // adapter. |
211 stream.flush(); | 212 stream.flush(); |
(...skipping 10 matching lines...) Expand all Loading... |
222 @OnlyRunNativeCronet | 223 @OnlyRunNativeCronet |
223 public void testSimplePostWithFlushAfterOneWrite() throws Exception { | 224 public void testSimplePostWithFlushAfterOneWrite() throws Exception { |
224 setUp(QuicBidirectionalStreams.ENABLED); | 225 setUp(QuicBidirectionalStreams.ENABLED); |
225 // TODO(xunjieli): Use ParameterizedTest instead of the loop. | 226 // TODO(xunjieli): Use ParameterizedTest instead of the loop. |
226 for (int i = 0; i < 2; i++) { | 227 for (int i = 0; i < 2; i++) { |
227 String path = "/simple.txt"; | 228 String path = "/simple.txt"; |
228 String url = QuicTestServer.getServerURL() + path; | 229 String url = QuicTestServer.getServerURL() + path; |
229 | 230 |
230 TestBidirectionalStreamCallback callback = new TestBidirectionalStre
amCallback(); | 231 TestBidirectionalStreamCallback callback = new TestBidirectionalStre
amCallback(); |
231 callback.addWriteData("Test String".getBytes(), true); | 232 callback.addWriteData("Test String".getBytes(), true); |
232 BidirectionalStream stream = new BidirectionalStream | 233 BidirectionalStream stream = |
233 .Builder(url, callback, callbac
k.getExecutor(), | 234 mTestFramework.mCronetEngine |
234 mTestFramework.mCronetE
ngine) | 235 .newBidirectionalStreamBuilder(url, callback, callba
ck.getExecutor()) |
235 .delayRequestHeadersUntilFirstF
lush(i == 0) | 236 .delayRequestHeadersUntilFirstFlush(i == 0) |
236 .addHeader("foo", "bar") | 237 .addHeader("foo", "bar") |
237 .addHeader("empty", "") | 238 .addHeader("empty", "") |
238 .addHeader("Content-Type", "zeb
ra") | 239 .addHeader("Content-Type", "zebra") |
239 .build(); | 240 .build(); |
240 stream.start(); | 241 stream.start(); |
241 callback.blockForDone(); | 242 callback.blockForDone(); |
242 assertTrue(stream.isDone()); | 243 assertTrue(stream.isDone()); |
243 | 244 |
244 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 245 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
245 assertEquals( | 246 assertEquals( |
246 "This is a simple text file served by QUIC.\n", callback.mRe
sponseAsString); | 247 "This is a simple text file served by QUIC.\n", callback.mRe
sponseAsString); |
247 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedPr
otocol()); | 248 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedPr
otocol()); |
248 } | 249 } |
249 } | 250 } |
250 | 251 |
251 @SmallTest | 252 @SmallTest |
252 @Feature({"Cronet"}) | 253 @Feature({"Cronet"}) |
253 @OnlyRunNativeCronet | 254 @OnlyRunNativeCronet |
254 public void testQuicBidirectionalStreamDisabled() throws Exception { | 255 public void testQuicBidirectionalStreamDisabled() throws Exception { |
255 setUp(QuicBidirectionalStreams.DISABLED); | 256 setUp(QuicBidirectionalStreams.DISABLED); |
256 String path = "/simple.txt"; | 257 String path = "/simple.txt"; |
257 String quicURL = QuicTestServer.getServerURL() + path; | 258 String quicURL = QuicTestServer.getServerURL() + path; |
258 | 259 |
259 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); | 260 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
260 BidirectionalStream stream = new BidirectionalStream | 261 BidirectionalStream stream = |
261 .Builder(quicURL, callback, callbac
k.getExecutor(), | 262 mTestFramework.mCronetEngine |
262 mTestFramework.mCronetEngin
e) | 263 .newBidirectionalStreamBuilder(quicURL, callback, callba
ck.getExecutor()) |
263 .setHttpMethod("GET") | 264 .setHttpMethod("GET") |
264 .build(); | 265 .build(); |
265 stream.start(); | 266 stream.start(); |
266 callback.blockForDone(); | 267 callback.blockForDone(); |
267 assertTrue(stream.isDone()); | 268 assertTrue(stream.isDone()); |
268 assertTrue(callback.mOnErrorCalled); | 269 assertTrue(callback.mOnErrorCalled); |
269 assertNull(callback.mResponseInfo); | 270 assertNull(callback.mResponseInfo); |
270 } | 271 } |
271 | 272 |
272 @SmallTest | 273 @SmallTest |
273 @Feature({"Cronet"}) | 274 @Feature({"Cronet"}) |
274 @OnlyRunNativeCronet | 275 @OnlyRunNativeCronet |
(...skipping 15 matching lines...) Expand all Loading... |
290 // Shut down the server, and the stream should error out. | 291 // Shut down the server, and the stream should error out. |
291 // The second call to shutdownQuicTestServer is no-op. | 292 // The second call to shutdownQuicTestServer is no-op. |
292 QuicTestServer.shutdownQuicTestServer(); | 293 QuicTestServer.shutdownQuicTestServer(); |
293 } | 294 } |
294 }; | 295 }; |
295 | 296 |
296 callback.addWriteData("Test String".getBytes()); | 297 callback.addWriteData("Test String".getBytes()); |
297 callback.addWriteData("1234567890".getBytes()); | 298 callback.addWriteData("1234567890".getBytes()); |
298 callback.addWriteData("woot!".getBytes()); | 299 callback.addWriteData("woot!".getBytes()); |
299 | 300 |
300 BidirectionalStream stream = new BidirectionalStream | 301 BidirectionalStream stream = |
301 .Builder(quicURL, callback, callbac
k.getExecutor(), | 302 mTestFramework.mCronetEngine |
302 mTestFramework.mCronetEngin
e) | 303 .newBidirectionalStreamBuilder(quicURL, callback, callba
ck.getExecutor()) |
303 .addHeader("foo", "bar") | 304 .addHeader("foo", "bar") |
304 .addHeader("empty", "") | 305 .addHeader("empty", "") |
305 .addHeader("Content-Type", "zebra") | 306 .addHeader("Content-Type", "zebra") |
306 .build(); | 307 .build(); |
307 stream.start(); | 308 stream.start(); |
308 callback.blockForDone(); | 309 callback.blockForDone(); |
309 assertTrue(stream.isDone()); | 310 assertTrue(stream.isDone()); |
310 // Server terminated on us, so the stream must fail. | 311 // Server terminated on us, so the stream must fail. |
311 // QUIC reports this as ERR_QUIC_PROTOCOL_ERROR. Sometimes we get ERR_CO
NNECTION_REFUSED. | 312 // QUIC reports this as ERR_QUIC_PROTOCOL_ERROR. Sometimes we get ERR_CO
NNECTION_REFUSED. |
312 assertNotNull(callback.mError); | 313 assertNotNull(callback.mError); |
313 assertTrue(NetError.ERR_QUIC_PROTOCOL_ERROR == callback.mError.getCronet
InternalErrorCode() | 314 assertTrue(NetError.ERR_QUIC_PROTOCOL_ERROR == callback.mError.getCronet
InternalErrorCode() |
314 || NetError.ERR_CONNECTION_REFUSED == callback.mError.getCronetI
nternalErrorCode()); | 315 || NetError.ERR_CONNECTION_REFUSED == callback.mError.getCronetI
nternalErrorCode()); |
315 } | 316 } |
316 | 317 |
317 @SmallTest | 318 @SmallTest |
318 @Feature({"Cronet"}) | 319 @Feature({"Cronet"}) |
319 @OnlyRunNativeCronet | 320 @OnlyRunNativeCronet |
320 // Test that certificate verify results are serialized and deserialized corr
ectly. | 321 // Test that certificate verify results are serialized and deserialized corr
ectly. |
321 public void testSerializeDeserialize() throws Exception { | 322 public void testSerializeDeserialize() throws Exception { |
322 setUp(QuicBidirectionalStreams.ENABLED); | 323 setUp(QuicBidirectionalStreams.ENABLED); |
323 String path = "/simple.txt"; | 324 String path = "/simple.txt"; |
324 String quicURL = QuicTestServer.getServerURL() + path; | 325 String quicURL = QuicTestServer.getServerURL() + path; |
325 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); | 326 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
326 BidirectionalStream stream = new BidirectionalStream | 327 BidirectionalStream stream = |
327 .Builder(quicURL, callback, callbac
k.getExecutor(), | 328 mTestFramework.mCronetEngine |
328 mTestFramework.mCronetEngin
e) | 329 .newBidirectionalStreamBuilder(quicURL, callback, callba
ck.getExecutor()) |
329 .setHttpMethod("GET") | 330 .setHttpMethod("GET") |
330 .build(); | 331 .build(); |
331 stream.start(); | 332 stream.start(); |
332 callback.blockForDone(); | 333 callback.blockForDone(); |
333 assertTrue(stream.isDone()); | 334 assertTrue(stream.isDone()); |
334 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 335 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
335 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); | 336 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); |
336 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); | 337 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
337 | 338 |
338 String serialized_data = mTestFramework.mCronetEngine.getCertVerifierDat
a(100); | 339 String serialized_data = mTestFramework.mCronetEngine.getCertVerifierDat
a(100); |
339 assertFalse(serialized_data.isEmpty()); | 340 assertFalse(serialized_data.isEmpty()); |
340 | 341 |
341 // Create a new builder and verify that the |serialized_data| is deseria
lized correctly. | 342 // Create a new builder and verify that the |serialized_data| is deseria
lized correctly. |
342 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); | 343 ExperimentalCronetEngine.Builder builder = |
| 344 new ExperimentalCronetEngine.Builder(getContext()); |
343 builder.enableQuic(true); | 345 builder.enableQuic(true); |
344 builder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVerif
ier()); | 346 CronetTestUtil.setMockCertVerifierForTesting( |
| 347 builder, QuicTestServer.createMockCertVerifier()); |
345 builder.setCertVerifierData(serialized_data); | 348 builder.setCertVerifierData(serialized_data); |
346 | 349 |
347 CronetTestFramework testFramework = | 350 CronetTestFramework testFramework = |
348 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, buil
der); | 351 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, buil
der); |
349 String deserialized_data = testFramework.mCronetEngine.getCertVerifierDa
ta(100); | 352 String deserialized_data = testFramework.mCronetEngine.getCertVerifierDa
ta(100); |
350 assertEquals(deserialized_data, serialized_data); | 353 assertEquals(deserialized_data, serialized_data); |
351 } | 354 } |
352 } | 355 } |
OLD | NEW |