| 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 import android.os.StrictMode; | 8 import android.os.StrictMode; |
| 9 | 9 |
| 10 import static junit.framework.Assert.assertEquals; | 10 import static junit.framework.Assert.assertEquals; |
| 11 import static junit.framework.Assert.assertFalse; | 11 import static junit.framework.Assert.assertFalse; |
| 12 import static junit.framework.Assert.assertNotNull; |
| 12 import static junit.framework.Assert.assertNull; | 13 import static junit.framework.Assert.assertNull; |
| 13 import static junit.framework.Assert.assertTrue; | 14 import static junit.framework.Assert.assertTrue; |
| 14 | 15 |
| 15 import java.nio.ByteBuffer; | 16 import java.nio.ByteBuffer; |
| 16 import java.util.ArrayList; | 17 import java.util.ArrayList; |
| 17 import java.util.concurrent.Executor; | 18 import java.util.concurrent.Executor; |
| 18 import java.util.concurrent.ExecutorService; | 19 import java.util.concurrent.ExecutorService; |
| 19 import java.util.concurrent.Executors; | 20 import java.util.concurrent.Executors; |
| 20 import java.util.concurrent.ThreadFactory; | 21 import java.util.concurrent.ThreadFactory; |
| 21 | 22 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 @Override | 225 @Override |
| 225 public void onFailed(UrlRequest request, UrlResponseInfo info, UrlRequestExc
eption error) { | 226 public void onFailed(UrlRequest request, UrlResponseInfo info, UrlRequestExc
eption error) { |
| 226 assertEquals(mExecutorThread, Thread.currentThread()); | 227 assertEquals(mExecutorThread, Thread.currentThread()); |
| 227 assertTrue(request.isDone()); | 228 assertTrue(request.isDone()); |
| 228 // Shouldn't happen after success. | 229 // Shouldn't happen after success. |
| 229 assertTrue(mResponseStep != ResponseStep.ON_SUCCEEDED); | 230 assertTrue(mResponseStep != ResponseStep.ON_SUCCEEDED); |
| 230 // Should happen at most once for a single request. | 231 // Should happen at most once for a single request. |
| 231 assertFalse(mOnErrorCalled); | 232 assertFalse(mOnErrorCalled); |
| 232 assertFalse(mOnCanceledCalled); | 233 assertFalse(mOnCanceledCalled); |
| 233 assertNull(mError); | 234 assertNull(mError); |
| 235 if (mFailureType == FailureType.THROW_SYNC) { |
| 236 assertEquals(UrlRequestError.LISTENER_EXCEPTION_THROWN, error.getErr
orCode()); |
| 237 assertEquals(0, error.getCronetInternalErrorCode()); |
| 238 assertEquals("UrlRequestListener method has thrown an exception", er
ror.getMessage()); |
| 239 assertNotNull(error.getCause()); |
| 240 assertTrue(error.getCause() instanceof IllegalStateException); |
| 241 assertEquals("Listener Exception.", error.getCause().getMessage()); |
| 242 assertFalse(error.immediatelyRetryable()); |
| 243 } |
| 234 | 244 |
| 235 mOnErrorCalled = true; | 245 mOnErrorCalled = true; |
| 236 mError = error; | 246 mError = error; |
| 237 openDone(); | 247 openDone(); |
| 238 maybeThrowCancelOrPause(request); | 248 maybeThrowCancelOrPause(request); |
| 239 } | 249 } |
| 240 | 250 |
| 241 @Override | 251 @Override |
| 242 public void onCanceled(UrlRequest request, UrlResponseInfo info) { | 252 public void onCanceled(UrlRequest request, UrlResponseInfo info) { |
| 243 assertEquals(mExecutorThread, Thread.currentThread()); | 253 assertEquals(mExecutorThread, Thread.currentThread()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 }; | 305 }; |
| 296 if (mFailureType == FailureType.CANCEL_ASYNC | 306 if (mFailureType == FailureType.CANCEL_ASYNC |
| 297 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { | 307 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { |
| 298 getExecutor().execute(task); | 308 getExecutor().execute(task); |
| 299 } else { | 309 } else { |
| 300 task.run(); | 310 task.run(); |
| 301 } | 311 } |
| 302 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; | 312 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; |
| 303 } | 313 } |
| 304 } | 314 } |
| OLD | NEW |