diff options
author | mef@chromium.org <mef@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 18:13:47 +0000 |
---|---|---|
committer | mef@chromium.org <mef@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 18:13:47 +0000 |
commit | 513bf8ce2c2f6e43ab89684f64847b7201f9c4bf (patch) | |
tree | a71476b932cd691eb949c9449f98a185463c4929 /net | |
parent | befa4c5e1bc53e67bc2d15b88d93e4ec5de3f8c4 (diff) | |
download | chromium_src-513bf8ce2c2f6e43ab89684f64847b7201f9c4bf.zip chromium_src-513bf8ce2c2f6e43ab89684f64847b7201f9c4bf.tar.gz chromium_src-513bf8ce2c2f6e43ab89684f64847b7201f9c4bf.tar.bz2 |
Add ChunkedWritableByteChannelTest to CronetSampleTest.
BUG=354143
Review URL: https://codereview.chromium.org/215023003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
4 files changed, 88 insertions, 8 deletions
diff --git a/net/cronet/android/java/src/org/chromium/net/ChunkedWritableByteChannel.java b/net/cronet/android/java/src/org/chromium/net/ChunkedWritableByteChannel.java index 638f2cb..9938985 100644 --- a/net/cronet/android/java/src/org/chromium/net/ChunkedWritableByteChannel.java +++ b/net/cronet/android/java/src/org/chromium/net/ChunkedWritableByteChannel.java @@ -52,16 +52,14 @@ public class ChunkedWritableByteChannel implements WritableByteChannel { } // The supplied initial size was incorrect. Keep the accumulated - // data - // and switch to the usual "sequence of buffers" mode. + // data and switch to the usual "sequence of buffers" mode. mInitialBuffer.flip(); mBuffers.add(mInitialBuffer); mInitialBuffer = null; } // We can't hold a reference to this buffer, because it may wrap native - // memory - // and is not guaranteed to be immutable. + // memory and is not guaranteed to be immutable. ByteBuffer tmpBuf = ByteBuffer.allocateDirect(size); tmpBuf.put(buffer).rewind(); mBuffers.add(tmpBuf); diff --git a/net/cronet/android/sample/javatests/AndroidManifest.xml b/net/cronet/android/sample/javatests/AndroidManifest.xml index fd3ac5e..0df0af9 100644 --- a/net/cronet/android/sample/javatests/AndroidManifest.xml +++ b/net/cronet/android/sample/javatests/AndroidManifest.xml @@ -14,7 +14,7 @@ <application> <uses-library android:name="android.test.runner" /> </application> - <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" /> + <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19" /> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="org.chromium.cronet_sample_apk" android:label="Tests for org.chromium.cronet_sample_apk"/> diff --git a/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/ChunkedWritableByteChannelTest.java b/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/ChunkedWritableByteChannelTest.java new file mode 100644 index 0000000..e459c1c --- /dev/null +++ b/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/ChunkedWritableByteChannelTest.java @@ -0,0 +1,82 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.cronet_sample_apk; + +import android.test.InstrumentationTestCase; +import android.test.suitebuilder.annotation.SmallTest; + +import org.chromium.base.test.util.Feature; +import org.chromium.net.ChunkedWritableByteChannel; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; +import java.nio.charset.Charset; +import java.util.Arrays; + +/** + * Tests for {@link ChunkedWritableByteChannel} + */ +public class ChunkedWritableByteChannelTest extends InstrumentationTestCase { + private ChunkedWritableByteChannel mChannel; + + @Override + public void setUp() { + mChannel = new ChunkedWritableByteChannel(); + } + + @SmallTest + @Feature({"Cronet"}) + public void testSetCapacity() { + int capacity = 100; + mChannel.setCapacity(capacity); + assertEquals("Bytebuffer capacity wasn't set properly", capacity, + mChannel.getByteBuffer().capacity()); + mChannel.close(); + } + + @SmallTest + @Feature({"Cronet"}) + public void testWrite() throws IOException { + String test = "Write in the buffer."; + mChannel.write( + ByteBuffer.wrap(test.getBytes(Charset.forName("UTF-8")))); + mChannel.write( + ByteBuffer.wrap(test.getBytes(Charset.forName("UTF-8")))); + assertEquals("Buffer didn't write the bytes properly", test + test, + new String(mChannel.getBytes(), "UTF-8")); + mChannel.close(); + } + + @SmallTest + @Feature({"Cronet"}) + public void testCloseChannel() { + assertTrue("Channel should be open", mChannel.isOpen()); + mChannel.close(); + assertFalse("Channel shouldn't be open", mChannel.isOpen()); + } + + @SmallTest + @Feature({"Cronet"}) + public void testWriteToClosedChannel() throws IOException { + try { + mChannel.close(); + mChannel.write(ByteBuffer.wrap(new byte[1])); + fail("ClosedChannelException should have been thrown."); + } catch (ClosedChannelException e) { + // Intended + } + } + + @SmallTest + @Feature({"Cronet"}) + public void testCapacityGrows() throws Exception { + mChannel.setCapacity(123); + byte[] data = new byte[1234]; + Arrays.fill(data, (byte)'G'); + mChannel.write(ByteBuffer.wrap(data)); + assertTrue(Arrays.equals(data, mChannel.getBytes())); + } +} diff --git a/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleUrlTest.java b/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleUrlTest.java index 68d7b2c..19260de 100644 --- a/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleUrlTest.java +++ b/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleUrlTest.java @@ -16,7 +16,7 @@ public class CronetSampleUrlTest extends CronetSampleTestBase { private static final String URL = "http://127.0.0.1:8000"; @SmallTest - @Feature({"Main"}) + @Feature({"Cronet"}) public void testLoadUrl() throws Exception { CronetSampleActivity activity = launchCronetSampleWithUrl(URL); @@ -31,7 +31,7 @@ public class CronetSampleUrlTest extends CronetSampleTestBase { } @SmallTest - @Feature({"Main"}) + @Feature({"Cronet"}) public void testInvalidUrl() throws Exception { CronetSampleActivity activity = launchCronetSampleWithUrl( "127.0.0.1:8000"); @@ -46,7 +46,7 @@ public class CronetSampleUrlTest extends CronetSampleTestBase { } @SmallTest - @Feature({"Main"}) + @Feature({"Cronet"}) public void testPostData() throws Exception { String[] commandLineArgs = { CronetSampleActivity.POST_DATA_KEY, "test" }; |