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

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

Issue 1911353003: [Cronet] Do not call into BidirectionalStream::SendData if stream failed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 8 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.net; 5 package org.chromium.net;
6 6
7 import android.test.suitebuilder.annotation.SmallTest; 7 import android.test.suitebuilder.annotation.SmallTest;
8 8
9 import org.chromium.base.test.util.Feature; 9 import org.chromium.base.test.util.Feature;
10 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; 10 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet;
11 import org.json.JSONObject; 11 import org.json.JSONObject;
12 12
13 import java.nio.ByteBuffer;
14
13 /** 15 /**
14 * Tests functionality of BidirectionalStream's QUIC implementation. 16 * Tests functionality of BidirectionalStream's QUIC implementation.
15 */ 17 */
16 public class BidirectionalStreamQuicTest extends CronetTestBase { 18 public class BidirectionalStreamQuicTest extends CronetTestBase {
17 private CronetTestFramework mTestFramework; 19 private CronetTestFramework mTestFramework;
18 private enum QuicBidirectionalStreams { 20 private enum QuicBidirectionalStreams {
19 ENABLED, 21 ENABLED,
20 DISABLED, 22 DISABLED,
21 } 23 }
22 24
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 .Builder(quicURL, callback, callbac k.getExecutor(), 87 .Builder(quicURL, callback, callbac k.getExecutor(),
86 mTestFramework.mCronetEngin e) 88 mTestFramework.mCronetEngin e)
87 .setHttpMethod("GET") 89 .setHttpMethod("GET")
88 .build(); 90 .build();
89 stream.start(); 91 stream.start();
90 callback.blockForDone(); 92 callback.blockForDone();
91 assertTrue(stream.isDone()); 93 assertTrue(stream.isDone());
92 assertTrue(callback.mOnErrorCalled); 94 assertTrue(callback.mOnErrorCalled);
93 assertNull(callback.mResponseInfo); 95 assertNull(callback.mResponseInfo);
94 } 96 }
97
98 @SmallTest
99 @Feature({"Cronet"})
100 @OnlyRunNativeCronet
101 // Tests that if the stream failed between the time when we issue a Write()
102 // and when the Write() is executed in the native stack, there is no crash.
103 // This test is racy, but it should catch a crash (if there is any) most of
104 // the time.
105 public void testStreamFailBeforeWriteIsExecutedOnNetworkThread() throws Exce ption {
106 setUp(QuicBidirectionalStreams.ENABLED);
107 String path = "/simple.txt";
108 String quicURL = QuicTestServer.getServerURL() + path;
109
110 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa llback() {
111 @Override
112 public void onWriteCompleted(
113 BidirectionalStream stream, UrlResponseInfo info, ByteBuffer buffer) {
114 // Super class will write the next piece of data.
115 super.onWriteCompleted(stream, info, buffer);
116 // Shut down the server, and the stream should error out.
117 // The second call to shutdownQuicTestServer is no-op.
118 QuicTestServer.shutdownQuicTestServer();
119 }
120 };
121
122 callback.addWriteData("Test String".getBytes());
123 callback.addWriteData("1234567890".getBytes());
124 callback.addWriteData("woot!".getBytes());
125
126 BidirectionalStream stream = new BidirectionalStream
127 .Builder(quicURL, callback, callbac k.getExecutor(),
128 mTestFramework.mCronetEngin e)
129 .addHeader("foo", "bar")
130 .addHeader("empty", "")
131 .addHeader("Content-Type", "zebra")
132 .build();
133 stream.start();
134 callback.blockForDone();
135 assertTrue(stream.isDone());
136 // Server terminated on us, so the stream must fail.
137 // QUIC reports this as QUIC_PROTOCOL_ERROR.
138 assertNotNull(callback.mError);
139 assertEquals(
140 NetError.ERR_QUIC_PROTOCOL_ERROR, callback.mError.getCronetInter nalErrorCode());
141 }
95 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698