| 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.urlconnection; | 5 package org.chromium.net.urlconnection; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
| 8 | 8 |
| 9 import org.json.JSONObject; |
| 10 |
| 9 import org.chromium.base.test.util.Feature; | 11 import org.chromium.base.test.util.Feature; |
| 10 import org.chromium.net.CronetEngine; | |
| 11 import org.chromium.net.CronetTestBase; | 12 import org.chromium.net.CronetTestBase; |
| 12 import org.chromium.net.CronetTestFramework; | 13 import org.chromium.net.CronetTestFramework; |
| 13 import org.chromium.net.CronetTestUtil; | 14 import org.chromium.net.CronetTestUtil; |
| 15 import org.chromium.net.ExperimentalCronetEngine; |
| 14 import org.chromium.net.QuicTestServer; | 16 import org.chromium.net.QuicTestServer; |
| 15 import org.json.JSONObject; | |
| 16 | 17 |
| 17 import java.io.OutputStream; | 18 import java.io.OutputStream; |
| 18 import java.net.HttpURLConnection; | 19 import java.net.HttpURLConnection; |
| 19 import java.net.URL; | 20 import java.net.URL; |
| 20 import java.util.Arrays; | 21 import java.util.Arrays; |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * Tests HttpURLConnection upload using QUIC. | 24 * Tests HttpURLConnection upload using QUIC. |
| 24 */ | 25 */ |
| 25 @SuppressWarnings("deprecation") | 26 @SuppressWarnings("deprecation") |
| 26 public class QuicUploadTest extends CronetTestBase { | 27 public class QuicUploadTest extends CronetTestBase { |
| 27 private CronetTestFramework mTestFramework; | 28 private CronetTestFramework mTestFramework; |
| 28 | 29 |
| 29 @Override | 30 @Override |
| 30 protected void setUp() throws Exception { | 31 protected void setUp() throws Exception { |
| 31 super.setUp(); | 32 super.setUp(); |
| 32 // Load library first to create MockCertVerifier. | 33 // Load library first to create MockCertVerifier. |
| 33 System.loadLibrary("cronet_tests"); | 34 System.loadLibrary("cronet_tests"); |
| 34 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); | 35 ExperimentalCronetEngine.Builder builder = |
| 36 new ExperimentalCronetEngine.Builder(getContext()); |
| 35 | 37 |
| 36 QuicTestServer.startQuicTestServer(getContext()); | 38 QuicTestServer.startQuicTestServer(getContext()); |
| 37 | 39 |
| 38 builder.enableQuic(true); | 40 builder.enableQuic(true); |
| 39 JSONObject quicParams = | 41 JSONObject quicParams = |
| 40 new JSONObject().put("host_whitelist", QuicTestServer.getServerH
ost()); | 42 new JSONObject().put("host_whitelist", QuicTestServer.getServerH
ost()); |
| 41 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules
(); | 43 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules
(); |
| 42 JSONObject experimentalOptions = new JSONObject() | 44 JSONObject experimentalOptions = new JSONObject() |
| 43 .put("QUIC", quicParams) | 45 .put("QUIC", quicParams) |
| 44 .put("HostResolverRules", hostR
esolverParams); | 46 .put("HostResolverRules", hostR
esolverParams); |
| 45 builder.setExperimentalOptions(experimentalOptions.toString()); | 47 builder.setExperimentalOptions(experimentalOptions.toString()); |
| 46 | 48 |
| 47 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe
rverPort(), | 49 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe
rverPort(), |
| 48 QuicTestServer.getServerPort()); | 50 QuicTestServer.getServerPort()); |
| 49 | 51 |
| 50 builder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVerif
ier()); | 52 CronetTestUtil.setMockCertVerifierForTesting( |
| 53 builder, QuicTestServer.createMockCertVerifier()); |
| 51 | 54 |
| 52 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, builder); | 55 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, builder); |
| 53 } | 56 } |
| 54 | 57 |
| 55 @SmallTest | 58 @SmallTest |
| 56 @Feature({"Cronet"}) | 59 @Feature({"Cronet"}) |
| 57 @OnlyRunNativeCronet | 60 @OnlyRunNativeCronet |
| 58 // Regression testing for crbug.com/618872. | 61 // Regression testing for crbug.com/618872. |
| 59 public void testOneMassiveWrite() throws Exception { | 62 public void testOneMassiveWrite() throws Exception { |
| 60 String path = "/simple.txt"; | 63 String path = "/simple.txt"; |
| 61 URL url = new URL(QuicTestServer.getServerURL() + path); | 64 URL url = new URL(QuicTestServer.getServerURL() + path); |
| 62 HttpURLConnection connection = | 65 HttpURLConnection connection = |
| 63 (HttpURLConnection) mTestFramework.mCronetEngine.openConnection(
url); | 66 (HttpURLConnection) mTestFramework.mCronetEngine.openConnection(
url); |
| 64 connection.setDoOutput(true); | 67 connection.setDoOutput(true); |
| 65 connection.setRequestMethod("POST"); | 68 connection.setRequestMethod("POST"); |
| 66 // Size is chosen so the last time mBuffer will be written 14831 bytes, | 69 // Size is chosen so the last time mBuffer will be written 14831 bytes, |
| 67 // which is larger than the internal QUIC read buffer size of 14520. | 70 // which is larger than the internal QUIC read buffer size of 14520. |
| 68 byte[] largeData = new byte[195055]; | 71 byte[] largeData = new byte[195055]; |
| 69 Arrays.fill(largeData, "a".getBytes("UTF-8")[0]); | 72 Arrays.fill(largeData, "a".getBytes("UTF-8")[0]); |
| 70 connection.setFixedLengthStreamingMode(largeData.length); | 73 connection.setFixedLengthStreamingMode(largeData.length); |
| 71 OutputStream out = connection.getOutputStream(); | 74 OutputStream out = connection.getOutputStream(); |
| 72 // Write everything at one go, so the data is larger than the buffer | 75 // Write everything at one go, so the data is larger than the buffer |
| 73 // used in CronetFixedModeOutputStream. | 76 // used in CronetFixedModeOutputStream. |
| 74 out.write(largeData); | 77 out.write(largeData); |
| 75 assertEquals(200, connection.getResponseCode()); | 78 assertEquals(200, connection.getResponseCode()); |
| 76 connection.disconnect(); | 79 connection.disconnect(); |
| 77 } | 80 } |
| 78 } | 81 } |
| OLD | NEW |