Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 93 } | 95 } |
| 94 | 96 |
| 95 public void blockForComplete() { | 97 public void blockForComplete() { |
| 96 mComplete.block(); | 98 mComplete.block(); |
| 97 } | 99 } |
| 98 } | 100 } |
| 99 | 101 |
| 100 // TODO(crbug.com/547160): Fix this findbugs error and remove the suppressio n. | 102 // TODO(crbug.com/547160): Fix this findbugs error and remove the suppressio n. |
| 101 @SuppressFBWarnings("EI_EXPOSE_REP2") | 103 @SuppressFBWarnings("EI_EXPOSE_REP2") |
| 102 public CronetTestFramework( | 104 public CronetTestFramework( |
| 103 String appUrl, String[] commandLine, Context context, CronetEngine.B uilder builder) { | 105 String appUrl, String[] commandLine, Context context, CronetEngine.B uilder builder) { |
|
mef
2015/11/24 20:38:33
I think the whole idea of commandLine is now outda
xunjieli
2015/11/24 21:28:06
Yea. Paul considered doing that too, but it was no
mef
2015/11/24 21:43:42
Acknowledged.
| |
| 104 mCommandLine = commandLine; | 106 mCommandLine = commandLine; |
| 105 mContext = context; | 107 mContext = context; |
| 106 prepareTestStorage(); | 108 prepareTestStorage(); |
| 107 | 109 |
| 108 // Print out extra arguments passed in starting this activity. | 110 // Print out extra arguments passed in starting this activity. |
| 109 if (commandLine != null) { | 111 if (commandLine != null) { |
| 110 assertEquals(0, commandLine.length % 2); | 112 assertEquals(0, commandLine.length % 2); |
| 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: |
|
mef
2015/11/24 20:38:33
can this be combined with default?
xunjieli
2015/11/24 21:28:06
I am not sure how to combine it with the default.
mef
2015/11/24 21:43:42
Would it hurt anything if we always createURLStrea
xunjieli
2015/11/24 21:54:13
Yes, you are right. But I'd like to think that the
| |
| 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 |