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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); | 531 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); |
532 urlRequest.cancel(); | 532 urlRequest.cancel(); |
533 testFramework.mCronetEngine.shutdown(); | 533 testFramework.mCronetEngine.shutdown(); |
534 } | 534 } |
535 | 535 |
536 @SmallTest | 536 @SmallTest |
537 @Feature({"Cronet"}) | 537 @Feature({"Cronet"}) |
538 @OnlyRunNativeCronet // No netlogs for pure java impl | 538 @OnlyRunNativeCronet // No netlogs for pure java impl |
539 public void testNetLog() throws Exception { | 539 public void testNetLog() throws Exception { |
540 Context context = getContext(); | 540 Context context = getContext(); |
541 File directory = new File(PathUtils.getDataDirectory(context)); | 541 File directory = new File(PathUtils.getDataDirectory()); |
542 File file = File.createTempFile("cronet", "json", directory); | 542 File file = File.createTempFile("cronet", "json", directory); |
543 CronetEngine cronetEngine = new CronetUrlRequestContext( | 543 CronetEngine cronetEngine = new CronetUrlRequestContext( |
544 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 544 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
545 // Start NetLog immediately after the request context is created to make | 545 // Start NetLog immediately after the request context is created to make |
546 // sure that the call won't crash the app even when the native request | 546 // sure that the call won't crash the app even when the native request |
547 // context is not fully initialized. See crbug.com/470196. | 547 // context is not fully initialized. See crbug.com/470196. |
548 cronetEngine.startNetLogToFile(file.getPath(), false); | 548 cronetEngine.startNetLogToFile(file.getPath(), false); |
549 | 549 |
550 // Start a request. | 550 // Start a request. |
551 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 551 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
552 UrlRequest.Builder urlRequestBuilder = | 552 UrlRequest.Builder urlRequestBuilder = |
553 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c
ronetEngine); | 553 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c
ronetEngine); |
554 urlRequestBuilder.build().start(); | 554 urlRequestBuilder.build().start(); |
555 callback.blockForDone(); | 555 callback.blockForDone(); |
556 cronetEngine.stopNetLog(); | 556 cronetEngine.stopNetLog(); |
557 assertTrue(file.exists()); | 557 assertTrue(file.exists()); |
558 assertTrue(file.length() != 0); | 558 assertTrue(file.length() != 0); |
559 assertFalse(hasBytesInNetLog(file)); | 559 assertFalse(hasBytesInNetLog(file)); |
560 assertTrue(file.delete()); | 560 assertTrue(file.delete()); |
561 assertTrue(!file.exists()); | 561 assertTrue(!file.exists()); |
562 } | 562 } |
563 | 563 |
564 @SmallTest | 564 @SmallTest |
565 @Feature({"Cronet"}) | 565 @Feature({"Cronet"}) |
566 @OnlyRunNativeCronet // No netlogs for pure java impl | 566 @OnlyRunNativeCronet // No netlogs for pure java impl |
567 public void testBoundedFileNetLog() throws Exception { | 567 public void testBoundedFileNetLog() throws Exception { |
568 Context context = getContext(); | 568 Context context = getContext(); |
569 File directory = new File(PathUtils.getDataDirectory(context)); | 569 File directory = new File(PathUtils.getDataDirectory()); |
570 File netLogDir = new File(directory, "NetLog"); | 570 File netLogDir = new File(directory, "NetLog"); |
571 assertFalse(netLogDir.exists()); | 571 assertFalse(netLogDir.exists()); |
572 assertTrue(netLogDir.mkdir()); | 572 assertTrue(netLogDir.mkdir()); |
573 File eventFile = new File(netLogDir, "event_file_0.json"); | 573 File eventFile = new File(netLogDir, "event_file_0.json"); |
574 CronetEngine cronetEngine = new CronetUrlRequestContext( | 574 CronetEngine cronetEngine = new CronetUrlRequestContext( |
575 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 575 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
576 // Start NetLog immediately after the request context is created to make | 576 // Start NetLog immediately after the request context is created to make |
577 // sure that the call won't crash the app even when the native request | 577 // sure that the call won't crash the app even when the native request |
578 // context is not fully initialized. See crbug.com/470196. | 578 // context is not fully initialized. See crbug.com/470196. |
579 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE
); | 579 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE
); |
(...skipping 12 matching lines...) Expand all Loading... |
592 assertFalse(netLogDir.exists()); | 592 assertFalse(netLogDir.exists()); |
593 } | 593 } |
594 | 594 |
595 @SmallTest | 595 @SmallTest |
596 @Feature({"Cronet"}) | 596 @Feature({"Cronet"}) |
597 @OnlyRunNativeCronet // No netlogs for pure java impl | 597 @OnlyRunNativeCronet // No netlogs for pure java impl |
598 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown() | 598 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown() |
599 // will take care of it. crbug.com/623701. | 599 // will take care of it. crbug.com/623701. |
600 public void testNoStopNetLog() throws Exception { | 600 public void testNoStopNetLog() throws Exception { |
601 Context context = getContext(); | 601 Context context = getContext(); |
602 File directory = new File(PathUtils.getDataDirectory(context)); | 602 File directory = new File(PathUtils.getDataDirectory()); |
603 File file = File.createTempFile("cronet", "json", directory); | 603 File file = File.createTempFile("cronet", "json", directory); |
604 CronetEngine cronetEngine = new CronetUrlRequestContext( | 604 CronetEngine cronetEngine = new CronetUrlRequestContext( |
605 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 605 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
606 cronetEngine.startNetLogToFile(file.getPath(), false); | 606 cronetEngine.startNetLogToFile(file.getPath(), false); |
607 | 607 |
608 // Start a request. | 608 // Start a request. |
609 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 609 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
610 UrlRequest.Builder urlRequestBuilder = | 610 UrlRequest.Builder urlRequestBuilder = |
611 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c
ronetEngine); | 611 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c
ronetEngine); |
612 urlRequestBuilder.build().start(); | 612 urlRequestBuilder.build().start(); |
613 callback.blockForDone(); | 613 callback.blockForDone(); |
614 // Shut down the engine without calling stopNetLog. | 614 // Shut down the engine without calling stopNetLog. |
615 cronetEngine.shutdown(); | 615 cronetEngine.shutdown(); |
616 assertTrue(file.exists()); | 616 assertTrue(file.exists()); |
617 assertTrue(file.length() != 0); | 617 assertTrue(file.length() != 0); |
618 assertFalse(hasBytesInNetLog(file)); | 618 assertFalse(hasBytesInNetLog(file)); |
619 assertTrue(file.delete()); | 619 assertTrue(file.delete()); |
620 assertTrue(!file.exists()); | 620 assertTrue(!file.exists()); |
621 } | 621 } |
622 | 622 |
623 @SmallTest | 623 @SmallTest |
624 @Feature({"Cronet"}) | 624 @Feature({"Cronet"}) |
625 @OnlyRunNativeCronet // No netlogs for pure java impl | 625 @OnlyRunNativeCronet // No netlogs for pure java impl |
626 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown() | 626 // Tests that if stopNetLog is not explicity called, CronetEngine.shutdown() |
627 // will take care of it. crbug.com/623701. | 627 // will take care of it. crbug.com/623701. |
628 public void testNoStopBoundedFileNetLog() throws Exception { | 628 public void testNoStopBoundedFileNetLog() throws Exception { |
629 Context context = getContext(); | 629 Context context = getContext(); |
630 File directory = new File(PathUtils.getDataDirectory(context)); | 630 File directory = new File(PathUtils.getDataDirectory()); |
631 File netLogDir = new File(directory, "NetLog"); | 631 File netLogDir = new File(directory, "NetLog"); |
632 assertFalse(netLogDir.exists()); | 632 assertFalse(netLogDir.exists()); |
633 assertTrue(netLogDir.mkdir()); | 633 assertTrue(netLogDir.mkdir()); |
634 File eventFile = new File(netLogDir, "event_file_0.json"); | 634 File eventFile = new File(netLogDir, "event_file_0.json"); |
635 CronetEngine cronetEngine = new CronetUrlRequestContext( | 635 CronetEngine cronetEngine = new CronetUrlRequestContext( |
636 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 636 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
637 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE
); | 637 cronetEngine.startNetLogToDisk(netLogDir.getPath(), false, MAX_FILE_SIZE
); |
638 | 638 |
639 // Start a request. | 639 // Start a request. |
640 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 640 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
641 UrlRequest.Builder urlRequestBuilder = | 641 UrlRequest.Builder urlRequestBuilder = |
642 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c
ronetEngine); | 642 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c
ronetEngine); |
643 urlRequestBuilder.build().start(); | 643 urlRequestBuilder.build().start(); |
644 callback.blockForDone(); | 644 callback.blockForDone(); |
645 // Shut down the engine without calling stopNetLog. | 645 // Shut down the engine without calling stopNetLog. |
646 cronetEngine.shutdown(); | 646 cronetEngine.shutdown(); |
647 assertTrue(eventFile.exists()); | 647 assertTrue(eventFile.exists()); |
648 assertTrue(eventFile.length() != 0); | 648 assertTrue(eventFile.length() != 0); |
649 | 649 |
650 FileUtils.recursivelyDeleteFile(netLogDir); | 650 FileUtils.recursivelyDeleteFile(netLogDir); |
651 assertFalse(netLogDir.exists()); | 651 assertFalse(netLogDir.exists()); |
652 } | 652 } |
653 | 653 |
654 @SmallTest | 654 @SmallTest |
655 @Feature({"Cronet"}) | 655 @Feature({"Cronet"}) |
656 @OnlyRunNativeCronet | 656 @OnlyRunNativeCronet |
657 // Tests that NetLog contains events emitted by all live CronetEngines. | 657 // Tests that NetLog contains events emitted by all live CronetEngines. |
658 public void testNetLogContainEventsFromAllLiveEngines() throws Exception { | 658 public void testNetLogContainEventsFromAllLiveEngines() throws Exception { |
659 Context context = getContext(); | 659 Context context = getContext(); |
660 File directory = new File(PathUtils.getDataDirectory(context)); | 660 File directory = new File(PathUtils.getDataDirectory()); |
661 File file1 = File.createTempFile("cronet1", "json", directory); | 661 File file1 = File.createTempFile("cronet1", "json", directory); |
662 File file2 = File.createTempFile("cronet2", "json", directory); | 662 File file2 = File.createTempFile("cronet2", "json", directory); |
663 CronetEngine cronetEngine1 = new CronetUrlRequestContext( | 663 CronetEngine cronetEngine1 = new CronetUrlRequestContext( |
664 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 664 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
665 CronetEngine cronetEngine2 = new CronetUrlRequestContext( | 665 CronetEngine cronetEngine2 = new CronetUrlRequestContext( |
666 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 666 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
667 | 667 |
668 cronetEngine1.startNetLogToFile(file1.getPath(), false); | 668 cronetEngine1.startNetLogToFile(file1.getPath(), false); |
669 cronetEngine2.startNetLogToFile(file2.getPath(), false); | 669 cronetEngine2.startNetLogToFile(file2.getPath(), false); |
670 | 670 |
(...skipping 21 matching lines...) Expand all Loading... |
692 assertTrue(file1.delete()); | 692 assertTrue(file1.delete()); |
693 assertTrue(file2.delete()); | 693 assertTrue(file2.delete()); |
694 } | 694 } |
695 | 695 |
696 @SmallTest | 696 @SmallTest |
697 @Feature({"Cronet"}) | 697 @Feature({"Cronet"}) |
698 @OnlyRunNativeCronet | 698 @OnlyRunNativeCronet |
699 // Tests that NetLog contains events emitted by all live CronetEngines. | 699 // Tests that NetLog contains events emitted by all live CronetEngines. |
700 public void testBoundedFileNetLogContainEventsFromAllLiveEngines() throws Ex
ception { | 700 public void testBoundedFileNetLogContainEventsFromAllLiveEngines() throws Ex
ception { |
701 Context context = getContext(); | 701 Context context = getContext(); |
702 File directory = new File(PathUtils.getDataDirectory(context)); | 702 File directory = new File(PathUtils.getDataDirectory()); |
703 File netLogDir1 = new File(directory, "NetLog1"); | 703 File netLogDir1 = new File(directory, "NetLog1"); |
704 assertFalse(netLogDir1.exists()); | 704 assertFalse(netLogDir1.exists()); |
705 assertTrue(netLogDir1.mkdir()); | 705 assertTrue(netLogDir1.mkdir()); |
706 File netLogDir2 = new File(directory, "NetLog2"); | 706 File netLogDir2 = new File(directory, "NetLog2"); |
707 assertFalse(netLogDir2.exists()); | 707 assertFalse(netLogDir2.exists()); |
708 assertTrue(netLogDir2.mkdir()); | 708 assertTrue(netLogDir2.mkdir()); |
709 File eventFile1 = new File(netLogDir1, "event_file_0.json"); | 709 File eventFile1 = new File(netLogDir1, "event_file_0.json"); |
710 File eventFile2 = new File(netLogDir2, "event_file_0.json"); | 710 File eventFile2 = new File(netLogDir2, "event_file_0.json"); |
711 | 711 |
712 CronetUrlRequestContext cronetEngine1 = new CronetUrlRequestContext( | 712 CronetUrlRequestContext cronetEngine1 = new CronetUrlRequestContext( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 @OnlyRunNativeCronet | 856 @OnlyRunNativeCronet |
857 public void testNetLogAfterShutdown() throws Exception { | 857 public void testNetLogAfterShutdown() throws Exception { |
858 final CronetTestFramework testFramework = startCronetTestFramework(); | 858 final CronetTestFramework testFramework = startCronetTestFramework(); |
859 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 859 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
860 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( | 860 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( |
861 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); | 861 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); |
862 urlRequestBuilder.build().start(); | 862 urlRequestBuilder.build().start(); |
863 callback.blockForDone(); | 863 callback.blockForDone(); |
864 testFramework.mCronetEngine.shutdown(); | 864 testFramework.mCronetEngine.shutdown(); |
865 | 865 |
866 File directory = new File(PathUtils.getDataDirectory(getContext())); | 866 File directory = new File(PathUtils.getDataDirectory()); |
867 File file = File.createTempFile("cronet", "json", directory); | 867 File file = File.createTempFile("cronet", "json", directory); |
868 try { | 868 try { |
869 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false)
; | 869 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false)
; |
870 fail("Should throw an exception."); | 870 fail("Should throw an exception."); |
871 } catch (Exception e) { | 871 } catch (Exception e) { |
872 assertEquals("Engine is shut down.", e.getMessage()); | 872 assertEquals("Engine is shut down.", e.getMessage()); |
873 } | 873 } |
874 assertFalse(hasBytesInNetLog(file)); | 874 assertFalse(hasBytesInNetLog(file)); |
875 assertTrue(file.delete()); | 875 assertTrue(file.delete()); |
876 assertTrue(!file.exists()); | 876 assertTrue(!file.exists()); |
877 } | 877 } |
878 | 878 |
879 @SmallTest | 879 @SmallTest |
880 @Feature({"Cronet"}) | 880 @Feature({"Cronet"}) |
881 @OnlyRunNativeCronet | 881 @OnlyRunNativeCronet |
882 public void testBoundedFileNetLogAfterShutdown() throws Exception { | 882 public void testBoundedFileNetLogAfterShutdown() throws Exception { |
883 final CronetTestFramework testFramework = startCronetTestFramework(); | 883 final CronetTestFramework testFramework = startCronetTestFramework(); |
884 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 884 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
885 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( | 885 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( |
886 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); | 886 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); |
887 urlRequestBuilder.build().start(); | 887 urlRequestBuilder.build().start(); |
888 callback.blockForDone(); | 888 callback.blockForDone(); |
889 testFramework.mCronetEngine.shutdown(); | 889 testFramework.mCronetEngine.shutdown(); |
890 | 890 |
891 File directory = new File(PathUtils.getDataDirectory(getContext())); | 891 File directory = new File(PathUtils.getDataDirectory()); |
892 File netLogDir = new File(directory, "NetLog"); | 892 File netLogDir = new File(directory, "NetLog"); |
893 assertFalse(netLogDir.exists()); | 893 assertFalse(netLogDir.exists()); |
894 assertTrue(netLogDir.mkdir()); | 894 assertTrue(netLogDir.mkdir()); |
895 File constantsFile = new File(netLogDir, "constants.json"); | 895 File constantsFile = new File(netLogDir, "constants.json"); |
896 try { | 896 try { |
897 testFramework.mCronetEngine.startNetLogToDisk( | 897 testFramework.mCronetEngine.startNetLogToDisk( |
898 netLogDir.getPath(), false, MAX_FILE_SIZE); | 898 netLogDir.getPath(), false, MAX_FILE_SIZE); |
899 fail("Should throw an exception."); | 899 fail("Should throw an exception."); |
900 } catch (Exception e) { | 900 } catch (Exception e) { |
901 assertEquals("Engine is shut down.", e.getMessage()); | 901 assertEquals("Engine is shut down.", e.getMessage()); |
902 } | 902 } |
903 assertFalse(constantsFile.exists()); | 903 assertFalse(constantsFile.exists()); |
904 FileUtils.recursivelyDeleteFile(netLogDir); | 904 FileUtils.recursivelyDeleteFile(netLogDir); |
905 assertFalse(netLogDir.exists()); | 905 assertFalse(netLogDir.exists()); |
906 } | 906 } |
907 | 907 |
908 @SmallTest | 908 @SmallTest |
909 @Feature({"Cronet"}) | 909 @Feature({"Cronet"}) |
910 public void testNetLogStartMultipleTimes() throws Exception { | 910 public void testNetLogStartMultipleTimes() throws Exception { |
911 final CronetTestFramework testFramework = startCronetTestFramework(); | 911 final CronetTestFramework testFramework = startCronetTestFramework(); |
912 File directory = new File(PathUtils.getDataDirectory(getContext())); | 912 File directory = new File(PathUtils.getDataDirectory()); |
913 File file = File.createTempFile("cronet", "json", directory); | 913 File file = File.createTempFile("cronet", "json", directory); |
914 // Start NetLog multiple times. | 914 // Start NetLog multiple times. |
915 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); | 915 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); |
916 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); | 916 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); |
917 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); | 917 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); |
918 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); | 918 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); |
919 // Start a request. | 919 // Start a request. |
920 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 920 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
921 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( | 921 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( |
922 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); | 922 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); |
923 urlRequestBuilder.build().start(); | 923 urlRequestBuilder.build().start(); |
924 callback.blockForDone(); | 924 callback.blockForDone(); |
925 testFramework.mCronetEngine.stopNetLog(); | 925 testFramework.mCronetEngine.stopNetLog(); |
926 assertTrue(file.exists()); | 926 assertTrue(file.exists()); |
927 assertTrue(file.length() != 0); | 927 assertTrue(file.length() != 0); |
928 assertFalse(hasBytesInNetLog(file)); | 928 assertFalse(hasBytesInNetLog(file)); |
929 assertTrue(file.delete()); | 929 assertTrue(file.delete()); |
930 assertTrue(!file.exists()); | 930 assertTrue(!file.exists()); |
931 } | 931 } |
932 | 932 |
933 @SmallTest | 933 @SmallTest |
934 @Feature({"Cronet"}) | 934 @Feature({"Cronet"}) |
935 public void testBoundedFileNetLogStartMultipleTimes() throws Exception { | 935 public void testBoundedFileNetLogStartMultipleTimes() throws Exception { |
936 final CronetTestFramework testFramework = startCronetTestFramework(); | 936 final CronetTestFramework testFramework = startCronetTestFramework(); |
937 File directory = new File(PathUtils.getDataDirectory(getContext())); | 937 File directory = new File(PathUtils.getDataDirectory()); |
938 File netLogDir = new File(directory, "NetLog"); | 938 File netLogDir = new File(directory, "NetLog"); |
939 assertFalse(netLogDir.exists()); | 939 assertFalse(netLogDir.exists()); |
940 assertTrue(netLogDir.mkdir()); | 940 assertTrue(netLogDir.mkdir()); |
941 File eventFile = new File(netLogDir, "event_file_0.json"); | 941 File eventFile = new File(netLogDir, "event_file_0.json"); |
942 // Start NetLog multiple times. This should be equivalent to starting Ne
tLog | 942 // Start NetLog multiple times. This should be equivalent to starting Ne
tLog |
943 // once. Each subsequent start (without calling stopNetLog) should be a
no-op. | 943 // once. Each subsequent start (without calling stopNetLog) should be a
no-op. |
944 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); | 944 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); |
945 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); | 945 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); |
946 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); | 946 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); |
947 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); | 947 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); |
948 // Start a request. | 948 // Start a request. |
949 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 949 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
950 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( | 950 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( |
951 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); | 951 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); |
952 urlRequestBuilder.build().start(); | 952 urlRequestBuilder.build().start(); |
953 callback.blockForDone(); | 953 callback.blockForDone(); |
954 testFramework.mCronetEngine.stopNetLog(); | 954 testFramework.mCronetEngine.stopNetLog(); |
955 assertTrue(eventFile.exists()); | 955 assertTrue(eventFile.exists()); |
956 assertTrue(eventFile.length() != 0); | 956 assertTrue(eventFile.length() != 0); |
957 assertFalse(hasBytesInNetLog(eventFile)); | 957 assertFalse(hasBytesInNetLog(eventFile)); |
958 FileUtils.recursivelyDeleteFile(netLogDir); | 958 FileUtils.recursivelyDeleteFile(netLogDir); |
959 assertFalse(netLogDir.exists()); | 959 assertFalse(netLogDir.exists()); |
960 } | 960 } |
961 | 961 |
962 @SmallTest | 962 @SmallTest |
963 @Feature({"Cronet"}) | 963 @Feature({"Cronet"}) |
964 public void testNetLogStopMultipleTimes() throws Exception { | 964 public void testNetLogStopMultipleTimes() throws Exception { |
965 final CronetTestFramework testFramework = startCronetTestFramework(); | 965 final CronetTestFramework testFramework = startCronetTestFramework(); |
966 File directory = new File(PathUtils.getDataDirectory(getContext())); | 966 File directory = new File(PathUtils.getDataDirectory()); |
967 File file = File.createTempFile("cronet", "json", directory); | 967 File file = File.createTempFile("cronet", "json", directory); |
968 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); | 968 testFramework.mCronetEngine.startNetLogToFile(file.getPath(), false); |
969 // Start a request. | 969 // Start a request. |
970 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 970 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
971 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( | 971 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( |
972 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); | 972 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); |
973 urlRequestBuilder.build().start(); | 973 urlRequestBuilder.build().start(); |
974 callback.blockForDone(); | 974 callback.blockForDone(); |
975 // Stop NetLog multiple times. | 975 // Stop NetLog multiple times. |
976 testFramework.mCronetEngine.stopNetLog(); | 976 testFramework.mCronetEngine.stopNetLog(); |
977 testFramework.mCronetEngine.stopNetLog(); | 977 testFramework.mCronetEngine.stopNetLog(); |
978 testFramework.mCronetEngine.stopNetLog(); | 978 testFramework.mCronetEngine.stopNetLog(); |
979 testFramework.mCronetEngine.stopNetLog(); | 979 testFramework.mCronetEngine.stopNetLog(); |
980 testFramework.mCronetEngine.stopNetLog(); | 980 testFramework.mCronetEngine.stopNetLog(); |
981 assertTrue(file.exists()); | 981 assertTrue(file.exists()); |
982 assertTrue(file.length() != 0); | 982 assertTrue(file.length() != 0); |
983 assertFalse(hasBytesInNetLog(file)); | 983 assertFalse(hasBytesInNetLog(file)); |
984 assertTrue(file.delete()); | 984 assertTrue(file.delete()); |
985 assertTrue(!file.exists()); | 985 assertTrue(!file.exists()); |
986 } | 986 } |
987 | 987 |
988 @SmallTest | 988 @SmallTest |
989 @Feature({"Cronet"}) | 989 @Feature({"Cronet"}) |
990 public void testBoundedFileNetLogStopMultipleTimes() throws Exception { | 990 public void testBoundedFileNetLogStopMultipleTimes() throws Exception { |
991 final CronetTestFramework testFramework = startCronetTestFramework(); | 991 final CronetTestFramework testFramework = startCronetTestFramework(); |
992 File directory = new File(PathUtils.getDataDirectory(getContext())); | 992 File directory = new File(PathUtils.getDataDirectory()); |
993 File netLogDir = new File(directory, "NetLog"); | 993 File netLogDir = new File(directory, "NetLog"); |
994 assertFalse(netLogDir.exists()); | 994 assertFalse(netLogDir.exists()); |
995 assertTrue(netLogDir.mkdir()); | 995 assertTrue(netLogDir.mkdir()); |
996 File eventFile = new File(netLogDir, "event_file_0.json"); | 996 File eventFile = new File(netLogDir, "event_file_0.json"); |
997 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); | 997 testFramework.mCronetEngine.startNetLogToDisk(netLogDir.getPath(), false
, MAX_FILE_SIZE); |
998 // Start a request. | 998 // Start a request. |
999 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 999 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
1000 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( | 1000 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( |
1001 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); | 1001 mUrl, callback, callback.getExecutor(), testFramework.mCronetEng
ine); |
1002 urlRequestBuilder.build().start(); | 1002 urlRequestBuilder.build().start(); |
(...skipping 10 matching lines...) Expand all Loading... |
1013 assertFalse(hasBytesInNetLog(eventFile)); | 1013 assertFalse(hasBytesInNetLog(eventFile)); |
1014 FileUtils.recursivelyDeleteFile(netLogDir); | 1014 FileUtils.recursivelyDeleteFile(netLogDir); |
1015 assertFalse(netLogDir.exists()); | 1015 assertFalse(netLogDir.exists()); |
1016 } | 1016 } |
1017 | 1017 |
1018 @SmallTest | 1018 @SmallTest |
1019 @Feature({"Cronet"}) | 1019 @Feature({"Cronet"}) |
1020 @OnlyRunNativeCronet | 1020 @OnlyRunNativeCronet |
1021 public void testNetLogWithBytes() throws Exception { | 1021 public void testNetLogWithBytes() throws Exception { |
1022 Context context = getContext(); | 1022 Context context = getContext(); |
1023 File directory = new File(PathUtils.getDataDirectory(context)); | 1023 File directory = new File(PathUtils.getDataDirectory()); |
1024 File file = File.createTempFile("cronet", "json", directory); | 1024 File file = File.createTempFile("cronet", "json", directory); |
1025 CronetEngine cronetEngine = new CronetUrlRequestContext( | 1025 CronetEngine cronetEngine = new CronetUrlRequestContext( |
1026 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 1026 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
1027 // Start NetLog with logAll as true. | 1027 // Start NetLog with logAll as true. |
1028 cronetEngine.startNetLogToFile(file.getPath(), true); | 1028 cronetEngine.startNetLogToFile(file.getPath(), true); |
1029 // Start a request. | 1029 // Start a request. |
1030 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 1030 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
1031 UrlRequest.Builder urlRequestBuilder = | 1031 UrlRequest.Builder urlRequestBuilder = |
1032 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c
ronetEngine); | 1032 new UrlRequest.Builder(mUrl, callback, callback.getExecutor(), c
ronetEngine); |
1033 urlRequestBuilder.build().start(); | 1033 urlRequestBuilder.build().start(); |
1034 callback.blockForDone(); | 1034 callback.blockForDone(); |
1035 cronetEngine.stopNetLog(); | 1035 cronetEngine.stopNetLog(); |
1036 assertTrue(file.exists()); | 1036 assertTrue(file.exists()); |
1037 assertTrue(file.length() != 0); | 1037 assertTrue(file.length() != 0); |
1038 assertTrue(hasBytesInNetLog(file)); | 1038 assertTrue(hasBytesInNetLog(file)); |
1039 assertTrue(file.delete()); | 1039 assertTrue(file.delete()); |
1040 assertTrue(!file.exists()); | 1040 assertTrue(!file.exists()); |
1041 } | 1041 } |
1042 | 1042 |
1043 @SmallTest | 1043 @SmallTest |
1044 @Feature({"Cronet"}) | 1044 @Feature({"Cronet"}) |
1045 @OnlyRunNativeCronet | 1045 @OnlyRunNativeCronet |
1046 public void testBoundedFileNetLogWithBytes() throws Exception { | 1046 public void testBoundedFileNetLogWithBytes() throws Exception { |
1047 Context context = getContext(); | 1047 Context context = getContext(); |
1048 File directory = new File(PathUtils.getDataDirectory(context)); | 1048 File directory = new File(PathUtils.getDataDirectory()); |
1049 File netLogDir = new File(directory, "NetLog"); | 1049 File netLogDir = new File(directory, "NetLog"); |
1050 assertFalse(netLogDir.exists()); | 1050 assertFalse(netLogDir.exists()); |
1051 assertTrue(netLogDir.mkdir()); | 1051 assertTrue(netLogDir.mkdir()); |
1052 File eventFile = new File(netLogDir, "event_file_0.json"); | 1052 File eventFile = new File(netLogDir, "event_file_0.json"); |
1053 CronetUrlRequestContext cronetEngine = new CronetUrlRequestContext( | 1053 CronetUrlRequestContext cronetEngine = new CronetUrlRequestContext( |
1054 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); | 1054 new CronetEngine.Builder(context).setLibraryName("cronet_tests")
); |
1055 // Start NetLog with logAll as true. | 1055 // Start NetLog with logAll as true. |
1056 cronetEngine.startNetLogToDisk(netLogDir.getPath(), true, MAX_FILE_SIZE)
; | 1056 cronetEngine.startNetLogToDisk(netLogDir.getPath(), true, MAX_FILE_SIZE)
; |
1057 // Start a request. | 1057 // Start a request. |
1058 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 1058 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 1466 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
1467 URL requestUrl = | 1467 URL requestUrl = |
1468 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl
.getFile()); | 1468 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl
.getFile()); |
1469 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(requestUrl
.toString(), | 1469 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(requestUrl
.toString(), |
1470 callback, callback.getExecutor(), testFramework.mCronetEngine); | 1470 callback, callback.getExecutor(), testFramework.mCronetEngine); |
1471 urlRequestBuilder.build().start(); | 1471 urlRequestBuilder.build().start(); |
1472 callback.blockForDone(); | 1472 callback.blockForDone(); |
1473 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 1473 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
1474 } | 1474 } |
1475 } | 1475 } |
OLD | NEW |