| 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.json.JSONObject; |
| 11 |
| 12 import java.io.OutputStream; |
| 13 import java.net.HttpURLConnection; |
| 14 import java.net.URL; |
| 15 |
| 16 /** |
| 17 * Tests HttpURLConnection upload using QUIC. |
| 18 */ |
| 19 @SuppressWarnings("deprecation") |
| 20 public class QuicUploadTest extends CronetTestBase { |
| 21 private CronetTestFramework mTestFramework; |
| 22 |
| 23 @Override |
| 24 protected void setUp() throws Exception { |
| 25 super.setUp(); |
| 26 // Load library first to create MockCertVerifier. |
| 27 System.loadLibrary("cronet_tests"); |
| 28 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); |
| 29 |
| 30 QuicTestServer.startQuicTestServer(getContext()); |
| 31 |
| 32 builder.enableQUIC(true); |
| 33 JSONObject quicParams = new JSONObject().put("host_whitelist", "test.exa
mple.com"); |
| 34 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams
); |
| 35 builder.setExperimentalOptions(experimentalOptions.toString()); |
| 36 |
| 37 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe
rverPort(), |
| 38 QuicTestServer.getServerPort()); |
| 39 |
| 40 builder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVerif
ier()); |
| 41 |
| 42 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, builder); |
| 43 registerHostResolver(mTestFramework); |
| 44 } |
| 45 |
| 46 @SmallTest |
| 47 @Feature({"Cronet"}) |
| 48 @OnlyRunNativeCronet |
| 49 // Regression testing for crbug.com/618872. |
| 50 public void testOneMassiveWrite() throws Exception { |
| 51 String path = "/simple.txt"; |
| 52 URL url = new URL(QuicTestServer.getServerURL() + path); |
| 53 HttpURLConnection connection = |
| 54 (HttpURLConnection) mTestFramework.mCronetEngine.openConnection(
url); |
| 55 connection.setDoOutput(true); |
| 56 connection.setRequestMethod("POST"); |
| 57 byte[] largeData = new byte[195055]; |
| 58 for (int i = 0; i < largeData.length; i++) { |
| 59 largeData[i] = 97; |
| 60 } |
| 61 connection.setFixedLengthStreamingMode(largeData.length); |
| 62 OutputStream out = connection.getOutputStream(); |
| 63 // Write everything at one go, so the data is larger than the buffer |
| 64 // used in CronetFixedModeOutputStream. |
| 65 out.write(largeData); |
| 66 assertEquals(200, connection.getResponseCode()); |
| 67 connection.disconnect(); |
| 68 } |
| 69 } |
| OLD | NEW |