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

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

Issue 1124333003: Rename CronetUploadDataStreamAdapter to CronetUploadDataStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 10
(...skipping 14 matching lines...) Expand all
25 25
26 @Override 26 @Override
27 protected void setUp() throws Exception { 27 protected void setUp() throws Exception {
28 super.setUp(); 28 super.setUp();
29 launchCronetTestApp(); 29 launchCronetTestApp();
30 ExecutorService executor = Executors.newSingleThreadExecutor(); 30 ExecutorService executor = Executors.newSingleThreadExecutor();
31 List<byte[]> reads = Arrays.asList("hello".getBytes()); 31 List<byte[]> reads = Arrays.asList("hello".getBytes());
32 mDataProvider = new TestDrivenDataProvider(executor, reads); 32 mDataProvider = new TestDrivenDataProvider(executor, reads);
33 mUploadDataStream = new CronetUploadDataStream(mDataProvider, executor); 33 mUploadDataStream = new CronetUploadDataStream(mDataProvider, executor);
34 mHandler = new TestUploadDataStreamHandler( 34 mHandler = new TestUploadDataStreamHandler(
35 mUploadDataStream.createAdapterForTesting()); 35 mUploadDataStream.createUploadDataStreamForTesting());
36 } 36 }
37 37
38 @Override 38 @Override
39 protected void tearDown() throws Exception { 39 protected void tearDown() throws Exception {
40 // Destroy handler's native objects. 40 // Destroy handler's native objects.
41 mHandler.destroyNativeObjects(); 41 mHandler.destroyNativeObjects();
42 super.tearDown(); 42 super.tearDown();
43 } 43 }
44 44
45 /** 45 /**
46 * Tests that after some data is read, init triggers a rewind, and that 46 * Tests that after some data is read, init triggers a rewind, and that
47 * before the rewind completes, init blocks. 47 * before the rewind completes, init blocks.
48 */ 48 */
49 @SmallTest 49 @SmallTest
50 @Feature({"Cronet"}) 50 @Feature({
51 "Cronet" })
xunjieli 2015/05/08 20:11:28 Strange that this formatting got changed somehow.
mmenke 2015/05/08 20:24:19 Done. No idea how that happened.
51 public void testInitTriggersRewindAndInitBeforeRewindCompletes() 52 public void testInitTriggersRewindAndInitBeforeRewindCompletes()
52 throws Exception { 53 throws Exception {
53 // Init completes synchronously and read succeeds. 54 // Init completes synchronously and read succeeds.
54 assertTrue(mHandler.init()); 55 assertTrue(mHandler.init());
55 mHandler.read(); 56 mHandler.read();
56 mDataProvider.waitForReadRequest(); 57 mDataProvider.waitForReadRequest();
57 mHandler.checkReadCallbackNotInvoked(); 58 mHandler.checkReadCallbackNotInvoked();
58 mDataProvider.onReadSucceeded(mUploadDataStream); 59 mDataProvider.onReadSucceeded(mUploadDataStream);
59 mHandler.waitForReadComplete(); 60 mHandler.waitForReadComplete();
60 mDataProvider.assertReadNotPending(); 61 mDataProvider.assertReadNotPending();
(...skipping 28 matching lines...) Expand all
89 assertEquals(1, mDataProvider.getNumRewindCalls()); 90 assertEquals(1, mDataProvider.getNumRewindCalls());
90 assertEquals(2, mDataProvider.getNumReadCalls()); 91 assertEquals(2, mDataProvider.getNumReadCalls());
91 assertEquals("hello", mHandler.getData()); 92 assertEquals("hello", mHandler.getData());
92 } 93 }
93 94
94 /** 95 /**
95 * Tests that after some data is read, init triggers a rewind, and that 96 * Tests that after some data is read, init triggers a rewind, and that
96 * after the rewind completes, init does not block. 97 * after the rewind completes, init does not block.
97 */ 98 */
98 @SmallTest 99 @SmallTest
99 @Feature({"Cronet"}) 100 @Feature({
101 "Cronet" })
100 public void testInitTriggersRewindAndInitAfterRewindCompletes() 102 public void testInitTriggersRewindAndInitAfterRewindCompletes()
101 throws Exception { 103 throws Exception {
102 // Init completes synchronously and read succeeds. 104 // Init completes synchronously and read succeeds.
103 assertTrue(mHandler.init()); 105 assertTrue(mHandler.init());
104 mHandler.read(); 106 mHandler.read();
105 mDataProvider.waitForReadRequest(); 107 mDataProvider.waitForReadRequest();
106 mHandler.checkReadCallbackNotInvoked(); 108 mHandler.checkReadCallbackNotInvoked();
107 mDataProvider.onReadSucceeded(mUploadDataStream); 109 mDataProvider.onReadSucceeded(mUploadDataStream);
108 mHandler.waitForReadComplete(); 110 mHandler.waitForReadComplete();
109 mDataProvider.assertReadNotPending(); 111 mDataProvider.assertReadNotPending();
(...skipping 27 matching lines...) Expand all
137 assertEquals(1, mDataProvider.getNumRewindCalls()); 139 assertEquals(1, mDataProvider.getNumRewindCalls());
138 assertEquals(2, mDataProvider.getNumReadCalls()); 140 assertEquals(2, mDataProvider.getNumReadCalls());
139 assertEquals("hello", mHandler.getData()); 141 assertEquals("hello", mHandler.getData());
140 } 142 }
141 143
142 /** 144 /**
143 * Tests that if init before read completes, a rewind is triggered when 145 * Tests that if init before read completes, a rewind is triggered when
144 * read completes. 146 * read completes.
145 */ 147 */
146 @SmallTest 148 @SmallTest
147 @Feature({"Cronet"}) 149 @Feature({
150 "Cronet" })
148 public void testReadCompleteTriggerRewind() throws Exception { 151 public void testReadCompleteTriggerRewind() throws Exception {
149 // Reset and init before read completes. 152 // Reset and init before read completes.
150 assertTrue(mHandler.init()); 153 assertTrue(mHandler.init());
151 mHandler.read(); 154 mHandler.read();
152 mDataProvider.waitForReadRequest(); 155 mDataProvider.waitForReadRequest();
153 mHandler.checkReadCallbackNotInvoked(); 156 mHandler.checkReadCallbackNotInvoked();
154 mHandler.reset(); 157 mHandler.reset();
155 // Init should return asynchronously, since there is a pending read. 158 // Init should return asynchronously, since there is a pending read.
156 assertFalse(mHandler.init()); 159 assertFalse(mHandler.init());
157 mDataProvider.assertRewindNotPending(); 160 mDataProvider.assertRewindNotPending();
(...skipping 13 matching lines...) Expand all
171 assertEquals(1, mDataProvider.getNumReadCalls()); 174 assertEquals(1, mDataProvider.getNumReadCalls());
172 assertEquals("", mHandler.getData()); 175 assertEquals("", mHandler.getData());
173 } 176 }
174 177
175 /** 178 /**
176 * Tests that when init again after rewind completes, no additional rewind 179 * Tests that when init again after rewind completes, no additional rewind
177 * is triggered. This test is the same as testReadCompleteTriggerRewind 180 * is triggered. This test is the same as testReadCompleteTriggerRewind
178 * except that this test invokes reset and init again in the end. 181 * except that this test invokes reset and init again in the end.
179 */ 182 */
180 @SmallTest 183 @SmallTest
181 @Feature({"Cronet"}) 184 @Feature({
185 "Cronet" })
182 public void testReadCompleteTriggerRewindOnlyOneRewind() throws Exception { 186 public void testReadCompleteTriggerRewindOnlyOneRewind() throws Exception {
183 testReadCompleteTriggerRewind(); 187 testReadCompleteTriggerRewind();
184 // Reset and Init again, no rewind should happen. 188 // Reset and Init again, no rewind should happen.
185 mHandler.reset(); 189 mHandler.reset();
186 assertTrue(mHandler.init()); 190 assertTrue(mHandler.init());
187 mDataProvider.assertRewindNotPending(); 191 mDataProvider.assertRewindNotPending();
188 assertEquals(1, mDataProvider.getNumRewindCalls()); 192 assertEquals(1, mDataProvider.getNumRewindCalls());
189 assertEquals(1, mDataProvider.getNumReadCalls()); 193 assertEquals(1, mDataProvider.getNumReadCalls());
190 assertEquals("", mHandler.getData()); 194 assertEquals("", mHandler.getData());
191 } 195 }
192 196
193 /** 197 /**
194 * Tests that if reset before read completes, no rewind is triggered, and 198 * Tests that if reset before read completes, no rewind is triggered, and
195 * that a following init triggers rewind. 199 * that a following init triggers rewind.
196 */ 200 */
197 @SmallTest 201 @SmallTest
198 @Feature({"Cronet"}) 202 @Feature({
203 "Cronet" })
199 public void testResetBeforeReadCompleteAndInitTriggerRewind() 204 public void testResetBeforeReadCompleteAndInitTriggerRewind()
200 throws Exception { 205 throws Exception {
201 // Reset before read completes. Rewind is not triggered. 206 // Reset before read completes. Rewind is not triggered.
202 assertTrue(mHandler.init()); 207 assertTrue(mHandler.init());
203 mHandler.read(); 208 mHandler.read();
204 mDataProvider.waitForReadRequest(); 209 mDataProvider.waitForReadRequest();
205 mHandler.checkReadCallbackNotInvoked(); 210 mHandler.checkReadCallbackNotInvoked();
206 mHandler.reset(); 211 mHandler.reset();
207 mDataProvider.onReadSucceeded(mUploadDataStream); 212 mDataProvider.onReadSucceeded(mUploadDataStream);
208 mDataProvider.assertRewindNotPending(); 213 mDataProvider.assertRewindNotPending();
(...skipping 14 matching lines...) Expand all
223 } 228 }
224 229
225 /** 230 /**
226 * Tests that there is no crash when native CronetUploadDataStreamAdapter is 231 * Tests that there is no crash when native CronetUploadDataStreamAdapter is
227 * destroyed while read is pending. The test is racy since read could 232 * destroyed while read is pending. The test is racy since read could
228 * complete either before or after onDestroyAdapter() is called in 233 * complete either before or after onDestroyAdapter() is called in
229 * CronetUploadDataStream. However, the test should pass either way, though 234 * CronetUploadDataStream. However, the test should pass either way, though
230 * we are interested in the latter case. 235 * we are interested in the latter case.
231 */ 236 */
232 @SmallTest 237 @SmallTest
233 @Feature({"Cronet"}) 238 @Feature({
239 "Cronet" })
234 public void testDestroyAdapterBeforeReadComplete() 240 public void testDestroyAdapterBeforeReadComplete()
235 throws Exception { 241 throws Exception {
236 // Start a read and wait for it to be pending. 242 // Start a read and wait for it to be pending.
237 assertTrue(mHandler.init()); 243 assertTrue(mHandler.init());
238 mHandler.read(); 244 mHandler.read();
239 mDataProvider.waitForReadRequest(); 245 mDataProvider.waitForReadRequest();
240 mHandler.checkReadCallbackNotInvoked(); 246 mHandler.checkReadCallbackNotInvoked();
241 247
242 // Destroy the C++ TestUploadDataStreamHandler. The handler owns the 248 // Destroy the C++ TestUploadDataStreamHandler. The handler will then
xunjieli 2015/05/08 20:11:27 nit: there are two spaces after the dot.
mmenke 2015/05/08 20:24:19 Done.
243 // CronetUploadDataStreamAdapter, which this will cause it to destroy on 249 // destroy the C++ CronetUploadDataStream it owns on the network thread.
244 // the network thread. Destroying the adapter will result in calling 250 // That will result in calling the Java CronetUploadDataSteam's
245 // the CronetUploadDataSteam's onAdapterDestroyed() method on its 251 // onCanceled() method on its executor thread, which will then destroy
246 // executor thread, which will then destroy the 252 // the CronetUploadDataStreamAdapter.
247 // CronetUploadDataStreamDelegate.
248 mHandler.destroyNativeObjects(); 253 mHandler.destroyNativeObjects();
249 254
250 // Make the read complete should not encounter a crash. 255 // Make the read complete should not encounter a crash.
251 mDataProvider.onReadSucceeded(mUploadDataStream); 256 mDataProvider.onReadSucceeded(mUploadDataStream);
252 257
253 assertEquals(0, mDataProvider.getNumRewindCalls()); 258 assertEquals(0, mDataProvider.getNumRewindCalls());
254 assertEquals(1, mDataProvider.getNumReadCalls()); 259 assertEquals(1, mDataProvider.getNumReadCalls());
255 } 260 }
256 261
257 /** 262 /**
258 * Tests that there is no crash when native CronetUploadDataStreamAdapter is 263 * Tests that there is no crash when native CronetUploadDataStreamAdapter is
259 * destroyed while rewind is pending. The test is racy since rewind could 264 * destroyed while rewind is pending. The test is racy since rewind could
260 * complete either before or after onDestroyAdapter() is called in 265 * complete either before or after onDestroyAdapter() is called in
261 * CronetUploadDataStream. However, the test should pass either way, though 266 * CronetUploadDataStream. However, the test should pass either way, though
262 * we are interested in the latter case. 267 * we are interested in the latter case.
263 */ 268 */
264 @SmallTest 269 @SmallTest
265 @Feature({"Cronet"}) 270 @Feature({
271 "Cronet" })
266 public void testDestroyAdapterBeforeRewindComplete() 272 public void testDestroyAdapterBeforeRewindComplete()
267 throws Exception { 273 throws Exception {
268 // Start a read and wait for it to complete. 274 // Start a read and wait for it to complete.
269 assertTrue(mHandler.init()); 275 assertTrue(mHandler.init());
270 mHandler.read(); 276 mHandler.read();
271 mDataProvider.waitForReadRequest(); 277 mDataProvider.waitForReadRequest();
272 mHandler.checkReadCallbackNotInvoked(); 278 mHandler.checkReadCallbackNotInvoked();
273 mDataProvider.onReadSucceeded(mUploadDataStream); 279 mDataProvider.onReadSucceeded(mUploadDataStream);
274 mHandler.waitForReadComplete(); 280 mHandler.waitForReadComplete();
275 mDataProvider.assertReadNotPending(); 281 mDataProvider.assertReadNotPending();
276 assertEquals(0, mDataProvider.getNumRewindCalls()); 282 assertEquals(0, mDataProvider.getNumRewindCalls());
277 assertEquals(1, mDataProvider.getNumReadCalls()); 283 assertEquals(1, mDataProvider.getNumReadCalls());
278 assertEquals("hello", mHandler.getData()); 284 assertEquals("hello", mHandler.getData());
279 285
280 // Reset and then init, which should trigger a rewind. 286 // Reset and then init, which should trigger a rewind.
281 mHandler.reset(); 287 mHandler.reset();
282 assertEquals("", mHandler.getData()); 288 assertEquals("", mHandler.getData());
283 assertFalse(mHandler.init()); 289 assertFalse(mHandler.init());
284 mDataProvider.waitForRewindRequest(); 290 mDataProvider.waitForRewindRequest();
285 mHandler.checkInitCallbackNotInvoked(); 291 mHandler.checkInitCallbackNotInvoked();
286 292
287 // Destroy the C++ TestUploadDataStreamHandler. The handler owns the 293 // Destroy the C++ TestUploadDataStreamHandler. The handler will then
xunjieli 2015/05/08 20:11:28 nit: there are two spaces after the dot.
mmenke 2015/05/08 20:24:19 Done.
288 // CronetUploadDataStreamAdapter, which this will cause it to destroy on 294 // destroy the C++ CronetUploadDataStream it owns on the network thread.
289 // the network thread. Destroying the adapter will result in calling 295 // That will result in calling the Java CronetUploadDataSteam's
290 // the CronetUploadDataSteam's onAdapterDestroyed() method on its 296 // onCanceled() method on its executor thread, which will then destroy
291 // executor thread, which will then destroy the 297 // the CronetUploadDataStreamAdapter.
292 // CronetUploadDataStreamDelegate.
293 mHandler.destroyNativeObjects(); 298 mHandler.destroyNativeObjects();
294 299
295 // Signal rewind completes, and wait for init to complete. 300 // Signal rewind completes, and wait for init to complete.
296 mDataProvider.onRewindSucceeded(mUploadDataStream); 301 mDataProvider.onRewindSucceeded(mUploadDataStream);
297 302
298 assertEquals(1, mDataProvider.getNumRewindCalls()); 303 assertEquals(1, mDataProvider.getNumRewindCalls());
299 assertEquals(1, mDataProvider.getNumReadCalls()); 304 assertEquals(1, mDataProvider.getNumReadCalls());
300 } 305 }
301 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698