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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // Make sure that the URL is set as expected. | 65 // Make sure that the URL is set as expected. |
66 assertEquals(mUrl, testFramework.getUrl()); | 66 assertEquals(mUrl, testFramework.getUrl()); |
67 assertEquals(200, testFramework.getHttpStatusCode()); | 67 assertEquals(200, testFramework.getHttpStatusCode()); |
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()); |
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, new CronetEngine.Builder(null /*context*/).setLibraryNa
me("cronet_tests")); | 78 context, new CronetEngine.Builder(null /*context*/).setLibraryNa
me("cronet_tests")); |
79 // Start NetLog immediately after the request context is created to make | 79 // Start NetLog immediately after the request context is created to make |
80 // 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 |
81 // context is not fully initialized. See crbug.com/470196. | 81 // context is not fully initialized. See crbug.com/470196. |
82 factory.startNetLogToFile(file.getPath(), false); | 82 factory.startNetLogToFile(file.getPath(), false); |
83 // Starts a request. | 83 // Starts a request. |
84 HashMap<String, String> headers = new HashMap<String, String>(); | 84 HashMap<String, String> headers = new HashMap<String, String>(); |
85 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); | 85 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener)
; | 171 mUrl, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener)
; |
172 request.setHttpMethod("HEAD"); | 172 request.setHttpMethod("HEAD"); |
173 request.start(); | 173 request.start(); |
174 listener.blockForComplete(); | 174 listener.blockForComplete(); |
175 assertEquals(200, listener.mHttpStatusCode); | 175 assertEquals(200, listener.mHttpStatusCode); |
176 // 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 |
177 // ignored. | 177 // ignored. |
178 assertEquals(0, listener.mResponseAsBytes.length); | 178 assertEquals(0, listener.mResponseAsBytes.length); |
179 } | 179 } |
180 } | 180 } |
OLD | NEW |