OLD | NEW |
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; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 callback.blockForDone(); | 70 callback.blockForDone(); |
71 assertTrue(stream.isDone()); | 71 assertTrue(stream.isDone()); |
72 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 72 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
73 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); | 73 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); |
74 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); | 74 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
75 } | 75 } |
76 | 76 |
77 @SmallTest | 77 @SmallTest |
78 @Feature({"Cronet"}) | 78 @Feature({"Cronet"}) |
79 @OnlyRunNativeCronet | 79 @OnlyRunNativeCronet |
| 80 public void testSimplePost() throws Exception { |
| 81 setUp(QuicBidirectionalStreams.ENABLED); |
| 82 String path = "/simple.txt"; |
| 83 String quicURL = QuicTestServer.getServerURL() + path; |
| 84 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
| 85 // Although we have no way to verify data sent at this point, this test |
| 86 // can make sure that onWriteCompleted is invoked appropriately. |
| 87 callback.addWriteData("Test String".getBytes()); |
| 88 callback.addWriteData("1234567890".getBytes()); |
| 89 callback.addWriteData("woot!".getBytes()); |
| 90 BidirectionalStream stream = new BidirectionalStream |
| 91 .Builder(quicURL, callback, callbac
k.getExecutor(), |
| 92 mTestFramework.mCronetEngin
e) |
| 93 .addHeader("foo", "bar") |
| 94 .addHeader("empty", "") |
| 95 .addHeader("Content-Type", "zebra") |
| 96 .build(); |
| 97 stream.start(); |
| 98 callback.blockForDone(); |
| 99 assertTrue(stream.isDone()); |
| 100 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 101 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); |
| 102 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
| 103 } |
| 104 |
| 105 @SmallTest |
| 106 @Feature({"Cronet"}) |
| 107 @OnlyRunNativeCronet |
| 108 public void testSimplePostWithFlush() throws Exception { |
| 109 setUp(QuicBidirectionalStreams.ENABLED); |
| 110 String path = "/simple.txt"; |
| 111 String quicURL = QuicTestServer.getServerURL() + path; |
| 112 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
| 113 // Although we have no way to verify data sent at this point, this test |
| 114 // can make sure that onWriteCompleted is invoked appropriately. |
| 115 callback.addWriteData("Test String".getBytes(), false); |
| 116 callback.addWriteData("1234567890".getBytes(), false); |
| 117 callback.addWriteData("woot!".getBytes(), true); |
| 118 BidirectionalStream stream = new BidirectionalStream |
| 119 .Builder(quicURL, callback, callbac
k.getExecutor(), |
| 120 mTestFramework.mCronetEngin
e) |
| 121 .disableAutoFlush(true) |
| 122 .addHeader("foo", "bar") |
| 123 .addHeader("empty", "") |
| 124 .addHeader("Content-Type", "zebra") |
| 125 .build(); |
| 126 stream.start(); |
| 127 callback.blockForDone(); |
| 128 assertTrue(stream.isDone()); |
| 129 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 130 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); |
| 131 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
| 132 } |
| 133 |
| 134 @SmallTest |
| 135 @Feature({"Cronet"}) |
| 136 @OnlyRunNativeCronet |
| 137 public void testSimplePostWithFlushTwice() throws Exception { |
| 138 setUp(QuicBidirectionalStreams.ENABLED); |
| 139 String path = "/simple.txt"; |
| 140 String quicURL = QuicTestServer.getServerURL() + path; |
| 141 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
| 142 // Although we have no way to verify data sent at this point, this test |
| 143 // can make sure that onWriteCompleted is invoked appropriately. |
| 144 callback.addWriteData("Test String".getBytes(), false); |
| 145 callback.addWriteData("1234567890".getBytes(), false); |
| 146 callback.addWriteData("woot!".getBytes(), true); |
| 147 callback.addWriteData("Test String".getBytes(), false); |
| 148 callback.addWriteData("1234567890".getBytes(), false); |
| 149 callback.addWriteData("woot!".getBytes(), true); |
| 150 BidirectionalStream stream = new BidirectionalStream |
| 151 .Builder(quicURL, callback, callbac
k.getExecutor(), |
| 152 mTestFramework.mCronetEngin
e) |
| 153 .disableAutoFlush(true) |
| 154 .addHeader("foo", "bar") |
| 155 .addHeader("empty", "") |
| 156 .addHeader("Content-Type", "zebra") |
| 157 .build(); |
| 158 stream.start(); |
| 159 callback.blockForDone(); |
| 160 assertTrue(stream.isDone()); |
| 161 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 162 assertEquals("This is a simple text file served by QUIC.\n", callback.mR
esponseAsString); |
| 163 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
| 164 } |
| 165 |
| 166 @SmallTest |
| 167 @Feature({"Cronet"}) |
| 168 @OnlyRunNativeCronet |
80 public void testQuicBidirectionalStreamDisabled() throws Exception { | 169 public void testQuicBidirectionalStreamDisabled() throws Exception { |
81 setUp(QuicBidirectionalStreams.DISABLED); | 170 setUp(QuicBidirectionalStreams.DISABLED); |
82 String path = "/simple.txt"; | 171 String path = "/simple.txt"; |
83 String quicURL = QuicTestServer.getServerURL() + path; | 172 String quicURL = QuicTestServer.getServerURL() + path; |
84 | 173 |
85 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); | 174 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback(); |
86 BidirectionalStream stream = new BidirectionalStream | 175 BidirectionalStream stream = new BidirectionalStream |
87 .Builder(quicURL, callback, callbac
k.getExecutor(), | 176 .Builder(quicURL, callback, callbac
k.getExecutor(), |
88 mTestFramework.mCronetEngin
e) | 177 mTestFramework.mCronetEngin
e) |
89 .setHttpMethod("GET") | 178 .setHttpMethod("GET") |
(...skipping 12 matching lines...) Expand all Loading... |
102 // and when the Write() is executed in the native stack, there is no crash. | 191 // 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 | 192 // This test is racy, but it should catch a crash (if there is any) most of |
104 // the time. | 193 // the time. |
105 public void testStreamFailBeforeWriteIsExecutedOnNetworkThread() throws Exce
ption { | 194 public void testStreamFailBeforeWriteIsExecutedOnNetworkThread() throws Exce
ption { |
106 setUp(QuicBidirectionalStreams.ENABLED); | 195 setUp(QuicBidirectionalStreams.ENABLED); |
107 String path = "/simple.txt"; | 196 String path = "/simple.txt"; |
108 String quicURL = QuicTestServer.getServerURL() + path; | 197 String quicURL = QuicTestServer.getServerURL() + path; |
109 | 198 |
110 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback() { | 199 TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCa
llback() { |
111 @Override | 200 @Override |
112 public void onWriteCompleted( | 201 public void onWriteCompleted(BidirectionalStream stream, UrlResponse
Info info, |
113 BidirectionalStream stream, UrlResponseInfo info, ByteBuffer
buffer) { | 202 ByteBuffer buffer, boolean endOfStream) { |
114 // Super class will write the next piece of data. | 203 // Super class will write the next piece of data. |
115 super.onWriteCompleted(stream, info, buffer); | 204 super.onWriteCompleted(stream, info, buffer, endOfStream); |
116 // Shut down the server, and the stream should error out. | 205 // Shut down the server, and the stream should error out. |
117 // The second call to shutdownQuicTestServer is no-op. | 206 // The second call to shutdownQuicTestServer is no-op. |
118 QuicTestServer.shutdownQuicTestServer(); | 207 QuicTestServer.shutdownQuicTestServer(); |
119 } | 208 } |
120 }; | 209 }; |
121 | 210 |
122 callback.addWriteData("Test String".getBytes()); | 211 callback.addWriteData("Test String".getBytes()); |
123 callback.addWriteData("1234567890".getBytes()); | 212 callback.addWriteData("1234567890".getBytes()); |
124 callback.addWriteData("woot!".getBytes()); | 213 callback.addWriteData("woot!".getBytes()); |
125 | 214 |
126 BidirectionalStream stream = new BidirectionalStream | 215 BidirectionalStream stream = new BidirectionalStream |
127 .Builder(quicURL, callback, callbac
k.getExecutor(), | 216 .Builder(quicURL, callback, callbac
k.getExecutor(), |
128 mTestFramework.mCronetEngin
e) | 217 mTestFramework.mCronetEngin
e) |
129 .addHeader("foo", "bar") | 218 .addHeader("foo", "bar") |
130 .addHeader("empty", "") | 219 .addHeader("empty", "") |
131 .addHeader("Content-Type", "zebra") | 220 .addHeader("Content-Type", "zebra") |
132 .build(); | 221 .build(); |
133 stream.start(); | 222 stream.start(); |
134 callback.blockForDone(); | 223 callback.blockForDone(); |
135 assertTrue(stream.isDone()); | 224 assertTrue(stream.isDone()); |
136 // Server terminated on us, so the stream must fail. | 225 // Server terminated on us, so the stream must fail. |
137 // QUIC reports this as QUIC_PROTOCOL_ERROR. | 226 // QUIC reports this as QUIC_PROTOCOL_ERROR. |
138 assertNotNull(callback.mError); | 227 assertNotNull(callback.mError); |
139 assertEquals( | 228 assertEquals( |
140 NetError.ERR_QUIC_PROTOCOL_ERROR, callback.mError.getCronetInter
nalErrorCode()); | 229 NetError.ERR_QUIC_PROTOCOL_ERROR, callback.mError.getCronetInter
nalErrorCode()); |
141 } | 230 } |
142 } | 231 } |
OLD | NEW |