Commit b459f829 authored by mef's avatar mef Committed by Commit bot

SetUploadData now throws an exception if contentType is null.

It used to crash in nativeSetUploadData instead.

BUG=409151

Review URL: https://codereview.chromium.org/526503002

Cr-Commit-Position: refs/heads/master@{#292729}
parent 13efe5ac
......@@ -214,6 +214,7 @@ public class ChromiumUrlRequest implements HttpUrlRequest {
public void setUploadData(String contentType, byte[] data) {
synchronized (mLock) {
validateNotStarted();
validateContentType(contentType);
mUploadContentType = contentType;
mUploadData = data;
mUploadChannel = null;
......@@ -234,6 +235,7 @@ public class ChromiumUrlRequest implements HttpUrlRequest {
ReadableByteChannel channel, long contentLength) {
synchronized (mLock) {
validateNotStarted();
validateContentType(contentType);
mUploadContentType = contentType;
mUploadChannel = channel;
mUploadContentLength = contentLength;
......@@ -252,6 +254,7 @@ public class ChromiumUrlRequest implements HttpUrlRequest {
public void setChunkedUpload(String contentType) {
synchronized (mLock) {
validateNotStarted();
validateContentType(contentType);
mUploadContentType = contentType;
mChunkedUpload = true;
mUploadData = null;
......@@ -455,6 +458,12 @@ public class ChromiumUrlRequest implements HttpUrlRequest {
}
}
private void validateContentType(String contentType) {
if (contentType == null) {
throw new NullPointerException("contentType is required");
}
}
// Private methods called by native library.
/**
......
......@@ -130,7 +130,7 @@ public class CronetSampleUrlTest extends CronetSampleTestBase {
HashMap<String, String> headers = new HashMap<String, String>();
BadHttpUrlRequestListener listener = new BadHttpUrlRequestListener();
// Create request with null listener to trigger an exception.
// Create request with bad listener to trigger an exception.
HttpUrlRequest request = activity.mChromiumRequestFactory.createRequest(
URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
request.start();
......@@ -138,7 +138,31 @@ public class CronetSampleUrlTest extends CronetSampleTestBase {
assertTrue(request.isCanceled());
assertNotNull(request.getException());
assertEquals(listener.THROW_TAG, request.getException().getCause().getMessage());
}
@SmallTest
@Feature({"Cronet"})
public void testSetUploadDataWithNullContentType() throws Exception {
CronetSampleActivity activity = launchCronetSampleWithUrl(URL);
// Make sure the activity was created as expected.
assertNotNull(activity);
waitForActiveShellToBeDoneLoading();
HashMap<String, String> headers = new HashMap<String, String>();
BadHttpUrlRequestListener listener = new BadHttpUrlRequestListener();
// Create request.
HttpUrlRequest request = activity.mChromiumRequestFactory.createRequest(
URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
byte[] uploadData = new byte[] {1, 2, 3};
try {
request.setUploadData(null, uploadData);
fail("setUploadData should throw on null content type");
} catch (NullPointerException e) {
// Nothing to do here.
}
}
@SmallTest
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment