Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java

Issue 1419033005: [Cronet] Remove CriteriaHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework CronetSamepleTest Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 public CronetURLStreamHandlerFactory mStreamHandlerFactory; 69 public CronetURLStreamHandlerFactory mStreamHandlerFactory;
70 public CronetEngine mCronetEngine; 70 public CronetEngine mCronetEngine;
71 HttpUrlRequestFactory mRequestFactory; 71 HttpUrlRequestFactory mRequestFactory;
72 @SuppressFBWarnings("URF_UNREAD_FIELD") HistogramManager mHistogramManager; 72 @SuppressFBWarnings("URF_UNREAD_FIELD") HistogramManager mHistogramManager;
73 73
74 private final String[] mCommandLine; 74 private final String[] mCommandLine;
75 private final Context mContext; 75 private final Context mContext;
76 76
77 private String mUrl; 77 private String mUrl;
78 private boolean mLoading = false;
79 private int mHttpStatusCode = 0; 78 private int mHttpStatusCode = 0;
80 79
81 // CronetEngine.Builder used for this activity. 80 // CronetEngine.Builder used for this activity.
82 private CronetEngine.Builder mCronetEngineBuilder; 81 private CronetEngine.Builder mCronetEngineBuilder;
83 82
84 private class TestHttpUrlRequestListener implements HttpUrlRequestListener { 83 private class TestHttpUrlRequestListener implements HttpUrlRequestListener {
85 private final ConditionVariable mComplete = new ConditionVariable(); 84 private final ConditionVariable mComplete = new ConditionVariable();
86 85
87 public TestHttpUrlRequestListener() {} 86 public TestHttpUrlRequestListener() {}
88 87
89 @Override 88 @Override
90 public void onResponseStarted(HttpUrlRequest request) { 89 public void onResponseStarted(HttpUrlRequest request) {
91 mHttpStatusCode = request.getHttpStatusCode(); 90 mHttpStatusCode = request.getHttpStatusCode();
92 } 91 }
93 92
94 @Override 93 @Override
95 public void onRequestComplete(HttpUrlRequest request) { 94 public void onRequestComplete(HttpUrlRequest request) {
96 mLoading = false;
97 mComplete.open(); 95 mComplete.open();
98 } 96 }
99 97
100 public void blockForComplete() { 98 public void blockForComplete() {
101 mComplete.block(); 99 mComplete.block();
102 } 100 }
103 } 101 }
104 102
105 // TODO(crbug.com/547160): Fix this findbugs error and remove the suppressio n. 103 // TODO(crbug.com/547160): Fix this findbugs error and remove the suppressio n.
106 @SuppressFBWarnings("EI_EXPOSE_REP2") 104 @SuppressFBWarnings("EI_EXPOSE_REP2")
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 InputStream dataStream = new ByteArrayInputStream(postData.getBytes( )); 243 InputStream dataStream = new ByteArrayInputStream(postData.getBytes( ));
246 ReadableByteChannel dataChannel = Channels.newChannel(dataStream); 244 ReadableByteChannel dataChannel = Channels.newChannel(dataStream);
247 request.setUploadChannel("text/plain", dataChannel, postData.length( )); 245 request.setUploadChannel("text/plain", dataChannel, postData.length( ));
248 request.setHttpMethod("POST"); 246 request.setHttpMethod("POST");
249 } 247 }
250 } 248 }
251 249
252 public void startWithURL(String url) { 250 public void startWithURL(String url) {
253 Log.i(TAG, "Cronet started: " + url); 251 Log.i(TAG, "Cronet started: " + url);
254 mUrl = url; 252 mUrl = url;
255 mLoading = true;
256 253
257 HashMap<String, String> headers = new HashMap<String, String>(); 254 HashMap<String, String> headers = new HashMap<String, String>();
258 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 255 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
259 HttpUrlRequest request = mRequestFactory.createRequest( 256 HttpUrlRequest request = mRequestFactory.createRequest(
260 url, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); 257 url, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
261 applyCommandLineToHttpUrlRequest(request); 258 applyCommandLineToHttpUrlRequest(request);
262 request.start(); 259 request.start();
263 listener.blockForComplete(); 260 listener.blockForComplete();
264 } 261 }
265 262
266 public String getUrl() { 263 public String getUrl() {
267 return mUrl; 264 return mUrl;
268 } 265 }
269 266
270 public boolean isLoading() {
271 return mLoading;
272 }
273
274 public int getHttpStatusCode() { 267 public int getHttpStatusCode() {
275 return mHttpStatusCode; 268 return mHttpStatusCode;
276 } 269 }
277 270
278 public void startNetLog() { 271 public void startNetLog() {
279 if (mRequestFactory != null) { 272 if (mRequestFactory != null) {
280 mRequestFactory.startNetLogToFile(Environment.getExternalStorageDire ctory().getPath() 273 mRequestFactory.startNetLogToFile(Environment.getExternalStorageDire ctory().getPath()
281 + "/cronet_sample_netlog_old_api.json", 274 + "/cronet_sample_netlog_old_api.json",
282 false); 275 false);
283 } 276 }
284 if (mCronetEngine != null) { 277 if (mCronetEngine != null) {
285 mCronetEngine.startNetLogToFile(Environment.getExternalStorageDirect ory().getPath() 278 mCronetEngine.startNetLogToFile(Environment.getExternalStorageDirect ory().getPath()
286 + "/cronet_sample_netlog_new_api.json", 279 + "/cronet_sample_netlog_new_api.json",
287 false); 280 false);
288 } 281 }
289 } 282 }
290 283
291 public void stopNetLog() { 284 public void stopNetLog() {
292 if (mRequestFactory != null) { 285 if (mRequestFactory != null) {
293 mRequestFactory.stopNetLog(); 286 mRequestFactory.stopNetLog();
294 } 287 }
295 if (mCronetEngine != null) { 288 if (mCronetEngine != null) {
296 mCronetEngine.stopNetLog(); 289 mCronetEngine.stopNetLog();
297 } 290 }
298 } 291 }
299 } 292 }
OLDNEW
« no previous file with comments | « components/cronet/android/test/javatests/src/org/chromium/net/CriteriaHelper.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698