| 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 import android.test.MoreAsserts; | 9 import android.test.MoreAsserts; |
| 10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 import java.util.regex.Pattern; | 32 import java.util.regex.Pattern; |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Test functionality of CronetUrlRequest. | 35 * Test functionality of CronetUrlRequest. |
| 36 */ | 36 */ |
| 37 public class CronetUrlRequestTest extends CronetTestBase { | 37 public class CronetUrlRequestTest extends CronetTestBase { |
| 38 // URL used for base tests. | 38 // URL used for base tests. |
| 39 private static final String TEST_URL = "http://127.0.0.1:8000"; | 39 private static final String TEST_URL = "http://127.0.0.1:8000"; |
| 40 | 40 |
| 41 private CronetTestFramework mTestFramework; | 41 private CronetTestFramework mTestFramework; |
| 42 private MockUrlRequestJobFactory mMockUrlRequestJobFactory; |
| 42 | 43 |
| 43 @Override | 44 @Override |
| 44 protected void setUp() throws Exception { | 45 protected void setUp() throws Exception { |
| 45 super.setUp(); | 46 super.setUp(); |
| 46 mTestFramework = startCronetTestFramework(); | 47 mTestFramework = startCronetTestFramework(); |
| 47 assertTrue(NativeTestServer.startNativeTestServer(getContext())); | 48 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
| 48 // Add url interceptors after native application context is initialized. | 49 // Add url interceptors after native application context is initialized. |
| 49 MockUrlRequestJobFactory.setUp(); | 50 mMockUrlRequestJobFactory = new MockUrlRequestJobFactory(mTestFramework.
mCronetEngine); |
| 50 } | 51 } |
| 51 | 52 |
| 52 @Override | 53 @Override |
| 53 protected void tearDown() throws Exception { | 54 protected void tearDown() throws Exception { |
| 55 mMockUrlRequestJobFactory.shutdown(); |
| 54 NativeTestServer.shutdownNativeTestServer(); | 56 NativeTestServer.shutdownNativeTestServer(); |
| 55 mTestFramework.mCronetEngine.shutdown(); | 57 mTestFramework.mCronetEngine.shutdown(); |
| 56 super.tearDown(); | 58 super.tearDown(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 private TestUrlRequestCallback startAndWaitForComplete(String url) throws Ex
ception { | 61 private TestUrlRequestCallback startAndWaitForComplete(String url) throws Ex
ception { |
| 60 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 62 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 61 // Create request. | 63 // Create request. |
| 62 UrlRequest.Builder builder = new UrlRequest.Builder( | 64 UrlRequest.Builder builder = new UrlRequest.Builder( |
| 63 url, callback, callback.getExecutor(), mTestFramework.mCronetEng
ine); | 65 url, callback, callback.getExecutor(), mTestFramework.mCronetEng
ine); |
| (...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2017 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { | 2019 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { |
| 2018 // Use a duplicate to avoid modifying byteBuffer. | 2020 // Use a duplicate to avoid modifying byteBuffer. |
| 2019 ByteBuffer duplicate = byteBuffer.duplicate(); | 2021 ByteBuffer duplicate = byteBuffer.duplicate(); |
| 2020 duplicate.position(start); | 2022 duplicate.position(start); |
| 2021 duplicate.limit(end); | 2023 duplicate.limit(end); |
| 2022 byte[] contents = new byte[duplicate.remaining()]; | 2024 byte[] contents = new byte[duplicate.remaining()]; |
| 2023 duplicate.get(contents); | 2025 duplicate.get(contents); |
| 2024 return new String(contents); | 2026 return new String(contents); |
| 2025 } | 2027 } |
| 2026 } | 2028 } |
| OLD | NEW |