Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: components/cronet/android/test/javatests/src/org/chromium/net/ChunkedWritableByteChannelTest.java

Issue 2339223002: Cronet API Refactoring (Closed)
Patch Set: Rebased onto Charles change + Paul's Comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.net;
6
7 import android.test.InstrumentationTestCase;
8 import android.test.suitebuilder.annotation.SmallTest;
9
10 import org.chromium.base.test.util.Feature;
11
12 import java.io.IOException;
13 import java.nio.ByteBuffer;
14 import java.nio.channels.ClosedChannelException;
15 import java.nio.charset.Charset;
16 import java.util.Arrays;
17
18 /**
19 * Tests for {@link ChunkedWritableByteChannel}
20 */
21 @SuppressWarnings("deprecation")
22 public class ChunkedWritableByteChannelTest extends InstrumentationTestCase {
23 private ChunkedWritableByteChannel mChannel;
24
25 @Override
26 public void setUp() {
27 mChannel = new ChunkedWritableByteChannel();
28 }
29
30 @SmallTest
31 @Feature({"Cronet"})
32 public void testSetCapacity() {
33 int capacity = 100;
34 mChannel.setCapacity(capacity);
35 assertEquals("Bytebuffer capacity wasn't set properly", capacity,
36 mChannel.getByteBuffer().capacity());
37 mChannel.close();
38 }
39
40 @SmallTest
41 @Feature({"Cronet"})
42 public void testWrite() throws IOException {
43 String test = "Write in the buffer.";
44 mChannel.write(
45 ByteBuffer.wrap(test.getBytes(Charset.forName("UTF-8"))));
46 mChannel.write(
47 ByteBuffer.wrap(test.getBytes(Charset.forName("UTF-8"))));
48 assertEquals("Buffer didn't write the bytes properly", test + test,
49 new String(mChannel.getBytes(), "UTF-8"));
50 mChannel.close();
51 }
52
53 @SmallTest
54 @Feature({"Cronet"})
55 public void testCloseChannel() {
56 assertTrue("Channel should be open", mChannel.isOpen());
57 mChannel.close();
58 assertFalse("Channel shouldn't be open", mChannel.isOpen());
59 }
60
61 @SmallTest
62 @Feature({"Cronet"})
63 public void testWriteToClosedChannel() throws IOException {
64 try {
65 mChannel.close();
66 mChannel.write(ByteBuffer.wrap(new byte[1]));
67 fail("ClosedChannelException should have been thrown.");
68 } catch (ClosedChannelException e) {
69 // Intended
70 }
71 }
72
73 @SmallTest
74 @Feature({"Cronet"})
75 public void testCapacityGrows() throws Exception {
76 mChannel.setCapacity(123);
77 byte[] data = new byte[1234];
78 Arrays.fill(data, (byte) 'G');
79 mChannel.write(ByteBuffer.wrap(data));
80 assertTrue(Arrays.equals(data, mChannel.getBytes()));
81 }
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698