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

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

Issue 1363723002: [Cronet] Create Builders, rename UrlRequestContext to CronetEngine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make old API work without renaming Created 5 years, 2 months 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
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.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.base.PathUtils; 10 import org.chromium.base.PathUtils;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 assertEquals(200, activity.getHttpStatusCode()); 54 assertEquals(200, activity.getHttpStatusCode());
55 } 55 }
56 56
57 @SmallTest 57 @SmallTest
58 @Feature({"Cronet"}) 58 @Feature({"Cronet"})
59 public void testNetLog() throws Exception { 59 public void testNetLog() throws Exception {
60 Context context = getInstrumentation().getTargetContext(); 60 Context context = getInstrumentation().getTargetContext();
61 File directory = new File(PathUtils.getDataDirectory(context)); 61 File directory = new File(PathUtils.getDataDirectory(context));
62 File file = File.createTempFile("cronet", "json", directory); 62 File file = File.createTempFile("cronet", "json", directory);
63 HttpUrlRequestFactory factory = HttpUrlRequestFactory.createFactory( 63 HttpUrlRequestFactory factory = HttpUrlRequestFactory.createFactory(
64 context, 64 new CronetEngine.Builder(context).setLibraryName("cronet_tests") );
mef 2015/10/02 16:46:58 will this work?
pauljensen 2015/10/02 18:23:15 I reverted this file.
65 new UrlRequestContextConfig().setLibraryName("cronet_tests"));
66 // Start NetLog immediately after the request context is created to make 65 // Start NetLog immediately after the request context is created to make
67 // sure that the call won't crash the app even when the native request 66 // sure that the call won't crash the app even when the native request
68 // context is not fully initialized. See crbug.com/470196. 67 // context is not fully initialized. See crbug.com/470196.
69 factory.startNetLogToFile(file.getPath(), false); 68 factory.startNetLogToFile(file.getPath(), false);
70 // Starts a request. 69 // Starts a request.
71 HashMap<String, String> headers = new HashMap<String, String>(); 70 HashMap<String, String> headers = new HashMap<String, String>();
72 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 71 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
73 HttpUrlRequest request = factory.createRequest( 72 HttpUrlRequest request = factory.createRequest(
74 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); 73 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
75 request.start(); 74 request.start();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 request.setUploadData(null, uploadData); 127 request.setUploadData(null, uploadData);
129 fail("setUploadData should throw on null content type"); 128 fail("setUploadData should throw on null content type");
130 } catch (NullPointerException e) { 129 } catch (NullPointerException e) {
131 // Nothing to do here. 130 // Nothing to do here.
132 } 131 }
133 } 132 }
134 133
135 @SmallTest 134 @SmallTest
136 @Feature({"Cronet"}) 135 @Feature({"Cronet"})
137 public void testLegacyLoadUrl() throws Exception { 136 public void testLegacyLoadUrl() throws Exception {
138 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig(); 137 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig(nul l);
mef 2015/10/02 16:46:58 Can we get rid of null?
pauljensen 2015/10/02 18:23:15 I reverted this file.
139 config.enableLegacyMode(true); 138 config.enableLegacyMode(true);
140 // TODO(mef) fix tests so that library isn't loaded for legacy stack 139 // TODO(mef) fix tests so that library isn't loaded for legacy stack
141 config.setLibraryName("cronet_tests"); 140 config.setLibraryName("cronet_tests");
142 141
143 String[] commandLineArgs = { 142 String[] commandLineArgs = {
144 CronetTestActivity.CONFIG_KEY, config.toString() }; 143 CronetTestActivity.CONFIG_KEY, config.toString() };
145 CronetTestActivity activity = 144 CronetTestActivity activity =
146 launchCronetTestAppWithUrlAndCommandLineArgs(URL, 145 launchCronetTestAppWithUrlAndCommandLineArgs(URL,
147 commandLineArgs); 146 commandLineArgs);
148 147
(...skipping 15 matching lines...) Expand all
164 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); 163 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
165 request.setHttpMethod("HEAD"); 164 request.setHttpMethod("HEAD");
166 request.start(); 165 request.start();
167 listener.blockForComplete(); 166 listener.blockForComplete();
168 assertEquals(200, listener.mHttpStatusCode); 167 assertEquals(200, listener.mHttpStatusCode);
169 // HEAD requests do not get any response data and Content-Length must be 168 // HEAD requests do not get any response data and Content-Length must be
170 // ignored. 169 // ignored.
171 assertEquals(0, listener.mResponseAsBytes.length); 170 assertEquals(0, listener.mResponseAsBytes.length);
172 } 171 }
173 } 172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698