Chromium Code Reviews| 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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/values_test_util.h" | 10 #include "base/test/values_test_util.h" |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 " 'chrome://favicon/'," | 582 " 'chrome://favicon/'," |
| 583 " 'http://*.*'," | 583 " 'http://*.*'," |
| 584 " ]" | 584 " ]" |
| 585 "}"); | 585 "}"); |
| 586 ASSERT_TRUE(CheckManifestProducesPermissions( | 586 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 587 "Read and change your data on all go.com sites", | 587 "Read and change your data on all go.com sites", |
| 588 "Read the icons of the websites you visit")); | 588 "Read the icons of the websites you visit")); |
| 589 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | 589 ASSERT_TRUE(CheckManifestProducesHostPermissions()); |
| 590 } | 590 } |
| 591 | 591 |
| 592 // Check that permission messages are generated correctly for the sockets | 592 // Check that permission messages are generated correctly for |
| 593 // permission, which has host-like permission messages. | 593 // SocketsManifestPermission, which has host-like permission messages. |
| 594 TEST_F(PermissionMessageCombinationsUnittest, SocketsPermissionMessages) { | 594 TEST_F(PermissionMessageCombinationsUnittest, |
| 595 SocketsManifestPermissionMessages) { | |
| 595 CreateAndInstall( | 596 CreateAndInstall( |
| 596 "{" | 597 "{" |
| 597 " 'app': {" | 598 " 'app': {" |
| 598 " 'background': {" | 599 " 'background': {" |
| 599 " 'scripts': ['background.js']" | 600 " 'scripts': ['background.js']" |
| 600 " }" | 601 " }" |
| 601 " }," | 602 " }," |
| 602 " 'sockets': {" | 603 " 'sockets': {" |
| 603 " 'udp': {'send': '*'}," | 604 " 'udp': {'send': '*'}," |
| 604 " }" | 605 " }" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 " 'sockets': {" | 750 " 'sockets': {" |
| 750 " 'tcp': {'send': '*:*'}," | 751 " 'tcp': {'send': '*:*'}," |
| 751 " 'tcpServer': {'listen': '*:*'}," | 752 " 'tcpServer': {'listen': '*:*'}," |
| 752 " }" | 753 " }" |
| 753 "}"); | 754 "}"); |
| 754 ASSERT_TRUE(CheckManifestProducesPermissions( | 755 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 755 "Exchange data with any computer on the local network or internet")); | 756 "Exchange data with any computer on the local network or internet")); |
| 756 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | 757 ASSERT_TRUE(CheckManifestProducesHostPermissions()); |
| 757 } | 758 } |
| 758 | 759 |
| 760 // Check that permission messages are generated correctly for | |
| 761 // MediaGalleriesPermission (an API permission with custom messages). | |
| 762 TEST_F(PermissionMessageCombinationsUnittest, | |
| 763 MediaGalleriesPermissionMessages) { | |
| 764 CreateAndInstall( | |
| 765 "{" | |
| 766 " 'app': {" | |
| 767 " 'background': {" | |
| 768 " 'scripts': ['background.js']" | |
| 769 " }" | |
| 770 " }," | |
| 771 " 'permissions': [" | |
| 772 " { 'mediaGalleries': ['read'] }" | |
| 773 " ]" | |
| 774 "}"); | |
| 775 ASSERT_TRUE(CheckManifestProducesPermissions()); | |
| 776 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 777 | |
| 778 CreateAndInstall( | |
| 779 "{" | |
| 780 " 'app': {" | |
| 781 " 'background': {" | |
| 782 " 'scripts': ['background.js']" | |
| 783 " }" | |
| 784 " }," | |
| 785 " 'permissions': [" | |
| 786 " { 'mediaGalleries': ['read', 'allAutoDetected'] }" | |
| 787 " ]" | |
| 788 "}"); | |
| 789 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 790 "Access photos, music, and other media from your computer")); | |
| 791 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 792 | |
| 793 // TODO(sashab): Add a test for the | |
| 794 // IDS_EXTENSION_PROMPT_WARNING_MEDIA_GALLERIES_READ_WRITE message (generated | |
| 795 // with the 'read' and 'copyTo' permissions, but not the 'delete' permission), | |
| 796 // if it's possible to get this message. Otherwise, remove it from the code. | |
| 797 | |
| 798 CreateAndInstall( | |
| 799 "{" | |
| 800 " 'app': {" | |
| 801 " 'background': {" | |
| 802 " 'scripts': ['background.js']" | |
| 803 " }" | |
| 804 " }," | |
| 805 " 'permissions': [" | |
| 806 " { 'mediaGalleries': ['read', 'delete', 'allAutoDetected'] }" | |
| 807 " ]" | |
| 808 "}"); | |
| 809 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 810 "Read and delete photos, music, and other media from your computer")); | |
| 811 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 812 | |
| 813 CreateAndInstall( | |
| 814 "{" | |
| 815 " 'app': {" | |
| 816 " 'background': {" | |
| 817 " 'scripts': ['background.js']" | |
| 818 " }" | |
| 819 " }," | |
| 820 " 'permissions': [" | |
| 821 " { 'mediaGalleries':" | |
| 822 " [ 'read', 'delete', 'copyTo', 'allAutoDetected' ] }" | |
| 823 " ]" | |
| 824 "}"); | |
| 825 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 826 "Read, change and delete photos, music, and other media from your " | |
| 827 "computer")); | |
| 828 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 829 | |
| 830 // Without the allAutoDetected permission, there should be no install-time | |
| 831 // permission messages. | |
| 832 CreateAndInstall( | |
| 833 "{" | |
| 834 " 'app': {" | |
| 835 " 'background': {" | |
| 836 " 'scripts': ['background.js']" | |
| 837 " }" | |
| 838 " }," | |
| 839 " 'permissions': [" | |
| 840 " { 'mediaGalleries': ['read', 'delete', 'copyTo'] }" | |
| 841 " ]" | |
| 842 "}"); | |
| 843 ASSERT_TRUE(CheckManifestProducesPermissions()); | |
| 844 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 845 } | |
| 846 | |
| 847 // TODO(sashab): Add tests for SettingsOverrideAPIPermission (an API permission | |
| 848 // with custom messages). | |
| 849 | |
| 850 // Check that permission messages are generated correctly for SocketPermission | |
| 851 // (an API permission with custom messages). | |
| 852 TEST_F(PermissionMessageCombinationsUnittest, SocketPermissionMessages) { | |
| 853 CreateAndInstall( | |
| 854 "{" | |
| 855 " 'app': {" | |
| 856 " 'background': {" | |
| 857 " 'scripts': ['background.js']" | |
| 858 " }" | |
| 859 " }," | |
| 860 " 'permissions': [" | |
| 861 " { 'socket': ['tcp-connect:*:*'] }" | |
| 862 " ]" | |
| 863 "}"); | |
| 864 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 865 "Exchange data with any computer on the local network or internet")); | |
| 866 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 867 | |
| 868 CreateAndInstall( | |
| 869 "{" | |
| 870 " 'app': {" | |
| 871 " 'background': {" | |
| 872 " 'scripts': ['background.js']" | |
| 873 " }" | |
| 874 " }," | |
| 875 " 'permissions': [" | |
| 876 " { 'socket': [" | |
| 877 " 'tcp-connect:*:443'," | |
| 878 " 'tcp-connect:*:50032'," | |
| 879 " 'tcp-connect:*:23'," | |
| 880 " ] }" | |
| 881 " ]" | |
| 882 "}"); | |
| 883 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 884 "Exchange data with any computer on the local network or internet")); | |
| 885 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 886 | |
| 887 CreateAndInstall( | |
| 888 "{" | |
| 889 " 'app': {" | |
| 890 " 'background': {" | |
| 891 " 'scripts': ['background.js']" | |
| 892 " }" | |
| 893 " }," | |
| 894 " 'permissions': [" | |
| 895 " { 'socket': ['tcp-connect:foo.example.com:443'] }" | |
| 896 " ]" | |
| 897 "}"); | |
| 898 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 899 "Exchange data with the computer named foo.example.com")); | |
| 900 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 901 | |
| 902 CreateAndInstall( | |
| 903 "{" | |
| 904 " 'app': {" | |
| 905 " 'background': {" | |
| 906 " 'scripts': ['background.js']" | |
| 907 " }" | |
| 908 " }," | |
| 909 " 'permissions': [" | |
| 910 " { 'socket': ['tcp-connect:foo.example.com:443', 'udp-send-to'] }" | |
| 911 " ]" | |
| 912 "}"); | |
| 913 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 914 "Exchange data with any computer on the local network or internet")); | |
| 915 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 916 | |
| 917 CreateAndInstall( | |
| 918 "{" | |
| 919 " 'app': {" | |
| 920 " 'background': {" | |
| 921 " 'scripts': ['background.js']" | |
| 922 " }" | |
| 923 " }," | |
| 924 " 'permissions': [" | |
| 925 " { 'socket': [" | |
| 926 " 'tcp-connect:foo.example.com:443'," | |
| 927 " 'udp-send-to:test.ping.com:50032'," | |
| 928 " ] }" | |
| 929 " ]" | |
| 930 "}"); | |
| 931 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 932 "Exchange data with the computers named: foo.example.com test.ping.com")); | |
| 933 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 934 | |
| 935 CreateAndInstall( | |
| 936 "{" | |
| 937 " 'app': {" | |
| 938 " 'background': {" | |
| 939 " 'scripts': ['background.js']" | |
| 940 " }" | |
| 941 " }," | |
| 942 " 'permissions': [" | |
| 943 " { 'socket': [" | |
| 944 " 'tcp-connect:foo.example.com:443'," | |
| 945 " 'udp-send-to:test.ping.com:50032'," | |
| 946 " 'udp-send-to:www.ping.com:50032'," | |
| 947 " 'udp-send-to:test2.ping.com:50032'," | |
| 948 " 'udp-bind:test.ping.com:50032'," | |
| 949 " 'udp-listen:other.ping.com:50032'," | |
| 950 " 'udp-listen:www.google.com:50032'," | |
| 951 " ] }" | |
| 952 " ]" | |
| 953 "}"); | |
| 954 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 955 "Exchange data with the computers named: foo.example.com test.ping.com " | |
| 956 "test2.ping.com www.ping.com")); | |
| 957 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 958 | |
| 959 CreateAndInstall( | |
| 960 "{" | |
| 961 " 'app': {" | |
| 962 " 'background': {" | |
| 963 " 'scripts': ['background.js']" | |
| 964 " }" | |
| 965 " }," | |
| 966 " 'permissions': [" | |
| 967 " { 'socket': [" | |
| 968 " 'tcp-connect:foo.example.com:443'," | |
| 969 " 'udp-send-to:test.ping.com:50032'," | |
| 970 " 'tcp-connect:*:23'," | |
| 971 " ] }" | |
| 972 " ]" | |
| 973 "}"); | |
| 974 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 975 "Exchange data with any computer on the local network or internet")); | |
| 976 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 977 } | |
| 978 | |
| 979 // Check that permission messages are generated correctly for | |
| 980 // USBDevicePermission (an API permission with custom messages). | |
| 981 TEST_F(PermissionMessageCombinationsUnittest, USBDevicePermissionMessages) { | |
| 982 CreateAndInstall( | |
| 983 "{" | |
| 984 " 'app': {" | |
| 985 " 'background': {" | |
| 986 " 'scripts': ['background.js']" | |
| 987 " }" | |
| 988 " }," | |
| 989 " 'permissions': [" | |
| 990 " { 'usbDevices': [" | |
| 991 " { 'vendorId': 0, 'productId': 0 }," | |
| 992 " ] }" | |
| 993 " ]" | |
| 994 "}"); | |
| 995 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 996 "Access USB devices from an unknown vendor")); | |
| 997 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 998 | |
| 999 CreateAndInstall( | |
| 1000 "{" | |
| 1001 " 'app': {" | |
| 1002 " 'background': {" | |
| 1003 " 'scripts': ['background.js']" | |
| 1004 " }" | |
| 1005 " }," | |
| 1006 " 'permissions': [" | |
| 1007 " { 'usbDevices': [" | |
| 1008 " { 'vendorId': 4179, 'productId': 529 }," | |
| 1009 " ] }" | |
| 1010 " ]" | |
| 1011 "}"); | |
| 1012 ASSERT_TRUE(CheckManifestProducesPermissions( | |
| 1013 "Access USB devices from Immanuel Electronics Co., Ltd")); | |
| 1014 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 1015 | |
| 1016 CreateAndInstall( | |
| 1017 "{" | |
| 1018 " 'app': {" | |
| 1019 " 'background': {" | |
| 1020 " 'scripts': ['background.js']" | |
| 1021 " }" | |
| 1022 " }," | |
| 1023 " 'permissions': [" | |
| 1024 " { 'usbDevices': [" | |
| 1025 " { 'vendorId': 6353, 'productId': 20194 }," | |
| 1026 " ] }" | |
| 1027 " ]" | |
| 1028 "}"); | |
| 1029 ASSERT_TRUE( | |
| 1030 CheckManifestProducesPermissions("Access USB devices from Google Inc.")); | |
| 1031 ASSERT_TRUE(CheckManifestProducesHostPermissions()); | |
| 1032 | |
| 1033 CreateAndInstall( | |
| 1034 "{" | |
| 1035 " 'app': {" | |
| 1036 " 'background': {" | |
| 1037 " 'scripts': ['background.js']" | |
| 1038 " }" | |
| 1039 " }," | |
| 1040 " 'permissions': [" | |
| 1041 " { 'usbDevices': [" | |
| 1042 " { 'vendorId': 4179, 'productId': 529 }," | |
| 1043 " { 'vendorId': 6353, 'productId': 20194 }," | |
| 1044 " ] }" | |
| 1045 " ]" | |
| 1046 "}"); | |
| 1047 ASSERT_TRUE( | |
| 1048 CheckManifestProducesPermissions("Access any of these USB devices")); | |
| 1049 ASSERT_TRUE(CheckManifestProducesHostPermissions( | |
| 1050 "unknown devices from Immanuel Electronics Co., Ltd", | |
|
Yoyo Zhou
2014/12/11 00:54:11
These are a little unorthodox for "host permission
sashab
2014/12/11 04:15:36
Hm; this is a good point. Technically, we should b
| |
| 1051 "unknown devices from Google Inc.")); | |
| 1052 | |
| 1053 // TODO(sashab): Add a test with a valid product/vendor USB device. | |
| 1054 } | |
| 1055 | |
| 759 // Test that hosted apps are not given any messages for host permissions. | 1056 // Test that hosted apps are not given any messages for host permissions. |
| 760 TEST_F(PermissionMessageCombinationsUnittest, | 1057 TEST_F(PermissionMessageCombinationsUnittest, |
| 761 PackagedAppsHaveNoHostPermissions) { | 1058 PackagedAppsHaveNoHostPermissions) { |
| 762 CreateAndInstall( | 1059 CreateAndInstall( |
| 763 "{" | 1060 "{" |
| 764 " 'app': {" | 1061 " 'app': {" |
| 765 " 'background': {" | 1062 " 'background': {" |
| 766 " 'scripts': ['background.js']" | 1063 " 'scripts': ['background.js']" |
| 767 " }" | 1064 " }" |
| 768 " }," | 1065 " }," |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 // TODO(sashab): Add a test that ensures that all permissions that can generate | 1260 // TODO(sashab): Add a test that ensures that all permissions that can generate |
| 964 // a coalesced message can also generate a message on their own (i.e. ensure | 1261 // a coalesced message can also generate a message on their own (i.e. ensure |
| 965 // that no permissions only modify other permissions). | 1262 // that no permissions only modify other permissions). |
| 966 | 1263 |
| 967 // TODO(sashab): Add a test for every permission message combination that can | 1264 // TODO(sashab): Add a test for every permission message combination that can |
| 968 // generate a message. | 1265 // generate a message. |
| 969 | 1266 |
| 970 // TODO(aboxhall): Add tests for the automation API permission messages. | 1267 // TODO(aboxhall): Add tests for the automation API permission messages. |
| 971 | 1268 |
| 972 } // namespace extensions | 1269 } // namespace extensions |
| OLD | NEW |