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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 context, |
65 new UrlRequestContextConfig().setLibraryName("cronet_tests")); | 65 new UrlRequestContextConfig().setLibraryName("cronet_tests")); |
66 // Start NetLog immediately after the request context is created to make | 66 // 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 | 67 // sure that the call won't crash the app even when the native request |
68 // context is not fully initialized. See crbug.com/470196. | 68 // context is not fully initialized. See crbug.com/470196. |
69 factory.startNetLogToFile(file.getPath()); | 69 factory.startNetLogToFile(file.getPath(), false); |
70 // Starts a request. | 70 // Starts a request. |
71 HashMap<String, String> headers = new HashMap<String, String>(); | 71 HashMap<String, String> headers = new HashMap<String, String>(); |
72 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); | 72 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); |
73 HttpUrlRequest request = factory.createRequest( | 73 HttpUrlRequest request = factory.createRequest( |
74 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); | 74 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); |
75 request.start(); | 75 request.start(); |
76 listener.blockForComplete(); | 76 listener.blockForComplete(); |
77 factory.stopNetLog(); | 77 factory.stopNetLog(); |
78 assertTrue(file.exists()); | 78 assertTrue(file.exists()); |
79 assertTrue(file.length() != 0); | 79 assertTrue(file.length() != 0); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); | 164 URL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener); |
165 request.setHttpMethod("HEAD"); | 165 request.setHttpMethod("HEAD"); |
166 request.start(); | 166 request.start(); |
167 listener.blockForComplete(); | 167 listener.blockForComplete(); |
168 assertEquals(200, listener.mHttpStatusCode); | 168 assertEquals(200, listener.mHttpStatusCode); |
169 // HEAD requests do not get any response data and Content-Length must be | 169 // HEAD requests do not get any response data and Content-Length must be |
170 // ignored. | 170 // ignored. |
171 assertEquals(0, listener.mResponseAsBytes.length); | 171 assertEquals(0, listener.mResponseAsBytes.length); |
172 } | 172 } |
173 } | 173 } |
OLD | NEW |