| 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 22 matching lines...) Expand all Loading... |
| 33 import java.util.regex.Pattern; | 33 import java.util.regex.Pattern; |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * Test functionality of CronetUrlRequest. | 36 * Test functionality of CronetUrlRequest. |
| 37 */ | 37 */ |
| 38 public class CronetUrlRequestTest extends CronetTestBase { | 38 public class CronetUrlRequestTest extends CronetTestBase { |
| 39 // URL used for base tests. | 39 // URL used for base tests. |
| 40 private static final String TEST_URL = "http://127.0.0.1:8000"; | 40 private static final String TEST_URL = "http://127.0.0.1:8000"; |
| 41 | 41 |
| 42 private CronetTestFramework mTestFramework; | 42 private CronetTestFramework mTestFramework; |
| 43 private MockUrlRequestJobFactory mMockUrlRequestJobFactory; |
| 43 | 44 |
| 44 @Override | 45 @Override |
| 45 protected void setUp() throws Exception { | 46 protected void setUp() throws Exception { |
| 46 super.setUp(); | 47 super.setUp(); |
| 47 mTestFramework = startCronetTestFramework(); | 48 mTestFramework = startCronetTestFramework(); |
| 48 assertTrue(NativeTestServer.startNativeTestServer(getContext())); | 49 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
| 49 // Add url interceptors after native application context is initialized. | 50 // Add url interceptors after native application context is initialized. |
| 50 MockUrlRequestJobFactory.setUp(); | 51 mMockUrlRequestJobFactory = new MockUrlRequestJobFactory(mTestFramework.
mCronetEngine); |
| 51 } | 52 } |
| 52 | 53 |
| 53 @Override | 54 @Override |
| 54 protected void tearDown() throws Exception { | 55 protected void tearDown() throws Exception { |
| 56 mMockUrlRequestJobFactory.shutdown(); |
| 55 NativeTestServer.shutdownNativeTestServer(); | 57 NativeTestServer.shutdownNativeTestServer(); |
| 56 mTestFramework.mCronetEngine.shutdown(); | 58 mTestFramework.mCronetEngine.shutdown(); |
| 57 super.tearDown(); | 59 super.tearDown(); |
| 58 } | 60 } |
| 59 | 61 |
| 60 private TestUrlRequestCallback startAndWaitForComplete(String url) throws Ex
ception { | 62 private TestUrlRequestCallback startAndWaitForComplete(String url) throws Ex
ception { |
| 61 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 63 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 62 // Create request. | 64 // Create request. |
| 63 UrlRequest.Builder builder = mTestFramework.mCronetEngine.newUrlRequestB
uilder( | 65 UrlRequest.Builder builder = mTestFramework.mCronetEngine.newUrlRequestB
uilder( |
| 64 url, callback, callback.getExecutor()); | 66 url, callback, callback.getExecutor()); |
| (...skipping 1941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { | 2008 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { |
| 2007 // Use a duplicate to avoid modifying byteBuffer. | 2009 // Use a duplicate to avoid modifying byteBuffer. |
| 2008 ByteBuffer duplicate = byteBuffer.duplicate(); | 2010 ByteBuffer duplicate = byteBuffer.duplicate(); |
| 2009 duplicate.position(start); | 2011 duplicate.position(start); |
| 2010 duplicate.limit(end); | 2012 duplicate.limit(end); |
| 2011 byte[] contents = new byte[duplicate.remaining()]; | 2013 byte[] contents = new byte[duplicate.remaining()]; |
| 2012 duplicate.get(contents); | 2014 duplicate.get(contents); |
| 2013 return new String(contents); | 2015 return new String(contents); |
| 2014 } | 2016 } |
| 2015 } | 2017 } |
| OLD | NEW |