| 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.ConditionVariable; | 8 import android.os.ConditionVariable; |
| 9 import android.os.Environment; | 9 import android.os.Environment; |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * Framework for testing Cronet. | 27 * Framework for testing Cronet. |
| 28 */ | 28 */ |
| 29 @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") | 29 @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") |
| 30 public class CronetTestFramework { | 30 public class CronetTestFramework { |
| 31 private static final String TAG = "CronetTestFramework"; | 31 private static final String TAG = "CronetTestFramework"; |
| 32 | 32 |
| 33 public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; | 33 public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; |
| 34 public static final String POST_DATA_KEY = "postData"; | 34 public static final String POST_DATA_KEY = "postData"; |
| 35 public static final String CACHE_KEY = "cache"; | 35 public static final String CACHE_KEY = "cache"; |
| 36 public static final String SDCH_KEY = "sdch"; | 36 public static final String SDCH_KEY = "sdch"; |
| 37 | |
| 38 public static final String LIBRARY_INIT_KEY = "libraryInit"; | 37 public static final String LIBRARY_INIT_KEY = "libraryInit"; |
| 39 /** | |
| 40 * Skips library initialization. | |
| 41 */ | |
| 42 public static final String LIBRARY_INIT_SKIP = "skip"; | |
| 43 | 38 |
| 44 // Uses disk cache. | 39 // Uses disk cache. |
| 45 public static final String CACHE_DISK = "disk"; | 40 public static final String CACHE_DISK = "disk"; |
| 46 | 41 |
| 47 // Uses disk cache but does not store http data. | 42 // Uses disk cache but does not store http data. |
| 48 public static final String CACHE_DISK_NO_HTTP = "diskNoHttp"; | 43 public static final String CACHE_DISK_NO_HTTP = "diskNoHttp"; |
| 49 | 44 |
| 50 // Uses in-memory cache. | 45 // Uses in-memory cache. |
| 51 public static final String CACHE_IN_MEMORY = "memory"; | 46 public static final String CACHE_IN_MEMORY = "memory"; |
| 52 | 47 |
| 53 // Enables Sdch. | 48 // Enables Sdch. |
| 54 public static final String SDCH_ENABLE = "enable"; | 49 public static final String SDCH_ENABLE = "enable"; |
| 55 | 50 |
| 56 /** | 51 /** |
| 57 * Initializes Cronet Async API only. | 52 * Library init type strings to use along with {@link LIBRARY_INIT_KEY}. |
| 58 */ | 53 * If unspecified, {@link LibraryInitType.CRONET} will be used. |
| 59 public static final String LIBRARY_INIT_CRONET_ONLY = "cronetOnly"; | 54 */ |
| 55 public static final class LibraryInitType { |
| 56 // Initializes Cronet Async API. |
| 57 public static final String CRONET = "cronet"; |
| 58 // Initializes Cronet legacy API. |
| 59 public static final String LEGACY = "legacy"; |
| 60 // Initializes Cronet HttpURLConnection API. |
| 61 public static final String HTTP_URL_CONNECTION = "http_url_connection"; |
| 62 // Do not initialize. |
| 63 public static final String NONE = "none"; |
| 60 | 64 |
| 61 /** | 65 private LibraryInitType() {} |
| 62 * Initializes Cronet HttpURLConnection Wrapper API. | 66 } |
| 63 */ | |
| 64 public static final String LIBRARY_INIT_WRAPPER = "wrapperOnly"; | |
| 65 | 67 |
| 66 public URLStreamHandlerFactory mStreamHandlerFactory; | 68 public URLStreamHandlerFactory mStreamHandlerFactory; |
| 67 public CronetEngine mCronetEngine; | 69 public CronetEngine mCronetEngine; |
| 68 @SuppressWarnings("deprecation") HttpUrlRequestFactory mRequestFactory; | 70 @SuppressWarnings("deprecation") HttpUrlRequestFactory mRequestFactory; |
| 69 | 71 |
| 70 private final String[] mCommandLine; | 72 private final String[] mCommandLine; |
| 71 private final Context mContext; | 73 private final Context mContext; |
| 72 | 74 |
| 73 private String mUrl; | 75 private String mUrl; |
| 74 private int mHttpStatusCode = 0; | 76 private int mHttpStatusCode = 0; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 for (int i = 0; i < commandLine.length / 2; i++) { | 113 for (int i = 0; i < commandLine.length / 2; i++) { |
| 112 Log.i(TAG, "Cronet commandLine %s = %s", commandLine[i * 2], | 114 Log.i(TAG, "Cronet commandLine %s = %s", commandLine[i * 2], |
| 113 commandLine[i * 2 + 1]); | 115 commandLine[i * 2 + 1]); |
| 114 } | 116 } |
| 115 } | 117 } |
| 116 | 118 |
| 117 // Initializes CronetEngine.Builder from commandLine args. | 119 // Initializes CronetEngine.Builder from commandLine args. |
| 118 mCronetEngineBuilder = initializeCronetEngineBuilderWithPresuppliedBuild
er(builder); | 120 mCronetEngineBuilder = initializeCronetEngineBuilderWithPresuppliedBuild
er(builder); |
| 119 | 121 |
| 120 String initString = getCommandLineArg(LIBRARY_INIT_KEY); | 122 String initString = getCommandLineArg(LIBRARY_INIT_KEY); |
| 121 if (LIBRARY_INIT_SKIP.equals(initString)) { | 123 |
| 122 return; | 124 if (initString == null) { |
| 125 initString = LibraryInitType.CRONET; |
| 123 } | 126 } |
| 124 | 127 |
| 125 mCronetEngine = initCronetEngine(); | 128 switch (initString) { |
| 126 | 129 case LibraryInitType.NONE: |
| 127 if (LIBRARY_INIT_WRAPPER.equals(initString)) { | 130 break; |
| 128 mStreamHandlerFactory = mCronetEngine.createURLStreamHandlerFactory(
); | 131 case LibraryInitType.LEGACY: |
| 129 } | 132 mRequestFactory = initRequestFactory(); |
| 130 | 133 if (appUrl != null) { |
| 131 // Start collecting metrics. | 134 startWithURL(appUrl); |
| 132 mCronetEngine.getGlobalMetricsDeltas(); | 135 } |
| 133 | 136 break; |
| 134 if (LIBRARY_INIT_CRONET_ONLY.equals(initString)) { | 137 case LibraryInitType.HTTP_URL_CONNECTION: |
| 135 return; | 138 mCronetEngine = initCronetEngine(); |
| 136 } | 139 mStreamHandlerFactory = mCronetEngine.createURLStreamHandlerFact
ory(); |
| 137 | 140 break; |
| 138 mRequestFactory = initRequestFactory(); | 141 default: |
| 139 if (appUrl != null) { | 142 mCronetEngine = initCronetEngine(); |
| 140 startWithURL(appUrl); | 143 // Start collecting metrics. |
| 144 mCronetEngine.getGlobalMetricsDeltas(); |
| 145 break; |
| 141 } | 146 } |
| 142 } | 147 } |
| 143 | 148 |
| 144 /** | 149 /** |
| 145 * Prepares the path for the test storage (http cache, QUIC server info). | 150 * Prepares the path for the test storage (http cache, QUIC server info). |
| 146 */ | 151 */ |
| 147 private void prepareTestStorage() { | 152 private void prepareTestStorage() { |
| 148 File storage = new File(getTestStorageDirectory(mContext)); | 153 File storage = new File(getTestStorageDirectory(mContext)); |
| 149 if (storage.exists()) { | 154 if (storage.exists()) { |
| 150 assertTrue(recursiveDelete(storage)); | 155 assertTrue(recursiveDelete(storage)); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 309 |
| 305 public void stopNetLog() { | 310 public void stopNetLog() { |
| 306 if (mRequestFactory != null) { | 311 if (mRequestFactory != null) { |
| 307 mRequestFactory.stopNetLog(); | 312 mRequestFactory.stopNetLog(); |
| 308 } | 313 } |
| 309 if (mCronetEngine != null) { | 314 if (mCronetEngine != null) { |
| 310 mCronetEngine.stopNetLog(); | 315 mCronetEngine.stopNetLog(); |
| 311 } | 316 } |
| 312 } | 317 } |
| 313 } | 318 } |
| OLD | NEW |