| 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/test/values_test_util.h" | 7 #include "base/test/values_test_util.h" |
| 8 #include "chrome/browser/extensions/test_extension_environment.h" | 8 #include "chrome/browser/extensions/test_extension_environment.h" |
| 9 #include "chrome/common/extensions/permissions/chrome_permission_message_provide
r.h" | 9 #include "chrome/common/extensions/permissions/chrome_permission_message_provide
r.h" |
| 10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 " 'app': {" | 538 " 'app': {" |
| 539 " 'background': {" | 539 " 'background': {" |
| 540 " 'scripts': ['background.js']" | 540 " 'scripts': ['background.js']" |
| 541 " }" | 541 " }" |
| 542 " }," | 542 " }," |
| 543 " 'sockets': {" | 543 " 'sockets': {" |
| 544 " 'udp': {'send': '*'}," | 544 " 'udp': {'send': '*'}," |
| 545 " }" | 545 " }" |
| 546 "}"); | 546 "}"); |
| 547 ASSERT_TRUE(CheckManifestProducesPermissions( | 547 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 548 "Exchange data with any computer on the local network or internet")); | 548 "Exchange data with any device on the local network or internet")); |
| 549 | 549 |
| 550 CreateAndInstall( | 550 CreateAndInstall( |
| 551 "{" | 551 "{" |
| 552 " 'app': {" | 552 " 'app': {" |
| 553 " 'background': {" | 553 " 'background': {" |
| 554 " 'scripts': ['background.js']" | 554 " 'scripts': ['background.js']" |
| 555 " }" | 555 " }" |
| 556 " }," | 556 " }," |
| 557 " 'sockets': {" | 557 " 'sockets': {" |
| 558 " 'udp': {'send': ':99'}," | 558 " 'udp': {'send': ':99'}," |
| 559 " }" | 559 " }" |
| 560 "}"); | 560 "}"); |
| 561 ASSERT_TRUE(CheckManifestProducesPermissions( | 561 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 562 "Exchange data with any computer on the local network or internet")); | 562 "Exchange data with any device on the local network or internet")); |
| 563 | 563 |
| 564 CreateAndInstall( | 564 CreateAndInstall( |
| 565 "{" | 565 "{" |
| 566 " 'app': {" | 566 " 'app': {" |
| 567 " 'background': {" | 567 " 'background': {" |
| 568 " 'scripts': ['background.js']" | 568 " 'scripts': ['background.js']" |
| 569 " }" | 569 " }" |
| 570 " }," | 570 " }," |
| 571 " 'sockets': {" | 571 " 'sockets': {" |
| 572 " 'tcp': {'connect': '127.0.0.1:80'}," | 572 " 'tcp': {'connect': '127.0.0.1:80'}," |
| 573 " }" | 573 " }" |
| 574 "}"); | 574 "}"); |
| 575 ASSERT_TRUE(CheckManifestProducesPermissions( | 575 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 576 "Exchange data with the computer named 127.0.0.1")); | 576 "Exchange data with the device named 127.0.0.1")); |
| 577 | 577 |
| 578 CreateAndInstall( | 578 CreateAndInstall( |
| 579 "{" | 579 "{" |
| 580 " 'app': {" | 580 " 'app': {" |
| 581 " 'background': {" | 581 " 'background': {" |
| 582 " 'scripts': ['background.js']" | 582 " 'scripts': ['background.js']" |
| 583 " }" | 583 " }" |
| 584 " }," | 584 " }," |
| 585 " 'sockets': {" | 585 " 'sockets': {" |
| 586 " 'tcp': {'connect': 'www.example.com:23'}," | 586 " 'tcp': {'connect': 'www.example.com:23'}," |
| 587 " }" | 587 " }" |
| 588 "}"); | 588 "}"); |
| 589 ASSERT_TRUE(CheckManifestProducesPermissions( | 589 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 590 "Exchange data with the computer named www.example.com")); | 590 "Exchange data with the device named www.example.com")); |
| 591 | 591 |
| 592 CreateAndInstall( | 592 CreateAndInstall( |
| 593 "{" | 593 "{" |
| 594 " 'app': {" | 594 " 'app': {" |
| 595 " 'background': {" | 595 " 'background': {" |
| 596 " 'scripts': ['background.js']" | 596 " 'scripts': ['background.js']" |
| 597 " }" | 597 " }" |
| 598 " }," | 598 " }," |
| 599 " 'sockets': {" | 599 " 'sockets': {" |
| 600 " 'tcpServer': {'listen': '127.0.0.1:80'}" | 600 " 'tcpServer': {'listen': '127.0.0.1:80'}" |
| 601 " }" | 601 " }" |
| 602 "}"); | 602 "}"); |
| 603 ASSERT_TRUE(CheckManifestProducesPermissions( | 603 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 604 "Exchange data with the computer named 127.0.0.1")); | 604 "Exchange data with the device named 127.0.0.1")); |
| 605 | 605 |
| 606 CreateAndInstall( | 606 CreateAndInstall( |
| 607 "{" | 607 "{" |
| 608 " 'app': {" | 608 " 'app': {" |
| 609 " 'background': {" | 609 " 'background': {" |
| 610 " 'scripts': ['background.js']" | 610 " 'scripts': ['background.js']" |
| 611 " }" | 611 " }" |
| 612 " }," | 612 " }," |
| 613 " 'sockets': {" | 613 " 'sockets': {" |
| 614 " 'tcpServer': {'listen': ':8080'}" | 614 " 'tcpServer': {'listen': ':8080'}" |
| 615 " }" | 615 " }" |
| 616 "}"); | 616 "}"); |
| 617 ASSERT_TRUE(CheckManifestProducesPermissions( | 617 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 618 "Exchange data with any computer on the local network or internet")); | 618 "Exchange data with any device on the local network or internet")); |
| 619 | 619 |
| 620 CreateAndInstall( | 620 CreateAndInstall( |
| 621 "{" | 621 "{" |
| 622 " 'app': {" | 622 " 'app': {" |
| 623 " 'background': {" | 623 " 'background': {" |
| 624 " 'scripts': ['background.js']" | 624 " 'scripts': ['background.js']" |
| 625 " }" | 625 " }" |
| 626 " }," | 626 " }," |
| 627 " 'sockets': {" | 627 " 'sockets': {" |
| 628 " 'tcpServer': {" | 628 " 'tcpServer': {" |
| 629 " 'listen': [" | 629 " 'listen': [" |
| 630 " '127.0.0.1:80'," | 630 " '127.0.0.1:80'," |
| 631 " 'www.google.com'," | 631 " 'www.google.com'," |
| 632 " 'www.example.com:*'," | 632 " 'www.example.com:*'," |
| 633 " 'www.foo.com:200'," | 633 " 'www.foo.com:200'," |
| 634 " 'www.bar.com:200'" | 634 " 'www.bar.com:200'" |
| 635 " ]" | 635 " ]" |
| 636 " }" | 636 " }" |
| 637 " }" | 637 " }" |
| 638 "}"); | 638 "}"); |
| 639 ASSERT_TRUE(CheckManifestProducesPermissions( | 639 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 640 "Exchange data with the computers named: 127.0.0.1 www.bar.com " | 640 "Exchange data with the devices named: 127.0.0.1 www.bar.com " |
| 641 "www.example.com www.foo.com www.google.com")); | 641 "www.example.com www.foo.com www.google.com")); |
| 642 | 642 |
| 643 CreateAndInstall( | 643 CreateAndInstall( |
| 644 "{" | 644 "{" |
| 645 " 'app': {" | 645 " 'app': {" |
| 646 " 'background': {" | 646 " 'background': {" |
| 647 " 'scripts': ['background.js']" | 647 " 'scripts': ['background.js']" |
| 648 " }" | 648 " }" |
| 649 " }," | 649 " }," |
| 650 " 'sockets': {" | 650 " 'sockets': {" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 661 " 'listen': [" | 661 " 'listen': [" |
| 662 " '127.0.0.1:80'," | 662 " '127.0.0.1:80'," |
| 663 " 'www.google.com'," | 663 " 'www.google.com'," |
| 664 " 'www.example.com:*'," | 664 " 'www.example.com:*'," |
| 665 " 'www.foo.com:200'," | 665 " 'www.foo.com:200'," |
| 666 " ]" | 666 " ]" |
| 667 " }" | 667 " }" |
| 668 " }" | 668 " }" |
| 669 "}"); | 669 "}"); |
| 670 ASSERT_TRUE(CheckManifestProducesPermissions( | 670 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 671 "Exchange data with the computers named: 127.0.0.1 www.abc.com " | 671 "Exchange data with the devices named: 127.0.0.1 www.abc.com " |
| 672 "www.example.com www.foo.com www.freestuff.com www.google.com " | 672 "www.example.com www.foo.com www.freestuff.com www.google.com " |
| 673 "www.mywebsite.com www.test.com")); | 673 "www.mywebsite.com www.test.com")); |
| 674 | 674 |
| 675 CreateAndInstall( | 675 CreateAndInstall( |
| 676 "{" | 676 "{" |
| 677 " 'app': {" | 677 " 'app': {" |
| 678 " 'background': {" | 678 " 'background': {" |
| 679 " 'scripts': ['background.js']" | 679 " 'scripts': ['background.js']" |
| 680 " }" | 680 " }" |
| 681 " }," | 681 " }," |
| 682 " 'sockets': {" | 682 " 'sockets': {" |
| 683 " 'tcp': {'send': '*:*'}," | 683 " 'tcp': {'send': '*:*'}," |
| 684 " 'tcpServer': {'listen': '*:*'}," | 684 " 'tcpServer': {'listen': '*:*'}," |
| 685 " }" | 685 " }" |
| 686 "}"); | 686 "}"); |
| 687 ASSERT_TRUE(CheckManifestProducesPermissions( | 687 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 688 "Exchange data with any computer on the local network or internet")); | 688 "Exchange data with any device on the local network or internet")); |
| 689 } | 689 } |
| 690 | 690 |
| 691 // Check that permission messages are generated correctly for | 691 // Check that permission messages are generated correctly for |
| 692 // MediaGalleriesPermission (an API permission with custom messages). | 692 // MediaGalleriesPermission (an API permission with custom messages). |
| 693 TEST_F(PermissionMessageCombinationsUnittest, | 693 TEST_F(PermissionMessageCombinationsUnittest, |
| 694 MediaGalleriesPermissionMessages) { | 694 MediaGalleriesPermissionMessages) { |
| 695 CreateAndInstall( | 695 CreateAndInstall( |
| 696 "{" | 696 "{" |
| 697 " 'app': {" | 697 " 'app': {" |
| 698 " 'background': {" | 698 " 'background': {" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 " 'app': {" | 781 " 'app': {" |
| 782 " 'background': {" | 782 " 'background': {" |
| 783 " 'scripts': ['background.js']" | 783 " 'scripts': ['background.js']" |
| 784 " }" | 784 " }" |
| 785 " }," | 785 " }," |
| 786 " 'permissions': [" | 786 " 'permissions': [" |
| 787 " { 'socket': ['tcp-connect:*:*'] }" | 787 " { 'socket': ['tcp-connect:*:*'] }" |
| 788 " ]" | 788 " ]" |
| 789 "}"); | 789 "}"); |
| 790 ASSERT_TRUE(CheckManifestProducesPermissions( | 790 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 791 "Exchange data with any computer on the local network or internet")); | 791 "Exchange data with any device on the local network or internet")); |
| 792 | 792 |
| 793 CreateAndInstall( | 793 CreateAndInstall( |
| 794 "{" | 794 "{" |
| 795 " 'app': {" | 795 " 'app': {" |
| 796 " 'background': {" | 796 " 'background': {" |
| 797 " 'scripts': ['background.js']" | 797 " 'scripts': ['background.js']" |
| 798 " }" | 798 " }" |
| 799 " }," | 799 " }," |
| 800 " 'permissions': [" | 800 " 'permissions': [" |
| 801 " { 'socket': [" | 801 " { 'socket': [" |
| 802 " 'tcp-connect:*:443'," | 802 " 'tcp-connect:*:443'," |
| 803 " 'tcp-connect:*:50032'," | 803 " 'tcp-connect:*:50032'," |
| 804 " 'tcp-connect:*:23'," | 804 " 'tcp-connect:*:23'," |
| 805 " ] }" | 805 " ] }" |
| 806 " ]" | 806 " ]" |
| 807 "}"); | 807 "}"); |
| 808 ASSERT_TRUE(CheckManifestProducesPermissions( | 808 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 809 "Exchange data with any computer on the local network or internet")); | 809 "Exchange data with any device on the local network or internet")); |
| 810 | 810 |
| 811 CreateAndInstall( | 811 CreateAndInstall( |
| 812 "{" | 812 "{" |
| 813 " 'app': {" | 813 " 'app': {" |
| 814 " 'background': {" | 814 " 'background': {" |
| 815 " 'scripts': ['background.js']" | 815 " 'scripts': ['background.js']" |
| 816 " }" | 816 " }" |
| 817 " }," | 817 " }," |
| 818 " 'permissions': [" | 818 " 'permissions': [" |
| 819 " { 'socket': ['tcp-connect:foo.example.com:443'] }" | 819 " { 'socket': ['tcp-connect:foo.example.com:443'] }" |
| 820 " ]" | 820 " ]" |
| 821 "}"); | 821 "}"); |
| 822 ASSERT_TRUE(CheckManifestProducesPermissions( | 822 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 823 "Exchange data with the computer named foo.example.com")); | 823 "Exchange data with the device named foo.example.com")); |
| 824 | 824 |
| 825 CreateAndInstall( | 825 CreateAndInstall( |
| 826 "{" | 826 "{" |
| 827 " 'app': {" | 827 " 'app': {" |
| 828 " 'background': {" | 828 " 'background': {" |
| 829 " 'scripts': ['background.js']" | 829 " 'scripts': ['background.js']" |
| 830 " }" | 830 " }" |
| 831 " }," | 831 " }," |
| 832 " 'permissions': [" | 832 " 'permissions': [" |
| 833 " { 'socket': ['tcp-connect:foo.example.com:443', 'udp-send-to'] }" | 833 " { 'socket': ['tcp-connect:foo.example.com:443', 'udp-send-to'] }" |
| 834 " ]" | 834 " ]" |
| 835 "}"); | 835 "}"); |
| 836 ASSERT_TRUE(CheckManifestProducesPermissions( | 836 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 837 "Exchange data with any computer on the local network or internet")); | 837 "Exchange data with any device on the local network or internet")); |
| 838 | 838 |
| 839 CreateAndInstall( | 839 CreateAndInstall( |
| 840 "{" | 840 "{" |
| 841 " 'app': {" | 841 " 'app': {" |
| 842 " 'background': {" | 842 " 'background': {" |
| 843 " 'scripts': ['background.js']" | 843 " 'scripts': ['background.js']" |
| 844 " }" | 844 " }" |
| 845 " }," | 845 " }," |
| 846 " 'permissions': [" | 846 " 'permissions': [" |
| 847 " { 'socket': [" | 847 " { 'socket': [" |
| 848 " 'tcp-connect:foo.example.com:443'," | 848 " 'tcp-connect:foo.example.com:443'," |
| 849 " 'udp-send-to:test.ping.com:50032'," | 849 " 'udp-send-to:test.ping.com:50032'," |
| 850 " ] }" | 850 " ] }" |
| 851 " ]" | 851 " ]" |
| 852 "}"); | 852 "}"); |
| 853 ASSERT_TRUE(CheckManifestProducesPermissions( | 853 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 854 "Exchange data with the computers named: foo.example.com test.ping.com")); | 854 "Exchange data with the devices named: foo.example.com test.ping.com")); |
| 855 | 855 |
| 856 CreateAndInstall( | 856 CreateAndInstall( |
| 857 "{" | 857 "{" |
| 858 " 'app': {" | 858 " 'app': {" |
| 859 " 'background': {" | 859 " 'background': {" |
| 860 " 'scripts': ['background.js']" | 860 " 'scripts': ['background.js']" |
| 861 " }" | 861 " }" |
| 862 " }," | 862 " }," |
| 863 " 'permissions': [" | 863 " 'permissions': [" |
| 864 " { 'socket': [" | 864 " { 'socket': [" |
| 865 " 'tcp-connect:foo.example.com:443'," | 865 " 'tcp-connect:foo.example.com:443'," |
| 866 " 'udp-send-to:test.ping.com:50032'," | 866 " 'udp-send-to:test.ping.com:50032'," |
| 867 " 'udp-send-to:www.ping.com:50032'," | 867 " 'udp-send-to:www.ping.com:50032'," |
| 868 " 'udp-send-to:test2.ping.com:50032'," | 868 " 'udp-send-to:test2.ping.com:50032'," |
| 869 " 'udp-bind:test.ping.com:50032'," | 869 " 'udp-bind:test.ping.com:50032'," |
| 870 " ] }" | 870 " ] }" |
| 871 " ]" | 871 " ]" |
| 872 "}"); | 872 "}"); |
| 873 ASSERT_TRUE(CheckManifestProducesPermissions( | 873 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 874 "Exchange data with the computers named: foo.example.com test.ping.com " | 874 "Exchange data with the devices named: foo.example.com test.ping.com " |
| 875 "test2.ping.com www.ping.com")); | 875 "test2.ping.com www.ping.com")); |
| 876 | 876 |
| 877 CreateAndInstall( | 877 CreateAndInstall( |
| 878 "{" | 878 "{" |
| 879 " 'app': {" | 879 " 'app': {" |
| 880 " 'background': {" | 880 " 'background': {" |
| 881 " 'scripts': ['background.js']" | 881 " 'scripts': ['background.js']" |
| 882 " }" | 882 " }" |
| 883 " }," | 883 " }," |
| 884 " 'permissions': [" | 884 " 'permissions': [" |
| 885 " { 'socket': [" | 885 " { 'socket': [" |
| 886 " 'tcp-connect:foo.example.com:443'," | 886 " 'tcp-connect:foo.example.com:443'," |
| 887 " 'udp-send-to:test.ping.com:50032'," | 887 " 'udp-send-to:test.ping.com:50032'," |
| 888 " 'tcp-connect:*:23'," | 888 " 'tcp-connect:*:23'," |
| 889 " ] }" | 889 " ] }" |
| 890 " ]" | 890 " ]" |
| 891 "}"); | 891 "}"); |
| 892 ASSERT_TRUE(CheckManifestProducesPermissions( | 892 ASSERT_TRUE(CheckManifestProducesPermissions( |
| 893 "Exchange data with any computer on the local network or internet")); | 893 "Exchange data with any device on the local network or internet")); |
| 894 } | 894 } |
| 895 | 895 |
| 896 // Check that permission messages are generated correctly for | 896 // Check that permission messages are generated correctly for |
| 897 // USBDevicePermission (an API permission with custom messages). | 897 // USBDevicePermission (an API permission with custom messages). |
| 898 TEST_F(PermissionMessageCombinationsUnittest, USBDevicePermissionMessages) { | 898 TEST_F(PermissionMessageCombinationsUnittest, USBDevicePermissionMessages) { |
| 899 CreateAndInstall( | 899 CreateAndInstall( |
| 900 "{" | 900 "{" |
| 901 " 'app': {" | 901 " 'app': {" |
| 902 " 'background': {" | 902 " 'background': {" |
| 903 " 'scripts': ['background.js']" | 903 " 'scripts': ['background.js']" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 // TODO(sashab): Add a test that ensures that all permissions that can generate | 1163 // TODO(sashab): Add a test that ensures that all permissions that can generate |
| 1164 // a coalesced message can also generate a message on their own (i.e. ensure | 1164 // a coalesced message can also generate a message on their own (i.e. ensure |
| 1165 // that no permissions only modify other permissions). | 1165 // that no permissions only modify other permissions). |
| 1166 | 1166 |
| 1167 // TODO(sashab): Add a test for every permission message combination that can | 1167 // TODO(sashab): Add a test for every permission message combination that can |
| 1168 // generate a message. | 1168 // generate a message. |
| 1169 | 1169 |
| 1170 // TODO(aboxhall): Add tests for the automation API permission messages. | 1170 // TODO(aboxhall): Add tests for the automation API permission messages. |
| 1171 | 1171 |
| 1172 } // namespace extensions | 1172 } // namespace extensions |
| OLD | NEW |