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

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

Issue 1924593002: Do a null check in CronetURLRequestAdapter::GetStatusOnNetworkThread (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
« no previous file with comments | « components/cronet/android/cronet_url_request_adapter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.os.ConditionVariable; 7 import android.os.ConditionVariable;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.base.test.util.Feature; 10 import org.chromium.base.test.util.Feature;
11 import org.chromium.net.TestUrlRequestCallback.ResponseStep; 11 import org.chromium.net.TestUrlRequestCallback.ResponseStep;
12 import org.chromium.net.UrlRequest.Status; 12 import org.chromium.net.UrlRequest.Status;
13 import org.chromium.net.UrlRequest.StatusListener; 13 import org.chromium.net.UrlRequest.StatusListener;
14 14
15 import java.io.IOException;
16 import java.util.concurrent.Executor;
17 import java.util.concurrent.Executors;
18
15 /** 19 /**
16 * Tests that {@link CronetUrlRequest#getStatus} works as expected. 20 * Tests that {@link CronetUrlRequest#getStatus} works as expected.
17 */ 21 */
18 public class GetStatusTest extends CronetTestBase { 22 public class GetStatusTest extends CronetTestBase {
19 private CronetTestFramework mTestFramework; 23 private CronetTestFramework mTestFramework;
20 24
21 private static class TestStatusListener extends StatusListener { 25 private static class TestStatusListener extends StatusListener {
22 boolean mOnStatusCalled = false; 26 boolean mOnStatusCalled = false;
23 int mStatus = Integer.MAX_VALUE; 27 int mStatus = Integer.MAX_VALUE;
24 private final ConditionVariable mBlock = new ConditionVariable(); 28 private final ConditionVariable mBlock = new ConditionVariable();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 try { 134 try {
131 Status.convertLoadState(16); 135 Status.convertLoadState(16);
132 fail(); 136 fail();
133 } catch (AssertionError e) { 137 } catch (AssertionError e) {
134 // Expected. 138 // Expected.
135 } catch (IllegalArgumentException e) { 139 } catch (IllegalArgumentException e) {
136 // If assertions are disabled, an IllegalArgumentException should be thrown. 140 // If assertions are disabled, an IllegalArgumentException should be thrown.
137 assertEquals("No request status found.", e.getMessage()); 141 assertEquals("No request status found.", e.getMessage());
138 } 142 }
139 } 143 }
144
145 @SmallTest
146 @Feature({"Cronet"})
147 // Regression test for crbug.com/606872.
148 @OnlyRunNativeCronet
149 public void testGetStatusForUpload() throws Exception {
150 TestUrlRequestCallback callback = new TestUrlRequestCallback();
151 UrlRequest.Builder builder = new UrlRequest.Builder(NativeTestServer.get EchoBodyURL(),
152 callback, callback.getExecutor(), mTestFramework.mCronetEngine);
153
154 final ConditionVariable block = new ConditionVariable();
155 // Use a separate executor for UploadDataProvider so the upload can be
156 // stalled while getStatus gets processed.
157 Executor uploadProviderExecutor = Executors.newSingleThreadExecutor();
158 TestUploadDataProvider dataProvider = new TestUploadDataProvider(
159 TestUploadDataProvider.SuccessCallbackMode.SYNC, uploadProviderE xecutor) {
160 @Override
161 public long getLength() throws IOException {
162 // Pause the data provider.
163 block.block();
164 block.close();
165 return super.getLength();
166 }
167 };
168 dataProvider.addRead("test".getBytes());
169 builder.setUploadDataProvider(dataProvider, uploadProviderExecutor);
170 builder.addHeader("Content-Type", "useless/string");
171 UrlRequest urlRequest = builder.build();
172 TestStatusListener statusListener = new TestStatusListener();
173 urlRequest.start();
174 // Call getStatus() immediately after start(), which will post
175 // startInternal() to the upload provider's executor because there is an
176 // upload. When CronetUrlRequestAdapter::GetStatusOnNetworkThread is
177 // executed, the |url_request_| is null.
178 urlRequest.getStatus(statusListener);
179 statusListener.waitUntilOnStatusCalled();
180 assertTrue(statusListener.mOnStatusCalled);
181 // The request should be in IDLE state because GetStatusOnNetworkThread
182 // is called before |url_request_| is initialized and started.
183 assertEquals(Status.IDLE, statusListener.mStatus);
184 // Resume the UploadDataProvider.
185 block.open();
186
187 // Make sure the request is successful and there is no crash.
188 callback.blockForDone();
189 dataProvider.assertClosed();
190
191 assertEquals(4, dataProvider.getUploadedLength());
192 assertEquals(1, dataProvider.getNumReadCalls());
193 assertEquals(0, dataProvider.getNumRewindCalls());
194
195 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
196 assertEquals("test", callback.mResponseAsString);
197 }
140 } 198 }
OLDNEW
« no previous file with comments | « components/cronet/android/cronet_url_request_adapter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698