| 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.content.ContextWrapper; |
| 7 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
| 8 | 9 |
| 9 import org.chromium.base.test.util.Feature; | 10 import org.chromium.base.test.util.Feature; |
| 10 | 11 |
| 11 import java.util.HashMap; | 12 import java.util.HashMap; |
| 12 | 13 |
| 13 /** | 14 /** |
| 14 * Tests that make sure ChromiumUrlRequestContext initialization will not | 15 * Tests that make sure ChromiumUrlRequestContext initialization will not |
| 15 * affect embedders' ability to make requests. | 16 * affect embedders' ability to make requests. |
| 16 */ | 17 */ |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Helper function to make a request. | 122 // Helper function to make a request. |
| 122 private TestHttpUrlRequestListener makeRequest( | 123 private TestHttpUrlRequestListener makeRequest( |
| 123 HttpUrlRequestFactory factory, String url) { | 124 HttpUrlRequestFactory factory, String url) { |
| 124 HashMap<String, String> headers = new HashMap<String, String>(); | 125 HashMap<String, String> headers = new HashMap<String, String>(); |
| 125 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); | 126 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); |
| 126 HttpUrlRequest request = factory.createRequest( | 127 HttpUrlRequest request = factory.createRequest( |
| 127 url, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); | 128 url, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); |
| 128 request.start(); | 129 request.start(); |
| 129 return listener; | 130 return listener; |
| 130 } | 131 } |
| 132 |
| 133 @SmallTest |
| 134 @Feature({"Cronet"}) |
| 135 public void testInitDifferentContexts() throws Exception { |
| 136 // Test that concurrently instantiating ChromiumUrlRequestContext's upon |
| 137 // various different versions of the same Android Context does not cause |
| 138 // crashes like crbug.com/453845 |
| 139 final CronetTestActivity activity = launchCronetTestApp(); |
| 140 HttpUrlRequestFactory firstFactory = |
| 141 HttpUrlRequestFactory.createFactory(activity, activity.getContex
tConfig()); |
| 142 HttpUrlRequestFactory secondFactory = HttpUrlRequestFactory.createFactor
y( |
| 143 activity.getApplicationContext(), activity.getContextConfig()); |
| 144 HttpUrlRequestFactory thirdFactory = HttpUrlRequestFactory.createFactory
( |
| 145 new ContextWrapper(activity), activity.getContextConfig()); |
| 146 // Meager attempt to extend lifetimes to ensure they're concurrently |
| 147 // alive. |
| 148 firstFactory.getName(); |
| 149 secondFactory.getName(); |
| 150 thirdFactory.getName(); |
| 151 } |
| 131 } | 152 } |
| OLD | NEW |