| 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.components.devtools_bridge; | 5 package org.chromium.components.devtools_bridge; |
| 6 | 6 |
| 7 import android.net.LocalServerSocket; | 7 import android.net.LocalServerSocket; |
| 8 import android.net.LocalSocket; | 8 import android.net.LocalSocket; |
| 9 import android.test.InstrumentationTestCase; | 9 import android.test.InstrumentationTestCase; |
| 10 import android.test.suitebuilder.annotation.MediumTest; | 10 import android.test.suitebuilder.annotation.MediumTest; |
| 11 | 11 |
| 12 import junit.framework.Assert; | 12 import junit.framework.Assert; |
| 13 | 13 |
| 14 import org.chromium.base.annotations.SuppressFBWarnings; |
| 15 |
| 14 import java.io.IOException; | 16 import java.io.IOException; |
| 15 import java.io.OutputStream; | 17 import java.io.OutputStream; |
| 16 import java.nio.ByteBuffer; | 18 import java.nio.ByteBuffer; |
| 17 | 19 |
| 18 /** | 20 /** |
| 19 * Tests for {@link SocketTunnelServer} | 21 * Tests for {@link SocketTunnelServer} |
| 20 */ | 22 */ |
| 21 public class SocketTunnelServerTest extends InstrumentationTestCase { | 23 public class SocketTunnelServerTest extends InstrumentationTestCase { |
| 22 private static final int CONNECTION_ID = 30; | 24 private static final int CONNECTION_ID = 30; |
| 23 private static final String SOCKET_NAME = "ksdjhflksjhdflk"; | 25 private static final String SOCKET_NAME = "ksdjhflksjhdflk"; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 188 |
| 187 socket.shutdownOutput(); | 189 socket.shutdownOutput(); |
| 188 | 190 |
| 189 sentData.limit(sentData.position()); | 191 sentData.limit(sentData.position()); |
| 190 sentData.position(0); | 192 sentData.position(0); |
| 191 ByteBuffer readData = receiveData(CONNECTION_ID, sentData.limit()); | 193 ByteBuffer readData = receiveData(CONNECTION_ID, sentData.limit()); |
| 192 | 194 |
| 193 Assert.assertEquals(sentData, readData); | 195 Assert.assertEquals(sentData, readData); |
| 194 } | 196 } |
| 195 | 197 |
| 198 @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") |
| 196 @MediumTest | 199 @MediumTest |
| 197 public void testReuseConnectionId() throws IOException, InterruptedException
{ | 200 public void testReuseConnectionId() throws IOException, InterruptedException
{ |
| 198 LocalSocket socket = connectToSocket(CONNECTION_ID); | 201 LocalSocket socket = connectToSocket(CONNECTION_ID); |
| 199 receiveOpenAck(CONNECTION_ID); | 202 receiveOpenAck(CONNECTION_ID); |
| 200 | 203 |
| 201 socket.close(); | 204 socket.close(); |
| 202 receiveClose(CONNECTION_ID); | 205 receiveClose(CONNECTION_ID); |
| 203 sendClose(CONNECTION_ID); | 206 sendClose(CONNECTION_ID); |
| 204 | 207 |
| 205 // Open connection with the same ID | 208 // Open connection with the same ID |
| (...skipping 16 matching lines...) Expand all Loading... |
| 222 int count = socket.getInputStream().read(result, 0, SAMPLE.length -
read); | 225 int count = socket.getInputStream().read(result, 0, SAMPLE.length -
read); |
| 223 Assert.assertTrue(count > 0); | 226 Assert.assertTrue(count > 0); |
| 224 read += count; | 227 read += count; |
| 225 } | 228 } |
| 226 | 229 |
| 227 Assert.assertEquals(ByteBuffer.wrap(SAMPLE), ByteBuffer.wrap(result)); | 230 Assert.assertEquals(ByteBuffer.wrap(SAMPLE), ByteBuffer.wrap(result)); |
| 228 | 231 |
| 229 socket.close(); | 232 socket.close(); |
| 230 } | 233 } |
| 231 } | 234 } |
| OLD | NEW |