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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 mComplete.block(); | 98 mComplete.block(); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 // 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. |
103 @SuppressFBWarnings("EI_EXPOSE_REP2") | 103 @SuppressFBWarnings("EI_EXPOSE_REP2") |
104 public CronetTestFramework( | 104 public CronetTestFramework( |
105 String appUrl, String[] commandLine, Context context, CronetEngine.B uilder builder) { | 105 String appUrl, String[] commandLine, Context context, CronetEngine.B uilder builder) { |
106 mCommandLine = commandLine; | 106 mCommandLine = commandLine; |
107 mContext = context; | 107 mContext = context; |
108 prepareTestStorage(); | |
109 | 108 |
110 // Print out extra arguments passed in starting this activity. | 109 // Print out extra arguments passed in starting this activity. |
111 if (commandLine != null) { | 110 if (commandLine != null) { |
112 assertEquals(0, commandLine.length % 2); | 111 assertEquals(0, commandLine.length % 2); |
113 for (int i = 0; i < commandLine.length / 2; i++) { | 112 for (int i = 0; i < commandLine.length / 2; i++) { |
114 Log.i(TAG, "Cronet commandLine %s = %s", commandLine[i * 2], | 113 Log.i(TAG, "Cronet commandLine %s = %s", commandLine[i * 2], |
115 commandLine[i * 2 + 1]); | 114 commandLine[i * 2 + 1]); |
116 } | 115 } |
117 } | 116 } |
118 | 117 |
(...skipping 23 matching lines...) Expand all Loading... | |
142 mCronetEngine = initCronetEngine(); | 141 mCronetEngine = initCronetEngine(); |
143 // Start collecting metrics. | 142 // Start collecting metrics. |
144 mCronetEngine.getGlobalMetricsDeltas(); | 143 mCronetEngine.getGlobalMetricsDeltas(); |
145 break; | 144 break; |
146 } | 145 } |
147 } | 146 } |
148 | 147 |
149 /** | 148 /** |
150 * Prepares the path for the test storage (http cache, QUIC server info). | 149 * Prepares the path for the test storage (http cache, QUIC server info). |
151 */ | 150 */ |
152 private void prepareTestStorage() { | 151 public static void prepareTestStorage(Context context) { |
xunjieli
2015/12/07 23:09:10
I think moving CronetTestFramework into CronetTest
kapishnikov
2015/12/08 01:09:37
Yes, I agree that we could move some of the Cronet
| |
153 File storage = new File(getTestStorageDirectory(mContext)); | 152 File storage = new File(getTestStorageDirectory(context)); |
154 if (storage.exists()) { | 153 if (storage.exists()) { |
155 assertTrue(recursiveDelete(storage)); | 154 assertTrue(recursiveDelete(storage)); |
156 } | 155 } |
157 ensureTestStorageExists(mContext); | 156 ensureTestStorageExists(context); |
158 } | 157 } |
159 | 158 |
160 /** | 159 /** |
161 * Returns the path for the test storage (http cache, QUIC server info). | 160 * Returns the path for the test storage (http cache, QUIC server info). |
162 * NOTE: Does not ensure it exists; tests should use {@link #getTestStorage} . | 161 * NOTE: Does not ensure it exists; tests should use {@link #getTestStorage} . |
163 */ | 162 */ |
164 private static String getTestStorageDirectory(Context context) { | 163 private static String getTestStorageDirectory(Context context) { |
165 return PathUtils.getDataDirectory(context) + "/test_storage"; | 164 return PathUtils.getDataDirectory(context) + "/test_storage"; |
166 } | 165 } |
167 | 166 |
(...skipping 10 matching lines...) Expand all Loading... | |
178 /** | 177 /** |
179 * Returns the path for the test storage (http cache, QUIC server info). | 178 * Returns the path for the test storage (http cache, QUIC server info). |
180 * Also ensures it exists. | 179 * Also ensures it exists. |
181 */ | 180 */ |
182 static String getTestStorage(Context context) { | 181 static String getTestStorage(Context context) { |
183 ensureTestStorageExists(context); | 182 ensureTestStorageExists(context); |
184 return getTestStorageDirectory(context); | 183 return getTestStorageDirectory(context); |
185 } | 184 } |
186 | 185 |
187 @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") | 186 @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") |
188 private boolean recursiveDelete(File path) { | 187 private static boolean recursiveDelete(File path) { |
189 if (path.isDirectory()) { | 188 if (path.isDirectory()) { |
190 for (File c : path.listFiles()) { | 189 for (File c : path.listFiles()) { |
191 if (!recursiveDelete(c)) { | 190 if (!recursiveDelete(c)) { |
192 return false; | 191 return false; |
193 } | 192 } |
194 } | 193 } |
195 } | 194 } |
196 return path.delete(); | 195 return path.delete(); |
197 } | 196 } |
198 | 197 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 | 308 |
310 public void stopNetLog() { | 309 public void stopNetLog() { |
311 if (mRequestFactory != null) { | 310 if (mRequestFactory != null) { |
312 mRequestFactory.stopNetLog(); | 311 mRequestFactory.stopNetLog(); |
313 } | 312 } |
314 if (mCronetEngine != null) { | 313 if (mCronetEngine != null) { |
315 mCronetEngine.stopNetLog(); | 314 mCronetEngine.stopNetLog(); |
316 } | 315 } |
317 } | 316 } |
318 } | 317 } |
OLD | NEW |