| 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.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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 | 69 |
| 70 @SmallTest | 70 @SmallTest |
| 71 @Feature({"Cronet"}) | 71 @Feature({"Cronet"}) |
| 72 @OnlyRunNativeCronet // No NetLog from HttpURLConnection | 72 @OnlyRunNativeCronet // No NetLog from HttpURLConnection |
| 73 public void testNetLog() throws Exception { | 73 public void testNetLog() throws Exception { |
| 74 Context context = getContext(); | 74 Context context = getContext(); |
| 75 File directory = new File(PathUtils.getDataDirectory(context)); | 75 File directory = new File(PathUtils.getDataDirectory(context)); |
| 76 File file = File.createTempFile("cronet", "json", directory); | 76 File file = File.createTempFile("cronet", "json", directory); |
| 77 HttpUrlRequestFactory factory = HttpUrlRequestFactory.createFactory( | 77 HttpUrlRequestFactory factory = HttpUrlRequestFactory.createFactory( |
| 78 context, | 78 context, new CronetEngine.Builder(null /*context*/).setLibraryNa
me("cronet_tests")); |
| 79 new UrlRequestContextConfig().setLibraryName("cronet_tests")); | |
| 80 // Start NetLog immediately after the request context is created to make | 79 // Start NetLog immediately after the request context is created to make |
| 81 // sure that the call won't crash the app even when the native request | 80 // sure that the call won't crash the app even when the native request |
| 82 // context is not fully initialized. See crbug.com/470196. | 81 // context is not fully initialized. See crbug.com/470196. |
| 83 factory.startNetLogToFile(file.getPath(), false); | 82 factory.startNetLogToFile(file.getPath(), false); |
| 84 // Starts a request. | 83 // Starts a request. |
| 85 HashMap<String, String> headers = new HashMap<String, String>(); | 84 HashMap<String, String> headers = new HashMap<String, String>(); |
| 86 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); | 85 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); |
| 87 HttpUrlRequest request = factory.createRequest( | 86 HttpUrlRequest request = factory.createRequest( |
| 88 mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener)
; | 87 mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener)
; |
| 89 request.start(); | 88 request.start(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener)
; | 171 mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener)
; |
| 173 request.setHttpMethod("HEAD"); | 172 request.setHttpMethod("HEAD"); |
| 174 request.start(); | 173 request.start(); |
| 175 listener.blockForComplete(); | 174 listener.blockForComplete(); |
| 176 assertEquals(200, listener.mHttpStatusCode); | 175 assertEquals(200, listener.mHttpStatusCode); |
| 177 // HEAD requests do not get any response data and Content-Length must be | 176 // HEAD requests do not get any response data and Content-Length must be |
| 178 // ignored. | 177 // ignored. |
| 179 assertEquals(0, listener.mResponseAsBytes.length); | 178 assertEquals(0, listener.mResponseAsBytes.length); |
| 180 } | 179 } |
| 181 } | 180 } |
| OLD | NEW |