| 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.assertNotNull; |
| 13 import static junit.framework.Assert.assertNull; | 13 import static junit.framework.Assert.assertNull; |
| 14 import static junit.framework.Assert.assertTrue; | 14 import static junit.framework.Assert.assertTrue; |
| 15 | 15 |
| 16 import static org.chromium.net.CronetTestBase.assertContains; |
| 17 |
| 16 import org.chromium.net.impl.UrlRequestError; | 18 import org.chromium.net.impl.UrlRequestError; |
| 17 | 19 |
| 18 import java.nio.ByteBuffer; | 20 import java.nio.ByteBuffer; |
| 19 import java.util.ArrayList; | 21 import java.util.ArrayList; |
| 20 import java.util.concurrent.ExecutorService; | 22 import java.util.concurrent.ExecutorService; |
| 21 import java.util.concurrent.Executors; | 23 import java.util.concurrent.Executors; |
| 22 import java.util.concurrent.ThreadFactory; | 24 import java.util.concurrent.ThreadFactory; |
| 23 import java.util.concurrent.TimeUnit; | 25 import java.util.concurrent.TimeUnit; |
| 24 | 26 |
| 25 /** | 27 /** |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 assertTrue(request.isDone()); | 249 assertTrue(request.isDone()); |
| 248 // Shouldn't happen after success. | 250 // Shouldn't happen after success. |
| 249 assertTrue(mResponseStep != ResponseStep.ON_SUCCEEDED); | 251 assertTrue(mResponseStep != ResponseStep.ON_SUCCEEDED); |
| 250 // Should happen at most once for a single request. | 252 // Should happen at most once for a single request. |
| 251 assertFalse(mOnErrorCalled); | 253 assertFalse(mOnErrorCalled); |
| 252 assertFalse(mOnCanceledCalled); | 254 assertFalse(mOnCanceledCalled); |
| 253 assertNull(mError); | 255 assertNull(mError); |
| 254 if (mListenerExceptionThrown) { | 256 if (mListenerExceptionThrown) { |
| 255 assertEquals(UrlRequestError.LISTENER_EXCEPTION_THROWN, error.getErr
orCode()); | 257 assertEquals(UrlRequestError.LISTENER_EXCEPTION_THROWN, error.getErr
orCode()); |
| 256 assertEquals(0, error.getCronetInternalErrorCode()); | 258 assertEquals(0, error.getCronetInternalErrorCode()); |
| 257 assertEquals("Exception received from UrlRequest.Callback", error.ge
tMessage()); | 259 assertContains("Exception received from UrlRequest.Callback", error.
getMessage()); |
| 258 assertNotNull(error.getCause()); | 260 assertNotNull(error.getCause()); |
| 259 assertTrue(error.getCause() instanceof IllegalStateException); | 261 assertTrue(error.getCause() instanceof IllegalStateException); |
| 260 assertEquals("Listener Exception.", error.getCause().getMessage()); | 262 assertContains("Listener Exception.", error.getCause().getMessage())
; |
| 261 assertFalse(error.immediatelyRetryable()); | 263 assertFalse(error.immediatelyRetryable()); |
| 262 } | 264 } |
| 263 | 265 |
| 264 mResponseStep = ResponseStep.ON_FAILED; | 266 mResponseStep = ResponseStep.ON_FAILED; |
| 265 mOnErrorCalled = true; | 267 mOnErrorCalled = true; |
| 266 mError = error; | 268 mError = error; |
| 267 openDone(); | 269 openDone(); |
| 268 maybeThrowCancelOrPause(request); | 270 maybeThrowCancelOrPause(request); |
| 269 } | 271 } |
| 270 | 272 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 }; | 337 }; |
| 336 if (mFailureType == FailureType.CANCEL_ASYNC | 338 if (mFailureType == FailureType.CANCEL_ASYNC |
| 337 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { | 339 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { |
| 338 getExecutor().execute(task); | 340 getExecutor().execute(task); |
| 339 } else { | 341 } else { |
| 340 task.run(); | 342 task.run(); |
| 341 } | 343 } |
| 342 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; | 344 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; |
| 343 } | 345 } |
| 344 } | 346 } |
| OLD | NEW |