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 static org.chromium.base.CollectionUtil.newHashSet; | 7 import static org.chromium.base.CollectionUtil.newHashSet; |
8 | 8 |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.content.ContextWrapper; | 10 import android.content.ContextWrapper; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return mThroughputObservationCount; | 128 return mThroughputObservationCount; |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 @SmallTest | 132 @SmallTest |
133 @Feature({"Cronet"}) | 133 @Feature({"Cronet"}) |
134 public void testConfigUserAgent() throws Exception { | 134 public void testConfigUserAgent() throws Exception { |
135 String userAgentName = "User-Agent"; | 135 String userAgentName = "User-Agent"; |
136 String userAgentValue = "User-Agent-Value"; | 136 String userAgentValue = "User-Agent-Value"; |
137 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC
ontext()); | 137 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC
ontext()); |
| 138 if (testingJavaImpl()) { |
| 139 cronetEngineBuilder.enableLegacyMode(true); |
| 140 } |
138 cronetEngineBuilder.setUserAgent(userAgentValue); | 141 cronetEngineBuilder.setUserAgent(userAgentValue); |
139 cronetEngineBuilder.setLibraryName("cronet_tests"); | 142 cronetEngineBuilder.setLibraryName("cronet_tests"); |
140 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder( | 143 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder( |
141 TEST_URL, cronetEngineBuilder); | 144 TEST_URL, cronetEngineBuilder); |
| 145 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re
turns false if it's |
| 146 // already running |
142 assertTrue(NativeTestServer.startNativeTestServer(getContext())); | 147 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
143 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 148 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
144 UrlRequest.Builder urlRequestBuilder = | 149 UrlRequest.Builder urlRequestBuilder = |
145 new UrlRequest.Builder(NativeTestServer.getEchoHeaderURL(userAge
ntName), callback, | 150 new UrlRequest.Builder(NativeTestServer.getEchoHeaderURL(userAge
ntName), callback, |
146 callback.getExecutor(), mTestFramework.mCronetEngine); | 151 callback.getExecutor(), mTestFramework.mCronetEngine); |
147 urlRequestBuilder.build().start(); | 152 urlRequestBuilder.build().start(); |
148 callback.blockForDone(); | 153 callback.blockForDone(); |
149 assertEquals(userAgentValue, callback.mResponseAsString); | 154 assertEquals(userAgentValue, callback.mResponseAsString); |
150 } | 155 } |
151 | 156 |
152 @SmallTest | 157 @SmallTest |
153 @Feature({"Cronet"}) | 158 @Feature({"Cronet"}) |
| 159 @OnlyRunNativeCronet |
154 // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed. | 160 // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed. |
155 @SuppressWarnings("deprecation") | 161 @SuppressWarnings("deprecation") |
156 public void testDataReductionProxyEnabled() throws Exception { | 162 public void testDataReductionProxyEnabled() throws Exception { |
157 mTestFramework = startCronetTestFrameworkAndSkipLibraryInit(); | 163 mTestFramework = startCronetTestFrameworkAndSkipLibraryInit(); |
158 | 164 |
159 // Ensure native code is loaded before trying to start test server. | 165 // Ensure native code is loaded before trying to start test server. |
160 new CronetEngine.Builder(getContext()).setLibraryName("cronet_tests").bu
ild().shutdown(); | 166 new CronetEngine.Builder(getContext()).setLibraryName("cronet_tests").bu
ild().shutdown(); |
161 | 167 |
162 assertTrue(NativeTestServer.startNativeTestServer(getContext())); | 168 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
163 if (!NativeTestServer.isDataReductionProxySupported()) { | 169 if (!NativeTestServer.isDataReductionProxySupported()) { |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 e.getMessage()); | 559 e.getMessage()); |
554 } | 560 } |
555 callback.waitForNextStep(); | 561 callback.waitForNextStep(); |
556 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); | 562 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); |
557 urlRequest.cancel(); | 563 urlRequest.cancel(); |
558 mTestFramework.mCronetEngine.shutdown(); | 564 mTestFramework.mCronetEngine.shutdown(); |
559 } | 565 } |
560 | 566 |
561 @SmallTest | 567 @SmallTest |
562 @Feature({"Cronet"}) | 568 @Feature({"Cronet"}) |
| 569 @OnlyRunNativeCronet // No netlogs for pure java impl |
563 public void testNetLog() throws Exception { | 570 public void testNetLog() throws Exception { |
564 Context context = getContext(); | 571 Context context = getContext(); |
565 File directory = new File(PathUtils.getDataDirectory(context)); | 572 File directory = new File(PathUtils.getDataDirectory(context)); |
566 File file = File.createTempFile("cronet", "json", directory); | 573 File file = File.createTempFile("cronet", "json", directory); |
567 CronetEngine cronetEngine = new CronetUrlRequestContext( | 574 CronetEngine cronetEngine = new CronetUrlRequestContext( |
568 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 575 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
569 // Start NetLog immediately after the request context is created to make | 576 // Start NetLog immediately after the request context is created to make |
570 // sure that the call won't crash the app even when the native request | 577 // sure that the call won't crash the app even when the native request |
571 // context is not fully initialized. See crbug.com/470196. | 578 // context is not fully initialized. See crbug.com/470196. |
572 cronetEngine.startNetLogToFile(file.getPath(), false); | 579 cronetEngine.startNetLogToFile(file.getPath(), false); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 mTestFramework.mCronetEngine.stopNetLog(); | 662 mTestFramework.mCronetEngine.stopNetLog(); |
656 assertTrue(file.exists()); | 663 assertTrue(file.exists()); |
657 assertTrue(file.length() != 0); | 664 assertTrue(file.length() != 0); |
658 assertFalse(hasBytesInNetLog(file)); | 665 assertFalse(hasBytesInNetLog(file)); |
659 assertTrue(file.delete()); | 666 assertTrue(file.delete()); |
660 assertTrue(!file.exists()); | 667 assertTrue(!file.exists()); |
661 } | 668 } |
662 | 669 |
663 @SmallTest | 670 @SmallTest |
664 @Feature({"Cronet"}) | 671 @Feature({"Cronet"}) |
| 672 @OnlyRunNativeCronet |
665 public void testNetLogWithBytes() throws Exception { | 673 public void testNetLogWithBytes() throws Exception { |
666 Context context = getContext(); | 674 Context context = getContext(); |
667 File directory = new File(PathUtils.getDataDirectory(context)); | 675 File directory = new File(PathUtils.getDataDirectory(context)); |
668 File file = File.createTempFile("cronet", "json", directory); | 676 File file = File.createTempFile("cronet", "json", directory); |
669 CronetEngine cronetEngine = new CronetUrlRequestContext( | 677 CronetEngine cronetEngine = new CronetUrlRequestContext( |
670 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 678 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
671 // Start NetLog with logAll as true. | 679 // Start NetLog with logAll as true. |
672 cronetEngine.startNetLogToFile(file.getPath(), true); | 680 cronetEngine.startNetLogToFile(file.getPath(), true); |
673 // Start a request. | 681 // Start a request. |
674 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 682 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 if (disableCache) { | 733 if (disableCache) { |
726 urlRequestBuilder.disableCache(); | 734 urlRequestBuilder.disableCache(); |
727 } | 735 } |
728 urlRequestBuilder.build().start(); | 736 urlRequestBuilder.build().start(); |
729 callback.blockForDone(); | 737 callback.blockForDone(); |
730 assertEquals(expectCached, callback.mResponseInfo.wasCached()); | 738 assertEquals(expectCached, callback.mResponseInfo.wasCached()); |
731 } | 739 } |
732 | 740 |
733 @SmallTest | 741 @SmallTest |
734 @Feature({"Cronet"}) | 742 @Feature({"Cronet"}) |
| 743 @OnlyRunNativeCronet |
735 public void testEnableHttpCacheDisabled() throws Exception { | 744 public void testEnableHttpCacheDisabled() throws Exception { |
736 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); | 745 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); |
737 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 746 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
738 checkRequestCaching(url, false); | 747 checkRequestCaching(url, false); |
739 checkRequestCaching(url, false); | 748 checkRequestCaching(url, false); |
740 checkRequestCaching(url, false); | 749 checkRequestCaching(url, false); |
741 } | 750 } |
742 | 751 |
743 @SmallTest | 752 @SmallTest |
744 @Feature({"Cronet"}) | 753 @Feature({"Cronet"}) |
(...skipping 12 matching lines...) Expand all Loading... |
757 enableCache(CronetEngine.Builder.HTTP_CACHE_DISK); | 766 enableCache(CronetEngine.Builder.HTTP_CACHE_DISK); |
758 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 767 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
759 checkRequestCaching(url, false); | 768 checkRequestCaching(url, false); |
760 checkRequestCaching(url, true); | 769 checkRequestCaching(url, true); |
761 NativeTestServer.shutdownNativeTestServer(); | 770 NativeTestServer.shutdownNativeTestServer(); |
762 checkRequestCaching(url, true); | 771 checkRequestCaching(url, true); |
763 } | 772 } |
764 | 773 |
765 @SmallTest | 774 @SmallTest |
766 @Feature({"Cronet"}) | 775 @Feature({"Cronet"}) |
| 776 @OnlyRunNativeCronet |
767 public void testEnableHttpCacheDiskNoHttp() throws Exception { | 777 public void testEnableHttpCacheDiskNoHttp() throws Exception { |
768 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); | 778 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); |
769 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 779 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
770 checkRequestCaching(url, false); | 780 checkRequestCaching(url, false); |
771 checkRequestCaching(url, false); | 781 checkRequestCaching(url, false); |
772 checkRequestCaching(url, false); | 782 checkRequestCaching(url, false); |
773 } | 783 } |
774 | 784 |
775 @SmallTest | 785 @SmallTest |
776 @Feature({"Cronet"}) | 786 @Feature({"Cronet"}) |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext()))
; | 954 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext()))
; |
945 nativeVerifyUrlRequestContextConfig( | 955 nativeVerifyUrlRequestContextConfig( |
946 CronetUrlRequestContext.createNativeUrlRequestContextConfig(buil
der), | 956 CronetUrlRequestContext.createNativeUrlRequestContextConfig(buil
der), |
947 CronetTestFramework.getTestStorage(getContext())); | 957 CronetTestFramework.getTestStorage(getContext())); |
948 } | 958 } |
949 | 959 |
950 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon
fig() is properly | 960 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon
fig() is properly |
951 // translated to a native UrlRequestContextConfig. | 961 // translated to a native UrlRequestContextConfig. |
952 private static native void nativeVerifyUrlRequestContextConfig(long config,
String storagePath); | 962 private static native void nativeVerifyUrlRequestContextConfig(long config,
String storagePath); |
953 } | 963 } |
OLD | NEW |