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