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

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: address two remaining comments 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;
11 import android.os.Looper; 11 import android.os.Looper;
12 import android.os.StrictMode; 12 import android.os.StrictMode;
13 import android.test.suitebuilder.annotation.SmallTest; 13 import android.test.suitebuilder.annotation.SmallTest;
14 14
15 import org.json.JSONObject;
16
15 import org.chromium.base.FileUtils; 17 import org.chromium.base.FileUtils;
16 import org.chromium.base.PathUtils; 18 import org.chromium.base.PathUtils;
17 import org.chromium.base.annotations.JNINamespace; 19 import org.chromium.base.annotations.JNINamespace;
18 import org.chromium.base.test.util.Feature; 20 import org.chromium.base.test.util.Feature;
19 import org.chromium.net.MetricsTestUtil.TestExecutor; 21 import org.chromium.net.MetricsTestUtil.TestExecutor;
20 import org.chromium.net.TestUrlRequestCallback.ResponseStep; 22 import org.chromium.net.TestUrlRequestCallback.ResponseStep;
21 import org.chromium.net.impl.CronetLibraryLoader; 23 import org.chromium.net.impl.CronetLibraryLoader;
22 import org.chromium.net.impl.CronetUrlRequestContext; 24 import org.chromium.net.impl.CronetUrlRequestContext;
23 import org.chromium.net.test.EmbeddedTestServer; 25 import org.chromium.net.test.EmbeddedTestServer;
24 import org.json.JSONObject;
25 26
26 import java.io.BufferedReader; 27 import java.io.BufferedReader;
27 import java.io.File; 28 import java.io.File;
28 import java.io.FileReader; 29 import java.io.FileReader;
29 import java.net.URL; 30 import java.net.URL;
30 import java.util.Arrays; 31 import java.util.Arrays;
31 import java.util.concurrent.Executor; 32 import java.util.concurrent.Executor;
32 import java.util.concurrent.Executors; 33 import java.util.concurrent.Executors;
33 import java.util.concurrent.ThreadFactory; 34 import java.util.concurrent.ThreadFactory;
34 import java.util.concurrent.atomic.AtomicReference; 35 import java.util.concurrent.atomic.AtomicReference;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 @Feature({"Cronet"}) 154 @Feature({"Cronet"})
154 @SuppressWarnings("deprecation") 155 @SuppressWarnings("deprecation")
155 public void testConfigUserAgent() throws Exception { 156 public void testConfigUserAgent() throws Exception {
156 String userAgentName = "User-Agent"; 157 String userAgentName = "User-Agent";
157 String userAgentValue = "User-Agent-Value"; 158 String userAgentValue = "User-Agent-Value";
158 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC ontext()); 159 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC ontext());
159 if (testingJavaImpl()) { 160 if (testingJavaImpl()) {
160 cronetEngineBuilder.enableLegacyMode(true); 161 cronetEngineBuilder.enableLegacyMode(true);
161 } 162 }
162 cronetEngineBuilder.setUserAgent(userAgentValue); 163 cronetEngineBuilder.setUserAgent(userAgentValue);
163 cronetEngineBuilder.setLibraryName("cronet_tests");
164 final CronetTestFramework testFramework = 164 final CronetTestFramework testFramework =
165 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cron etEngineBuilder); 165 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(mUrl, cron etEngineBuilder);
166 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re turns false if it's 166 NativeTestServer.shutdownNativeTestServer(); // startNativeTestServer re turns false if it's
167 // already running 167 // already running
168 assertTrue(NativeTestServer.startNativeTestServer(getContext())); 168 assertTrue(NativeTestServer.startNativeTestServer(getContext()));
169 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 169 TestUrlRequestCallback callback = new TestUrlRequestCallback();
170 UrlRequest.Builder urlRequestBuilder = 170 UrlRequest.Builder urlRequestBuilder =
171 new UrlRequest.Builder(NativeTestServer.getEchoHeaderURL(userAge ntName), callback, 171 new UrlRequest.Builder(NativeTestServer.getEchoHeaderURL(userAge ntName), callback,
172 callback.getExecutor(), testFramework.mCronetEngine); 172 callback.getExecutor(), testFramework.mCronetEngine);
173 urlRequestBuilder.build().start(); 173 urlRequestBuilder.build().start();
174 callback.blockForDone(); 174 callback.blockForDone();
175 assertEquals(userAgentValue, callback.mResponseAsString); 175 assertEquals(userAgentValue, callback.mResponseAsString);
176 } 176 }
177 177
178 @SmallTest 178 @SmallTest
179 @Feature({"Cronet"}) 179 @Feature({"Cronet"})
180 @OnlyRunNativeCronet 180 @OnlyRunNativeCronet
181 public void testDataReductionProxyEnabled() throws Exception { 181 public void testDataReductionProxyEnabled() throws Exception {
182 final CronetTestFramework testFramework = startCronetTestFrameworkAndSki pLibraryInit(); 182 final CronetTestFramework testFramework = startCronetTestFrameworkAndSki pLibraryInit();
183 183
184 // Ensure native code is loaded before trying to start test server. 184 // Ensure native code is loaded before trying to start test server.
185 new CronetEngine.Builder(getContext()).setLibraryName("cronet_tests").bu ild().shutdown(); 185 new CronetEngine.Builder(getContext()).build().shutdown();
186 186
187 assertTrue(NativeTestServer.startNativeTestServer(getContext())); 187 assertTrue(NativeTestServer.startNativeTestServer(getContext()));
188 if (!NativeTestServer.isDataReductionProxySupported()) { 188 if (!NativeTestServer.isDataReductionProxySupported()) {
189 return; 189 return;
190 } 190 }
191 String serverHostPort = NativeTestServer.getHostPort(); 191 String serverHostPort = NativeTestServer.getHostPort();
192 192
193 // Enable the Data Reduction Proxy and configure it to use the test 193 // Enable the Data Reduction Proxy and configure it to use the test
194 // server as its primary proxy, and to check successfully that this 194 // server as its primary proxy, and to check successfully that this
195 // proxy is OK to use. 195 // proxy is OK to use.
196 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC ontext()); 196 CronetEngine.Builder cronetEngineBuilder = new CronetEngine.Builder(getC ontext());
197 cronetEngineBuilder.enableDataReductionProxy("test-key"); 197 cronetEngineBuilder.enableDataReductionProxy("test-key");
198 cronetEngineBuilder.setDataReductionProxyOptions(serverHostPort, "unused .net:9999", 198 cronetEngineBuilder.setDataReductionProxyOptions(serverHostPort, "unused .net:9999",
199 NativeTestServer.getFileURL("/secureproxychecksuccess.txt")); 199 NativeTestServer.getFileURL("/secureproxychecksuccess.txt"));
200 cronetEngineBuilder.setLibraryName("cronet_tests");
201 testFramework.mCronetEngine = cronetEngineBuilder.build(); 200 testFramework.mCronetEngine = cronetEngineBuilder.build();
202 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 201 TestUrlRequestCallback callback = new TestUrlRequestCallback();
203 202
204 // Construct and start a request that can only be returned by the test 203 // Construct and start a request that can only be returned by the test
205 // server. This request will fail if the configuration logic for the 204 // server. This request will fail if the configuration logic for the
206 // Data Reduction Proxy is not used. 205 // Data Reduction Proxy is not used.
207 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( 206 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
208 "http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt", callback, 207 "http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt", callback,
209 callback.getExecutor(), testFramework.mCronetEngine); 208 callback.getExecutor(), testFramework.mCronetEngine);
210 urlRequestBuilder.build().start(); 209 urlRequestBuilder.build().start();
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 testFramework.mCronetEngine.shutdown(); 513 testFramework.mCronetEngine.shutdown();
515 } 514 }
516 515
517 @SmallTest 516 @SmallTest
518 @Feature({"Cronet"}) 517 @Feature({"Cronet"})
519 @OnlyRunNativeCronet // No netlogs for pure java impl 518 @OnlyRunNativeCronet // No netlogs for pure java impl
520 public void testNetLog() throws Exception { 519 public void testNetLog() throws Exception {
521 Context context = getContext(); 520 Context context = getContext();
522 File directory = new File(PathUtils.getDataDirectory()); 521 File directory = new File(PathUtils.getDataDirectory());
523 File file = File.createTempFile("cronet", "json", directory); 522 File file = File.createTempFile("cronet", "json", directory);
524 CronetEngine cronetEngine = new CronetUrlRequestContext( 523 CronetEngine cronetEngine = new CronetUrlRequestContext(new CronetEngine .Builder(context));
525 new CronetEngine.Builder(context).setLibraryName("cronet_tests") );
526 // Start NetLog immediately after the request context is created to make 524 // Start NetLog immediately after the request context is created to make
527 // sure that the call won't crash the app even when the native request 525 // sure that the call won't crash the app even when the native request
528 // context is not fully initialized. See crbug.com/470196. 526 // context is not fully initialized. See crbug.com/470196.
529 cronetEngine.startNetLogToFile(file.getPath(), false); 527 cronetEngine.startNetLogToFile(file.getPath(), false);
530 528
531 // Start a request. 529 // Start a request.
532 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 530 TestUrlRequestCallback callback = new TestUrlRequestCallback();
533 UrlRequest.Builder urlRequestBuilder = 531 UrlRequest.Builder urlRequestBuilder =
534 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine); 532 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine);
535 urlRequestBuilder.build().start(); 533 urlRequestBuilder.build().start();
536 callback.blockForDone(); 534 callback.blockForDone();
537 cronetEngine.stopNetLog(); 535 cronetEngine.stopNetLog();
538 assertTrue(file.exists()); 536 assertTrue(file.exists());
539 assertTrue(file.length() != 0); 537 assertTrue(file.length() != 0);
540 assertFalse(hasBytesInNetLog(file)); 538 assertFalse(hasBytesInNetLog(file));
541 assertTrue(file.delete()); 539 assertTrue(file.delete());
542 assertTrue(!file.exists()); 540 assertTrue(!file.exists());
543 } 541 }
544 542
545 @SmallTest 543 @SmallTest
546 @Feature({"Cronet"}) 544 @Feature({"Cronet"})
547 @OnlyRunNativeCronet // No netlogs for pure java impl 545 @OnlyRunNativeCronet // No netlogs for pure java impl
548 public void testBoundedFileNetLog() throws Exception { 546 public void testBoundedFileNetLog() throws Exception {
549 Context context = getContext(); 547 Context context = getContext();
550 File directory = new File(PathUtils.getDataDirectory()); 548 File directory = new File(PathUtils.getDataDirectory());
551 File netLogDir = new File(directory, "NetLog"); 549 File netLogDir = new File(directory, "NetLog");
552 assertFalse(netLogDir.exists()); 550 assertFalse(netLogDir.exists());
553 assertTrue(netLogDir.mkdir()); 551 assertTrue(netLogDir.mkdir());
554 File eventFile = new File(netLogDir, "event_file_0.json"); 552 File eventFile = new File(netLogDir, "event_file_0.json");
555 CronetEngine cronetEngine = new CronetUrlRequestContext( 553 CronetEngine cronetEngine = new CronetUrlRequestContext(new CronetEngine .Builder(context));
556 new CronetEngine.Builder(context).setLibraryName("cronet_tests") );
557 // Start NetLog immediately after the request context is created to make 554 // Start NetLog immediately after the request context is created to make
558 // sure that the call won't crash the app even when the native request 555 // sure that the call won't crash the app even when the native request
559 // context is not fully initialized. See crbug.com/470196. 556 // context is not fully initialized. See crbug.com/470196.
560 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE ); 557 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE );
561 558
562 // Start a request. 559 // Start a request.
563 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 560 TestUrlRequestCallback callback = new TestUrlRequestCallback();
564 UrlRequest.Builder urlRequestBuilder = 561 UrlRequest.Builder urlRequestBuilder =
565 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine); 562 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine);
566 urlRequestBuilder.build().start(); 563 urlRequestBuilder.build().start();
567 callback.blockForDone(); 564 callback.blockForDone();
568 cronetEngine.stopNetLog(); 565 cronetEngine.stopNetLog();
569 assertTrue(eventFile.exists()); 566 assertTrue(eventFile.exists());
570 assertTrue(eventFile.length() != 0); 567 assertTrue(eventFile.length() != 0);
571 assertFalse(hasBytesInNetLog(eventFile)); 568 assertFalse(hasBytesInNetLog(eventFile));
572 FileUtils.recursivelyDeleteFile(netLogDir); 569 FileUtils.recursivelyDeleteFile(netLogDir);
573 assertFalse(netLogDir.exists()); 570 assertFalse(netLogDir.exists());
574 } 571 }
575 572
576 @SmallTest 573 @SmallTest
577 @Feature({"Cronet"}) 574 @Feature({"Cronet"})
578 @OnlyRunNativeCronet // No netlogs for pure java impl 575 @OnlyRunNativeCronet // No netlogs for pure java impl
579 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown() 576 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown()
580 // will take care of it. crbug.com/623701. 577 // will take care of it. crbug.com/623701.
581 public void testNoStopNetLog() throws Exception { 578 public void testNoStopNetLog() throws Exception {
582 Context context = getContext(); 579 Context context = getContext();
583 File directory = new File(PathUtils.getDataDirectory()); 580 File directory = new File(PathUtils.getDataDirectory());
584 File file = File.createTempFile("cronet", "json", directory); 581 File file = File.createTempFile("cronet", "json", directory);
585 CronetEngine cronetEngine = new CronetUrlRequestContext( 582 CronetEngine cronetEngine = new CronetUrlRequestContext(new CronetEngine .Builder(context));
586 new CronetEngine.Builder(context).setLibraryName("cronet_tests") );
587 cronetEngine.startNetLogToFile(file.getPath(), false); 583 cronetEngine.startNetLogToFile(file.getPath(), false);
588 584
589 // Start a request. 585 // Start a request.
590 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 586 TestUrlRequestCallback callback = new TestUrlRequestCallback();
591 UrlRequest.Builder urlRequestBuilder = 587 UrlRequest.Builder urlRequestBuilder =
592 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine); 588 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine);
593 urlRequestBuilder.build().start(); 589 urlRequestBuilder.build().start();
594 callback.blockForDone(); 590 callback.blockForDone();
595 // Shut down the engine without calling stopNetLog. 591 // Shut down the engine without calling stopNetLog.
596 cronetEngine.shutdown(); 592 cronetEngine.shutdown();
597 assertTrue(file.exists()); 593 assertTrue(file.exists());
598 assertTrue(file.length() != 0); 594 assertTrue(file.length() != 0);
599 assertFalse(hasBytesInNetLog(file)); 595 assertFalse(hasBytesInNetLog(file));
600 assertTrue(file.delete()); 596 assertTrue(file.delete());
601 assertTrue(!file.exists()); 597 assertTrue(!file.exists());
602 } 598 }
603 599
604 @SmallTest 600 @SmallTest
605 @Feature({"Cronet"}) 601 @Feature({"Cronet"})
606 @OnlyRunNativeCronet // No netlogs for pure java impl 602 @OnlyRunNativeCronet // No netlogs for pure java impl
607 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown() 603 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown()
608 // will take care of it. crbug.com/623701. 604 // will take care of it. crbug.com/623701.
609 public void testNoStopBoundedFileNetLog() throws Exception { 605 public void testNoStopBoundedFileNetLog() throws Exception {
610 Context context = getContext(); 606 Context context = getContext();
611 File directory = new File(PathUtils.getDataDirectory()); 607 File directory = new File(PathUtils.getDataDirectory());
612 File netLogDir = new File(directory, "NetLog"); 608 File netLogDir = new File(directory, "NetLog");
613 assertFalse(netLogDir.exists()); 609 assertFalse(netLogDir.exists());
614 assertTrue(netLogDir.mkdir()); 610 assertTrue(netLogDir.mkdir());
615 File eventFile = new File(netLogDir, "event_file_0.json"); 611 File eventFile = new File(netLogDir, "event_file_0.json");
616 CronetEngine cronetEngine = new CronetUrlRequestContext( 612 CronetEngine cronetEngine = new CronetUrlRequestContext(new CronetEngine .Builder(context));
617 new CronetEngine.Builder(context).setLibraryName("cronet_tests") );
618 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE ); 613 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE );
619 614
620 // Start a request. 615 // Start a request.
621 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 616 TestUrlRequestCallback callback = new TestUrlRequestCallback();
622 UrlRequest.Builder urlRequestBuilder = 617 UrlRequest.Builder urlRequestBuilder =
623 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine); 618 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine);
624 urlRequestBuilder.build().start(); 619 urlRequestBuilder.build().start();
625 callback.blockForDone(); 620 callback.blockForDone();
626 // Shut down the engine without calling stopNetLog. 621 // Shut down the engine without calling stopNetLog.
627 cronetEngine.shutdown(); 622 cronetEngine.shutdown();
628 assertTrue(eventFile.exists()); 623 assertTrue(eventFile.exists());
629 assertTrue(eventFile.length() != 0); 624 assertTrue(eventFile.length() != 0);
630 625
631 FileUtils.recursivelyDeleteFile(netLogDir); 626 FileUtils.recursivelyDeleteFile(netLogDir);
632 assertFalse(netLogDir.exists()); 627 assertFalse(netLogDir.exists());
633 } 628 }
634 629
635 @SmallTest 630 @SmallTest
636 @Feature({"Cronet"}) 631 @Feature({"Cronet"})
637 @OnlyRunNativeCronet 632 @OnlyRunNativeCronet
638 // Tests that NetLog contains events emitted by all live CronetEngines. 633 // Tests that NetLog contains events emitted by all live CronetEngines.
639 public void testNetLogContainEventsFromAllLiveEngines() throws Exception { 634 public void testNetLogContainEventsFromAllLiveEngines() throws Exception {
640 Context context = getContext(); 635 Context context = getContext();
641 File directory = new File(PathUtils.getDataDirectory()); 636 File directory = new File(PathUtils.getDataDirectory());
642 File file1 = File.createTempFile("cronet1", "json", directory); 637 File file1 = File.createTempFile("cronet1", "json", directory);
643 File file2 = File.createTempFile("cronet2", "json", directory); 638 File file2 = File.createTempFile("cronet2", "json", directory);
644 CronetEngine cronetEngine1 = new CronetUrlRequestContext( 639 CronetEngine cronetEngine1 = new CronetUrlRequestContext(new CronetEngin e.Builder(context));
645 new CronetEngine.Builder(context).setLibraryName("cronet_tests") ); 640 CronetEngine cronetEngine2 = new CronetUrlRequestContext(new CronetEngin e.Builder(context));
646 CronetEngine cronetEngine2 = new CronetUrlRequestContext(
647 new CronetEngine.Builder(context).setLibraryName("cronet_tests") );
648 641
649 cronetEngine1.startNetLogToFile(file1.getPath(), false); 642 cronetEngine1.startNetLogToFile(file1.getPath(), false);
650 cronetEngine2.startNetLogToFile(file2.getPath(), false); 643 cronetEngine2.startNetLogToFile(file2.getPath(), false);
651 644
652 // Warm CronetEngine and make sure both CronetUrlRequestContexts are 645 // Warm CronetEngine and make sure both CronetUrlRequestContexts are
653 // initialized before testing the logs. 646 // initialized before testing the logs.
654 makeRequestAndCheckStatus(cronetEngine1, mUrl, 200); 647 makeRequestAndCheckStatus(cronetEngine1, mUrl, 200);
655 makeRequestAndCheckStatus(cronetEngine2, mUrl, 200); 648 makeRequestAndCheckStatus(cronetEngine2, mUrl, 200);
656 649
657 // Use cronetEngine1 to make a request to mUrl404. 650 // Use cronetEngine1 to make a request to mUrl404.
(...skipping 25 matching lines...) Expand all
683 File directory = new File(PathUtils.getDataDirectory()); 676 File directory = new File(PathUtils.getDataDirectory());
684 File netLogDir1 = new File(directory, "NetLog1"); 677 File netLogDir1 = new File(directory, "NetLog1");
685 assertFalse(netLogDir1.exists()); 678 assertFalse(netLogDir1.exists());
686 assertTrue(netLogDir1.mkdir()); 679 assertTrue(netLogDir1.mkdir());
687 File netLogDir2 = new File(directory, "NetLog2"); 680 File netLogDir2 = new File(directory, "NetLog2");
688 assertFalse(netLogDir2.exists()); 681 assertFalse(netLogDir2.exists());
689 assertTrue(netLogDir2.mkdir()); 682 assertTrue(netLogDir2.mkdir());
690 File eventFile1 = new File(netLogDir1, "event_file_0.json"); 683 File eventFile1 = new File(netLogDir1, "event_file_0.json");
691 File eventFile2 = new File(netLogDir2, "event_file_0.json"); 684 File eventFile2 = new File(netLogDir2, "event_file_0.json");
692 685
693 CronetUrlRequestContext cronetEngine1 = new CronetUrlRequestContext( 686 CronetUrlRequestContext cronetEngine1 =
694 new CronetEngine.Builder(context).setLibraryName("cronet_tests") ); 687 new CronetUrlRequestContext(new CronetEngine.Builder(context));
695 CronetUrlRequestContext cronetEngine2 = new CronetUrlRequestContext( 688 CronetUrlRequestContext cronetEngine2 =
696 new CronetEngine.Builder(context).setLibraryName("cronet_tests") ); 689 new CronetUrlRequestContext(new CronetEngine.Builder(context));
697 690
698 cronetEngine1.startNetLogToDisk(netLogDir1.getPath(), false, MAX_FILE_SI ZE); 691 cronetEngine1.startNetLogToDisk(netLogDir1.getPath(), false, MAX_FILE_SI ZE);
699 cronetEngine2.startNetLogToDisk(netLogDir2.getPath(), false, MAX_FILE_SI ZE); 692 cronetEngine2.startNetLogToDisk(netLogDir2.getPath(), false, MAX_FILE_SI ZE);
700 693
701 // Warm CronetEngine and make sure both CronetUrlRequestContexts are 694 // Warm CronetEngine and make sure both CronetUrlRequestContexts are
702 // initialized before testing the logs. 695 // initialized before testing the logs.
703 makeRequestAndCheckStatus(cronetEngine1, mUrl, 200); 696 makeRequestAndCheckStatus(cronetEngine1, mUrl, 200);
704 makeRequestAndCheckStatus(cronetEngine2, mUrl, 200); 697 makeRequestAndCheckStatus(cronetEngine2, mUrl, 200);
705 698
706 // Use cronetEngine1 to make a request to mUrl404. 699 // Use cronetEngine1 to make a request to mUrl404.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 assertFalse(netLogDir.exists()); 989 assertFalse(netLogDir.exists());
997 } 990 }
998 991
999 @SmallTest 992 @SmallTest
1000 @Feature({"Cronet"}) 993 @Feature({"Cronet"})
1001 @OnlyRunNativeCronet 994 @OnlyRunNativeCronet
1002 public void testNetLogWithBytes() throws Exception { 995 public void testNetLogWithBytes() throws Exception {
1003 Context context = getContext(); 996 Context context = getContext();
1004 File directory = new File(PathUtils.getDataDirectory()); 997 File directory = new File(PathUtils.getDataDirectory());
1005 File file = File.createTempFile("cronet", "json", directory); 998 File file = File.createTempFile("cronet", "json", directory);
1006 CronetEngine cronetEngine = new CronetUrlRequestContext( 999 CronetEngine cronetEngine = new CronetUrlRequestContext(new CronetEngine .Builder(context));
1007 new CronetEngine.Builder(context).setLibraryName("cronet_tests") );
1008 // Start NetLog with logAll as true. 1000 // Start NetLog with logAll as true.
1009 cronetEngine.startNetLogToFile(file.getPath(), true); 1001 cronetEngine.startNetLogToFile(file.getPath(), true);
1010 // Start a request. 1002 // Start a request.
1011 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1003 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1012 UrlRequest.Builder urlRequestBuilder = 1004 UrlRequest.Builder urlRequestBuilder =
1013 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine); 1005 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine);
1014 urlRequestBuilder.build().start(); 1006 urlRequestBuilder.build().start();
1015 callback.blockForDone(); 1007 callback.blockForDone();
1016 cronetEngine.stopNetLog(); 1008 cronetEngine.stopNetLog();
1017 assertTrue(file.exists()); 1009 assertTrue(file.exists());
1018 assertTrue(file.length() != 0); 1010 assertTrue(file.length() != 0);
1019 assertTrue(hasBytesInNetLog(file)); 1011 assertTrue(hasBytesInNetLog(file));
1020 assertTrue(file.delete()); 1012 assertTrue(file.delete());
1021 assertTrue(!file.exists()); 1013 assertTrue(!file.exists());
1022 } 1014 }
1023 1015
1024 @SmallTest 1016 @SmallTest
1025 @Feature({"Cronet"}) 1017 @Feature({"Cronet"})
1026 @OnlyRunNativeCronet 1018 @OnlyRunNativeCronet
1027 public void testBoundedFileNetLogWithBytes() throws Exception { 1019 public void testBoundedFileNetLogWithBytes() throws Exception {
1028 Context context = getContext(); 1020 Context context = getContext();
1029 File directory = new File(PathUtils.getDataDirectory()); 1021 File directory = new File(PathUtils.getDataDirectory());
1030 File netLogDir = new File(directory, "NetLog"); 1022 File netLogDir = new File(directory, "NetLog");
1031 assertFalse(netLogDir.exists()); 1023 assertFalse(netLogDir.exists());
1032 assertTrue(netLogDir.mkdir()); 1024 assertTrue(netLogDir.mkdir());
1033 File eventFile = new File(netLogDir, "event_file_0.json"); 1025 File eventFile = new File(netLogDir, "event_file_0.json");
1034 CronetUrlRequestContext cronetEngine = new CronetUrlRequestContext( 1026 CronetUrlRequestContext cronetEngine =
1035 new CronetEngine.Builder(context).setLibraryName("cronet_tests") ); 1027 new CronetUrlRequestContext(new CronetEngine.Builder(context));
1036 // Start NetLog with logAll as true. 1028 // Start NetLog with logAll as true.
1037 cronetEngine.startNetLogToDisk(netLogDir.getPath(), true, MAX_FILE_SIZE) ; 1029 cronetEngine.startNetLogToDisk(netLogDir.getPath(), true, MAX_FILE_SIZE) ;
1038 // Start a request. 1030 // Start a request.
1039 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1031 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1040 UrlRequest.Builder urlRequestBuilder = 1032 UrlRequest.Builder urlRequestBuilder =
1041 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine); 1033 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c ronetEngine);
1042 urlRequestBuilder.build().start(); 1034 urlRequestBuilder.build().start();
1043 callback.blockForDone(); 1035 callback.blockForDone();
1044 cronetEngine.stopNetLog(); 1036 cronetEngine.stopNetLog();
1045 1037
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 return mWasCalled; 1378 return mWasCalled;
1387 } 1379 }
1388 } 1380 }
1389 1381
1390 @SmallTest 1382 @SmallTest
1391 @Feature({"Cronet"}) 1383 @Feature({"Cronet"})
1392 @OnlyRunNativeCronet 1384 @OnlyRunNativeCronet
1393 public void testSkipLibraryLoading() throws Exception { 1385 public void testSkipLibraryLoading() throws Exception {
1394 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); 1386 CronetEngine.Builder builder = new CronetEngine.Builder(getContext());
1395 TestBadLibraryLoader loader = new TestBadLibraryLoader(); 1387 TestBadLibraryLoader loader = new TestBadLibraryLoader();
1396 builder.setLibraryLoader(loader).setLibraryName("cronet_tests"); 1388 builder.setLibraryLoader(loader);
1397 try { 1389 try {
1398 // ensureInitialized() calls native code to check the version right after library load 1390 // ensureInitialized() calls native code to check the version right after library load
1399 // and will error with the message below if library loading was skip ped 1391 // and will error with the message below if library loading was skip ped
1400 CronetLibraryLoader.ensureInitialized(getContext(), builder); 1392 CronetLibraryLoader.ensureInitialized(getContext(), builder);
1401 fail("Native library should not be loaded"); 1393 fail("Native library should not be loaded");
1402 } catch (UnsatisfiedLinkError e) { 1394 } catch (UnsatisfiedLinkError e) {
1403 assertTrue(loader.wasCalled()); 1395 assertTrue(loader.wasCalled());
1404 } 1396 }
1405 } 1397 }
1406 1398
1407 // Creates a CronetEngine on another thread and then one on the main thread. This shouldn't 1399 // Creates a CronetEngine on another thread and then one on the main thread. This shouldn't
1408 // crash. 1400 // crash.
1409 @SmallTest 1401 @SmallTest
1410 @Feature({"Cronet"}) 1402 @Feature({"Cronet"})
1411 public void testThreadedStartup() throws Exception { 1403 public void testThreadedStartup() throws Exception {
1412 final ConditionVariable otherThreadDone = new ConditionVariable(); 1404 final ConditionVariable otherThreadDone = new ConditionVariable();
1413 final ConditionVariable uiThreadDone = new ConditionVariable(); 1405 final ConditionVariable uiThreadDone = new ConditionVariable();
1414 new Handler(Looper.getMainLooper()).post(new Runnable() { 1406 new Handler(Looper.getMainLooper()).post(new Runnable() {
1415 public void run() { 1407 public void run() {
1416 final CronetEngine.Builder builder = 1408 final CronetEngine.Builder builder = new CronetEngine.Builder(ge tContext());
1417 new CronetEngine.Builder(getContext()).setLibraryName("c ronet_tests");
1418 new Thread() { 1409 new Thread() {
1419 public void run() { 1410 public void run() {
1420 CronetEngine cronetEngine = builder.build(); 1411 CronetEngine cronetEngine = builder.build();
1421 otherThreadDone.open(); 1412 otherThreadDone.open();
1422 cronetEngine.shutdown(); 1413 cronetEngine.shutdown();
1423 } 1414 }
1424 }.start(); 1415 }.start();
1425 otherThreadDone.block(); 1416 otherThreadDone.block();
1426 builder.build().shutdown(); 1417 builder.build().shutdown();
1427 uiThreadDone.open(); 1418 uiThreadDone.open();
(...skipping 19 matching lines...) Expand all
1447 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1438 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1448 URL requestUrl = 1439 URL requestUrl =
1449 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile()); 1440 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile());
1450 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(requestUrl .toString(), 1441 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(requestUrl .toString(),
1451 callback, callback.getExecutor(), testFramework.mCronetEngine); 1442 callback, callback.getExecutor(), testFramework.mCronetEngine);
1452 urlRequestBuilder.build().start(); 1443 urlRequestBuilder.build().start();
1453 callback.blockForDone(); 1444 callback.blockForDone();
1454 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 1445 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
1455 } 1446 }
1456 } 1447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698