| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 8 |
| 9 import static junit.framework.Assert.assertEquals; | 9 import static junit.framework.Assert.assertEquals; |
| 10 import static junit.framework.Assert.assertFalse; | 10 import static junit.framework.Assert.assertFalse; |
| 11 import static junit.framework.Assert.assertNotNull; |
| 11 import static junit.framework.Assert.assertNull; | 12 import static junit.framework.Assert.assertNull; |
| 12 import static junit.framework.Assert.assertTrue; | 13 import static junit.framework.Assert.assertTrue; |
| 13 | 14 |
| 14 import java.nio.ByteBuffer; | 15 import java.nio.ByteBuffer; |
| 15 import java.util.ArrayList; | 16 import java.util.ArrayList; |
| 16 import java.util.concurrent.Executor; | 17 import java.util.concurrent.Executor; |
| 17 import java.util.concurrent.ExecutorService; | 18 import java.util.concurrent.ExecutorService; |
| 18 import java.util.concurrent.Executors; | 19 import java.util.concurrent.Executors; |
| 19 import java.util.concurrent.ThreadFactory; | 20 import java.util.concurrent.ThreadFactory; |
| 20 | 21 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 @Override | 209 @Override |
| 209 public void onFailed(UrlRequest request, UrlResponseInfo info, UrlRequestExc
eption error) { | 210 public void onFailed(UrlRequest request, UrlResponseInfo info, UrlRequestExc
eption error) { |
| 210 assertEquals(mExecutorThread, Thread.currentThread()); | 211 assertEquals(mExecutorThread, Thread.currentThread()); |
| 211 assertTrue(request.isDone()); | 212 assertTrue(request.isDone()); |
| 212 // Shouldn't happen after success. | 213 // Shouldn't happen after success. |
| 213 assertTrue(mResponseStep != ResponseStep.ON_SUCCEEDED); | 214 assertTrue(mResponseStep != ResponseStep.ON_SUCCEEDED); |
| 214 // Should happen at most once for a single request. | 215 // Should happen at most once for a single request. |
| 215 assertFalse(mOnErrorCalled); | 216 assertFalse(mOnErrorCalled); |
| 216 assertFalse(mOnCanceledCalled); | 217 assertFalse(mOnCanceledCalled); |
| 217 assertNull(mError); | 218 assertNull(mError); |
| 219 if (mFailureType == FailureType.THROW_SYNC) { |
| 220 assertEquals(UrlRequestError.LISTENER_THREW, error.getErrorCode()); |
| 221 assertEquals(0, error.getCronetInternalErrorCode()); |
| 222 assertEquals("UrlRequestListener method has thrown an exception", er
ror.getMessage()); |
| 223 assertNotNull(error.getCause()); |
| 224 assertTrue(error.getCause() instanceof IllegalStateException); |
| 225 assertEquals("Listener Exception.", error.getCause().getMessage()); |
| 226 assertFalse(error.immediatelyRetryable()); |
| 227 } |
| 218 | 228 |
| 219 mOnErrorCalled = true; | 229 mOnErrorCalled = true; |
| 220 mError = error; | 230 mError = error; |
| 221 openDone(); | 231 openDone(); |
| 222 maybeThrowCancelOrPause(request); | 232 maybeThrowCancelOrPause(request); |
| 223 } | 233 } |
| 224 | 234 |
| 225 @Override | 235 @Override |
| 226 public void onCanceled(UrlRequest request, UrlResponseInfo info) { | 236 public void onCanceled(UrlRequest request, UrlResponseInfo info) { |
| 227 assertEquals(mExecutorThread, Thread.currentThread()); | 237 assertEquals(mExecutorThread, Thread.currentThread()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 }; | 289 }; |
| 280 if (mFailureType == FailureType.CANCEL_ASYNC | 290 if (mFailureType == FailureType.CANCEL_ASYNC |
| 281 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { | 291 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { |
| 282 getExecutor().execute(task); | 292 getExecutor().execute(task); |
| 283 } else { | 293 } else { |
| 284 task.run(); | 294 task.run(); |
| 285 } | 295 } |
| 286 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; | 296 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; |
| 287 } | 297 } |
| 288 } | 298 } |
| OLD | NEW |