| 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.Context; | 7 import android.content.Context; |
| 8 import android.os.StrictMode; |
| 8 import android.test.AndroidTestCase; | 9 import android.test.AndroidTestCase; |
| 9 | 10 |
| 10 import org.chromium.base.ContextUtils; | 11 import org.chromium.base.ContextUtils; |
| 11 import org.chromium.base.PathUtils; | 12 import org.chromium.base.PathUtils; |
| 12 import org.chromium.base.annotations.SuppressFBWarnings; | 13 import org.chromium.base.annotations.SuppressFBWarnings; |
| 13 import org.chromium.net.impl.CronetEngineBase; | 14 import org.chromium.net.impl.CronetEngineBase; |
| 14 import org.chromium.net.impl.JavaCronetEngine; | 15 import org.chromium.net.impl.JavaCronetEngine; |
| 15 import org.chromium.net.impl.JavaCronetProvider; | 16 import org.chromium.net.impl.JavaCronetProvider; |
| 16 import org.chromium.net.impl.UserAgent; | 17 import org.chromium.net.impl.UserAgent; |
| 17 | 18 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 56 |
| 56 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "cronet_test"; | 57 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "cronet_test"; |
| 57 private static final String LOOPBACK_ADDRESS = "127.0.0.1"; | 58 private static final String LOOPBACK_ADDRESS = "127.0.0.1"; |
| 58 | 59 |
| 59 private CronetTestFramework mCronetTestFramework; | 60 private CronetTestFramework mCronetTestFramework; |
| 60 private URLStreamHandlerFactory mStreamHandlerFactory; | 61 private URLStreamHandlerFactory mStreamHandlerFactory; |
| 61 | 62 |
| 62 // {@code true} when test is being run against system HttpURLConnection impl
ementation. | 63 // {@code true} when test is being run against system HttpURLConnection impl
ementation. |
| 63 private boolean mTestingSystemHttpURLConnection; | 64 private boolean mTestingSystemHttpURLConnection; |
| 64 private boolean mTestingJavaImpl = false; | 65 private boolean mTestingJavaImpl = false; |
| 66 private StrictMode.VmPolicy mOldVmPolicy; |
| 65 | 67 |
| 66 @Override | 68 @Override |
| 67 protected void setUp() throws Exception { | 69 protected void setUp() throws Exception { |
| 68 super.setUp(); | 70 super.setUp(); |
| 69 System.loadLibrary("cronet_tests"); | 71 System.loadLibrary("cronet_tests"); |
| 70 ContextUtils.initApplicationContext(getContext().getApplicationContext()
); | 72 ContextUtils.initApplicationContext(getContext().getApplicationContext()
); |
| 71 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); | 73 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); |
| 72 prepareTestStorage(getContext()); | 74 prepareTestStorage(getContext()); |
| 75 mOldVmPolicy = StrictMode.getVmPolicy(); |
| 76 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() |
| 77 .detectLeakedClosableObjects() |
| 78 .penaltyLog() |
| 79 .penaltyDeath() |
| 80 .build()); |
| 81 } |
| 82 |
| 83 @SuppressFBWarnings("DM_GC") // Used to trigger strictmode detecting leaked
closeables |
| 84 @Override |
| 85 protected void tearDown() throws Exception { |
| 86 try { |
| 87 // Run GC and finalizers a few times to pick up leaked closeables |
| 88 for (int i = 0; i < 10; i++) { |
| 89 System.gc(); |
| 90 System.runFinalization(); |
| 91 } |
| 92 System.gc(); |
| 93 System.runFinalization(); |
| 94 super.tearDown(); |
| 95 } finally { |
| 96 StrictMode.setVmPolicy(mOldVmPolicy); |
| 97 } |
| 73 } | 98 } |
| 74 | 99 |
| 75 /** | 100 /** |
| 76 * Starts the CronetTest framework. | 101 * Starts the CronetTest framework. |
| 77 */ | 102 */ |
| 78 protected CronetTestFramework startCronetTestFramework() { | 103 protected CronetTestFramework startCronetTestFramework() { |
| 79 mCronetTestFramework = new CronetTestFramework(getContext()); | 104 mCronetTestFramework = new CronetTestFramework(getContext()); |
| 80 return mCronetTestFramework; | 105 return mCronetTestFramework; |
| 81 } | 106 } |
| 82 | 107 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 if (path.isDirectory()) { | 275 if (path.isDirectory()) { |
| 251 for (File c : path.listFiles()) { | 276 for (File c : path.listFiles()) { |
| 252 if (!recursiveDelete(c)) { | 277 if (!recursiveDelete(c)) { |
| 253 return false; | 278 return false; |
| 254 } | 279 } |
| 255 } | 280 } |
| 256 } | 281 } |
| 257 return path.delete(); | 282 return path.delete(); |
| 258 } | 283 } |
| 259 } | 284 } |
| OLD | NEW |