| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 10 |
| 11 import java.io.ByteArrayInputStream; | 11 import java.io.ByteArrayInputStream; |
| 12 import java.io.IOException; | 12 import java.io.IOException; |
| 13 import java.io.InputStream; | 13 import java.io.InputStream; |
| 14 import java.nio.ByteBuffer; | 14 import java.nio.ByteBuffer; |
| 15 import java.nio.channels.Channels; | 15 import java.nio.channels.Channels; |
| 16 import java.nio.channels.ReadableByteChannel; | 16 import java.nio.channels.ReadableByteChannel; |
| 17 import java.util.HashMap; | 17 import java.util.HashMap; |
| 18 import java.util.concurrent.Executors; | 18 import java.util.concurrent.Executors; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Test fixture to test upload APIs. Uses an in-process test server. | 21 * Test fixture to test upload APIs. Uses an in-process test server. |
| 22 */ | 22 */ |
| 23 public class UploadTest extends CronetTestBase { | 23 public class UploadTest extends CronetTestBase { |
| 24 private static final String UPLOAD_DATA = "Nifty upload data!"; | 24 private static final String UPLOAD_DATA = "Nifty upload data!"; |
| 25 private static final String UPLOAD_CHANNEL_DATA = "Upload channel data"; | 25 private static final String UPLOAD_CHANNEL_DATA = "Upload channel data"; |
| 26 | 26 |
| 27 private CronetTestActivity mActivity; | 27 private CronetTestFramework mTestFramework; |
| 28 | 28 |
| 29 // @Override | 29 // @Override |
| 30 protected void setUp() throws Exception { | 30 protected void setUp() throws Exception { |
| 31 super.setUp(); | 31 super.setUp(); |
| 32 mActivity = launchCronetTestApp(); | 32 mTestFramework = startCronetTestFramework(); |
| 33 assertNotNull(mActivity); | 33 assertNotNull(mTestFramework); |
| 34 assertTrue(NativeTestServer.startNativeTestServer( | 34 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
| 35 getInstrumentation().getTargetContext())); | |
| 36 } | 35 } |
| 37 | 36 |
| 38 private HttpUrlRequest createRequest( | 37 private HttpUrlRequest createRequest( |
| 39 String url, HttpUrlRequestListener listener) { | 38 String url, HttpUrlRequestListener listener) { |
| 40 HashMap<String, String> headers = new HashMap<String, String>(); | 39 HashMap<String, String> headers = new HashMap<String, String>(); |
| 41 return mActivity.mRequestFactory.createRequest( | 40 return mTestFramework.mRequestFactory.createRequest( |
| 42 url, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); | 41 url, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); |
| 43 } | 42 } |
| 44 | 43 |
| 45 /** | 44 /** |
| 46 * Sets request to have an upload channel containing the given data. | 45 * Sets request to have an upload channel containing the given data. |
| 47 * uploadDataLength should generally be uploadData.length(), unless a test | 46 * uploadDataLength should generally be uploadData.length(), unless a test |
| 48 * needs to get a read error. | 47 * needs to get a read error. |
| 49 */ | 48 */ |
| 50 private void setUploadChannel(HttpUrlRequest request, | 49 private void setUploadChannel(HttpUrlRequest request, |
| 51 String contentType, | 50 String contentType, |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 // Upload a single empty chunk. | 338 // Upload a single empty chunk. |
| 340 ByteBuffer byteBuffer = ByteBuffer.allocateDirect(0); | 339 ByteBuffer byteBuffer = ByteBuffer.allocateDirect(0); |
| 341 request.appendChunk(byteBuffer, true); | 340 request.appendChunk(byteBuffer, true); |
| 342 | 341 |
| 343 listener.blockForComplete(); | 342 listener.blockForComplete(); |
| 344 | 343 |
| 345 assertEquals(200, listener.mHttpStatusCode); | 344 assertEquals(200, listener.mHttpStatusCode); |
| 346 assertEquals("", listener.mResponseAsString); | 345 assertEquals("", listener.mResponseAsString); |
| 347 } | 346 } |
| 348 } | 347 } |
| OLD | NEW |