Chromium Code Reviews| 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; | |
|
pauljensen
2016/06/13 12:22:13
I think this should be moved to the urlconnection
xunjieli
2016/06/13 14:23:23
Done.
| |
| 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"); | |
|
pauljensen
2016/06/13 12:22:13
use QuicTestServer.getServerHost()
xunjieli
2016/06/13 14:23:23
Done.
| |
| 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 } | |
|
pauljensen
2016/06/13 12:22:13
use Arrays.fill(largeData, 97)
xunjieli
2016/06/13 14:23:23
Done.
| |
| 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 |