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.content.ContextWrapper; | 8 import android.content.ContextWrapper; |
9 import android.os.ConditionVariable; | 9 import android.os.ConditionVariable; |
10 import android.os.Handler; | 10 import android.os.Handler; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return mRttObservationCount; | 118 return mRttObservationCount; |
119 } | 119 } |
120 | 120 |
121 public int throughputObservationCount() { | 121 public int throughputObservationCount() { |
122 return mThroughputObservationCount; | 122 return mThroughputObservationCount; |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 @SmallTest | 126 @SmallTest |
127 @Feature({"Cronet"}) | 127 @Feature({"Cronet"}) |
| 128 @OnlyRunNativeCronet |
| 129 // Depends on creating a new CronetEngine, which the test framework doesn't
yet support |
128 public void testConfigUserAgent() throws Exception { | 130 public void testConfigUserAgent() throws Exception { |
129 String userAgentName = "User-Agent"; | 131 String userAgentName = "User-Agent"; |
130 String userAgentValue = "User-Agent-Value"; | 132 String userAgentValue = "User-Agent-Value"; |
131 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC
ontext()); | 133 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC
ontext()); |
132 cronetEngineBuilder.setUserAgent(userAgentValue); | 134 cronetEngineBuilder.setUserAgent(userAgentValue); |
133 cronetEngineBuilder.setLibraryName("cronet_tests"); | 135 cronetEngineBuilder.setLibraryName("cronet_tests"); |
134 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder( | 136 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder( |
135 TEST_URL, cronetEngineBuilder); | 137 TEST_URL, cronetEngineBuilder); |
136 assertTrue(NativeTestServer.startNativeTestServer(getContext())); | 138 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
137 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 139 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
138 UrlRequest.Builder urlRequestBuilder = | 140 UrlRequest.Builder urlRequestBuilder = |
139 new UrlRequest.Builder(NativeTestServer.getEchoHeaderURL(userAge
ntName), callback, | 141 new UrlRequest.Builder(NativeTestServer.getEchoHeaderURL(userAge
ntName), callback, |
140 callback.getExecutor(), mTestFramework.mCronetEngine); | 142 callback.getExecutor(), mTestFramework.mCronetEngine); |
141 urlRequestBuilder.build().start(); | 143 urlRequestBuilder.build().start(); |
142 callback.blockForDone(); | 144 callback.blockForDone(); |
143 assertEquals(userAgentValue, callback.mResponseAsString); | 145 assertEquals(userAgentValue, callback.mResponseAsString); |
144 } | 146 } |
145 | 147 |
146 @SmallTest | 148 @SmallTest |
147 @Feature({"Cronet"}) | 149 @Feature({"Cronet"}) |
| 150 @OnlyRunNativeCronet |
148 // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed. | 151 // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed. |
149 @SuppressWarnings("deprecation") | 152 @SuppressWarnings("deprecation") |
150 public void testDataReductionProxyEnabled() throws Exception { | 153 public void testDataReductionProxyEnabled() throws Exception { |
151 mTestFramework = startCronetTestFrameworkAndSkipLibraryInit(); | 154 mTestFramework = startCronetTestFrameworkAndSkipLibraryInit(); |
152 | 155 |
153 // Ensure native code is loaded before trying to start test server. | 156 // Ensure native code is loaded before trying to start test server. |
154 new CronetEngine.Builder(getContext()).setLibraryName("cronet_tests").bu
ild().shutdown(); | 157 new CronetEngine.Builder(getContext()).setLibraryName("cronet_tests").bu
ild().shutdown(); |
155 | 158 |
156 assertTrue(NativeTestServer.startNativeTestServer(getContext())); | 159 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
157 if (!NativeTestServer.isDataReductionProxySupported()) { | 160 if (!NativeTestServer.isDataReductionProxySupported()) { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 e.getMessage()); | 425 e.getMessage()); |
423 } | 426 } |
424 callback.waitForNextStep(); | 427 callback.waitForNextStep(); |
425 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); | 428 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); |
426 urlRequest.cancel(); | 429 urlRequest.cancel(); |
427 mTestFramework.mCronetEngine.shutdown(); | 430 mTestFramework.mCronetEngine.shutdown(); |
428 } | 431 } |
429 | 432 |
430 @SmallTest | 433 @SmallTest |
431 @Feature({"Cronet"}) | 434 @Feature({"Cronet"}) |
| 435 @OnlyRunNativeCronet |
432 public void testNetLog() throws Exception { | 436 public void testNetLog() throws Exception { |
433 Context context = getContext(); | 437 Context context = getContext(); |
434 File directory = new File(PathUtils.getDataDirectory(context)); | 438 File directory = new File(PathUtils.getDataDirectory(context)); |
435 File file = File.createTempFile("cronet", "json", directory); | 439 File file = File.createTempFile("cronet", "json", directory); |
436 CronetEngine cronetEngine = new CronetUrlRequestContext( | 440 CronetEngine cronetEngine = new CronetUrlRequestContext( |
437 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 441 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
438 // Start NetLog immediately after the request context is created to make | 442 // Start NetLog immediately after the request context is created to make |
439 // sure that the call won't crash the app even when the native request | 443 // sure that the call won't crash the app even when the native request |
440 // context is not fully initialized. See crbug.com/470196. | 444 // context is not fully initialized. See crbug.com/470196. |
441 cronetEngine.startNetLogToFile(file.getPath(), false); | 445 cronetEngine.startNetLogToFile(file.getPath(), false); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 mTestFramework.mCronetEngine.stopNetLog(); | 528 mTestFramework.mCronetEngine.stopNetLog(); |
525 assertTrue(file.exists()); | 529 assertTrue(file.exists()); |
526 assertTrue(file.length() != 0); | 530 assertTrue(file.length() != 0); |
527 assertFalse(hasBytesInNetLog(file)); | 531 assertFalse(hasBytesInNetLog(file)); |
528 assertTrue(file.delete()); | 532 assertTrue(file.delete()); |
529 assertTrue(!file.exists()); | 533 assertTrue(!file.exists()); |
530 } | 534 } |
531 | 535 |
532 @SmallTest | 536 @SmallTest |
533 @Feature({"Cronet"}) | 537 @Feature({"Cronet"}) |
| 538 @OnlyRunNativeCronet |
534 public void testNetLogWithBytes() throws Exception { | 539 public void testNetLogWithBytes() throws Exception { |
535 Context context = getContext(); | 540 Context context = getContext(); |
536 File directory = new File(PathUtils.getDataDirectory(context)); | 541 File directory = new File(PathUtils.getDataDirectory(context)); |
537 File file = File.createTempFile("cronet", "json", directory); | 542 File file = File.createTempFile("cronet", "json", directory); |
538 CronetEngine cronetEngine = new CronetUrlRequestContext( | 543 CronetEngine cronetEngine = new CronetUrlRequestContext( |
539 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 544 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
540 // Start NetLog with logAll as true. | 545 // Start NetLog with logAll as true. |
541 cronetEngine.startNetLogToFile(file.getPath(), true); | 546 cronetEngine.startNetLogToFile(file.getPath(), true); |
542 // Start a request. | 547 // Start a request. |
543 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 548 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 if (disableCache) { | 599 if (disableCache) { |
595 urlRequestBuilder.disableCache(); | 600 urlRequestBuilder.disableCache(); |
596 } | 601 } |
597 urlRequestBuilder.build().start(); | 602 urlRequestBuilder.build().start(); |
598 callback.blockForDone(); | 603 callback.blockForDone(); |
599 assertEquals(expectCached, callback.mResponseInfo.wasCached()); | 604 assertEquals(expectCached, callback.mResponseInfo.wasCached()); |
600 } | 605 } |
601 | 606 |
602 @SmallTest | 607 @SmallTest |
603 @Feature({"Cronet"}) | 608 @Feature({"Cronet"}) |
| 609 @OnlyRunNativeCronet |
604 public void testEnableHttpCacheDisabled() throws Exception { | 610 public void testEnableHttpCacheDisabled() throws Exception { |
605 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); | 611 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); |
606 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 612 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
607 checkRequestCaching(url, false); | 613 checkRequestCaching(url, false); |
608 checkRequestCaching(url, false); | 614 checkRequestCaching(url, false); |
609 checkRequestCaching(url, false); | 615 checkRequestCaching(url, false); |
610 } | 616 } |
611 | 617 |
612 @SmallTest | 618 @SmallTest |
613 @Feature({"Cronet"}) | 619 @Feature({"Cronet"}) |
(...skipping 12 matching lines...) Expand all Loading... |
626 enableCache(CronetEngine.Builder.HTTP_CACHE_DISK); | 632 enableCache(CronetEngine.Builder.HTTP_CACHE_DISK); |
627 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 633 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
628 checkRequestCaching(url, false); | 634 checkRequestCaching(url, false); |
629 checkRequestCaching(url, true); | 635 checkRequestCaching(url, true); |
630 NativeTestServer.shutdownNativeTestServer(); | 636 NativeTestServer.shutdownNativeTestServer(); |
631 checkRequestCaching(url, true); | 637 checkRequestCaching(url, true); |
632 } | 638 } |
633 | 639 |
634 @SmallTest | 640 @SmallTest |
635 @Feature({"Cronet"}) | 641 @Feature({"Cronet"}) |
| 642 @OnlyRunNativeCronet |
636 public void testEnableHttpCacheDiskNoHttp() throws Exception { | 643 public void testEnableHttpCacheDiskNoHttp() throws Exception { |
637 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); | 644 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); |
638 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 645 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
639 checkRequestCaching(url, false); | 646 checkRequestCaching(url, false); |
640 checkRequestCaching(url, false); | 647 checkRequestCaching(url, false); |
641 checkRequestCaching(url, false); | 648 checkRequestCaching(url, false); |
642 } | 649 } |
643 | 650 |
644 @SmallTest | 651 @SmallTest |
645 @Feature({"Cronet"}) | 652 @Feature({"Cronet"}) |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext()))
; | 820 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext()))
; |
814 nativeVerifyUrlRequestContextConfig( | 821 nativeVerifyUrlRequestContextConfig( |
815 CronetUrlRequestContext.createNativeUrlRequestContextConfig(buil
der), | 822 CronetUrlRequestContext.createNativeUrlRequestContextConfig(buil
der), |
816 CronetTestFramework.getTestStorage(getContext())); | 823 CronetTestFramework.getTestStorage(getContext())); |
817 } | 824 } |
818 | 825 |
819 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon
fig() is properly | 826 // Verifies that CronetEngine.Builder config from testCronetEngineBuilderCon
fig() is properly |
820 // translated to a native UrlRequestContextConfig. | 827 // translated to a native UrlRequestContextConfig. |
821 private static native void nativeVerifyUrlRequestContextConfig(long config,
String storagePath); | 828 private static native void nativeVerifyUrlRequestContextConfig(long config,
String storagePath); |
822 } | 829 } |
OLD | NEW |