| Index: components/cronet/android/test/javatests/src/org/chromium/net/BidirectionalStreamQuicTest.java
|
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/BidirectionalStreamQuicTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/BidirectionalStreamQuicTest.java
|
| index 10557b5cbc65c07290ef90cd294c2c00e141911c..a6591ef3dd430588e5249c8d55a42f566d3d9ecf 100644
|
| --- a/components/cronet/android/test/javatests/src/org/chromium/net/BidirectionalStreamQuicTest.java
|
| +++ b/components/cronet/android/test/javatests/src/org/chromium/net/BidirectionalStreamQuicTest.java
|
| @@ -10,6 +10,8 @@ import org.chromium.base.test.util.Feature;
|
| import org.chromium.net.CronetTestBase.OnlyRunNativeCronet;
|
| import org.json.JSONObject;
|
|
|
| +import java.nio.ByteBuffer;
|
| +
|
| /**
|
| * Tests functionality of BidirectionalStream's QUIC implementation.
|
| */
|
| @@ -92,4 +94,49 @@ public class BidirectionalStreamQuicTest extends CronetTestBase {
|
| assertTrue(callback.mOnErrorCalled);
|
| assertNull(callback.mResponseInfo);
|
| }
|
| +
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + @OnlyRunNativeCronet
|
| + // Tests that if the stream failed between the time when we issue a Write()
|
| + // and when the Write() is executed in the native stack, there is no crash.
|
| + // This test is racy, but it should catch a crash (if there is any) most of
|
| + // the time.
|
| + public void testStreamFailBeforeWriteIsExecutedOnNetworkThread() throws Exception {
|
| + setUp(QuicBidirectionalStreams.ENABLED);
|
| + String path = "/simple.txt";
|
| + String quicURL = QuicTestServer.getServerURL() + path;
|
| +
|
| + TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCallback() {
|
| + @Override
|
| + public void onWriteCompleted(
|
| + BidirectionalStream stream, UrlResponseInfo info, ByteBuffer buffer) {
|
| + // Super class will write the next piece of data.
|
| + super.onWriteCompleted(stream, info, buffer);
|
| + // Shut down the server, and the stream should error out.
|
| + // The second call to shutdownQuicTestServer is no-op.
|
| + QuicTestServer.shutdownQuicTestServer();
|
| + }
|
| + };
|
| +
|
| + callback.addWriteData("Test String".getBytes());
|
| + callback.addWriteData("1234567890".getBytes());
|
| + callback.addWriteData("woot!".getBytes());
|
| +
|
| + BidirectionalStream stream = new BidirectionalStream
|
| + .Builder(quicURL, callback, callback.getExecutor(),
|
| + mTestFramework.mCronetEngine)
|
| + .addHeader("foo", "bar")
|
| + .addHeader("empty", "")
|
| + .addHeader("Content-Type", "zebra")
|
| + .build();
|
| + stream.start();
|
| + callback.blockForDone();
|
| + assertTrue(stream.isDone());
|
| + // Server terminated on us, so the stream must fail.
|
| + // QUIC reports this as QUIC_PROTOCOL_ERROR.
|
| + assertNotNull(callback.mError);
|
| + assertEquals(
|
| + NetError.ERR_QUIC_PROTOCOL_ERROR, callback.mError.getCronetInternalErrorCode());
|
| + }
|
| }
|
|
|