| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 return mRttObservationCount; | 116 return mRttObservationCount; |
| 117 } | 117 } |
| 118 | 118 |
| 119 public int throughputObservationCount() { | 119 public int throughputObservationCount() { |
| 120 return mThroughputObservationCount; | 120 return mThroughputObservationCount; |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 @SmallTest | 124 @SmallTest |
| 125 @Feature({"Cronet"}) | 125 @Feature({"Cronet"}) |
| 126 @OnlyRunNativeCronet |
| 126 public void testConfigUserAgent() throws Exception { | 127 public void testConfigUserAgent() throws Exception { |
| 127 String userAgentName = "User-Agent"; | 128 String userAgentName = "User-Agent"; |
| 128 String userAgentValue = "User-Agent-Value"; | 129 String userAgentValue = "User-Agent-Value"; |
| 129 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC
ontext()); | 130 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC
ontext()); |
| 130 cronetEngineBuilder.setUserAgent(userAgentValue); | 131 cronetEngineBuilder.setUserAgent(userAgentValue); |
| 131 cronetEngineBuilder.setLibraryName("cronet_tests"); | 132 cronetEngineBuilder.setLibraryName("cronet_tests"); |
| 132 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder( | 133 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder( |
| 133 TEST_URL, cronetEngineBuilder); | 134 TEST_URL, cronetEngineBuilder); |
| 134 assertTrue(NativeTestServer.startNativeTestServer(getContext())); | 135 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
| 135 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 136 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 136 UrlRequest.Builder urlRequestBuilder = | 137 UrlRequest.Builder urlRequestBuilder = |
| 137 new UrlRequest.Builder(NativeTestServer.getEchoHeaderURL(userAge
ntName), callback, | 138 new UrlRequest.Builder(NativeTestServer.getEchoHeaderURL(userAge
ntName), callback, |
| 138 callback.getExecutor(), mTestFramework.mCronetEngine); | 139 callback.getExecutor(), mTestFramework.mCronetEngine); |
| 139 urlRequestBuilder.build().start(); | 140 urlRequestBuilder.build().start(); |
| 140 callback.blockForDone(); | 141 callback.blockForDone(); |
| 141 assertEquals(userAgentValue, callback.mResponseAsString); | 142 assertEquals(userAgentValue, callback.mResponseAsString); |
| 142 } | 143 } |
| 143 | 144 |
| 144 @SmallTest | 145 @SmallTest |
| 145 @Feature({"Cronet"}) | 146 @Feature({"Cronet"}) |
| 147 @OnlyRunNativeCronet |
| 146 // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed. | 148 // TODO(xunjieli): Remove annotation after crbug.com/539519 is fixed. |
| 147 @SuppressWarnings("deprecation") | 149 @SuppressWarnings("deprecation") |
| 148 public void testDataReductionProxyEnabled() throws Exception { | 150 public void testDataReductionProxyEnabled() throws Exception { |
| 149 mTestFramework = startCronetTestFrameworkAndSkipFactoryInit(); | 151 mTestFramework = startCronetTestFrameworkAndSkipFactoryInit(); |
| 150 | 152 |
| 151 // Ensure native code is loaded before trying to start test server. | 153 // Ensure native code is loaded before trying to start test server. |
| 152 new CronetEngine.Builder(getContext()).setLibraryName("cronet_tests").bu
ild().shutdown(); | 154 new CronetEngine.Builder(getContext()).setLibraryName("cronet_tests").bu
ild().shutdown(); |
| 153 | 155 |
| 154 assertTrue(NativeTestServer.startNativeTestServer(getContext())); | 156 assertTrue(NativeTestServer.startNativeTestServer(getContext())); |
| 155 if (!NativeTestServer.isDataReductionProxySupported()) { | 157 if (!NativeTestServer.isDataReductionProxySupported()) { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 e.getMessage()); | 422 e.getMessage()); |
| 421 } | 423 } |
| 422 callback.waitForNextStep(); | 424 callback.waitForNextStep(); |
| 423 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); | 425 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); |
| 424 urlRequest.cancel(); | 426 urlRequest.cancel(); |
| 425 mTestFramework.mCronetEngine.shutdown(); | 427 mTestFramework.mCronetEngine.shutdown(); |
| 426 } | 428 } |
| 427 | 429 |
| 428 @SmallTest | 430 @SmallTest |
| 429 @Feature({"Cronet"}) | 431 @Feature({"Cronet"}) |
| 432 @OnlyRunNativeCronet |
| 430 public void testNetLog() throws Exception { | 433 public void testNetLog() throws Exception { |
| 431 Context context = getContext(); | 434 Context context = getContext(); |
| 432 File directory = new File(PathUtils.getDataDirectory(context)); | 435 File directory = new File(PathUtils.getDataDirectory(context)); |
| 433 File file = File.createTempFile("cronet", "json", directory); | 436 File file = File.createTempFile("cronet", "json", directory); |
| 434 CronetEngine cronetEngine = new CronetUrlRequestContext( | 437 CronetEngine cronetEngine = new CronetUrlRequestContext( |
| 435 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 438 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
| 436 // Start NetLog immediately after the request context is created to make | 439 // Start NetLog immediately after the request context is created to make |
| 437 // sure that the call won't crash the app even when the native request | 440 // sure that the call won't crash the app even when the native request |
| 438 // context is not fully initialized. See crbug.com/470196. | 441 // context is not fully initialized. See crbug.com/470196. |
| 439 cronetEngine.startNetLogToFile(file.getPath(), false); | 442 cronetEngine.startNetLogToFile(file.getPath(), false); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 mTestFramework.mCronetEngine.stopNetLog(); | 525 mTestFramework.mCronetEngine.stopNetLog(); |
| 523 assertTrue(file.exists()); | 526 assertTrue(file.exists()); |
| 524 assertTrue(file.length() != 0); | 527 assertTrue(file.length() != 0); |
| 525 assertFalse(hasBytesInNetLog(file)); | 528 assertFalse(hasBytesInNetLog(file)); |
| 526 assertTrue(file.delete()); | 529 assertTrue(file.delete()); |
| 527 assertTrue(!file.exists()); | 530 assertTrue(!file.exists()); |
| 528 } | 531 } |
| 529 | 532 |
| 530 @SmallTest | 533 @SmallTest |
| 531 @Feature({"Cronet"}) | 534 @Feature({"Cronet"}) |
| 535 @OnlyRunNativeCronet |
| 532 public void testNetLogWithBytes() throws Exception { | 536 public void testNetLogWithBytes() throws Exception { |
| 533 Context context = getContext(); | 537 Context context = getContext(); |
| 534 File directory = new File(PathUtils.getDataDirectory(context)); | 538 File directory = new File(PathUtils.getDataDirectory(context)); |
| 535 File file = File.createTempFile("cronet", "json", directory); | 539 File file = File.createTempFile("cronet", "json", directory); |
| 536 CronetEngine cronetEngine = new CronetUrlRequestContext( | 540 CronetEngine cronetEngine = new CronetUrlRequestContext( |
| 537 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 541 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
| 538 // Start NetLog with logAll as true. | 542 // Start NetLog with logAll as true. |
| 539 cronetEngine.startNetLogToFile(file.getPath(), true); | 543 cronetEngine.startNetLogToFile(file.getPath(), true); |
| 540 // Start a request. | 544 // Start a request. |
| 541 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 545 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 if (disableCache) { | 596 if (disableCache) { |
| 593 urlRequestBuilder.disableCache(); | 597 urlRequestBuilder.disableCache(); |
| 594 } | 598 } |
| 595 urlRequestBuilder.build().start(); | 599 urlRequestBuilder.build().start(); |
| 596 callback.blockForDone(); | 600 callback.blockForDone(); |
| 597 assertEquals(expectCached, callback.mResponseInfo.wasCached()); | 601 assertEquals(expectCached, callback.mResponseInfo.wasCached()); |
| 598 } | 602 } |
| 599 | 603 |
| 600 @SmallTest | 604 @SmallTest |
| 601 @Feature({"Cronet"}) | 605 @Feature({"Cronet"}) |
| 606 @OnlyRunNativeCronet |
| 602 public void testEnableHttpCacheDisabled() throws Exception { | 607 public void testEnableHttpCacheDisabled() throws Exception { |
| 603 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); | 608 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); |
| 604 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 609 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
| 605 checkRequestCaching(url, false); | 610 checkRequestCaching(url, false); |
| 606 checkRequestCaching(url, false); | 611 checkRequestCaching(url, false); |
| 607 checkRequestCaching(url, false); | 612 checkRequestCaching(url, false); |
| 608 } | 613 } |
| 609 | 614 |
| 610 @SmallTest | 615 @SmallTest |
| 611 @Feature({"Cronet"}) | 616 @Feature({"Cronet"}) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 624 enableCache(CronetEngine.Builder.HTTP_CACHE_DISK); | 629 enableCache(CronetEngine.Builder.HTTP_CACHE_DISK); |
| 625 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 630 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
| 626 checkRequestCaching(url, false); | 631 checkRequestCaching(url, false); |
| 627 checkRequestCaching(url, true); | 632 checkRequestCaching(url, true); |
| 628 NativeTestServer.shutdownNativeTestServer(); | 633 NativeTestServer.shutdownNativeTestServer(); |
| 629 checkRequestCaching(url, true); | 634 checkRequestCaching(url, true); |
| 630 } | 635 } |
| 631 | 636 |
| 632 @SmallTest | 637 @SmallTest |
| 633 @Feature({"Cronet"}) | 638 @Feature({"Cronet"}) |
| 639 @OnlyRunNativeCronet |
| 634 public void testEnableHttpCacheDiskNoHttp() throws Exception { | 640 public void testEnableHttpCacheDiskNoHttp() throws Exception { |
| 635 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); | 641 enableCache(CronetEngine.Builder.HTTP_CACHE_DISABLED); |
| 636 String url = NativeTestServer.getFileURL("/cacheable.txt"); | 642 String url = NativeTestServer.getFileURL("/cacheable.txt"); |
| 637 checkRequestCaching(url, false); | 643 checkRequestCaching(url, false); |
| 638 checkRequestCaching(url, false); | 644 checkRequestCaching(url, false); |
| 639 checkRequestCaching(url, false); | 645 checkRequestCaching(url, false); |
| 640 } | 646 } |
| 641 | 647 |
| 642 @SmallTest | 648 @SmallTest |
| 643 @Feature({"Cronet"}) | 649 @Feature({"Cronet"}) |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 791 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 786 UrlRequest.Builder builder = new UrlRequest.Builder( | 792 UrlRequest.Builder builder = new UrlRequest.Builder( |
| 787 TEST_URL, callback, callback.getExecutor(), mTestFramework.mCron
etEngine); | 793 TEST_URL, callback, callback.getExecutor(), mTestFramework.mCron
etEngine); |
| 788 builder.build().start(); | 794 builder.build().start(); |
| 789 callback.blockForDone(); | 795 callback.blockForDone(); |
| 790 byte delta2[] = mTestFramework.mCronetEngine.getGlobalMetricsDeltas(); | 796 byte delta2[] = mTestFramework.mCronetEngine.getGlobalMetricsDeltas(); |
| 791 assertTrue(delta2.length != 0); | 797 assertTrue(delta2.length != 0); |
| 792 assertFalse(Arrays.equals(delta1, delta2)); | 798 assertFalse(Arrays.equals(delta1, delta2)); |
| 793 } | 799 } |
| 794 } | 800 } |
| OLD | NEW |