OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.net; | |
6 | |
7 import android.test.suitebuilder.annotation.SmallTest; | |
8 | |
9 import org.chromium.base.test.util.Feature; | |
10 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; | |
11 import org.json.JSONObject; | |
12 | |
13 /** | |
14 * Tests functionality of BidirectionalStream's QUIC implementation. | |
15 */ | |
16 public class BidirectionalStreamQuicTest extends CronetTestBase { | |
17 private CronetTestFramework mTestFramework; | |
18 private enum QuicBidirectionalStreams { | |
19 ENABLED, | |
20 DISABLED, | |
21 } | |
22 | |
23 private void setUp(QuicBidirectionalStreams enabled) throws Exception { | |
24 // Load library first to create MockCertVerifier. | |
25 System.loadLibrary("cronet_tests"); | |
26 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); | |
27 | |
28 QuicTestServer.startQuicTestServer(getContext()); | |
29 | |
30 builder.enableQUIC(true); | |
31 JSONObject quicParams = new JSONObject().put("host_whitelist", "test.exa mple.com"); | |
32 if (enabled == QuicBidirectionalStreams.DISABLED) { | |
mef
2016/03/28 20:17:33
nits: The expression 'enabled == xyz.DISABLED' see
xunjieli
2016/03/28 20:25:51
I can s/enabled/type if that makes it less weird?
mef
2016/03/29 20:33:35
Acknowledged.
| |
33 quicParams.put("quic_disable_bidirectional_streams", true); | |
34 } | |
35 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams ); | |
36 builder.setExperimentalOptions(experimentalOptions.toString()); | |
37 | |
38 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe rverPort(), | |
39 QuicTestServer.getServerPort()); | |
40 | |
41 builder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVerif ier()); | |
42 | |
43 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder); | |
44 registerHostResolver(mTestFramework); | |
45 } | |
46 | |
47 @Override | |
48 protected void tearDown() throws Exception { | |
49 QuicTestServer.shutdownQuicTestServer(); | |
50 super.tearDown(); | |
51 } | |
52 | |
53 @SmallTest | |
54 @Feature({"Cronet"}) | |
55 @OnlyRunNativeCronet | |
56 // Test that QUIC is negotiated. | |
57 public void testSimpleGet() throws Exception { | |
58 setUp(QuicBidirectionalStreams.ENABLED); | |
59 String path = "/simple.txt"; | |
60 String quicURL = QuicTestServer.getServerURL() + path; | |
61 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa llback(); | |
62 BidirectionalStream stream = new BidirectionalStream | |
63 .Builder(quicURL, callback, callbac k.getExecutor(), | |
64 mTestFramework.mCronetEngin e) | |
65 .setHttpMethod("GET") | |
66 .build(); | |
67 stream.start(); | |
68 callback.blockForDone(); | |
69 assertTrue(stream.isDone()); | |
70 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | |
71 assertEquals("This is a simple text file served by QUIC.\n", callback.mR esponseAsString); | |
72 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc ol()); | |
73 } | |
74 | |
75 @SmallTest | |
76 @Feature({"Cronet"}) | |
77 @OnlyRunNativeCronet | |
78 public void testQuicBidirectionalStreamDisabled() throws Exception { | |
79 setUp(QuicBidirectionalStreams.DISABLED); | |
80 String path = "/simple.txt"; | |
81 String quicURL = QuicTestServer.getServerURL() + path; | |
82 | |
83 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa llback(); | |
84 BidirectionalStream stream = new BidirectionalStream | |
85 .Builder(quicURL, callback, callbac k.getExecutor(), | |
86 mTestFramework.mCronetEngin e) | |
87 .setHttpMethod("GET") | |
88 .build(); | |
89 stream.start(); | |
90 callback.blockForDone(); | |
91 assertTrue(stream.isDone()); | |
92 assertTrue(callback.mOnErrorCalled); | |
93 assertNull(callback.mResponseInfo); | |
94 } | |
95 } | |
OLD | NEW |