Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java

Issue 2406273002: [Cronet] Test the libcronet that's shipped, not libcronet_test (Closed)
Patch Set: fix shutdown race Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 @SuppressWarnings("deprecation") 159 @SuppressWarnings("deprecation")
160 public void testConfigUserAgent() throws Exception { 160 public void testConfigUserAgent() throws Exception {
161 String userAgentName = "User-Agent"; 161 String userAgentName = "User-Agent";
162 String userAgentValue = "User-Agent-Value"; 162 String userAgentValue = "User-Agent-Value";
163 ExperimentalCronetEngine.Builder cronetEngineBuilder = 163 ExperimentalCronetEngine.Builder cronetEngineBuilder =
164 new ExperimentalCronetEngine.Builder(getContext()); 164 new ExperimentalCronetEngine.Builder(getContext());
165 if (testingJavaImpl()) { 165 if (testingJavaImpl()) {
166 cronetEngineBuilder.enableLegacyMode(true); 166 cronetEngineBuilder.enableLegacyMode(true);
167 } 167 }
168 cronetEngineBuilder.setUserAgent(userAgentValue); 168 cronetEngineBuilder.setUserAgent(userAgentValue);
169 CronetTestUtil.setLibraryName(cronetEngineBuilder, "cronet_tests");
170 final CronetTestFramework testFramework = 169 final CronetTestFramework testFramework =
171 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cron etEngineBuilder); 170 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cron etEngineBuilder);
172 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re turns false if it's 171 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re turns false if it's
173 // already running 172 // already running
174 assertTrue(NativeTestServer.startNativeTestServer(getContext())); 173 assertTrue(NativeTestServer.startNativeTestServer(getContext()));
175 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 174 TestUrlRequestCallback callback = new TestUrlRequestCallback();
176 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder( 175 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder(
177 NativeTestServer.getEchoHeaderURL(userAgentName), callback, call back.getExecutor()); 176 NativeTestServer.getEchoHeaderURL(userAgentName), callback, call back.getExecutor());
178 urlRequestBuilder.build().start(); 177 urlRequestBuilder.build().start();
179 callback.blockForDone(); 178 callback.blockForDone();
180 assertEquals(userAgentValue, callback.mResponseAsString); 179 assertEquals(userAgentValue, callback.mResponseAsString);
181 } 180 }
182 181
183 @SmallTest 182 @SmallTest
184 @Feature({"Cronet"}) 183 @Feature({"Cronet"})
185 @OnlyRunNativeCronet 184 @OnlyRunNativeCronet
186 public void testDataReductionProxyEnabled() throws Exception { 185 public void testDataReductionProxyEnabled() throws Exception {
187 final CronetTestFramework testFramework = startCronetTestFrameworkAndSki pLibraryInit(); 186 final CronetTestFramework testFramework = startCronetTestFrameworkAndSki pLibraryInit();
188 187
189 // Ensure native code is loaded before trying to start test server. 188 // Ensure native code is loaded before trying to start test server.
190 ExperimentalCronetEngine.Builder engineBuilder = 189 new ExperimentalCronetEngine.Builder(getContext()).build().shutdown();
191 new ExperimentalCronetEngine.Builder(getContext());
192 CronetTestUtil.setLibraryName(engineBuilder, "cronet_tests");
193 engineBuilder.build().shutdown();
194 190
195 assertTrue(NativeTestServer.startNativeTestServer(getContext())); 191 assertTrue(NativeTestServer.startNativeTestServer(getContext()));
196 if (!NativeTestServer.isDataReductionProxySupported()) { 192 if (!NativeTestServer.isDataReductionProxySupported()) {
197 return; 193 return;
198 } 194 }
199 String serverHostPort = NativeTestServer.getHostPort(); 195 String serverHostPort = NativeTestServer.getHostPort();
200 196
201 // Enable the Data Reduction Proxy and configure it to use the test 197 // Enable the Data Reduction Proxy and configure it to use the test
202 // server as its primary proxy, and to check successfully that this 198 // server as its primary proxy, and to check successfully that this
203 // proxy is OK to use. 199 // proxy is OK to use.
204 ExperimentalCronetEngine.Builder cronetEngineBuilder = 200 ExperimentalCronetEngine.Builder cronetEngineBuilder =
205 new ExperimentalCronetEngine.Builder(getContext()); 201 new ExperimentalCronetEngine.Builder(getContext());
206 cronetEngineBuilder.enableDataReductionProxy("test-key"); 202 cronetEngineBuilder.enableDataReductionProxy("test-key");
207 cronetEngineBuilder.setDataReductionProxyOptions(serverHostPort, "unused .net:9999", 203 cronetEngineBuilder.setDataReductionProxyOptions(serverHostPort, "unused .net:9999",
208 NativeTestServer.getFileURL("/secureproxychecksuccess.txt")); 204 NativeTestServer.getFileURL("/secureproxychecksuccess.txt"));
209 CronetTestUtil.setLibraryName(cronetEngineBuilder, "cronet_tests");
210 testFramework.mCronetEngine = (CronetEngineBase) cronetEngineBuilder.bui ld(); 205 testFramework.mCronetEngine = (CronetEngineBase) cronetEngineBuilder.bui ld();
211 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 206 TestUrlRequestCallback callback = new TestUrlRequestCallback();
212 207
213 // Construct and start a request that can only be returned by the test 208 // Construct and start a request that can only be returned by the test
214 // server. This request will fail if the configuration logic for the 209 // server. This request will fail if the configuration logic for the
215 // Data Reduction Proxy is not used. 210 // Data Reduction Proxy is not used.
216 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder( 211 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder(
217 "http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt", callback, 212 "http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt", callback,
218 callback.getExecutor()); 213 callback.getExecutor());
219 urlRequestBuilder.build().start(); 214 urlRequestBuilder.build().start();
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 testFramework.mCronetEngine.shutdown(); 538 testFramework.mCronetEngine.shutdown();
544 } 539 }
545 540
546 @SmallTest 541 @SmallTest
547 @Feature({"Cronet"}) 542 @Feature({"Cronet"})
548 @OnlyRunNativeCronet // No netlogs for pure java impl 543 @OnlyRunNativeCronet // No netlogs for pure java impl
549 public void testNetLog() throws Exception { 544 public void testNetLog() throws Exception {
550 Context context = getContext(); 545 Context context = getContext();
551 File directory = new File(PathUtils.getDataDirectory()); 546 File directory = new File(PathUtils.getDataDirectory());
552 File file = File.createTempFile("cronet", "json", directory); 547 File file = File.createTempFile("cronet", "json", directory);
553 CronetEngine cronetEngine = new CronetUrlRequestContext( 548 CronetEngine cronetEngine =
554 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 549 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
555 // Start NetLog immediately after the request context is created to make 550 // Start NetLog immediately after the request context is created to make
556 // sure that the call won't crash the app even when the native request 551 // sure that the call won't crash the app even when the native request
557 // context is not fully initialized. See crbug.com/470196. 552 // context is not fully initialized. See crbug.com/470196.
558 cronetEngine.startNetLogToFile(file.getPath(), false); 553 cronetEngine.startNetLogToFile(file.getPath(), false);
559 554
560 // Start a request. 555 // Start a request.
561 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 556 TestUrlRequestCallback callback = new TestUrlRequestCallback();
562 UrlRequest.Builder urlRequestBuilder = 557 UrlRequest.Builder urlRequestBuilder =
563 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor()); 558 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor());
564 urlRequestBuilder.build().start(); 559 urlRequestBuilder.build().start();
565 callback.blockForDone(); 560 callback.blockForDone();
566 cronetEngine.stopNetLog(); 561 cronetEngine.stopNetLog();
567 assertTrue(file.exists()); 562 assertTrue(file.exists());
568 assertTrue(file.length() != 0); 563 assertTrue(file.length() != 0);
569 assertFalse(hasBytesInNetLog(file)); 564 assertFalse(hasBytesInNetLog(file));
570 assertTrue(file.delete()); 565 assertTrue(file.delete());
571 assertTrue(!file.exists()); 566 assertTrue(!file.exists());
572 } 567 }
573 568
574 @SmallTest 569 @SmallTest
575 @Feature({"Cronet"}) 570 @Feature({"Cronet"})
576 @OnlyRunNativeCronet // No netlogs for pure java impl 571 @OnlyRunNativeCronet // No netlogs for pure java impl
577 public void testBoundedFileNetLog() throws Exception { 572 public void testBoundedFileNetLog() throws Exception {
578 Context context = getContext(); 573 Context context = getContext();
579 File directory = new File(PathUtils.getDataDirectory()); 574 File directory = new File(PathUtils.getDataDirectory());
580 File netLogDir = new File(directory, "NetLog"); 575 File netLogDir = new File(directory, "NetLog");
581 assertFalse(netLogDir.exists()); 576 assertFalse(netLogDir.exists());
582 assertTrue(netLogDir.mkdir()); 577 assertTrue(netLogDir.mkdir());
583 File eventFile = new File(netLogDir, "event_file_0.json"); 578 File eventFile = new File(netLogDir, "event_file_0.json");
584 CronetUrlRequestContext cronetEngine = new CronetUrlRequestContext( 579 CronetUrlRequestContext cronetEngine =
585 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 580 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
586 // Start NetLog immediately after the request context is created to make 581 // Start NetLog immediately after the request context is created to make
587 // sure that the call won't crash the app even when the native request 582 // sure that the call won't crash the app even when the native request
588 // context is not fully initialized. See crbug.com/470196. 583 // context is not fully initialized. See crbug.com/470196.
589 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE ); 584 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE );
590 585
591 // Start a request. 586 // Start a request.
592 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 587 TestUrlRequestCallback callback = new TestUrlRequestCallback();
593 UrlRequest.Builder urlRequestBuilder = 588 UrlRequest.Builder urlRequestBuilder =
594 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor()); 589 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor());
595 urlRequestBuilder.build().start(); 590 urlRequestBuilder.build().start();
596 callback.blockForDone(); 591 callback.blockForDone();
597 cronetEngine.stopNetLog(); 592 cronetEngine.stopNetLog();
598 assertTrue(eventFile.exists()); 593 assertTrue(eventFile.exists());
599 assertTrue(eventFile.length() != 0); 594 assertTrue(eventFile.length() != 0);
600 assertFalse(hasBytesInNetLog(eventFile)); 595 assertFalse(hasBytesInNetLog(eventFile));
601 FileUtils.recursivelyDeleteFile(netLogDir); 596 FileUtils.recursivelyDeleteFile(netLogDir);
602 assertFalse(netLogDir.exists()); 597 assertFalse(netLogDir.exists());
603 } 598 }
604 599
605 @SmallTest 600 @SmallTest
606 @Feature({"Cronet"}) 601 @Feature({"Cronet"})
607 @OnlyRunNativeCronet // No netlogs for pure java impl 602 @OnlyRunNativeCronet // No netlogs for pure java impl
608 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown() 603 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown()
609 // will take care of it. crbug.com/623701. 604 // will take care of it. crbug.com/623701.
610 public void testNoStopNetLog() throws Exception { 605 public void testNoStopNetLog() throws Exception {
611 Context context = getContext(); 606 Context context = getContext();
612 File directory = new File(PathUtils.getDataDirectory()); 607 File directory = new File(PathUtils.getDataDirectory());
613 File file = File.createTempFile("cronet", "json", directory); 608 File file = File.createTempFile("cronet", "json", directory);
614 CronetUrlRequestContext cronetEngine = new CronetUrlRequestContext( 609 CronetUrlRequestContext cronetEngine =
615 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 610 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
616 cronetEngine.startNetLogToFile(file.getPath(), false); 611 cronetEngine.startNetLogToFile(file.getPath(), false);
617 612
618 // Start a request. 613 // Start a request.
619 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 614 TestUrlRequestCallback callback = new TestUrlRequestCallback();
620 UrlRequest.Builder urlRequestBuilder = 615 UrlRequest.Builder urlRequestBuilder =
621 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor()); 616 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor());
622 urlRequestBuilder.build().start(); 617 urlRequestBuilder.build().start();
623 callback.blockForDone(); 618 callback.blockForDone();
624 // Shut down the engine without calling stopNetLog. 619 // Shut down the engine without calling stopNetLog.
625 cronetEngine.shutdown(); 620 cronetEngine.shutdown();
626 assertTrue(file.exists()); 621 assertTrue(file.exists());
627 assertTrue(file.length() != 0); 622 assertTrue(file.length() != 0);
628 assertFalse(hasBytesInNetLog(file)); 623 assertFalse(hasBytesInNetLog(file));
629 assertTrue(file.delete()); 624 assertTrue(file.delete());
630 assertTrue(!file.exists()); 625 assertTrue(!file.exists());
631 } 626 }
632 627
633 @SmallTest 628 @SmallTest
634 @Feature({"Cronet"}) 629 @Feature({"Cronet"})
635 @OnlyRunNativeCronet // No netlogs for pure java impl 630 @OnlyRunNativeCronet // No netlogs for pure java impl
636 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown() 631 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown()
637 // will take care of it. crbug.com/623701. 632 // will take care of it. crbug.com/623701.
638 public void testNoStopBoundedFileNetLog() throws Exception { 633 public void testNoStopBoundedFileNetLog() throws Exception {
639 Context context = getContext(); 634 Context context = getContext();
640 File directory = new File(PathUtils.getDataDirectory()); 635 File directory = new File(PathUtils.getDataDirectory());
641 File netLogDir = new File(directory, "NetLog"); 636 File netLogDir = new File(directory, "NetLog");
642 assertFalse(netLogDir.exists()); 637 assertFalse(netLogDir.exists());
643 assertTrue(netLogDir.mkdir()); 638 assertTrue(netLogDir.mkdir());
644 File eventFile = new File(netLogDir, "event_file_0.json"); 639 File eventFile = new File(netLogDir, "event_file_0.json");
645 CronetUrlRequestContext cronetEngine = new CronetUrlRequestContext( 640 CronetUrlRequestContext cronetEngine =
646 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 641 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
647 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE ); 642 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE );
648 643
649 // Start a request. 644 // Start a request.
650 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 645 TestUrlRequestCallback callback = new TestUrlRequestCallback();
651 UrlRequest.Builder urlRequestBuilder = 646 UrlRequest.Builder urlRequestBuilder =
652 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor()); 647 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor());
653 urlRequestBuilder.build().start(); 648 urlRequestBuilder.build().start();
654 callback.blockForDone(); 649 callback.blockForDone();
655 // Shut down the engine without calling stopNetLog. 650 // Shut down the engine without calling stopNetLog.
656 cronetEngine.shutdown(); 651 cronetEngine.shutdown();
657 assertTrue(eventFile.exists()); 652 assertTrue(eventFile.exists());
658 assertTrue(eventFile.length() != 0); 653 assertTrue(eventFile.length() != 0);
659 654
660 FileUtils.recursivelyDeleteFile(netLogDir); 655 FileUtils.recursivelyDeleteFile(netLogDir);
661 assertFalse(netLogDir.exists()); 656 assertFalse(netLogDir.exists());
662 } 657 }
663 658
664 @SmallTest 659 @SmallTest
665 @Feature({"Cronet"}) 660 @Feature({"Cronet"})
666 @OnlyRunNativeCronet 661 @OnlyRunNativeCronet
667 // Tests that NetLog contains events emitted by all live CronetEngines. 662 // Tests that NetLog contains events emitted by all live CronetEngines.
668 public void testNetLogContainEventsFromAllLiveEngines() throws Exception { 663 public void testNetLogContainEventsFromAllLiveEngines() throws Exception {
669 Context context = getContext(); 664 Context context = getContext();
670 File directory = new File(PathUtils.getDataDirectory()); 665 File directory = new File(PathUtils.getDataDirectory());
671 File file1 = File.createTempFile("cronet1", "json", directory); 666 File file1 = File.createTempFile("cronet1", "json", directory);
672 File file2 = File.createTempFile("cronet2", "json", directory); 667 File file2 = File.createTempFile("cronet2", "json", directory);
673 CronetEngine cronetEngine1 = new CronetUrlRequestContext( 668 CronetEngine cronetEngine1 =
674 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 669 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
675 CronetEngine cronetEngine2 = new CronetUrlRequestContext( 670 CronetEngine cronetEngine2 =
676 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 671 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
677 672
678 cronetEngine1.startNetLogToFile(file1.getPath(), false); 673 cronetEngine1.startNetLogToFile(file1.getPath(), false);
679 cronetEngine2.startNetLogToFile(file2.getPath(), false); 674 cronetEngine2.startNetLogToFile(file2.getPath(), false);
680 675
681 // Warm CronetEngine and make sure both CronetUrlRequestContexts are 676 // Warm CronetEngine and make sure both CronetUrlRequestContexts are
682 // initialized before testing the logs. 677 // initialized before testing the logs.
683 makeRequestAndCheckStatus(cronetEngine1, mUrl, 200); 678 makeRequestAndCheckStatus(cronetEngine1, mUrl, 200);
684 makeRequestAndCheckStatus(cronetEngine2, mUrl, 200); 679 makeRequestAndCheckStatus(cronetEngine2, mUrl, 200);
685 680
686 // Use cronetEngine1 to make a request to mUrl404. 681 // Use cronetEngine1 to make a request to mUrl404.
(...skipping 25 matching lines...) Expand all
712 File directory = new File(PathUtils.getDataDirectory()); 707 File directory = new File(PathUtils.getDataDirectory());
713 File netLogDir1 = new File(directory, "NetLog1"); 708 File netLogDir1 = new File(directory, "NetLog1");
714 assertFalse(netLogDir1.exists()); 709 assertFalse(netLogDir1.exists());
715 assertTrue(netLogDir1.mkdir()); 710 assertTrue(netLogDir1.mkdir());
716 File netLogDir2 = new File(directory, "NetLog2"); 711 File netLogDir2 = new File(directory, "NetLog2");
717 assertFalse(netLogDir2.exists()); 712 assertFalse(netLogDir2.exists());
718 assertTrue(netLogDir2.mkdir()); 713 assertTrue(netLogDir2.mkdir());
719 File eventFile1 = new File(netLogDir1, "event_file_0.json"); 714 File eventFile1 = new File(netLogDir1, "event_file_0.json");
720 File eventFile2 = new File(netLogDir2, "event_file_0.json"); 715 File eventFile2 = new File(netLogDir2, "event_file_0.json");
721 716
722 CronetUrlRequestContext cronetEngine1 = new CronetUrlRequestContext( 717 CronetUrlRequestContext cronetEngine1 =
723 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 718 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
724 CronetUrlRequestContext cronetEngine2 = new CronetUrlRequestContext( 719 CronetUrlRequestContext cronetEngine2 =
725 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 720 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
726 721
727 cronetEngine1.startNetLogToDisk(netLogDir1.getPath(), false, MAX_FILE_SI ZE); 722 cronetEngine1.startNetLogToDisk(netLogDir1.getPath(), false, MAX_FILE_SI ZE);
728 cronetEngine2.startNetLogToDisk(netLogDir2.getPath(), false, MAX_FILE_SI ZE); 723 cronetEngine2.startNetLogToDisk(netLogDir2.getPath(), false, MAX_FILE_SI ZE);
729 724
730 // Warm CronetEngine and make sure both CronetUrlRequestContexts are 725 // Warm CronetEngine and make sure both CronetUrlRequestContexts are
731 // initialized before testing the logs. 726 // initialized before testing the logs.
732 makeRequestAndCheckStatus(cronetEngine1, mUrl, 200); 727 makeRequestAndCheckStatus(cronetEngine1, mUrl, 200);
733 makeRequestAndCheckStatus(cronetEngine2, mUrl, 200); 728 makeRequestAndCheckStatus(cronetEngine2, mUrl, 200);
734 729
735 // Use cronetEngine1 to make a request to mUrl404. 730 // Use cronetEngine1 to make a request to mUrl404.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 assertFalse(netLogDir.exists()); 1020 assertFalse(netLogDir.exists());
1026 } 1021 }
1027 1022
1028 @SmallTest 1023 @SmallTest
1029 @Feature({"Cronet"}) 1024 @Feature({"Cronet"})
1030 @OnlyRunNativeCronet 1025 @OnlyRunNativeCronet
1031 public void testNetLogWithBytes() throws Exception { 1026 public void testNetLogWithBytes() throws Exception {
1032 Context context = getContext(); 1027 Context context = getContext();
1033 File directory = new File(PathUtils.getDataDirectory()); 1028 File directory = new File(PathUtils.getDataDirectory());
1034 File file = File.createTempFile("cronet", "json", directory); 1029 File file = File.createTempFile("cronet", "json", directory);
1035 CronetEngine cronetEngine = new CronetUrlRequestContext( 1030 CronetEngine cronetEngine =
1036 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 1031 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
1037 // Start NetLog with logAll as true. 1032 // Start NetLog with logAll as true.
1038 cronetEngine.startNetLogToFile(file.getPath(), true); 1033 cronetEngine.startNetLogToFile(file.getPath(), true);
1039 // Start a request. 1034 // Start a request.
1040 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1035 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1041 UrlRequest.Builder urlRequestBuilder = 1036 UrlRequest.Builder urlRequestBuilder =
1042 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor()); 1037 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor());
1043 urlRequestBuilder.build().start(); 1038 urlRequestBuilder.build().start();
1044 callback.blockForDone(); 1039 callback.blockForDone();
1045 cronetEngine.stopNetLog(); 1040 cronetEngine.stopNetLog();
1046 assertTrue(file.exists()); 1041 assertTrue(file.exists());
1047 assertTrue(file.length() != 0); 1042 assertTrue(file.length() != 0);
1048 assertTrue(hasBytesInNetLog(file)); 1043 assertTrue(hasBytesInNetLog(file));
1049 assertTrue(file.delete()); 1044 assertTrue(file.delete());
1050 assertTrue(!file.exists()); 1045 assertTrue(!file.exists());
1051 } 1046 }
1052 1047
1053 @SmallTest 1048 @SmallTest
1054 @Feature({"Cronet"}) 1049 @Feature({"Cronet"})
1055 @OnlyRunNativeCronet 1050 @OnlyRunNativeCronet
1056 public void testBoundedFileNetLogWithBytes() throws Exception { 1051 public void testBoundedFileNetLogWithBytes() throws Exception {
1057 Context context = getContext(); 1052 Context context = getContext();
1058 File directory = new File(PathUtils.getDataDirectory()); 1053 File directory = new File(PathUtils.getDataDirectory());
1059 File netLogDir = new File(directory, "NetLog"); 1054 File netLogDir = new File(directory, "NetLog");
1060 assertFalse(netLogDir.exists()); 1055 assertFalse(netLogDir.exists());
1061 assertTrue(netLogDir.mkdir()); 1056 assertTrue(netLogDir.mkdir());
1062 File eventFile = new File(netLogDir, "event_file_0.json"); 1057 File eventFile = new File(netLogDir, "event_file_0.json");
1063 CronetUrlRequestContext cronetEngine = new CronetUrlRequestContext( 1058 CronetUrlRequestContext cronetEngine =
1064 new CronetEngineBuilderImpl(context).setLibraryName("cronet_test s")); 1059 new CronetUrlRequestContext(new CronetEngineBuilderImpl(context) );
1065 // Start NetLog with logAll as true. 1060 // Start NetLog with logAll as true.
1066 cronetEngine.startNetLogToDisk(netLogDir.getPath(), true, MAX_FILE_SIZE) ; 1061 cronetEngine.startNetLogToDisk(netLogDir.getPath(), true, MAX_FILE_SIZE) ;
1067 // Start a request. 1062 // Start a request.
1068 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1063 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1069 UrlRequest.Builder urlRequestBuilder = 1064 UrlRequest.Builder urlRequestBuilder =
1070 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor()); 1065 cronetEngine.newUrlRequestBuilder(mUrl, callback, callback.getEx ecutor());
1071 urlRequestBuilder.build().start(); 1066 urlRequestBuilder.build().start();
1072 callback.blockForDone(); 1067 callback.blockForDone();
1073 cronetEngine.stopNetLog(); 1068 cronetEngine.stopNetLog();
1074 1069
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 return mWasCalled; 1414 return mWasCalled;
1420 } 1415 }
1421 } 1416 }
1422 1417
1423 @SmallTest 1418 @SmallTest
1424 @Feature({"Cronet"}) 1419 @Feature({"Cronet"})
1425 @OnlyRunNativeCronet 1420 @OnlyRunNativeCronet
1426 public void testSkipLibraryLoading() throws Exception { 1421 public void testSkipLibraryLoading() throws Exception {
1427 CronetEngineBuilderImpl builder = new CronetEngineBuilderImpl(getContext ()); 1422 CronetEngineBuilderImpl builder = new CronetEngineBuilderImpl(getContext ());
1428 TestBadLibraryLoader loader = new TestBadLibraryLoader(); 1423 TestBadLibraryLoader loader = new TestBadLibraryLoader();
1429 builder.setLibraryLoader(loader).setLibraryName("cronet_tests"); 1424 builder.setLibraryLoader(loader);
1430 try { 1425 try {
1431 // ensureInitialized() calls native code to check the version right after library load 1426 // ensureInitialized() calls native code to check the version right after library load
1432 // and will error with the message below if library loading was skip ped 1427 // and will error with the message below if library loading was skip ped
1433 CronetLibraryLoader.ensureInitialized(getContext().getApplicationCon text(), builder); 1428 CronetLibraryLoader.ensureInitialized(getContext().getApplicationCon text(), builder);
1434 fail("Native library should not be loaded"); 1429 fail("Native library should not be loaded");
1435 } catch (UnsatisfiedLinkError e) { 1430 } catch (UnsatisfiedLinkError e) {
1436 assertTrue(loader.wasCalled()); 1431 assertTrue(loader.wasCalled());
1437 } 1432 }
1438 } 1433 }
1439 1434
1440 // Creates a CronetEngine on another thread and then one on the main thread. This shouldn't 1435 // Creates a CronetEngine on another thread and then one on the main thread. This shouldn't
1441 // crash. 1436 // crash.
1442 @SmallTest 1437 @SmallTest
1443 @Feature({"Cronet"}) 1438 @Feature({"Cronet"})
1444 public void testThreadedStartup() throws Exception { 1439 public void testThreadedStartup() throws Exception {
1445 final ConditionVariable otherThreadDone = new ConditionVariable(); 1440 final ConditionVariable otherThreadDone = new ConditionVariable();
1446 final ConditionVariable uiThreadDone = new ConditionVariable(); 1441 final ConditionVariable uiThreadDone = new ConditionVariable();
1447 new Handler(Looper.getMainLooper()).post(new Runnable() { 1442 new Handler(Looper.getMainLooper()).post(new Runnable() {
1448 public void run() { 1443 public void run() {
1449 final ExperimentalCronetEngine.Builder builder = 1444 final ExperimentalCronetEngine.Builder builder =
1450 new ExperimentalCronetEngine.Builder(getContext()); 1445 new ExperimentalCronetEngine.Builder(getContext());
1451 CronetTestUtil.setLibraryName(builder, "cronet_tests");
1452 new Thread() { 1446 new Thread() {
1453 public void run() { 1447 public void run() {
1454 CronetEngine cronetEngine = builder.build(); 1448 CronetEngine cronetEngine = builder.build();
1455 otherThreadDone.open(); 1449 otherThreadDone.open();
1456 cronetEngine.shutdown(); 1450 cronetEngine.shutdown();
1457 } 1451 }
1458 }.start(); 1452 }.start();
1459 otherThreadDone.block(); 1453 otherThreadDone.block();
1460 builder.build().shutdown(); 1454 builder.build().shutdown();
1461 uiThreadDone.open(); 1455 uiThreadDone.open();
(...skipping 20 matching lines...) Expand all
1482 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1476 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1483 URL requestUrl = 1477 URL requestUrl =
1484 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile()); 1478 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile());
1485 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder( 1479 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder(
1486 requestUrl.toString(), callback, callback.getExecutor()); 1480 requestUrl.toString(), callback, callback.getExecutor());
1487 urlRequestBuilder.build().start(); 1481 urlRequestBuilder.build().start();
1488 callback.blockForDone(); 1482 callback.blockForDone();
1489 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 1483 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
1490 } 1484 }
1491 } 1485 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698