| 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.Build; | 7 import android.os.Build; |
| 8 import android.os.ConditionVariable; | 8 import android.os.ConditionVariable; |
| 9 import android.os.StrictMode; | 9 import android.os.StrictMode; |
| 10 import android.support.test.filters.SmallTest; | 10 import android.support.test.filters.SmallTest; |
| (...skipping 2100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 // https requests to it are tested in QuicTest, so this checks that
we're only blocking | 2111 // https requests to it are tested in QuicTest, so this checks that
we're only blocking |
| 2112 // cleartext. | 2112 // cleartext. |
| 2113 final String url = "http://example.com/simple.txt"; | 2113 final String url = "http://example.com/simple.txt"; |
| 2114 TestUrlRequestCallback callback = startAndWaitForComplete(url); | 2114 TestUrlRequestCallback callback = startAndWaitForComplete(url); |
| 2115 assertNull(callback.mResponseInfo); | 2115 assertNull(callback.mResponseInfo); |
| 2116 assertNotNull(callback.mError); | 2116 assertNotNull(callback.mError); |
| 2117 assertEquals(cleartextNotPermitted, | 2117 assertEquals(cleartextNotPermitted, |
| 2118 ((NetworkException) callback.mError).getCronetInternalErrorC
ode()); | 2118 ((NetworkException) callback.mError).getCronetInternalErrorC
ode()); |
| 2119 } | 2119 } |
| 2120 } | 2120 } |
| 2121 |
| 2122 @SmallTest |
| 2123 @Feature({"Cronet"}) |
| 2124 /** |
| 2125 * Open many connections and cancel them right away. This test verifies all
internal |
| 2126 * sockets and other Closeables are properly closed. See crbug.com/726193. |
| 2127 */ |
| 2128 public void testGzipCancel() throws Exception { |
| 2129 String url = NativeTestServer.getFileURL("/gzipped.html"); |
| 2130 for (int i = 0; i < 100; i++) { |
| 2131 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 2132 callback.setAutoAdvance(false); |
| 2133 UrlRequest urlRequest = |
| 2134 mTestFramework.mCronetEngine |
| 2135 .newUrlRequestBuilder(url, callback, callback.getExe
cutor()) |
| 2136 .build(); |
| 2137 urlRequest.start(); |
| 2138 urlRequest.cancel(); |
| 2139 // If the test blocks until each UrlRequest finishes before starting
the next UrlRequest |
| 2140 // then it never catches the leak. If it starts all UrlRequests and
then blocks until |
| 2141 // all UrlRequests finish, it only catches the leak ~10% of the time
. In its current |
| 2142 // form it appears to catch the leak ~70% of the time. |
| 2143 // Catching the leak may require a lot of busy threads so that the c
ancel() happens |
| 2144 // before the UrlRequest has made much progress (and set mCurrentUrl
Connection and |
| 2145 // mResponseChannel). This may be why blocking until each UrlReques
t finishes doesn't |
| 2146 // catch the leak. |
| 2147 // The other quirk of this is that from teardown(), JavaCronetEngine
.shutdown() is |
| 2148 // called which calls ExecutorService.shutdown() which doesn't wait
for the thread to |
| 2149 // finish running tasks, and then teardown() calls GC looking for le
aks. One possible |
| 2150 // modification would be to expose the ExecutorService and then have
tests call |
| 2151 // awaitTermination() but this would complicate things, and adding a
1s sleep() to |
| 2152 // allow the ExecutorService to terminate did not increase the chanc
es of catching the |
| 2153 // leak. |
| 2154 } |
| 2155 } |
| 2121 } | 2156 } |
| OLD | NEW |